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

Stabilize

Caster Level(s): Wizard / Sorcerer 9
Innate Level: 9
School: Abjuration
Descriptor(s): Wild Magic
Component(s): Verbal, Somatic
Range: 0
Area of Effect / Target: 30' diameter circle 
Duration: ld4 + 1 turns
Casting Time: 4 rounds
Save: None
Spell Resistance: None

     This spell requires immense magical effort to cast,
relegating it to the highest spell level. Stabilize 
negates the effects of wild magic regions, allowing the 
caster and all creatures in a 30-foot radius to cast spells 
and use magical items normally. The spell is centered on the 
caster and follows his movements. 
     The caster’s own spells never cause wild surges when 
cast within the duration of a stabilize spell, nor do the 
effects of wild surges extend into the protected area. 
Furthermore, the wild mage’s spells function at his true 
level. A random roll is not used to determine level 
variation. The spell affects wildstrike and wildzone.

2d2f_sp_stabilize.nss
*/
//::///////////////////////////////////////////////
//:: Created By: 2DruNk2Frag
//:: Created On: 3-08-2008
//:: Last Update: 3-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 >= 15) || (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 nDur = d4() + 1;
	float fDuration = TurnsToSeconds(nDur);
			
	effect eVis = EffectVisualEffect(VFX_DUR_STABILIZE_AOE_EFFECT);
	effect eVis2 = EffectVisualEffect(VFX_FNF_LOS_NORMAL_30);
	
	JXApplyEffectToObject(DURATION_TYPE_INSTANT,eVis2,oCaster);
	JXApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oCaster, fDuration);
	JXApplyAreaEffectToObject(AOE_PER_STABILIZE, 
										oCaster , 
										fDuration, 
										"2d2f_sp_stabilize_enter", 
										"2d2f_sp_stabilize_heart",
										"2d2f_sp_stabilize_exit");
 

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

}