#region Health
//$Color 10

class HealVial : Stimpack replaces CrystalVial
{
	Default
	{
		//$Title Healing Vial
		inventory.amount 10;
		inventory.pickupsound "Pot/Use";
		inventory.pickupmessage "Obtained a healing vial.";
   }
   
   States
   {
   Spawn:
	   PTN1 AABBCCDDEE 1 {
			If(!(A_CheckSight("Null") || GetCVar("GC_PickupParticleChoker")))
			{
				A_SpawnItemEx("RedParticle",
					frandom(3.0,-3.0),frandom(3.0,-3.0),frandom(15.0,2.0),
					frandom(0.2,-0.2),frandom(0.2,-0.2),frandom(1.6,0.4),
					frandom(0.0,360.0),SXF_CLIENTSIDE,64);
			}
		}
		Loop;
   }
}

class HealPot : HealthPickup // replaces ArtiHealth
{
	Default
	{
		//$Title Potion of Healing
		Tag "Potion of Healing";
		Inventory.Amount 1;
		Inventory.MaxAmount 10;
		Inventory.InterHubAmount 0x7FFFFFFF;
		Inventory.PickupSound "Pot/Pickup";
		Inventory.UseSound "Pot/Use";
		Inventory.PickupMessage "Picked up a healing pot.";
		Inventory.Icon 'ARTIPTN2';
		HealthPickup.Autouse 1;
		Health 25;
		+INVENTORY.INVBAR
	}
	
	States
	{
	Spawn:
		PTN2 AABBCCDDEEFF 1 {
			If(!(A_CheckSight("Null") || GetCVar("GC_PickupParticleChoker")))
			{
				A_SpawnItemEx("RedParticle",
					frandom(5.0,-5.0),frandom(5.0,-5.0),frandom(15.0,2.0),
					frandom(0.2,-0.2),frandom(0.2,-0.2),frandom(1.6,0.4),
					frandom(0.0,360.0),SXF_CLIENTSIDE,64);
			}
		}
		Loop;
   } 
}

class GiverShared : CustomInventory
{
	Default
	{
		Inventory.MaxAmount 0;
		-INVENTORY.AUTOACTIVATE
		+COUNTITEM
	}
}

class RejuvPotGiver : GiverShared
{
	Default
	{
		//$Title Rejuvenation Pot
		Inventory.PickupSound "Pot/Pickup";
		Inventory.PickupMessage "Grabbed a rejuvenation pot.";
	}
	
	States
	{
	Spawn:
		PTN5 AABBCCDDEEFF 1 {
			If(!(A_CheckSight("Null") || GetCVar("GC_PickupParticleChoker")))
			{
				A_SpawnItemEx("YellowParticle",
					frandom(5.0,-5.0),frandom(5.0,-5.0),frandom(15.0,2.0),
					frandom(0.2,-0.2),frandom(0.2,-0.2),frandom(1.6,0.4),
					frandom(0.0,360.0),SXF_CLIENTSIDE,64);
			}
		}
		Loop;
	Pickup:
		TNT1 A 0 A_JumpIf(GetCVar("GC_AutoUse") == 2, "BringIt");
		TNT1 A 0 A_JumpIf(CountInv("RejuvPot") >= GetDefaultByType("RejuvPot").MaxAmount && GetCVar("GC_AutoUse") == 1, "BringIt");
		TNT1 A 0 A_GiveInventory("RejuvPot",1);
		Stop;
	BringIt:
		TNT1 A 0 {
			If(Health < PlayerPawn(self).MaxHealth ||
			   CountInv("Mana") < FindInventory("Mana").MaxAmount)
			{
				A_PlaySound("Pot/Use",3);
				let RejuvManager = RejuvenationManager(FindInventory("RejuvenationManager"));
				if(RejuvManager)
				{
					RejuvManager.NewTimer();
				}
				else
				{
					let RejuvManager = RejuvenationManager(GiveInventoryType("RejuvenationManager"));
					RejuvManager.NewTimer();
				}
				Return true;
			}
			else If(GetCVar("GC_AutoUse") == 2 && CountInv("RejuvCaps") < GetDefaultByType("RejuvCaps").MaxAmount) {
				A_GiveInventory("RejuvCaps",1);
				Return true;
			}
			else { Return false; }
		}
		Stop;
	}
}

