//:: Wild Mage Spell - Mass Magical Propensity Modifier Heart Script
//::///////////////////////////////////////////////
/*
Mass Magical Propensity Modifier

Caster Level(s): Wizard / Sorcerer 7
Innate Level: 7
School: Divination 
Descriptor(s): Wild Magic
Component(s): Verbal, Somatic
Range: Centered on caster
Area of Effect / Target: 60' diameter shpere around caster
Duration: 1d4 + 1 round / 4 levels
Save: None
Spell Resistance: Yes


2d2f_sp_mass_propensity_heart.nss
*/
//::///////////////////////////////////////////////
//:: Created By: 2DruNk2Frag
//:: Created On: 04-14-08
//:: Last Update: 04-14-08
//::///////////////////////////////////////////////

#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 main()
{
	object oCaster = JXGetAOERealCreator();
	int nLvl = JXGetCasterLevel(oCaster);
	
	float fDur = 6.0;
			
	object oTarget = GetFirstInPersistentObject();
	
	while(GetIsObjectValid(oTarget))
	{
		int nModifier;
		int nRand1 = Random(nLvl);
		int nRandMod1 = d2(1);
		int nRand2 = Random(nLvl);
		int nRandMod2 = d2(1);
		
		effect eVis ;
		effect eVisHit = EffectVisualEffect(VFX_HIT_SPELL_DIVINATION);	
		
		if(GetIsDead(oCaster) || !GetIsObjectValid(OBJECT_SELF))
    	{
        	DestroyObject(OBJECT_SELF, 0.0);
    	}
		
		if(nRandMod1 == 1) // negative
		{
			nRand1 = nRand1 * -1;
		}
		if(nRandMod2 == 1) // negative
		{
			nRand2 = nRand2 * -1;
		}	
		if (spellsIsTarget(oTarget, SPELL_TARGET_SELECTIVEHOSTILE, OBJECT_SELF))
		{
			//Fire cast spell at event for the specified target
		    SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_MASS_PROPENSITY_MODIFIER));
		    //Make SR check
		    if (!MyResistSpell(OBJECT_SELF, oTarget))
			{ 
				if(nRand1 <= nRand2) // take the lowest score
				{
					nModifier = nRand1;
				}
				else
				{
					nModifier = nRand2;
				}
				
				
				if(nModifier<= 0)
				{
					SendMessageToPC(oCaster, GetName(oTarget) + "'s outlook is good.");
					eVis = EffectVisualEffect(VFX_DUR_PROPENSITY_MODIFIER_POS);
					eVis = SetEffectSpellId(eVis,SPELL_MASS_PROPENSITY_MODIFIER);
				}
				else
				{
					SendMessageToPC(oCaster, GetName(oTarget) + "'s outlook is poor.");
					eVis = EffectVisualEffect(VFX_DUR_PROPENSITY_MODIFIER_NEG);
					eVis = SetEffectSpellId(eVis,SPELL_MASS_PROPENSITY_MODIFIER);			
				}
				
				JXApplyEffectToObject(DURATION_TYPE_INSTANT,eVisHit,oTarget);
				JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eVis,oTarget,fDur);
				SetLocalInt(oTarget,"nPropensityModifier", nModifier);
				SetLocalObject(oTarget,"oPropensityCaster", oCaster);			
			}
		}	
		else		
		{			
			 SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_MASS_PROPENSITY_MODIFIER, FALSE));
		       	
			 if(nRand1 >= nRand2) // take the highest score
				{
					nModifier = nRand1;
				}
				else
				{
					nModifier = nRand2;
				}
				
				
				if(nModifier<= 0)
				{
					SendMessageToPC(oCaster, GetName(oTarget) + "'s outlook is good.");
					eVis = EffectVisualEffect(VFX_DUR_PROPENSITY_MODIFIER_POS);
					eVis = SetEffectSpellId(eVis,SPELL_MASS_PROPENSITY_MODIFIER);
				}
				else
				{
					SendMessageToPC(oCaster, GetName(oTarget) + "'s outlook is poor.");
					eVis = EffectVisualEffect(VFX_DUR_PROPENSITY_MODIFIER_NEG);
					eVis = SetEffectSpellId(eVis,SPELL_MASS_PROPENSITY_MODIFIER);			
				}
				
				JXApplyEffectToObject(DURATION_TYPE_INSTANT,eVisHit,oTarget);
				JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eVis,oTarget,fDur);
				SetLocalInt(oTarget,"nPropensityModifier", nModifier);
				SetLocalObject(oTarget,"oPropensityCaster", oCaster);		
		}
	oTarget = GetNextInPersistentObject();	
	}	 

}