//::///////////////////////////////////////////////
//:: Wild Mage Spell - Wild Storm
//::///////////////////////////////////////////////
/*
Wild Storm

2d2f_sp_wild_storm.nss
*/
//::///////////////////////////////////////////////
//:: Created By: 2DruNk2Frag
//:: Created On: 04-25-2008
//:: Last Update: 04-26-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; }
    }
	//:://////////////////////////////////////////
	
	int nLvl = JXGetCasterLevel();
	int nDur = nLvl;
	float fDur = RoundsToSeconds(nDur);
	location lTarget = GetSpellTargetLocation();
	fDur = ApplyMetamagicDurationMods(fDur);
    	
	effect eVis = EffectVisualEffect(VFX_DUR_WILD_STORM);
	
	//::2d2f: For some reason the spell doesn't like placeables
	object oFakeCaster = CreateObject(OBJECT_TYPE_CREATURE, "c_rabbit", lTarget, FALSE, "wild_storm_caster");
	SetImmortal(oFakeCaster, TRUE);
	SetScriptHidden(oFakeCaster,TRUE,TRUE);
	SetLocalObject(oCaster, "oFakeCasterStorm", 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 ", 
									 lTarget, 
									 FALSE, 
									 "jx_ipoint_caster");
	SetLocalObject(oCaster, "oVisPlaceStorm", oVisPlace);
			
	JXApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oVisPlace, fDur);
	JXApplyAreaEffectToObject(AOE_PER_WILD_STORM, 
										oFakeCaster , 
										fDur, 
										"2d2f_sp_wild_storm_enter", 
										"2d2f_sp_wild_storm_heart",
										"");
		
	DestroyObject(oFakeCaster, fDur);
	DestroyObject(oVisPlace, fDur);
	DelayCommand(fDur, DeleteLocalObject(oCaster, "oFakeCaster"));
	DelayCommand(fDur, DeleteLocalObject(oCaster, "oVisPlace"));
 

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

}