class RejuvPot : CustomInventory
{
	Default
	{
		//$Title Potion of Rejuvenation
		Tag "Potion of Rejuvenation";
		Inventory.Amount 1;
		Inventory.MaxAmount 10;
		Inventory.InterHubAmount 0x7FFFFFFF;
		Inventory.Icon 'ARTIPTN5';
		Inventory.PickupSound "Pot/Pickup";
		Inventory.UseSound "Pot/Use";
		Inventory.PickupMessage "Grabbed a rejuvenation pot.";
		+INVENTORY.INVBAR
	}
	
	States
	{
	Spawn:
		PTN5 AABBCCDDEEFF 1 {
			If(!(A_CheckSight("Null") || GetCVar("GC_PickupParticleChoker")))
			{
				A_SpawnItemEx("YellowParticle",
					frandom(5.0,-5.0),frandom(5.0,-5.0),frandom(15.0,2.0),
					frandom(0.2,-0.2),frandom(0.2,-0.2),frandom(1.6,0.4),
					frandom(0.0,360.0),SXF_CLIENTSIDE,64);
			}
		}
		Loop;
	Use:
		TNT1 A 0 {
			If(invoker.owner.Health < PlayerPawn(invoker.owner).MaxHealth ||
			   invoker.owner.CountInv("Mana") < invoker.owner.FindInventory("Mana").MaxAmount)
			{
				A_PlaySound("Pot/Use",3);
				let RejuvManager = RejuvenationManager(invoker.owner.FindInventory("RejuvenationManager"));
				if(RejuvManager)
				{
					RejuvManager.NewTimer();
				}
				else
				{
					let RejuvManager = RejuvenationManager(invoker.owner.GiveInventoryType("RejuvenationManager"));
					RejuvManager.NewTimer();
				}
				Return true;
			}
			else { Return false; }
		}
		Stop;
	}
}

class RejuvenationManager : Inventory
{
	Array<Int> EffectTimers;
	
	Default
	{
		Inventory.MaxAmount 1; // Only one copy may exist.
	}
	
	void NewTimer()
	{
		EffectTimers.Push(level.maptime);
		//A_Log(String.Format("EffectTimer started at %i maptime", EffectTimers[EffectTimers.Size()-1]));
	}
	
	override void DoEffect()
	{
		if(EffectTimers.Size())
		{
			for(int i = 0; i < EffectTimers.Size(); i++)
			{
				// If the current level time is lower than
				// the effect's timer, it is no longer valid.
				if((level.maptime < EffectTimers[i]) ||
				// If the effect has lasted for fifteen seconds,
				// expire it.
				(level.maptime >= (EffectTimers[i] + (35 * 15))))
				{
					//A_Log(String.Format("EffectTimer started at %i maptime removed at %i maptime", EffectTimers[i], level.maptime));
					EffectTimers.Delete(i);
				}
			}
			
			// The for loop runs twice - once for cleaning up,
			// and once for rejuvenation.
			for(int i = 0; i < EffectTimers.Size(); i++)
			{
				// Regenerate one mana on every seventh tic.
				if(!((level.maptime - EffectTimers[i]) % 7))
				{
					owner.GiveInventory("Mana", 1);
				}
				
				// Regenerate one health on every tenth tic.
				if(!((level.maptime - EffectTimers[i]) % 10))
				{
					owner.GiveInventory("Health", 1);
				}
			}
		}
		
		Super.DoEffect();
	}
}

#endregion

#region Poweroops
//$Color 10

class BerserkPotGiver : GiverShared
{
	Default
	{
		//$Title Berserk Pot
		Inventory.PickupSound "Pot/Pickup";
		Inventory.PickupMessage "You've got the Berserk potion!";
	}
	
	States
	{
	Spawn:
		BZPT AABBCCDDEEFFGG 1 {
			If(!(A_CheckSight("Null") || GetCVar("GC_PickupParticleChoker")))
			{
				A_SpawnItemEx("RedParticle",
					frandom(5.0,-5.0),frandom(5.0,-5.0),frandom(15.0,2.0),
					frandom(0.2,-0.2),frandom(0.2,-0.2),frandom(1.6,0.4),
					frandom(0.0,360.0),SXF_CLIENTSIDE,64);
			}
		}
		Loop;
	Pickup:
		TNT1 A 0 A_JumpIf(GetCVar("GC_AutoUse") == 2, "BringIt");
		TNT1 A 0 A_JumpIf(CountInv("BerserkPot") >= GetDefaultByType("BerserkPot").MaxAmount && !GetCvar("sv_unlimited_pickup"), "Nope");
		TNT1 A 0 A_GiveInventory("BerserkPot",1);
		Stop;
	BringIt:
		TNT1 A 0 {
			A_PlaySound("Berserk/Use",3);
			A_GiveInventory("PowerJumping",1);
			A_GiveInventory("PowerSpeeding",1);
			A_GiveInventory("PowerBerserkingResist",1);
			A_GiveInventory("PowerBerserking",1);
			A_GiveInventory("BerserkExtender",1);
			A_GiveInventory("PowerAfterBerserking",1);
			A_SetBlend("Red",0.2,35);
			HealThing(200, 0);
		}
		Stop;
	Nope:
		TNT1 A 0 A_JumpIf(GetCVar("GC_AutoUse") == 1,"BringIt");
		Fail;
	}
}

