//::///////////////////////////////////////////////
//:: Wild Mage Spell - Phase Affliction Heartbeat script
//::///////////////////////////////////////////////
/*

Phase Affliction

Caster Level(s): Wizard / Sorcerer 2
Innate Level: 2
School: Transmutation
Descriptor(s): Wild Magic
Component(s): Verbal, Somatic
Range: Short
Area of Effect / Target: Single Creature
Duration: 1d4 + 2 rounds
Save: Fortitude Negates
Spell Resistance: Yes

     The studious Wild Mage Shazbotian longed for a way to 
make himself incorporeal yet still interact with physical 
objects.  He achieved his goal but with unforeseen 
consequences.  The incantation struck him with a kind of 
ethereal sickness that reverberated throughout his body like 
a crescendo.  His flesh was partially transformed into ether 
and the bits that remained were stained in wild colors 
making out a wire frame depiction of his former self.  The 
ether would concentrate at different parts of his body for 
no apparent reason completely phasing that part out.  This 
caused considerable problems. Among other things anything he 
was wearing in that spot would fall to the floor.  Naked 
and frustrated Shazbotian had an idea that saved these spell 
pages from the kiln; perhaps his enemies should taste this 
phase affliction.

     The victim of Phase Affliction turns partially ethereal 
and benefits from a random amount of concealment ranging 
from 1 to 50 percent each round for the duration of the 
spell.  In addition, every round of the affliction an 
additional random effect is applied depending on where the 
affliction is most concentrated within their body. Depending 
on the location there is a chance that the item their will 
be returned to the owners inventory or dropped on the 
ground.  All other effects last 1 round.  The results are 
determined by the following table.

D100
<1 - 10> Arms.  Bracers or gloves are returned to inventory.  
Victim suffers -2 on attack rolls. 
<11 - 22> Waist and Legs.  Belt is returned to inventory. 
Victim moves at a 50 percent reduction in speed.
<23 - 33> Feet.  Boots are returned to inventory.  
Victim falls down as per knockdown.
<34 - 44> Shoulders.  Cloak is returned to inventory.  
Victim gains a +2 to his armor class (dodge).
<45 - 55> Head. Helmets are returned to inventory.  Victim 
is blinded and deafened.
<56 - 66> Left Hand.  Weapon or shield is dropped on the 
ground. Rings are returned to inventory.
<67 - 77> Right Hand.  Weapon is dropped on the ground. 
Rings are returned to inventory.
<78 - 88> Neck.  Amulets are returned to inventory.  Victim 
is silenced.
<89 - 99> Chest.  Armor is returned to inventory.  Victim 
gains 2 points of damage resistance to piercing and slashing.
<100> Entire Body.  Victim becomes completely ethereal as 
per Etherealness spell.

2d2f_sp_phase_affliction_heart.nss
*/
//::///////////////////////////////////////////////
//:: Created By: 2DruNk2Frag
//:: Created On: 03-11-2008
//:: Last Update: 05-19-2008
//::///////////////////////////////////////////////

// 2d2f - redundant includes caused major problems
//#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 "2d2f_inc_magic_wild"

