//::///////////////////////////////////////////////
//:: Wild Mage Spell - Paithan's Lucky Streak
//::///////////////////////////////////////////////
/*

Paithan’s Lucky Streak

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

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

     This spell gives the recipient an incredible streak of luck.  Each round a random bonus 
from 0-3 is individually calculated and added to the following; all saves, attack rolls, all 
skills, and armor class (dodge).  If the benefactor of Paithan’s Lucky Streak is the victim 
of a wild surge, a random bonus of 0 - 6 is added to the wild urge table increasing the 
likelihood of a positive result.
     Each round of Paithan’s Lucky Streak a d20 is rolled to determine its course.  If a 1 
or 2 is rolled the spell ends immediately due to bad luck.  However, if a 20 is rolled for 
that round the target has extremely good luck and receives a bonus of 6 on all his actions 
and 12 to any wild surge results.
     The duration of Paithan’s Lucky streak is indefinite.  It can continue as long as the 
target does not have bad luck by rolling a 1 or 2.


2d2f_sp_lucky_streak.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 mainSpell();
void main()
{
	AssignCommand(JXGetCaster(), mainSpell());
}

void mainSpell()
{
	object oCaster = JXGetCaster();
	int nWMLvl = GetLevelByClass(CLASS_WILDMAGE, oCaster);
	if((nWMLvl >= 3) || (GetObjectType(oCaster) == OBJECT_TYPE_PLACEABLE))
	{
/* 
  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; }
    }
	//:://////////////////////////////////////////
	
	object oTarget = JXGetSpellTargetObject();
	SetLocalObject(oCaster, "oLuckyTarget", oTarget);
	
	int nRandBonus1 = d4(1) - 1;
	int nRandBonus2 = d4(1) - 1;
	int nRandBonus3 = d4(1) - 1;
	int nRandBonus4 = d4(1) - 1;
	int nRandBonus5 = d4(1) - 1;

	
	effect eVisHit = EffectVisualEffect(VFX_HIT_SPELL_ENCHANTMENT);
		
	effect eEffectIconBase = EffectVisualEffect(VFX_DUR_LIGHT_PURPLE_5);
	effect eEffectIcon = EffectEffectIcon(EFFECT_ICON_LUCKY_STREAK);
	effect eScale = EffectSetScale(1.0);
	effect eLinkEffectIcon = EffectLinkEffects(eEffectIconBase,eEffectIcon);
	eLinkEffectIcon = EffectLinkEffects(eLinkEffectIcon,eScale);
	eLinkEffectIcon = SetEffectSpellId(eLinkEffectIcon,SPELL_LUCKY_STREAK);
		
	effect eIcon = EffectVisualEffect(VFX_LUCKY_STREAK_ICON);
	eIcon = SetEffectSpellId(eIcon,SPELL_LUCKY_STREAK);
		
	effect eHit = EffectAttackIncrease(nRandBonus1);
	effect eSave = EffectSavingThrowIncrease(SAVING_THROW_ALL,nRandBonus2);
	effect eSkill = EffectSkillIncrease(SKILL_ALL_SKILLS,nRandBonus3);
	effect eAC = EffectACIncrease(nRandBonus4);
	effect eLink = EffectLinkEffects(eHit,eSave);
	eLink = EffectLinkEffects(eLink,eSkill);
	eLink = EffectLinkEffects(eLink,eAC);

	SetLocalInt(oTarget,"nPiathansModifier", nRandBonus5 * 2);
	
	SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_LUCKY_STREAK, FALSE));
	
	JXApplyAreaEffectToObject(AOE_PER_CUSTOM_AOE,oTarget,0.0,"","2d2f_sp_lucky_streak_heart","");
	JXApplyEffectToObject(DURATION_TYPE_INSTANT, eVisHit, oTarget);
	JXApplyEffectToObject(DURATION_TYPE_PERMANENT, eLinkEffectIcon, oTarget);
	JXApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oTarget,RoundsToSeconds(1));
	JXApplyEffectToObject(DURATION_TYPE_PERMANENT, eIcon, oTarget);
		
	
	}
	else
	{
	SendMessageToPC(oCaster, "You must be at least a level 3 Wild Mage to use this spell");
	}
	
	
	JXPostSpellCastCode();
	return;
}