///////////////////////////////////////////////////////////////
//	Author: Drammel											 //
//	Date: 4/28/2009											 //
//	Name: clf_bcunning									     //
//	Description: Grants a damage bouns based on Int to any   //
//	any target that is usually vaild for a sneak attack. Ie: //
//	flanked or flatfooted.									 //
///////////////////////////////////////////////////////////////

#include "bot9s_include"
#include "bot9s_inc_constants"

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

	SetLocalInt(oToB, "BCunningActive", 1); //Loop status check.

	if (GetIsInCombat(oPC))
	{
		object oFoe = GetAttackTarget(oPC);

		if ((IsFlankValid(oPC, oFoe)) || (!GetIsInCombat(oFoe)))
		{
			int nIntelligence = GetAbilityModifier(ABILITY_INTELLIGENCE);

			if (nIntelligence < 1)
			{
				DelayCommand(1.0f, BattleCunning());
				return;
			}

			object oWeapon = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND);
			int nWeapon = GetWeaponType(oWeapon);
			int nDamageType = GetWeaponDamageType(oWeapon);

			effect eDamage = EffectDamageIncrease(nIntelligence, nDamageType);
			eDamage = SupernaturalEffect(eDamage);

			ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eDamage, oPC, 6.0f);
			DelayCommand(6.0f, BattleCunning());
		}
		else DelayCommand(1.0f, BattleCunning());
	}
	else DelayCommand(1.0f, BattleCunning());
}

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

	if (GetLocalInt(oToB, "BCunningActive") == 1)
	{
		return;
	}
	else if (GetLocalInt(oToB, "BCunningActive") == 0)
	{
		BattleCunning();
	}
}