//This script is an imitation of MrSatan's script for the LegendaryDemonRune

#library "DemonMorph"
#include "zcommon.acs"

World Int 16: arrayHealth[];
World Int 17: arrayArmor[];
World Str 18: arrayArmorClass[];

Script "BaronMorph" (VOID)
{
	Int Countdown;
	arrayHealth[PlayerNumber()] = GetActorProperty(0, APROP_HEALTH);
	arrayArmor[PlayerNumber()] = CheckInventory("BasicArmor");
	arrayArmorClass[PlayerNumber()] = GetArmorInfo(ARMORINFO_CLASSNAME);
	//Log(s:"Health= ", i: arrayHealth[PlayerNumber()]);
	//Log(s:"Armor#= ", i: arrayArmor[PlayerNumber()]);
	//Log(s:"ArmorClass= ", s: arrayArmorClass[PlayerNumber()]);

	GiveInventory("DemonRuneBaron", 1);
	GiveInventory("DemonSight", 1);
	GiveInventory("MorphToken", 1);

	While (CheckActorClass(PlayerNumber(), "BaronPlayer"))
	{
			Delay(35);
			Countdown++;
		If(Countdown == 30)
		{
			GiveInventory("CeaseMorph",1);
		}
	}

	SetActorProperty(PlayerNumber(), APROP_HEALTH, arrayHealth[PlayerNumber()]);
	//Log(s:"Returned Health= ", i:GetActorProperty(PlayerNumber(), APROP_HEALTH));
	arrayHealth[PlayerNumber()] = 0;

	if (StrICmp(arrayArmorClass[PlayerNumber()], "None") != 0)
	{
		GiveInventory(arrayArmorClass[PlayerNumber()], 1);
		//Log(s:"Returned ArmorClass= ", s:GetArmorInfo(ARMORINFO_CLASSNAME));
		arrayArmorClass[PlayerNumber()] = "None";
	}

	if (CheckInventory("BasicArmor") > arrayArmor[PlayerNumber()])
	{
		While(CheckInventory("BasicArmor") > arrayArmor[PlayerNumber()])
		{
			TakeInventory("BasicArmor",1);
		}
	}
	else if (CheckInventory("BasicArmor") < arrayArmor[PlayerNumber()])
	{
		While (CheckInventory("BasicArmor") < arrayArmor[PlayerNumber()])
		{
			GiveInventory("GiveArmor",1);
		}
	}
	arrayArmor[PlayerNumber()] = 0;
	//Log(s:"Returned InitialArmor#= ", i:CheckInventory("BasicArmor"));
	TakeInventory("MorphToken", 1);
	TakeInventory("CeaseMorph", 1);
	TakeInventory("PowerTorch", 1);
	Delay(4);
}

Script "RevenantMorph" (VOID)
{
	Int Countdown;
	arrayHealth[PlayerNumber()] = GetActorProperty(0, APROP_HEALTH);
	arrayArmor[PlayerNumber()] = CheckInventory("BasicArmor");
	arrayArmorClass[PlayerNumber()] = GetArmorInfo(ARMORINFO_CLASSNAME);
	//Log(s:"Health= ", i: arrayHealth[PlayerNumber()]);
	//Log(s:"Armor#= ", i: arrayArmor[PlayerNumber()]);
	//Log(s:"ArmorClass= ", s: arrayArmorClass[PlayerNumber()]);

	GiveInventory("DemonRuneRevenant", 1);
	GiveInventory("DemonSight", 1);
	GiveInventory("MorphToken", 1);

	While (CheckActorClass(PlayerNumber(), "RevenantPlayer"))
	{
			Delay(35);
			Countdown++;
		If(Countdown == 30)
		{
			GiveInventory("CeaseMorph",1);
		}
	}

	SetActorProperty(PlayerNumber(), APROP_HEALTH, arrayHealth[PlayerNumber()]);
	//Log(s:"Returned Health= ", i:GetActorProperty(PlayerNumber(), APROP_HEALTH));
	arrayHealth[PlayerNumber()] = 0;

	if (StrICmp(arrayArmorClass[PlayerNumber()], "None") != 0)
	{
		GiveInventory(arrayArmorClass[PlayerNumber()], 1);
		//Log(s:"Returned ArmorClass= ", s:GetArmorInfo(ARMORINFO_CLASSNAME));
		arrayArmorClass[PlayerNumber()] = "None";
	}

	if (CheckInventory("BasicArmor") > arrayArmor[PlayerNumber()])
	{
		While(CheckInventory("BasicArmor") > arrayArmor[PlayerNumber()])
		{
			TakeInventory("BasicArmor",1);
		}
	}
	else if (CheckInventory("BasicArmor") < arrayArmor[PlayerNumber()])
	{
		While (CheckInventory("BasicArmor") < arrayArmor[PlayerNumber()])
		{
			GiveInventory("GiveArmor",1);
		}
	}
	arrayArmor[PlayerNumber()] = 0;
	//Log(s:"Returned InitialArmor#= ", i:CheckInventory("BasicArmor"));
	TakeInventory("MorphToken", 1);
	TakeInventory("CeaseMorph", 1);
	TakeInventory("PowerTorch", 1);
	Delay(4);
}

Script "MorphedLevelChange" Enter
{
	If (CheckInventory("Morphtoken") >= 1)
	{
		SetActorProperty(PlayerNumber(), APROP_HEALTH, arrayHealth[PlayerNumber()]);
		//Log(s:"Returned Health= ", i:GetActorProperty(PlayerNumber(), APROP_HEALTH));
		arrayHealth[PlayerNumber()] = 0;

		if (StrICmp(arrayArmorClass[PlayerNumber()], "None") != 0)
		{
			GiveInventory(arrayArmorClass[PlayerNumber()], 1);
			//Log(s:"Returned ArmorClass= ", s:GetArmorInfo(ARMORINFO_CLASSNAME));
			arrayArmorClass[PlayerNumber()] = "None";
		}

		if (CheckInventory("BasicArmor") > arrayArmor[PlayerNumber()])
		{
			While(CheckInventory("BasicArmor") > arrayArmor[PlayerNumber()])
			{
				TakeInventory("BasicArmor",1);
			}
		}
		else if (CheckInventory("BasicArmor") < arrayArmor[PlayerNumber()])
		{
			While (CheckInventory("BasicArmor") < arrayArmor[PlayerNumber()])
			{
				GiveInventory("GiveArmor",1);
			}
		}
		arrayArmor[PlayerNumber()] = 0;
		//Log(s:"Returned InitialArmor#= ", i:CheckInventory("BasicArmor"));
		UnMorphActor(0, 0);
		TakeInventory("MorphToken", 1);
		TakeInventory("CeaseMorph", 1);
		TakeInventory("PowerTorch", 1);
		Delay(4);
	}
}