ACTOR ComplexChest: SwitchableDecoration
{
 Radius 16
 Height 8
 Mass 0x7fffffff
 Tag "Complex Chest (loot)"
 -SOLID
 +NEVERRESPAWN
 +DONTGIB
 Activation THINGSPEC_Activate
 +USESPECIAL
 var int user_nochildren;
 States
 {
  Spawn:
	CEST A 0 Nodelay ACS_NamedExecuteAlways("ttkCrateIcon",0)
  SpawnLoop:
	CEST X 1
	Loop
  Active:
	"####" "#" 0 A_SetUserVar("user_nochildren",1)
	"####" "#" 0 A_RemoveChildren(true)
	"####" "#" 1 A_NoBlocking
	"####" "#" 0 A_PlaySound("chest/open",7)
	"####" "#" 1 A_Jump(256,"ActiveCont")
	Wait
  ActiveCont:
	TNT1 A 0 A_Jump(128,"Death2","Death3","Death4","DeathMonster","DeathMonster","DeathMonster")
	TNT1 AAAAAAAA 0 A_SpawnItemEx("ChestAmmo",0,0,2,random(1,8),0,2,random(0,360),0,0)
	TNT1 AAA 0 A_SpawnItemEx("ChestBox",0,0,2,random(1,8),0,2,random(0,360),0,0)
	TNT1 A 0 A_SpawnItemEx("ChestWeapon",0,0,2,random(1,8),0,2,random(0,360),0,200)
	TNT1 A 0 A_Jump(75,"DeathMonster")
	Goto DeathLoop
  Death2:
	TNT1 A 0 A_Jump(60,"Death2Jackpot")
	TNT1 A 0 A_SpawnItemEx("PlayingCard",0,0,2,random(1,8),0,2,random(0,360),0,0)
	TNT1 A 0 A_Jump(75,"DeathMonster")
	Goto DeathLoop
  Death2Jackpot:
	TNT1 A 0 A_SpawnItemEx("ChestWeapon",0,0,2,random(1,8),0,2,random(0,360),0,120)
	TNT1 A 0 A_SpawnItemEx("ChestWeaponFromTXS",0,0,2,random(1,8),0,2,random(0,360),0,120)
	TNT1 A 0 A_SpawnItemEx("ChestWeapon",0,0,2,random(1,8),0,2,random(0,360),0,120)
	TNT1 A 1 A_PlaySound("jackpot/other",7)
	Goto DeathLoop
  Death3:
	TNT1 A 0 A_Jump(60,"Death3Jackpot")
	TNT1 A 0 A_SpawnItemEx("ChestCrate",0,0,2,random(1,8),0,2,random(0,360),0,0)
	TNT1 A 0 A_Jump(75,"DeathMonster")
	Goto DeathLoop
  Death3Jackpot:
	TNT1 A 0 A_SpawnItemEx("SuperCrate",0,0,2,random(1,8),0,2,random(0,360),0,0)
	TNT1 A 0 A_SpawnItemEx("ChestCrate",0,0,2,random(1,8),0,2,random(0,360),0,0)
	TNT1 A 0 A_SpawnItemEx("ChestCrate",0,0,2,random(1,8),0,2,random(0,360),0,0)
	TNT1 A 0 A_SpawnItemEx("ChestWeaponFromTXS",0,0,2,random(1,8),0,2,random(0,360),0,0)
	TNT1 A 1 A_PlaySound("jackpot/other",7)
	Goto DeathLoop
  Death4:
	//TNT1 A 0 A_Jump(60,"Death4Jackpot")
	TNT1 A 0 A_SpawnItemEx("MagicCard",0,0,2,random(1,8),0,2,random(0,360),0,0)
	TNT1 A 0 A_Jump(75,"DeathMonster")
	Goto DeathLoop
 /* Death4Jackpot:
	TNT1 A 0 A_SpawnItemEx("UnknownSpawner",0,0,2,random(1,8),0,2,random(0,360),0,0)
	Goto DeathLoop*/
  DeathMonster:
    TNT1 A 0 A_Jump(80,"DeathSS")
	TNT1 A 0 A_SpawnItemEx("ChestMonsters",0,0,64,0,0,2,random(0,360),0,0)
	Goto DeathLoop
  DeathSS:
	TNT1 A 0 A_SpawnItemEx("WolfensteinSS",0,0,64,0,0,2,random(0,360),0,0)
	Goto DeathLoop
  DeathLoop:
	CEST Z 70
	CEST Z 5 A_Fadeout(0.05)
	Wait
 }
}

Actor ChestMonsters : RandomSpawner
{
+DROPPED
DropItem "ZombieMan", 256, 10
DropItem "ShotgunGuy", 256, 10
DropItem "ChaingunGuy", 256, 10
DropItem "DoomImp", 256, 10
DropItem "Demon", 256, 10
DropItem "Spectre", 256, 10
DropItem "Revenant", 256, 10
DropItem "Cacodemon", 256, 10
DropItem "PainElemental", 256, 10
DropItem "HellKnight", 256, 10
DropItem "BaronOfHell", 256, 10
DropItem "Archvile", 256, 10
}

Actor ChestCrate: RandomSpawner
{
+DROPPED
DropItem "WeaponCrate", 256, 10
DropItem "UtilityCrate", 256, 10
DropItem "HealthCrate", 256, 10
}

ACTOR HeavyChest : ComplexChest
{
  Health 2000
  DamageFactor 0.5
  Tag "\c[i6]Heavy Chest\c- (loot)"
}
