//::///////////////////////////////////////////////
//:: Wild Mage Spell - Wildzone on Exit
//::///////////////////////////////////////////////
/*
Description modified from AD&D 2nd Edition - "Tome of Magic"

Wildzone

Caster Level(s): Wizard / Sorcerer 8
Innate Level: 8
School: Conjuration 
Descriptor(s): Wild Magic
Component(s): Verbal, Somatic
Range: 0
Area of Effect / Target: 300‘ x 300’ square
Duration: 2d6 turns 
Save: None
Spell Resistance: No
This powerful spell creates a disruption in magical forces 
similar to the conditions found in wild magic regions (areas 
where the effects of magic have been permanently altered). 
This spell has only a temporary effect, although the effects 
of wildzone could possibly be rendered permanent. The spell 
creates a wild magic region centered on the caster. The area 
of effect cannot be shaped in any way; it is always a square 
300 feet long on each side (90,000 square feet). Within the 
wildzone, wild magic reigns. Any spell cast in the area of 
effect is automatically treated as a wild surge. Spells cast 
into the wildzone from outside the area of effect function 
normally, but spells cannot be cast out of the area of effect 
without triggering a wild surge. 




2d2f_sp_wildzone_exit.nss
*/
//::///////////////////////////////////////////////
//:: Created By: 2DruNk2Frag
//:: Created On: 02-18-2008
//:: Last Update: 03-24-2008
//::///////////////////////////////////////////////

#include "2d2f_includes"
#include "jx_inc_magic"
#include "x2_inc_spellhook" 
#include "jx_inc_magic_info"
#include "nwn2_inc_spells"
#include "nw_i0_spells"

void main()
{
	
	object oTarget = GetExitingObject();
    int bValid = FALSE;
    effect eAOE;
    if(GetHasSpellEffect(SPELL_WILDZONE, oTarget))
    {
		//Search through the valid effects on the target.
        eAOE = GetFirstEffect(oTarget);
        while (GetIsEffectValid(eAOE))
        {
            if (GetEffectCreator(eAOE) == GetAreaOfEffectCreator())
            {
                //If the effect was created by the AOE then remove it
                if(GetEffectSpellId(eAOE) == SPELL_WILDZONE)
                {
                    RemoveEffect(oTarget, eAOE);
					object oPC = GetFirstPC();
					//SendMessageToPC(oPC, "Removing wildzone from " + GetName(oTarget));
                }
            }
            //Get next effect on the target
            eAOE = GetNextEffect(oTarget);
        }
    }
    
}