//::///////////////////////////////////////////////
//:: Wild Mage Spell - Organic Un-wounding heatbeat script
//::///////////////////////////////////////////////
/*

Organic Un-Wounding

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

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

     Organic Un-Wounding appears to accomplish the 
impossible; an arcane spell that heals.  However, this is 
far from what it actually does.  This spell simply reveals 
the impression that a living creature had previously made on 
the weave and then forces that creature’s body to return to 
that time before it had been injured.  It is not healing if 
the person had never been injured in the first place.
     While ultimately beneficial, this process is extremely 
stressful on the recipient’s body.  Organic Un-Wounding 
causes its target to fall down in a paralytic state for 7 
rounds during which they are completely vulnerable.  This 
state is critical to the un-wounding process and creatures 
immune to paralysis will not be affected by this spell.  
Additionally, the recipient looses 1 point of constitution 
for 1 hour after they regain use of their body.  After the 
first round, the un-wounding process takes 6 additional 
rounds.  Damage is removed each round according to the 
following table.

Round 1 - 1 point
Round 2 - 1d4 points
Round 3 - 1d4 points + 1 point / 4 caster levels (up to + 5)
Round 4 - 1d4 points + 1 point / 4 caster levels (up to + 5)
Round 5 - 1d4 points
Round 6 - 1 point


2d2f_sp_un_wounding_heart.nss
*/
//::///////////////////////////////////////////////
//:: Created By: 2DruNk2Frag
//:: Created On: 03-28-2008
//:: Last Update: 03-28-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 oPC = GetFirstPC();
		
		//SendMessageToPC(oPC,"Un-Wounding heart fired");
		
		object oCaster = JXGetAOERealCreator();
		object oTarget = GetLocalObject(oCaster,"oUnWoundingTarget");
		int nIsParalyzed =  0;
		int nHealBonus;
		int nRound = GetLocalInt(oTarget,"nUnwoundingRound");
		
		//SendMessageToPC(oPC,"nUnwoundingRound = " + IntToString(nRound));
				
		effect eCon = EffectAbilityDecrease(ABILITY_CONSTITUTION,1);
		effect eHeal;
		
		// set heal bonus
		if(JXGetCasterLevel() > 20)
		{
			nHealBonus = 5;
		}
		else
		{
			nHealBonus = JXGetCasterLevel() / 4;
		}
				
		//round 1
		if(nRound == 0)
		{
			eHeal = EffectHeal(1);
			JXApplyEffectToObject(DURATION_TYPE_INSTANT,eHeal,oTarget);
		
			SetLocalInt(oTarget,"nUnwoundingRound", GetLocalInt(oTarget,"nUnwoundingRound") + 1);
		return;
		}
		// round 2
		else if(nRound == 1)
		{
			eHeal = EffectHeal(d4(1));
			JXApplyEffectToObject(DURATION_TYPE_INSTANT,eHeal,oTarget);
		
			SetLocalInt(oTarget,"nUnwoundingRound", GetLocalInt(oTarget,"nUnwoundingRound") + 1);
		return;
		}
		// round 3
		else if(nRound == 2)
		{
			eHeal = EffectHeal(d4(1) + nHealBonus);
			JXApplyEffectToObject(DURATION_TYPE_INSTANT,eHeal,oTarget);
			
			SetLocalInt(oTarget,"nUnwoundingRound", GetLocalInt(oTarget,"nUnwoundingRound") + 1);
		return;
		}
		// round 4
		else if(nRound == 3)
		{
			eHeal = EffectHeal(d4(1) + nHealBonus);
			JXApplyEffectToObject(DURATION_TYPE_INSTANT,eHeal,oTarget);
					
			SetLocalInt(oTarget,"nUnwoundingRound", GetLocalInt(oTarget,"nUnwoundingRound") + 1);
		return;
		}
		// round 5
		else if(nRound == 4)
		{
			eHeal = EffectHeal(d4(1));
			JXApplyEffectToObject(DURATION_TYPE_INSTANT,eHeal,oTarget);
		
			SetLocalInt(oTarget,"nUnwoundingRound", GetLocalInt(oTarget,"nUnwoundingRound") + 1);
		return;
		}
		// round 6
		else if(nRound == 5)
		{
			eHeal = EffectHeal(1);
			JXApplyEffectToObject(DURATION_TYPE_INSTANT,eHeal,oTarget);
				
			RemoveSpellEffects(SPELL_ORGANIC_UNWOUNDING,oCaster,oTarget);
			DestroyObject(OBJECT_SELF);
			DeleteLocalObject(oCaster, "oUnWoundingTarget");
			DeleteLocalInt(oTarget, "nUnwoundingRound");
					
			JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eCon,oTarget,HoursToSeconds(1));
		}
}