//::///////////////////////////////////////////////
//:: Protective Aura
//:: NW_S2_ProtAura.nss
//:: Copyright (c) 2006 Obsidian Entertainment, Inc.
//:://////////////////////////////////////////////
/*
    Grants a bonus to saves and AC to allies within
	the spell radius.
*/
//:://////////////////////////////////////////////
//:: Created By: Andrew Woo (AFW-OEI)
//:: Created On: 05/17/2006
//:://////////////////////////////////////////////
#include "nw_i0_spells"
#include "jx_inc_magic"
#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; }
    }

    object oTarget = JXGetSpellTargetObject();
    int    nLevel  = GetLevelByClass(CLASS_NWNINE_WARDER);

	// Strip any Protective Auras first
	//RemoveSpellEffects(SPELLABILITY_PROTECTIVE_AURA, OBJECT_SELF, oTarget);
	
	// Default to Protective Aura; if you have 4 or more levels of NW9, then use Protective Aura II.
	// AFW-OEI 10/24/2006: Only apply effects if you don't already have them; the RemoveSpellEffects brute-force call was causing problems.
	if (!GetHasSpellEffect(SPELLABILITY_PROTECTIVE_AURA, OBJECT_SELF))
	{
		//Create an instance of the AOE Object using the Apply Effect function
		SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELLABILITY_PROTECTIVE_AURA, FALSE));

		if (nLevel >= 4)
	    JXApplyAreaEffectToObject(AOE_PER_PROTECTIVE_AURA_II, oTarget);
		else
	    JXApplyAreaEffectToObject(AOE_PER_PROTECTIVE_AURA, oTarget);
	}

	JXPostSpellCastCode();
}