void main()
{
		object oCaster = GetFirstPC();//JXGetAOERealCreator();//GetFirstPC();
		object oTarget = GetLocalObject(oCaster,"oPhaseTarget");
		float fDur = RoundsToSeconds(1);
		effect eVis = EffectVisualEffect(VFX_DUR_WILDSTRIKE);
		object oItem;
		object oItem1;
		int nRandConceal = 50 - Random(50);
		
		effect eVis1;
		effect eVis2;
		effect eConc = EffectConcealment(nRandConceal);
		
		int nRand = d100(1);
			
			// Arms
			if(nRand < 11)
			{
				oItem = GetItemInSlot(INVENTORY_SLOT_ARMS, oTarget);
				
				AssignCommand(oTarget,ClearAllActions(TRUE));
				AssignCommand(oTarget,ActionDoCommand(ActionUnequipItem(oItem)));
				DelayCommand(1.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_ARMS));
				DelayCommand(2.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_ARMS));
				DelayCommand(3.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_ARMS));
				
				eVis1 = EffectVisualEffect(VFX_DUR_PHASE_AFFLICTION_ARMS);
				effect eAttack = EffectAttackDecrease(2);
				effect eLink = EffectLinkEffects(eAttack,eVis1);
				JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eLink,oTarget,fDur);
			}
			// waste/legs
			else if(nRand >= 11 && nRand < 22)
			{
				oItem = GetItemInSlot(INVENTORY_SLOT_BELT, oTarget);
				
				AssignCommand(oTarget,ClearAllActions(TRUE));
				AssignCommand(oTarget,ActionDoCommand(ActionUnequipItem(oItem)));
				//DelayCommand(1.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_BELT));
				//DelayCommand(2.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_BELT));
				//DelayCommand(3.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_BELT));
				
				eVis1 = EffectVisualEffect(VFX_DUR_PHASE_AFFLICTION_WAIST);
				effect eMove = EffectMovementSpeedDecrease(50);
				effect eLink = EffectLinkEffects(eMove,eVis1);
				JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eLink,oTarget,fDur);
			}
			//feet
			else if(nRand >= 22 && nRand < 33)
			{
				oItem = GetItemInSlot(INVENTORY_SLOT_BOOTS, oTarget);
				
				AssignCommand(oTarget,ClearAllActions(TRUE));
				AssignCommand(oTarget,ActionDoCommand(ActionUnequipItem(oItem)));
				//DelayCommand(1.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_BOOTS));
				//DelayCommand(2.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_BOOTS));
				//DelayCommand(3.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_BOOTS));
				
				eVis1 = EffectVisualEffect(VFX_DUR_PHASE_AFFLICTION_FEET);
				effect eKnock = EffectKnockdown();
				effect eLink = EffectLinkEffects(eKnock,eVis1);
				JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eLink,oTarget,fDur);
			}
			//shoulders
			else if(nRand >= 33 && nRand < 44)
			{		
				oItem = GetItemInSlot(INVENTORY_SLOT_CLOAK, oTarget);
				
				AssignCommand(oTarget,ClearAllActions(TRUE));
				AssignCommand(oTarget,ActionDoCommand(ActionUnequipItem(oItem)));
				DelayCommand(1.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_CLOAK));
				DelayCommand(2.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_CLOAK));
				DelayCommand(3.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_CLOAK));
				
				eVis1 = EffectVisualEffect(VFX_DUR_PHASE_AFFLICTION_SHOULDERS);
				effect eAC = EffectACIncrease(2);
				effect eLink = EffectLinkEffects(eAC,eVis1);
				JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eLink,oTarget,fDur);
			}
			//head	
			else if(nRand >= 44 && nRand < 55)
			{
				oItem = GetItemInSlot(INVENTORY_SLOT_HEAD, oTarget);
				
				AssignCommand(oTarget,ClearAllActions(TRUE));
				AssignCommand(oTarget,ActionDoCommand(ActionUnequipItem(oItem)));
				DelayCommand(1.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_HEAD));
				DelayCommand(2.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_HEAD));
				DelayCommand(3.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_HEAD));
				
				eVis1 = EffectVisualEffect(VFX_DUR_PHASE_AFFLICTION_HEAD);
				eVis2 = EffectVisualEffect(VFX_DUR_SPELL_BLIND_DEAF);
				effect eBlind = EffectBlindness();
				effect eDeaf = EffectDeaf();
				effect eLink = EffectLinkEffects(eVis1,eBlind);
				eLink = EffectLinkEffects(eVis2,eLink);
				eLink = EffectLinkEffects(eDeaf,eLink);				
				JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eLink,oTarget,fDur);
			}
			// lefthand
			else if(nRand >= 55 && nRand < 66)
			{
				oItem = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oTarget);
				oItem1 = GetItemInSlot(INVENTORY_SLOT_LEFTRING, oTarget);
								
				AssignCommand(oTarget,ClearAllActions(TRUE));
				AssignCommand(oTarget,ActionDoCommand(ActionPutDownItem(oItem)));
				AssignCommand(oTarget,ActionDoCommand(ActionUnequipItem(oItem1)));
				DelayCommand(1.0,forcePutDownItem(oTarget, oItem, INVENTORY_SLOT_LEFTHAND));
				DelayCommand(2.0,forcePutDownItem(oTarget, oItem, INVENTORY_SLOT_LEFTHAND));
				DelayCommand(3.0,forcePutDownItem(oTarget, oItem, INVENTORY_SLOT_LEFTHAND));
						
				DelayCommand(1.0,forceUnequip(oTarget, oItem1, INVENTORY_SLOT_LEFTRING));
				DelayCommand(2.0,forceUnequip(oTarget, oItem1, INVENTORY_SLOT_LEFTRING));
				DelayCommand(3.0,forceUnequip(oTarget, oItem1, INVENTORY_SLOT_LEFTRING));
				
				eVis1 = EffectVisualEffect(VFX_DUR_PHASE_AFFLICTION_HANDL);
				JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eVis1,oTarget,fDur);
			}
			//righthand
			else if(nRand >= 66 && nRand < 77)
			{
				oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oTarget);
				oItem1 = GetItemInSlot(INVENTORY_SLOT_RIGHTRING, oTarget);
				
				AssignCommand(oTarget,ClearAllActions(TRUE));
				AssignCommand(oTarget,ActionDoCommand(ActionPutDownItem(oItem)));
				AssignCommand(oTarget,ActionDoCommand(ActionUnequipItem(oItem1)));
				DelayCommand(1.0,forcePutDownItem(oTarget, oItem, INVENTORY_SLOT_RIGHTHAND));
				DelayCommand(2.0,forcePutDownItem(oTarget, oItem, INVENTORY_SLOT_RIGHTHAND));
				DelayCommand(3.0,forcePutDownItem(oTarget, oItem, INVENTORY_SLOT_RIGHTHAND));
				
				DelayCommand(1.0,forceUnequip(oTarget, oItem1, INVENTORY_SLOT_RIGHTRING));
				DelayCommand(2.0,forceUnequip(oTarget, oItem1, INVENTORY_SLOT_RIGHTRING));
				DelayCommand(3.0,forceUnequip(oTarget, oItem1, INVENTORY_SLOT_RIGHTRING));
				
				
				eVis1 = EffectVisualEffect(VFX_DUR_PHASE_AFFLICTION_HANDR);
				JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eVis1,oTarget,fDur);
			}
			// neck
			else if(nRand >=77 && nRand < 88)
			{
				oItem = GetItemInSlot(INVENTORY_SLOT_NECK, oTarget);
				AssignCommand(oTarget,ClearAllActions(TRUE));
				AssignCommand(oTarget,ActionDoCommand(ActionUnequipItem(oItem)));
				DelayCommand(1.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_NECK));
				DelayCommand(2.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_NECK));
				DelayCommand(3.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_NECK));
				
				eVis1 = EffectVisualEffect(VFX_DUR_SPELL_SILENCE);
				eVis2 = EffectVisualEffect(VFX_DUR_PHASE_AFFLICTION_NECK);
				effect eSilence = EffectSilence();
				effect eLink = EffectLinkEffects(eVis1,eSilence);
				eLink = EffectLinkEffects(eLink,eVis2);
				JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eLink,oTarget,fDur);
			}
			//chest
			else if(nRand >=88 && nRand <= 99)
			{
				object oItem = GetItemInSlot(INVENTORY_SLOT_CHEST, oTarget);
				AssignCommand(oTarget,ClearAllActions(TRUE));
				AssignCommand(oTarget,ActionDoCommand(ActionUnequipItem(oItem)));
				DelayCommand(1.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_CHEST));
				DelayCommand(2.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_CHEST));
				DelayCommand(3.0,forceUnequip(oTarget, oItem, INVENTORY_SLOT_CHEST));
				
				effect eRes1 = EffectDamageResistance(DAMAGE_TYPE_PIERCING,2,10);
				effect eRes2 = EffectDamageResistance(DAMAGE_TYPE_SLASHING,2,10);
				eVis1 = EffectVisualEffect(VFX_DUR_PHASE_AFFLICTION_CHEST);
				effect eLink = EffectLinkEffects(eRes1,eRes2);
				eLink = EffectLinkEffects(eLink,eVis1);
				
				JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eLink,oTarget,fDur);
			}
			//everything
			else
			{
				eVis2 = EffectVisualEffect( VFX_DUR_SPELL_ETHEREALNESS );	
		    	effect eSanc = EffectEthereal();
				eVis1 = EffectVisualEffect(VFX_DUR_PHASE_AFFLICTION_ETHER);
				effect eLink = EffectLinkEffects(eVis2, eSanc);
				eLink = EffectLinkEffects(eLink, eVis1);
				JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eLink,oTarget,fDur);
			
			}			
							
        	JXApplyEffectToObject(DURATION_TYPE_TEMPORARY, eConc, oTarget, fDur);
				
}