//::///////////////////////////////////////////////
//:: Wild Mage Spell - Wildzone
//::///////////////////////////////////////////////
/*
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.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"
#include "X0_I0_SPELLS"
#include "x0_i0_spells"




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

void mainSpell()
{
	object oCaster = JXGetCaster();
	int nWMLvl = GetLevelByClass(CLASS_WILDMAGE, oCaster);
	if((nWMLvl >= 13) || (GetObjectType(oCaster) == OBJECT_TYPE_PLACEABLE))
	{
/* 
  Spellcast Hook Code 
  Added 2003-06-23 by GeorgZ
  If you want to make changes to all spells,
  check x2_inc_spellhook.nss to find out more
  
*/

    if (!X2PreSpellCastCode())
   {
	 //If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
        { JXPostSpellCastCode(); return; }
    }
	//:://////////////////////////////////////////
	
	location lTarget = GetSpellTargetLocation();
	
	int nDur = d6(2);
	float fDuration = TurnsToSeconds(nDur);
		
	//::2d2f: For some reason the spell doesn't like placeables
	object oFakeCaster = CreateObject(OBJECT_TYPE_CREATURE, "c_rabbit", GetLocation(oCaster), FALSE, "wildzone_caster");
	SetImmortal(oFakeCaster, TRUE);
	SetScriptHidden(oFakeCaster,TRUE,TRUE);
	AssignCommand(oFakeCaster, SetFacing(90.0f, TRUE));
	SetLocalObject(oCaster, "oFakeCaster", oFakeCaster);
	effect eImobel = EffectCutsceneImmobilize();
	ApplyEffectToObject(DURATION_TYPE_PERMANENT,eImobel,oFakeCaster);
	
	//::2d2f: another oddity. the vfx doesn't care for creatures.
	object oVisPlace = CreateObject(OBJECT_TYPE_PLACEABLE,
									 "plc_ipoint ", 
									 GetLocation(oCaster), 
									 FALSE, 
									 "jx_ipoint_caster");
	AssignCommand(oVisPlace, SetFacing(90.0f, TRUE));
	SetLocalObject(oCaster, "oVisPlace", oVisPlace);
		
	effect eVis = EffectVisualEffect(VFX_DUR_WILDZONE_AOE_EFFECT);

	JXApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oVisPlace, fDuration);
	JXApplyAreaEffectToObject(AOE_PER_WILDZONE, 
									oFakeCaster , 
									fDuration, 
									"2d2f_sp_wildzone_enter", 
									"2d2f_sp_wildzone_heart",
									"2d2f_sp_wildzone_exit");
 		
	DestroyObject(oFakeCaster, fDuration);
	DestroyObject(oVisPlace, fDuration);
	DelayCommand(fDuration, DeleteLocalObject(oCaster, "oFakeCaster"));
	DelayCommand(fDuration, DeleteLocalObject(oCaster, "oVisPlace"));

	}
	else
	{
	SendMessageToPC(oCaster, "You must be at least a level 13 Wild Mage to use this spell");
	}
	
	
	JXPostSpellCastCode();

}