//::///////////////////////////////////////////////
//:: Wild Mage Spell - Nahal's Reckless Dweomer creature
//::///////////////////////////////////////////////
/*
From AD&D 2nd Edition - "Tome of Magic"

Nahal's Reckless Dweomer *
(Invocation/Evocation)
Range: Special
Components: V, S
Duration: Special
Casting Time: 5
Area of Effect: Special
Saving Throw: Special
This spell is the wild mage's ultimate last-resort
spell. When cast, the mage releases a sudden
flood of wild magical enorgy in the hope of seizing
and shaping that energy into a desired spell
effect. The attempt usually fails, but something
almost always occurs in the process.
Before casting the spell, the mage announces
the spell effect he is trying to create. The mage
must be able to cast the spell (i.e., have it in his
spell books), but need not have it memorized. After
announcing the spell (along with the target
and any other conditions required by the spell),
the wild mage casts Nahal's reckless dweomer. A
burst of magical energy is released, which the
wild mage tries to manipulate into the desired
form. The actual effect of the spell is rolled randomly
on Table 2: Wild Surge Results.
Because the release of energy is planned by the
mage, his level is added to the dice roll. If the result
indicates success, the mage has shaped the
magical energy into the desired effect. More often
than not, the effect is completely unexpected.
The result may be beneficial to the mage or it may
be completely disastrous; this is the risk the mage
takes in casting Nahal's reckless dweomer.

2d2f_sp_reckless_dweomer_obj.nss
*/
//::///////////////////////////////////////////////
//:: Created By: 2DruNk2Frag
//:: Created On: 02-10-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 > 0)
	{
		if(GetHasFeat(FEAT_RECKLESS_DWEOMER_SPELL_SELECT,oCaster) == FALSE)
		{
			FeatAdd(oCaster,FEAT_RECKLESS_DWEOMER_SPELL_SELECT,FALSE);
		}
		if(GetLocalInt(oCaster,"nReclessSelected") != 1)
		{
		SendMessageToPC(oCaster, "Please select a spell to cast with the Nahal's Reckless Dweomer 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, "nRecklessSpellId");
	int nMeta = GetLocalInt(oCaster, "nRecklessMeta");
	int nAreaSpell = JXGetHasSpellTargetTypeArea(nSpellId);
	//location lTarget = JXGetSpellTargetLocation();
	object oTarget = JXGetSpellTargetObject();
	SetLocalInt(oCaster,"nReckless", 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());
		
	JXCastSpellFromObjectAtObject(oCaster, oTarget, nSpellId, nMeta, JXGetCasterLevel(), JXGetSpellSaveDC(), TRUE);
	
	
	
	}
	else
	{
	SendMessageToPC(oCaster, "You must be a Wild Mage to use this spell");
	}
	
	JXPostSpellCastCode();
	
	return;
}