//////////////////////////////////////////////////////////
//	Author: Drammel										//
//	Date: 3/31/2009										//
//	Title: feat_rpd_assault								//
//	Description: During the first round of combat in	//
//	an encounter you gain +1d6 to melee weapon damage.	//
//////////////////////////////////////////////////////////

#include "x2_inc_itemprop"

void RapidAssault()
{
	object oPC = OBJECT_SELF;
	string sToB = GetFirstName(oPC) + "tob";
	object oToB = GetObjectByTag(sToB);

	SetLocalInt(oToB, "RpdAssaultActive", 1); //Loops status check.

	if (GetLocalInt(oToB, "Encounter") == 1)
	{
		object oWeapon = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND);

		if ((GetIsObjectValid(oWeapon) == FALSE) || (GetWeaponRanged(oWeapon) == TRUE))
		{
			oWeapon = GetItemInSlot(INVENTORY_SLOT_ARMS);
		}

		int nWeapon = GetWeaponType(oWeapon);
		int nDamageType;

		if (nWeapon == WEAPON_TYPE_PIERCING_AND_SLASHING || nWeapon == WEAPON_TYPE_PIERCING)
		{
			nDamageType = IP_CONST_DAMAGETYPE_PIERCING;
		}
		else if (nWeapon == WEAPON_TYPE_SLASHING)
		{
			nDamageType = IP_CONST_DAMAGETYPE_SLASHING;
		}
		else nDamageType = IP_CONST_DAMAGETYPE_BLUDGEONING;

		if (GetCurrentHitPoints(oPC) > 0)
		{
			itemproperty iWeapon = ItemPropertyDamageBonus(nDamageType, IP_CONST_DAMAGEBONUS_1d6);
			IPSafeAddItemProperty(oWeapon, iWeapon, 6.0f, X2_IP_ADDPROP_POLICY_REPLACE_EXISTING, FALSE, TRUE);
		}	
	}
	DelayCommand(6.0f, RapidAssault());
}

void main()
{
	object oPC = OBJECT_SELF;
	string sToB = GetFirstName(oPC) + "tob";
	object oToB = GetObjectByTag(sToB);

	if (GetLocalInt(oToB, "RpdAssaultActive") == 1)
	{
		return; // Prevents duplicate checks.
	}
	else if (GetLocalInt(oToB, "RpdAssaultActive") == 0)
	{
		DelayCommand(0.1f, RapidAssault());
	}
}