//::///////////////////////////////////////////////
//:: Wild Mage Spell - Hornung's Baneful Deflector Enter
//::///////////////////////////////////////////////
/*
Description modified from AD&D 2nd Edition - "Tome of Magic"

Hornung’s Baneful Deflector 

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

     This spell surrounds the recipient in a shimmering, 
hemispherical field of force. The field is transparent and 
moves with the subject, forming a shell about one foot away 
from his body. The shell serves as a shield against all 
forms of individually targeted missile attacks (including 
the spells, Magic Missile, Melf’s Acid Arrow, Flame Arrow, 
and Quill Fire).  The Spell will deflect enchanted missiles, 
but any additional effects such as fire damage will still 
strike the protected.
     Whenever an individual missile attack is directed at a 
protected creature, the baneful deflector activates. Instead 
of striking the target creature, the missile’s target is 
determined randomly among all creatures within a 30-foot 
hemisphere of the protected creature, including the 
protected creature. The missile then changes course toward 
its new target.  The new target must make a Reflex save vs. 
spells to avoid the projectile.


2d2f_sp_baneful_d_enter.nss
*/
//::///////////////////////////////////////////////
//:: Created By: 2DruNk2Frag
//:: Created On: 02-18-2008
//:: Last Update: 03-22-2008
//::///////////////////////////////////////////////

#include "x2_inc_itemprop"
#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 "x2_inc_switches"

void main()
{
	object oPC = GetFirstPC();//OBJECT_SELF;
	object oCaster = JXGetAOERealCreator();
	//float nRadius = FeetToMeters(150.0);//45.0;//150.0 ft
	object oTarget = GetEnteringObject();
	//int nSpellId = GetLocalInt(oPC, "nBanefulSpellId");
	//SendMessageToPC(oCaster, "baneful enter fired");	
	
	//Apply the itemproperty to all baddies
	if(spellsIsTarget(oTarget,SPELL_TARGET_SELECTIVEHOSTILE,oCaster) == TRUE && GetObjectType(oTarget) == OBJECT_TYPE_CREATURE)
	{
	
	itemproperty ip = ItemPropertyOnHitCastSpell(IP_BANEFULL_D_ONHIT,1);
	object oRHWeapon = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oTarget);
	int nItem = GetBaseItemType(oRHWeapon);
	object oWeapon;	
	
	/* // Orientation scheme worked, but damage resistance was problem.
	int nTargToCast = abs(FloatToInt(GetFacing(oTarget)) - FloatToInt(GetFacing(oPC)));;
	int nOrientCorrect = 0;
	
	if(nSpellId == 3640) // front
	{
		if(nTargToCast >= 135 && nTargToCast <= 225)
		{
			nOrientCorrect = 1;
		}
		else
		{
			nOrientCorrect = 0;		
		}	
	}
	else if(nSpellId == 3641) // right
	{
		if(nTargToCast >= 45 && nTargToCast <= 135)
		{
			nOrientCorrect = 1;
		}
		else
		{
			nOrientCorrect = 0;		
		}	
	
	}
	else if(nSpellId == 3642) // left
	{
		if(nTargToCast >= 225 && nTargToCast <= 315)
		{
			nOrientCorrect = 1;
		}
		else
		{
			nOrientCorrect = 0;		
		}	
	}
	else if(nSpellId == 3642) // back
	{
		if(nTargToCast >= 315 && nTargToCast <= 45)
		{
			nOrientCorrect = 1;
		}
		else
		{
			nOrientCorrect = 0;		
		}
	}
	
	if(nOrientCorrect == 1)
	{*/	
		
	if(nItem == BASE_ITEM_LONGBOW || nItem == BASE_ITEM_SHORTBOW)
	{
		oWeapon = GetItemInSlot(INVENTORY_SLOT_ARROWS, oTarget);
		
		IPSafeAddItemProperty(oWeapon, 
								ip,
								6.0,
								X2_IP_ADDPROP_POLICY_KEEP_EXISTING);
		
	}
	else if(nItem == BASE_ITEM_HEAVYCROSSBOW || nItem == BASE_ITEM_LIGHTCROSSBOW)
	{
		oWeapon = GetItemInSlot(INVENTORY_SLOT_BOLTS, oTarget);
		
		IPSafeAddItemProperty(oWeapon, 
								ip,
								6.0,
								X2_IP_ADDPROP_POLICY_KEEP_EXISTING);
	
	}
	else if(nItem == BASE_ITEM_SLING)
	{
		oWeapon = GetItemInSlot(INVENTORY_SLOT_BULLETS, oTarget);
		
		IPSafeAddItemProperty(oWeapon, 
								ip,
								6.0,
								X2_IP_ADDPROP_POLICY_KEEP_EXISTING);
	
	}
	else if(nItem == BASE_ITEM_DART ||
	nItem == BASE_ITEM_SHURIKEN ||
	nItem == BASE_ITEM_THROWINGAXE)
	{
		IPSafeAddItemProperty(oRHWeapon, 
								ip,
								6.0,
								X2_IP_ADDPROP_POLICY_KEEP_EXISTING);
	}
	
	
	//oTarget = GetNextObjectInShape(SHAPE_SPHERE, nRadius, GetLocation(oCaster), TRUE);
	
	//}// end orientCorrect
	}// end spellsis 
}