//::///////////////////////////////////////////////
//:: Wild Mage Spell - Paithan's Fiasco Heart script
//::///////////////////////////////////////////////
/*

Paithan’s Fiasco

Caster Level(s): Wizard / Sorcerer 4
Innate Level: 4
School: Enchantment
Descriptor(s): Wild Magic
Component(s): Verbal, Somatic
Range: Touch
Area of Effect / Target: One Creature
Duration: Special
Save: None
Spell Resistance: Yes

!!! This is a Wild Magic Spell and can only be cast by a Wild Mage !!!

     This spell is the reverse of Paithan’s Lucky Streak (Level 3).  The recipient has an 
unfortunate run of bad luck.  The caster must make a successful melee touch attack against 
the target. If successful, each round a random penalty from 0-3 is individually calculated 
and subtracted from the following; all saves, attack rolls, all skills, and armor class 
(dodge).  If the target of Paithan’s Lucky Streak is the victim of a wild surge, a random 
penalty of 0 - 6 is subtracted from the wild surge table increasing the likelihood of a 
negative result.
     Each round of Paithan’s Fiasco a d20 is rolled to determine its course.  If a 1 or 2 is 
rolled the spell ends immediately due to good luck luck.  However, if a 20 is rolled for 
that round the target extremely doomed and receives a penalty of 6 on all his actions and 12 
to any wild surge results.
     The duration of Paithan’s Fiasco is indefinite.  It can continue as long as the target 
does not have good luck by rolling a 1 or 2.

2d2f_sp_fiasco_heart.nss
*/
//::///////////////////////////////////////////////
//:: Created By: 2DruNk2Frag
//:: Created On: 04-05-2008
//:: Last Update: 04-05-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 main()
{
		object oCaster = JXGetAOERealCreator();//GetFirstPC
		object oTarget = GetLocalObject(oCaster,"oFiascoTarget");
		float fDur = RoundsToSeconds(1);
		
		int nRandStreak = d20(1);
		
		int nRandPenalty1 = d4(1) - 1;
		int nRandPenalty2 = d4(1) - 1;
		int nRandPenalty3 = d4(1) - 1;
		int nRandPenalty4 = d4(1) - 1;
		int nRandPenalty5 = d4(1) - 1;
		
		if(GetIsDead(oTarget) || !GetIsObjectValid(oTarget) )
		{
			DestroyObject(OBJECT_SELF,0.0);
			RemoveSpellEffects(SPELL_FIASCO, oCaster, oTarget);
			DeleteLocalInt(oTarget,"nPiathansModifier");
			DeleteLocalObject(oCaster,"oFiascoTarget");
			return;
    	}		
		
		if(nRandStreak == 2)
		{
			DestroyObject(OBJECT_SELF,0.0);
			RemoveSpellEffects(SPELL_FIASCO, oCaster, oTarget);
			DeleteLocalInt(oTarget,"nPiathansModifier");
			DeleteLocalObject(oCaster,"oFiascoTarget");
			return;
		}
		else if(nRandStreak == 2)
		{
			effect eHit = EffectAttackIncrease(1);
			effect eSave = EffectSavingThrowIncrease(SAVING_THROW_ALL,1);
			effect eSkill = EffectSkillIncrease(SKILL_ALL_SKILLS,1);
			effect eAC = EffectACIncrease(1);
			effect eLink = EffectLinkEffects(eHit,eSave);
			eLink = EffectLinkEffects(eLink,eSkill);
			eLink = EffectLinkEffects(eLink,eAC);
			
			SetLocalInt(oTarget,"nPiathansModifier", 2);
			
			JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eLink,oTarget,fDur);
			return;
		}
		else if(nRandStreak == 20)
		{
			nRandPenalty1 = 6;
			nRandPenalty2 = 6;
			nRandPenalty3 = 6;
			nRandPenalty4 = 6;
			nRandPenalty5 = 6;
		}
		
		
		
		effect eHit = EffectAttackDecrease(nRandPenalty1);
		effect eSave = EffectSavingThrowDecrease(SAVING_THROW_ALL,nRandPenalty2);
		effect eSkill = EffectSkillDecrease(SKILL_ALL_SKILLS,nRandPenalty3);
		effect eAC = EffectACDecrease(nRandPenalty4);
		effect eLink = EffectLinkEffects(eHit,eSave);
		eLink = EffectLinkEffects(eLink,eSkill);
		eLink = EffectLinkEffects(eLink,eAC);
		
		SetLocalInt(oTarget,"nPiathansModifier", nRandPenalty5 * 2);
		
		JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eLink,oTarget,fDur);
		
	
}