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

Wildzone

Caster Level(s): Wizard / Sorcerer 8
Innate Level: 8
School: Conjuration 
Descriptor(s): Wild Magic
Component(s): Verbal, Somatic
Range: 0
Area of Effect / Target: 300‘ x 300’ square
Duration: 2d6 turns 
Save: None
Spell Resistance: No
This powerful spell creates a disruption in magical forces 
similar to the conditions found in wild magic regions (areas 
where the effects of magic have been permanently altered). 
This spell has only a temporary effect, although the effects 
of wildzone could possibly be rendered permanent. The spell 
creates a wild magic region centered on the caster. The area 
of effect cannot be shaped in any way; it is always a square 
300 feet long on each side (90,000 square feet). Within the 
wildzone, wild magic reigns. Any spell cast in the area of 
effect is automatically treated as a wild surge. Spells cast 
into the wildzone from outside the area of effect function 
normally, but spells cannot be cast out of the area of effect 
without triggering a wild surge. 

2d2f_sp_wildzone_heart.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"
#include "X0_I0_SPELLS"

void main()
{
		object oPC = GetFirstPC();
		object oCaster = GetLocalObject(oPC,"oFakeCaster");
		object oVisPlace = GetLocalObject(oPC,"oVisPlace");
		int nSpellId = SPELL_WILDZONE;
		object oTarget = GetFirstInPersistentObject();
		
		effect eVis = EffectVisualEffect(VFX_DUR_WILDZONE);
		eVis = SetEffectSpellId(eVis,nSpellId);
	
		//SendMessageToPC(oPC, "wildzone heart script fired");
	
		if(GetIsDead(oPC) || 
		!GetIsObjectValid(oCaster) 
		|| !GetIsObjectValid(oVisPlace) ||
		GetIsResting(oPC) == TRUE)
    	{
			DestroyObject(oVisPlace, 0.0);
	        DestroyObject(oCaster, 0.0);
			DeleteLocalObject(oPC, "oFakeCaster");
			DeleteLocalObject(oPC, "oVisPlace");
    	}		
				
		vector vCenter = GetPosition(oCaster);

		int i;
		for(i = 0; i < 6; i++)
		{			
			int nRandVfx1 = Random(1042);
			int nRandOk = FALSE;
			
			int nReRoll1 = FALSE;
			int nReRoll2 = FALSE;
			int nReRoll3 = FALSE;
			int nReRoll4 = FALSE;
			int nReRoll5 = FALSE;
				
			string sImp_HeadCon_Node = Get2DAString("visualeffects",
					"Imp_HeadCon_Node",nRandVfx1);
			string sImp_Impact_Node = Get2DAString("visualeffects",
 					"Imp_Impact_Node",nRandVfx1);
			string sImp_Root_S_Node = Get2DAString("visualeffects",
 					"Imp_Root_S_Node",nRandVfx1);
			string sImp_Root_M_Node = Get2DAString("visualeffects",
 					"Imp_Root_M_Node",nRandVfx1);
			string sImp_Root_L_Node = Get2DAString("visualeffects",
 					"Imp_Root_L_Node",nRandVfx1);
			string sImp_Root_H_Node = Get2DAString("visualeffects",
 					"Imp_Root_H_Node",nRandVfx1);
			string sDur_HeadCon_Node = Get2DAString("visualeffects",
 					"Dur_HeadCon_Node",nRandVfx1);
			string sDur_Impact_Node = Get2DAString("visualeffects",
 					"Dur_Impact_Node",nRandVfx1);
			string sDur_Root_S_Node = Get2DAString("visualeffects",
 					"Dur_Root_S_Node",nRandVfx1);
			string sDur_Root_M_Node = Get2DAString("visualeffects",
 					"Dur_Root_M_Node",nRandVfx1);
			string sDur_Root_L_Node = Get2DAString("visualeffects",
 					"Dur_Root_L_Node",nRandVfx1);
			string sDur_Root_H_Node = Get2DAString("visualeffects",
 					"Dur_Root_H_Node",nRandVfx1);
			string sCes_HeadCon_Node = Get2DAString("visualeffects",
 					"Ces_HeadCon_Node",nRandVfx1);
			string sCes_Impact_Node = Get2DAString("visualeffects",
 					"Ces_Impact_Node",nRandVfx1);
			string sLowQuality = Get2DAString("visualeffects",
 					"LowQuality",nRandVfx1);
		
				if(nRandVfx1 >= 127 && nRandVfx1 <= 131)
				{
					nReRoll1 =TRUE;
				}
				else if(nRandVfx1 >= 321 && nRandVfx1 <= 345)
				{
					nReRoll2 =TRUE;
				}
				else if(nRandVfx1 >= 360 && nRandVfx1 <= 400)
				{
					nReRoll3 =TRUE;
				}
				else if(nRandVfx1 >= 741 && nRandVfx1 <= 749)
				{
					nReRoll4 =TRUE;
				}
				
				if(sImp_HeadCon_Node == "fx_question_fountain.sef" ||
				sImp_Impact_Node == "fx_question_fountain.sef" ||
				sImp_Root_S_Node == "fx_question_fountain.sef" ||
				sImp_Root_M_Node == "fx_question_fountain.sef" ||
				sImp_Root_L_Node == "fx_question_fountain.sef" ||
				sImp_Root_H_Node == "fx_question_fountain.sef"  ||
				sDur_HeadCon_Node == "fx_question_fountain.sef" ||
				sDur_Impact_Node == "fx_question_fountain.sef" ||
				sDur_Root_S_Node == "fx_question_fountain.sef" ||
				sDur_Root_M_Node == "fx_question_fountain.sef" ||
				sDur_Root_L_Node == "fx_question_fountain.sef" ||
				sDur_Root_H_Node == "fx_question_fountain.sef" ||
				sCes_HeadCon_Node == "fx_question_fountain.sef" ||
				sCes_Impact_Node == "fx_question_fountain.sef" ||
				sLowQuality == "fx_question_fountain.sef")				
				{
					nReRoll5 = TRUE;
				}
				
				if(nReRoll1 == TRUE ||
				nReRoll2 == TRUE ||
				nReRoll3 == TRUE ||
				nReRoll4 == TRUE ||
				nReRoll5 == TRUE)
				{
					nRandOk = FALSE;
				}
				else
				{
					nRandOk = TRUE;
				}
				
			if(nRandOk == TRUE)
			{
			float fDelay = IntToFloat(i);
			vector vRand1 = Vector(IntToFloat(Random(90)-45),IntToFloat(Random(90)-45),IntToFloat(Random(3)));
			vector vNewLoc1 = Vector(vCenter.x + vRand1.x,vCenter.y + vRand1.y,vCenter.z + vRand1.z);
			location lRandom1 = Location(GetArea(oCaster), vNewLoc1, 0.0f);
			effect eRandVfx1 = EffectVisualEffect(nRandVfx1);
			DelayCommand(fDelay,JXApplyEffectAtLocation(DURATION_TYPE_INSTANT,eRandVfx1,lRandom1));
			}
		}
}