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

Wildstrike 

Caster Level(s): Wizard / Sorcerer 6
Innate Level: 6
School: Conjuration 
Descriptor(s): Wild Magic
Component(s): Verbal, Somatic
Range: 30 yards
Area of Effect / Target: One Creature
Duration: 2d4 rounds
Save: Will save Negates
Spell Resistance: Yes

This spell is used primarily against hostile spellcasters.
It distorts all attempts at spellcasting, converting spell 
energy into wild surges. The victim of a wildstrike is 
allowed a saving throw; if successful, the spell has no 
effect. If the saving throw is failed, the target is 
enclosed within a field of wild magic. If the victim 
casts spellsa wild surge is automatically created.
When determining the effects of this surge, the true 
level of the wild mage who cast the wildstrike is 
subtracted from the die roll, making the effects of 
the wild surge more likely to affect the victim. 



2d2f_sp_wildstrike.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 mainSpell();
void main()
{
	AssignCommand(JXGetCaster(), mainSpell());
}

void mainSpell()
{
	object oCaster = JXGetCaster();
	int nWMLvl = GetLevelByClass(CLASS_WILDMAGE, oCaster);
	if((nWMLvl >= 9) || (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; }
    }
	//:://////////////////////////////////////////
	
	object oTarget = JXGetSpellTargetObject();
	int nLvl = JXGetCasterLevel();
	int nDur = d3(4);
	float fDuration = RoundsToSeconds(nDur);

	effect eVis = EffectVisualEffect(VFX_DUR_WILDSTRIKE);
	eVis = SetEffectSpellId(eVis,SPELL_WILDSTRIKE);

	//Check for metamagic extend
    fDuration = ApplyMetamagicDurationMods(fDuration);
    int nDurType = ApplyMetamagicDurationTypeMods(DURATION_TYPE_TEMPORARY);
	
	if (spellsIsTarget(oTarget, SPELL_TARGET_STANDARDHOSTILE, OBJECT_SELF))
	{
        //Fire cast spell at event for the specified target
        SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_WILDSTRIKE));
       //Make SR check
       if (!MyResistSpell(OBJECT_SELF, oTarget))
	   {
            //Make Will save
            if (!/*Will Save*/ MySavingThrow(SAVING_THROW_WILL, oTarget, JXGetSpellSaveDC(),SAVING_THROW_TYPE_SPELL ))
            {			
            JXApplyEffectToObject(nDurType, eVis, oTarget, fDuration);
			SetLocalInt(oTarget,"nWildstrikeCasterLvl", nLvl);
			DelayCommand(fDuration,DeleteLocalInt(oTarget,"nWildstrikeCasterLvl"));
			}
        }
    }
	
	
	}
	else
	{
	SendMessageToPC(oCaster, "You must be at least a level 9 Wild Mage to use this spell");
	}
	
	
	JXPostSpellCastCode();
	return;
}