class BerserkPot : CustomInventory
{
	Default
	{
		Inventory.Icon 'ARTIBZPT';
		Inventory.PickupMessage "You've got the Berserk potion!";
		Inventory.Amount 1;
		Inventory.MaxAmount 5;
		Inventory.InterHubAmount 0x7FFFFFFF;
		Inventory.PickupSound "Pot/Pickup";
		Inventory.UseSound "Berserk/Use";
		Tag "Potion of Berserking";
		+INVENTORY.INVBAR
	}
	States
	{
	Spawn:
		BZPT AABBCCDDEEFFGG 1 {
			If(!(A_CheckSight("Null") || GetCVar("GC_PickupParticleChoker")))
			{
				A_SpawnItemEx("RedParticle",
					frandom(5.0,-5.0),frandom(5.0,-5.0),frandom(15.0,2.0),
					frandom(0.2,-0.2),frandom(0.2,-0.2),frandom(1.6,0.4),
					frandom(0.0,360.0),SXF_CLIENTSIDE,64);
			}
		}
		Loop;
		
		
	Use:
		TNT1 A 0 {
			A_GiveInventory("PowerJumping",1);
			A_GiveInventory("PowerSpeeding",1);
			A_GiveInventory("PowerBerserkingResist",1);
			A_GiveInventory("PowerBerserking",1);
			A_GiveInventory("BerserkExtender",1);
			A_GiveInventory("PowerAfterBerserking",1);
			A_SetBlend("Red",0.2,35);
			HealThing(200, 0);
		}
		Stop;
	}
}

class GunzerkPotGiver : GiverShared
{
	Default
	{
		//$Title Gunzerk Pot
		Inventory.PickupSound "Pot/Pickup";
		Inventory.PickupMessage "You've got the Gunzerk potion!";
	}
	
	States
	{
	Spawn:
		GZPT AABBCCDDEEFFGG 1 {
			If(!(A_CheckSight("Null") || GetCVar("GC_PickupParticleChoker")))
			{
				A_SpawnItemEx("PurpleParticle",
					frandom(5.0,-5.0),frandom(5.0,-5.0),frandom(17.0,2.0),
					frandom(0.2,-0.2),frandom(0.2,-0.2),frandom(1.6,0.4),
					frandom(0.0,360.0),SXF_CLIENTSIDE,64);
			}
		}
		Loop;
	Pickup:
		TNT1 A 0 A_JumpIf(GetCVar("GC_AutoUse") == 2, "BringIt");
		TNT1 A 0 A_JumpIf(CountInv("GunzerkPot") >= GetDefaultByType("GunzerkPot").MaxAmount && !GetCvar("sv_unlimited_pickup"), "Nope");
		TNT1 A 0 A_GiveInventory("GunzerkPot",1);
		Stop;
	BringIt:
		TNT1 A 0 {
			A_PlaySound("Gunzerk/Use",3);
			A_GiveInventory("PowerGunzerkingResist",1);
			A_GiveInventory("GunzerkingGiver",1);
			//ACS_NamedExecute("GC Ammo Regen");	
			A_GiveInventory("GunzerkExtender",1);
			A_SetBlend("Purple",0.2,35);
			HealThing(200, 0);
		}
		Stop;
	Nope:
		TNT1 A 0 A_JumpIf(GetCVar("GC_AutoUse") == 1,"BringIt");
		Fail;
	}
}

class GunzerkPot : CustomInventory
{
	Default
	{
		Inventory.Icon 'ARTIGZPT';
		Inventory.PickupMessage "You've got the Gunzerk potion!";
		Inventory.Amount 1;
		Inventory.MaxAmount 5;
		Inventory.InterHubAmount 0x7FFFFFFF;
		Inventory.PickupSound "Pot/Pickup";
		Inventory.UseSound "Gunzerk/Use";
		Tag "Potion of Gunzerking";
		+INVENTORY.INVBAR
	}
	
