///////////////////////////////////////////////////////////////
//	Author: Drammel											 //
//	Date: 5/9/2009											 //
//	Name: clf_stlyresolve								     //
//	Description: Creates a Delayed Damage Pool from which the//
//	player can draw multiple benefits.						 //
///////////////////////////////////////////////////////////////

#include "bot9s_include"
#include "bot9s_inc_constants"

void DelayedDamagePool()
{
	object oPC = OBJECT_SELF;
	string sToB = GetFirstName(oPC) + "tob";
	object oToB = GetObjectByTag(sToB);
	int nPC = ObjectToInt(oPC);
	string sName = GetFirstName(oPC);
	int nLevel = GetLevelByClass(CLASS_TYPE_CRUSADER, oPC);
	object oArea = GetArea(oPC);

	SetLocalInt(oToB, "DDPoolActive", 1);
	SetLocalInt(oToB, "PC", nPC);

	string sTemplate;

	if (nLevel < 4)
	{
		sTemplate = "c_ddp_5";
	}
	else if (nLevel < 8)
	{
		 sTemplate = "c_ddp_10";
	}
	else if (nLevel < 12)
	{
		 sTemplate = "c_ddp_15";
	}
	else if (nLevel < 16)
	{
		 sTemplate = "c_ddp_20";
	}
	else if (nLevel < 20)
	{
		 sTemplate = "c_ddp_25";
	}
	else if (nLevel < 24)
	{
		 sTemplate = "c_ddp_30";
	}
	else if (nLevel < 28)
	{
		 sTemplate = "c_ddp_35";
	}
	else sTemplate = "c_ddp_40";

	string sNewTag = sName + sTemplate;
	object oPool = GetObjectByTag(sNewTag);

	if ((GetIsInCombat(oPC)) && (GetIsObjectValid(oPool) == FALSE))
	{
		location lLocation = GetLocation(oPC);

		SetLocalString(oArea, sNewTag, sName);
		WrapperCreateObject(OBJECT_TYPE_CREATURE, sTemplate, lLocation, FALSE, sNewTag);
	}
	else if (GetIsInCombat(oPC) == FALSE)
	{
		if (GetIsObjectValid(oPool))
		{
			DestroyObject(oPool);
			DeleteLocalString(oArea, sNewTag);
		}
	}
	DelayCommand(0.1f, DelayedDamagePool());
}

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

	if (GetLocalInt(oToB, "DDPoolActive") == 1)
	{
		return; // Prevents duplicate checks.
	}
	else if (GetLocalInt(oToB, "DDPoolActive") == 0)
	{
		DelayedDamagePool();
	}
}