///////////////////////////////////////////////////////////////
//	Author: Drammel											 //
//	Date: 5/12/2009											 //
//	Name: clf_furious_ctrs								     //
//	Description: Grants a bonus to attack and damage based on//
//	the amount of points in the delayed damage pool.		 //
///////////////////////////////////////////////////////////////

#include "bot9s_include"

void FuriousCounterstrike()
{
	object oPC = OBJECT_SELF;
	string sToB = GetFirstName(oPC) + "tob";
	object oToB = GetObjectByTag(sToB);
	int nPool = GetLocalInt(oToB, "DDPool");

	SetLocalInt(oPC, "FuriousCtrsActive", 1);
	SetLocalInt(oToB, "FuriousCtrsActive", 1);

	if ((nPool > 0) && (GetIsInCombat(oPC)))
	{
		object oWeapon = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
		int nWeapon = GetWeaponType(oWeapon);
		int nDamagePool;
		int nDamageType;

		if ((nPool > 0) && (nPool <= 9))
		{
			nDamagePool = DAMAGE_BONUS_1;
		}
		else if ((nPool > 9) && (nPool <= 14))
		{
			nDamagePool = DAMAGE_BONUS_2;
		}
		else if ((nPool > 14) && (nPool <= 19))
		{
			nDamagePool = DAMAGE_BONUS_3;
		}
		else if ((nPool > 19) && (nPool <= 24))
		{
			nDamagePool = DAMAGE_BONUS_4;
		}
		else if ((nPool > 24) && (nPool <= 29))
		{
			nDamagePool = DAMAGE_BONUS_5;
		}
		else if ((nPool > 29) && (nPool <= 34))
		{
			nDamagePool = DAMAGE_BONUS_6;
		}
		else if ((nPool > 34) && (nPool <= 39))
		{
			nDamagePool = DAMAGE_BONUS_7;
		}
		else if (nPool > 39)
		{
			nDamagePool = DAMAGE_BONUS_8;
		}

		if (nWeapon == WEAPON_TYPE_BLUDGEONING || nWeapon == WEAPON_TYPE_NONE)
		{
			nDamageType = DAMAGE_TYPE_BLUDGEONING;
		}
		else if (nWeapon == WEAPON_TYPE_PIERCING || nWeapon == WEAPON_TYPE_PIERCING_AND_SLASHING)
		{
			nDamageType = DAMAGE_TYPE_PIERCING;
		}
		else nDamageType = DAMAGE_TYPE_SLASHING;

		effect eAttack = EffectAttackIncrease(nPool);
		effect eDamage = EffectDamageIncrease(nDamagePool, nDamageType);
		effect eFurious = EffectLinkEffects(eAttack, eDamage);
		eFurious = SupernaturalEffect(eFurious);

		ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eFurious, oPC, 6.0f);
	}
	DelayCommand(6.0f, FuriousCounterstrike());
}		

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

	if ((GetLocalInt(oPC, "FuriousCtrsActive") == 1) || (GetLocalInt(oToB, "FuriousCtrsActive") == 1))
	{
		return; // Prevents duplicate checks.
	}
	else if ((GetLocalInt(oPC, "FuriousCtrsActive") == 0) || (GetLocalInt(oToB, "FuriousCtrsActive") == 0))
	{
		FuriousCounterstrike();
	}
}