//::///////////////////////////////////////////////
//:: Light (Drow/Aasimar Racial Ability)
//:: NW_S2_Light.nss
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Applies a light source to the target for
    1 hour per level

    XP2
    If cast on an item, item will get temporary
    property "light" for the duration of the spell
    Brightness on an item is lower than on the
    continual light version.

*/

// JLR-OEI 03/16/06: For GDD Update


#include "jx_inc_magic"
#include "x2_inc_spellhook"

void mainSpell();
void main()
{
	AssignCommand(JXGetCaster(), mainSpell());
}

void mainSpell()
{

   // If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run
    // this spell.
    if (!X2PreSpellCastCode())
    {
        { JXPostSpellCastCode(); return; }
    }

    //Declare major variables
    object oTarget = JXGetSpellTargetObject();

    int nDuration;
    int nMetaMagic;

    // Handle spell cast on item....
    if (GetObjectType(oTarget) == OBJECT_TYPE_ITEM && ! CIGetIsCraftFeatBaseItem(oTarget))
    {
        // Do not allow casting on not equippable items
        if (!IPGetIsItemEquipable(oTarget))
        {
         // Item must be equipable...
             FloatingTextStrRefOnCreature(83326,OBJECT_SELF);
            { JXPostSpellCastCode(); return; }
        }

        itemproperty ip = ItemPropertyLight (IP_CONST_LIGHTBRIGHTNESS_NORMAL, IP_CONST_LIGHTCOLOR_WHITE);

        if (GetItemHasItemProperty(oTarget, ITEM_PROPERTY_LIGHT))
        {
            IPRemoveMatchingItemProperties(oTarget,ITEM_PROPERTY_LIGHT,DURATION_TYPE_TEMPORARY);
        }

        nDuration = GetTotalLevels(OBJECT_SELF, 1); //GetCasterLevel(OBJECT_SELF);
        nMetaMagic = JXGetMetaMagicFeat();
        //Enter Metamagic conditions
        if (nMetaMagic & METAMAGIC_EXTEND)
        {
            nDuration = nDuration *2; //Duration is +100%
        }

        AddItemProperty(DURATION_TYPE_TEMPORARY,ip,oTarget,HoursToSeconds(nDuration));
    }
    else
    {
		// JLR-OEI 03/21/06: Changed to match normal light spell changes
        //effect eVis = EffectVisualEffect(VFX_DUR_LIGHT_WHITE_20);
        //effect eDur = EffectVisualEffect(VFX_DUR_CESSATE_POSITIVE);
        //effect eLink = EffectLinkEffects(eVis, eDur);
        effect eVis = EffectVisualEffect(VFX_DUR_LIGHT);

        nDuration = GetTotalLevels(OBJECT_SELF, 1); //GetCasterLevel(OBJECT_SELF);
        nMetaMagic = JXGetMetaMagicFeat();
        //Enter Metamagic conditions
        if (nMetaMagic & METAMAGIC_EXTEND)
        {
            nDuration = nDuration *2; //Duration is +100%
        }
        //Fire cast spell at event for the specified target
        SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_LIGHT, FALSE));

        //Apply the VFX impact and effects
        //JXApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oTarget, HoursToSeconds(nDuration));
        JXApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oTarget, HoursToSeconds(nDuration));
    }


	JXPostSpellCastCode();
}
