//::///////////////////////////////////////////////
//:: Immunity to Electricity
//:: nx_s2_immunityelectricity.nss
//:: Copyright (c) 2007 Obsidian Entertainment, Inc.
//:://////////////////////////////////////////////
/*
    At 9th level, a stormlord gains immunity to
    electricity.
*/
//:://////////////////////////////////////////////
//:: Created By: Andrew Woo (AFW-OEI)
//:: Created On: 03/21/2007
//:://////////////////////////////////////////////

#include "nwn2_inc_spells"
#include "x2_inc_spellhook"

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

void mainSpell()
{
    if (!X2PreSpellCastCode())
    {   // If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
		JXPostSpellCastCode();
        return;
    }
    
    //Declare major variables
    object oTarget = JXGetSpellTargetObject();

    // Does not stack with itself
    if (!GetHasSpellEffect(JXGetSpellId(), oTarget))
    {
        effect eImmune = EffectDamageImmunityIncrease(DAMAGE_TYPE_ELECTRICAL, 100);
        eImmune = ExtraordinaryEffect(eImmune); // Make it not dispellable.
    
        //Fire cast spell at event for the specified target
        SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, JXGetSpellId(), FALSE));
    
        //Apply the effects
        JXApplyEffectToObject(DURATION_TYPE_PERMANENT, eImmune, oTarget);
    }

	JXPostSpellCastCode();
}
