#region Poweroops
//$Color 10

class TomeOfPowahGiver : CustomInventory replaces ArtiTomeOfPower
{
	Default
	{
		Tag "\c[purple]Tome of Power";
		Inventory.MaxAmount 0;
		Inventory.PickupSound "Tome/Pickup";
		Inventory.PickupMessage "Obtained a \c[purple]Tome of Power\c-!";
		+INVENTORY.AUTOACTIVATE
		+COUNTITEM
		+FLOATBOB
	}
	
	int User_Fade;
	
	States
	{
	Spawn:
		TOME AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP 1 { 
		If(!(A_CheckSight("Null") || GetCVar("GC_PickupParticleChoker")))
		{
			if(Invoker.User_Fade % 2 == 0)
			{
				A_SpawnItemEx("Tome_Shadow",
					random(3.0,-3.0),random(3.0,-3.0),random(3.0,-3.0),
					0,0,0,0,SXF_CLIENTSIDE);
				Invoker.User_Fade = 0;
			}
			Invoker.User_Fade = Invoker.User_Fade + 1;
			A_SpawnItemEx("TomeOfPowerParticle",
				frandom(10.0,-10.0),frandom(10.0,-10.0),35+frandom(10.0,-10.0),
				frandom(0.6,-0.6),frandom(0.6,-0.6),frandom(1.2,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("TomeOfPowah") >= GetDefaultByType("TomeOfPowah").MaxAmount && !GetCvar("sv_unlimited_pickup"), "Nope");
		TNT1 A 0 A_GiveInventory("TomeOfPowah",1);
		Stop;
	BringIt:
		TNT1 A 0 {
			A_PlaySound("Tome/Use",3);
			A_GiveInventory("Amplify");
			A_GiveInventory("AmplifierExtender");
			A_SetBlend("Purple",0.2,35);
		}
		Stop;
	Nope:
		TNT1 A 0 A_JumpIf(GetCVar("GC_AutoUse") == 1,"BringIt");
		Fail;
	}
}

class TomeOfPowah : CustomInventory
{
	Default
	{
		Tag "\c[purple]Tome of Power";
		Inventory.Amount 1;
		Inventory.MaxAmount 5;
		Inventory.InterHubAmount 5;
		Inventory.PickupSound "Tome/Pickup";
		Inventory.UseSound "Tome/Use";
		Inventory.Icon "ARTIPWBK";
		Inventory.PickupMessage "Obtained a \c[purple]Tome of Power\c-!";
		+COUNTITEM
		+FLOATBOB
		+INVENTORY.INVBAR
	}
	
	int User_Fade;
	
	States
	{
	Spawn:
		TOME AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP 1 { 
		If(!(A_CheckSight("Null") || GetCVar("GC_PickupParticleChoker")))
		{
			if(Invoker.User_Fade % 2 == 0)
			{
				A_SpawnItemEx("Tome_Shadow",
					random(3.0,-3.0),random(3.0,-3.0),random(3.0,-3.0),
					0,0,0,0,SXF_CLIENTSIDE);
				Invoker.User_Fade = 0;
			}
			Invoker.User_Fade = Invoker.User_Fade + 1;
			A_SpawnItemEx("TomeOfPowerParticle",
				frandom(10.0,-10.0),frandom(10.0,-10.0),35+frandom(10.0,-10.0),
				frandom(0.6,-0.6),frandom(0.6,-0.6),frandom(1.2,0.4),
				frandom(0.0,360.0),SXF_CLIENTSIDE,64);
			}
		}
		Loop;
	Use:
		TNT1 A 0 {
			A_PlaySound("Tome/Use",3);
			A_GiveInventory("Amplify");
			A_GiveInventory("AmplifierExtender");
			A_SetBlend("Purple",0.2,35);
		}
		Stop;
	}
}

class PowerTomeEffect : Powerup
{
	Default
	{
		Inventory.Icon "TOMEON0";
	}
	
	override void DoEffect()
	{
		if(owner.CountInv("PowerExtremeDamage"))
		{
			Icon = TexMan.CheckForTexture("", TexMan.Type_Sprite);
		}
		else
		{
			Icon = GetDefaultByType("PowerTomeEffect").Icon;
		}
		Super.DoEffect();
		return;
	}
}

class Amplify : PowerupGiver
{
	Default
	{
		Powerup.Duration -45;
		Powerup.Type "PowerTomeEffect";
		+INVENTORY.AUTOACTIVATE
		+INVENTORY.ALWAYSPICKUP
		+INVENTORY.ADDITIVETIME
	}
}

class Tome_Shadow : Actor
{
	Default
	{
		Alpha 0.5;
		RenderStyle 'Stencil';
		+NoInteraction;
	}
	States
	{
		Spawn:
			TOME ABCDEFGHIJKLMNOP 2 A_FadeOut(0.03);
			Stop;
	}
}

class AmplifierExtender : PowerupExtender
{
    override void AttachToOwner(Actor user)
    {
        ExtendThese.Push("PowerTomeEffect");
		
		Super.AttachToOwner(user);
    }
}

#endregion