	States
	{
	Spawn:
		GZPT AABBCCDDEEFFGG 1 {
			If(!(A_CheckSight("Null") || GetCVar("GC_PickupParticleChoker")))
			{
				A_SpawnItemEx("PurpleParticle",
					frandom(5.0,-5.0),frandom(5.0,-5.0),frandom(17.0,2.0),
					frandom(0.2,-0.2),frandom(0.2,-0.2),frandom(1.6,0.4),
					frandom(0.0,360.0),SXF_CLIENTSIDE,64);
			}
		}
		Loop;
	Use:
		TNT1 A 0 {
			A_GiveInventory("PowerGunzerkingResist",1);
			A_GiveInventory("GunzerkingGiver",1);
			//ACS_NamedExecute("GC Ammo Regen",1);
			A_GiveInventory("GunzerkExtender",1);
			A_SetBlend("Purple",0.2,35);
			HealThing(200, 0);
		}
		Stop;
	}
}

class IronLizardPotGiver : GiverShared
{
	Default
	{
		//$Title Iron Lizard Potion
		Inventory.PickupSound "Pot/Pickup";
		Inventory.PickupMessage "You've got the Iron Lizard potion!";
	}
	
	States
	{
	Spawn:
		IRNP AABBCCDDEEFFGG 1 {
			If(!(A_CheckSight("Null") || GetCVar("GC_PickupParticleChoker")))
			{
				A_SpawnItemEx("CyanParticle",
					frandom(5.0,-5.0),frandom(5.0,-5.0),frandom(15.0,2.0),
					frandom(0.2,-0.2),frandom(0.2,-0.2),frandom(1.6,0.4),
					frandom(0.0,360.0),SXF_CLIENTSIDE,64);
			}
		}
		Loop;
		
	Pickup:
		TNT1 A 0 A_JumpIf(GetCVar("GC_AutoUse") == 2, "BringIt");
		TNT1 A 0 A_JumpIf(CountInv("IronLizardPot") >= GetDefaultByType("IronLizardPot").MaxAmount && !GetCvar("sv_unlimited_pickup"), "Nope");
		TNT1 A 0 A_GiveInventory("IronLizardPot",1);
		Stop;
	BringIt:
		TNT1 A 0 {
			A_PlaySound("Pot/Use",3);
			A_GiveInventory("DragonTerminator",1);
			A_GiveInventory("GodModeExtender",1);
			A_SetBlend("Yellow",0.2,35);
		}
		Stop;
	Nope:
		TNT1 A 0 A_JumpIf(GetCVar("GC_AutoUse") == 1,"BringIt");
		Fail;
	}
}

class IronLizardPot : CustomInventory
{
	Default
	{
		Inventory.Icon 'ARTIIRNP';
		Inventory.PickupMessage "You've got the Iron Lizard potion!";
		Inventory.Amount 1;
		Inventory.MaxAmount 5;
		Inventory.InterHubAmount 0x7FFFFFFF;
		Inventory.PickupSound "Pot/Pickup";
		Inventory.UseSound "IronLizard/Use";
		Tag "Potion of Iron Lizard";
		+INVENTORY.INVBAR
	}
	
	States
	{
	Spawn:
		IRNP AABBCCDDEEFFGG 1 {
			If(!(A_CheckSight("Null") || GetCVar("GC_PickupParticleChoker")))
			{
				A_SpawnItemEx("CyanParticle",
					frandom(5.0,-5.0),frandom(5.0,-5.0),frandom(15.0,2.0),
					frandom(0.2,-0.2),frandom(0.2,-0.2),frandom(1.6,0.4),
					frandom(0.0,360.0),SXF_CLIENTSIDE,64);
			}
		}
		Loop;
	Use:
		TNT1 A 0 {
			A_PlaySound("Pot/Use",3);
			A_GiveInventory("DragonTerminator",1);
			A_GiveInventory("GodModeExtender",1);
			A_SetBlend("Yellow",0.2,35);
		}
		Stop;
	}
}

class DragonTerminator : PowerupGiver
{
	Default
	{
		Powerup.Duration -45;
		Powerup.Color 'Grey', 0.05;
		Powerup.Type "PowerGodMode"; //"IronLizard"
		+INVENTORY.AUTOACTIVATE
		+INVENTORY.ADDITIVETIME
	}
}

#endregion
