//////////////////////////////////////////////////////
//	Author: Drammel									//
//	Date: 3/31/2009									//
//	Title: feat_ih_aura								//
//	Description: While in an ironheart stance all	//
//	adjacent allies gain +2 saves.					//
//////////////////////////////////////////////////////

#include "bot9s_inc_constants"
#include "bot9s_include"

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

	SetLocalInt(oPC, "IHAuraActive", 1); // Loop status check.

	int nStance = GetLocalInt(oToB, "Stance");
	int nStance2 = GetLocalInt(oToB, "Stance2");
	
	if (nStance == STANCE_ABSOLUTE_STEEL || nStance2 == STANCE_ABSOLUTE_STEEL
	|| nStance == STANCE_DANCING_BLADE_FORM || nStance2 == STANCE_DANCING_BLADE_FORM
	|| nStance == STANCE_PUNISHING_STANCE || nStance2 == STANCE_PUNISHING_STANCE
	|| nStance == STANCE_SUPREME_BLADE_PARRY || nStance2 == STANCE_SUPREME_BLADE_PARRY)
	{
		location lPC = GetLocation(oPC);
		float fRange = GetGirth(oPC) + FeetToMeters(5.0f);
		
		object oFriend;
		float fDist;

		oFriend = GetFirstObjectInShape(SHAPE_SPHERE, fRange, lPC);

		while (GetIsObjectValid(oFriend))
		{
			fDist = GetDistanceBetween(oPC, oFriend);

			if ((fDist <= fRange) && (!GetIsReactionTypeHostile(oFriend, oPC)))
			{
				effect eSaves = EffectSavingThrowIncrease(SAVING_THROW_ALL, 2);
				eSaves = ExtraordinaryEffect(eSaves);

				ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSaves, oFriend, 6.0f);
			}

			oFriend = GetNextObjectInShape(SHAPE_SPHERE, fRange, lPC);
		}
	}

	DelayCommand(6.0f, IronHeartAura());
}

void main()
{
	object oPC = OBJECT_SELF;
	int nIronHeart = GetLocalInt(oPC, "IHAuraActive");

	if (nIronHeart == 1)
	{
		return; // Prevents duplicate checks.
	}
	else if (nIronHeart == 0)
	{
		IronHeartAura();
	}
}