//::///////////////////////////////////////////////
//:: Wild Mage Spell - Wildfire area
//::///////////////////////////////////////////////
/*
Desription modified from AD&D 2nd Edition - "Tome of Magic"

Wildfire 

Caster Level(s): Wizard / Sorcerer 9
Innate Level: 9
School: Evocation
Descriptor(s): Wild Magic
Component(s): Verbal
Range: 0
Area of Effect / Target: Special
Duration: Special
Save: Special
Spell Resistance: Special

***Note to Player: To use Wildfire you first need to 
activate the feat Wildfire Spell Select.  This Feat will be 
granted to you the first time you cast Wildfire.  It is 
recommended that you cast Wildfire as soon as it is learned 
to gain this feat.***

     By means of this spell, the Wild Mage is able to 
channel raw magical energy through himself, shaping it 
into any form or effect he desires. However, the 
results are more often than not unpredictable and not 
what the Wild Mage had intended.  The energy is similar 
in many ways to a Nahal’s Reckless Dweomer,  but has unique 
differences. 
     Wildfire allows the caster a chance to create the effect of 
any spell including mimicking the effects of divine magic. 
He need only have general knowledge of the spell and its 
effects; the spell does not need to be in his own spellbooks. 
The Wild Mage must first specify the attempted spell and 
its target.  When Wildfire is cast the Wild Mage he 
automatically rolls on the wild surge table to determine 
its result.  The level of the wild mage is added to this 
roll increasing the chance of a shaping the weave as 
intended.


2d2f_sp_wildfire_area.nss
*/
//::///////////////////////////////////////////////
//:: Created By: 2DruNk2Frag
//:: Created On: 03-02-2008
//:: Last Update: 06-15-2008
//::///////////////////////////////////////////////

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


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

void mainSpell()
{
	object oCaster = JXGetCaster();
	int nWMLvl = GetLevelByClass(CLASS_WILDMAGE, oCaster);
	if(nWMLvl > 15)
	{
		if(GetHasFeat(FEAT_WILDFIRE_SPELL_SELECT,oCaster) == FALSE)
		{
			FeatAdd(oCaster,FEAT_WILDFIRE_SPELL_SELECT,FALSE);
		}
		if(GetLocalInt(oCaster,"nWildfireSelected") != 1)
		{
		SendMessageToPC(oCaster, "Please select a spell to cast with the Wildfire Spell Selection Feat");
		return;
		}
	
	
/* 
  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 nSpellId = GetLocalInt(oCaster, "nWildfireSpellId");
	int nMeta = GetLocalInt(oCaster, "nWildfireMeta");
	int nAreaSpell = JXGetHasSpellTargetTypeArea(nSpellId);
	location lTarget = GetSpellTargetLocation();	// shaz: made it use this to fix a bizzare bug, where an aoe spell after a "rebound" surge would go to the place the PC had been at
	SetLocalInt(oCaster,"nWildfire", 1);
	
	effect eVis1 = EffectVisualEffect(VFX_HIT_SPELL_SONIC);
	effect eVis2 = EffectVisualEffect(VFX_DUR_SPELL_DIVINE_FAVOR);
	effect eLink = EffectLinkEffects(eVis1, eVis2);
	
	JXApplyEffectToObject(DURATION_TYPE_INSTANT, eLink, oCaster);
	
	// Shaz: put this here as using "cheat" with CastSpellFromObjectAtXXX causes both the internal and the JX caster levels to be set to 10
	SetLocalInt(oCaster, "shazCasterLevel", JXGetCasterLevel());
	
	JXCastSpellFromObjectAtLocation(oCaster, lTarget, nSpellId, nMeta, JXGetCasterLevel(), JXGetSpellSaveDC(), TRUE);
		
	}
	else
	{
	SendMessageToPC(oCaster, "You must be a Wild Mage of level 15 or greater to use this spell");
	return;
	}
	
	
	JXPostSpellCastCode();
	return;
}