Actor SoulCube : weapon
{
   Weapon.BobRangeX 0.3
   Weapon.BobRangeY 0.5
   Weapon.BobStyle InverseSmooth
   Weapon.BobSpeed 2.0
   Weapon.SlotNumber 3
   Weapon.SelectionOrder 350
   Inventory.PickupSound "SoulCube/Pickup"
   Obituary "%o's soul was taken by %k."
   Tag "Soul Cube"
   Weapon.SlotNumber 7
   +WEAPON.NO_AUTO_SWITCH
   AttackSound "SoulCube/Use" 
   damagetype Cube
   Scale 0.5
   States 
   { 
   Spawn: 
      SCBG A -1
      Stop
   Ready: 
      SCUB A 0 A_JumpIfInventory ("CubeAmmo", 50, "UseUs")
      SCUB A 1 A_WeaponReady
      Loop
   UseUs:
	  SCUB A 0 A_Print("The \crSoul Cube\c- is ready to be used!")
	  SCUB A 0 A_PlaySound("SoulCube/UseUs")
	  SCUB ABCDEFGHI 2 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
	  Goto ActuallyReady
   ActuallyReady:
      SCUB I 1 A_WeaponReady
      Loop 
   Deselect: 
      SCUB A 1 A_Lower
	  SCUB A 0 A_Lower
      Loop 
   Select: 
      SCUB A 1 A_Raise
	  SCUB A 0 A_Raise
      Loop 
   Fire:
      SCUB A 0 A_JumpIfInventory ("CubeAmmo", 50, "Fire2")
	  SCUB A 0 A_PlaySound("SoulCube/NotYet")
      SCUB A 1 A_Print ("You don't have enough souls to use the \crSoul Cube\c-!")
	  SCUB AAAA 1 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
      Goto Ready
   Fire2: 
      SCUB J 1 A_FireCustomMissile("SoulCubeProj",0,0,0,0,0)
	  SCUB JJJJ 1 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
	  SCUB J 1 Offset(0,10)
	  SCUB J 1 Offset(0,20)
	  SCUB J 1 Offset(0,30)
	  SCUB J 1 Offset(0,40)
	  SCUB J 1 Offset(0,50)
	  SCUB J 1 Offset(0,60)
	  SCUB J 1 Offset(0,70)
	  SCUB J 1 Offset(0,80)
	  SCUB J 1 Offset(0,90)
      SCUB P 0 A_TakeInventory("SoulCube")
      Goto Ready 
  AltFire:
	  TNT1 A 0 A_GunFlash("WeaponStill")
	  TNT1 A 0 A_PlaySound ("weapons/KICK")
	  FOOT AB 1 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
	  FOOT C 1 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
	  FOOT D 1 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
	  FOOT D 1 A_CustomPunch(5,0,0,"KickPuff")
	  FOOT D 0 A_Quake(1,2,0,10)
	  FOOT EF 1 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
	  FOOT FEDCBA 1 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
	  TNT1 A 8 A_WeaponReady(WRF_NoFire|WRF_NoSwitch)
	  TNT1 A 0 A_ReFire
	  TNT1 A 0 A_JumpIfInventory("CubeAmmo", 50, "ActuallyReady")
	  Goto Ready
  WeaponStill:
	  SCUB A 0 A_JumpIfInventory("CubeAmmo", 50, "WeaponStill2")
	  SCUB A 22
	  Goto LightDone
  WeaponStill2:
	  SCUB I 22
	  Goto LightDone
   } 
}
  
actor SoulCubeProj
{
  radius 13
  height 8
  speed 25
  damage 5000
  damagetype "Cube"
  seesound "SoulCube/Use"
  deathsound "SoulCube/Slice"
   Scale 0.25
  PROJECTILE
  +SKYEXPLODE
  +SCREENSEEKER
  states
  {
  Spawn:
    SCBW A 1 A_SeekerMissile (90, 90, SMF_PRECISE)
    SCBW A 1 A_SeekerMissile (90, 90, SMF_PRECISE)
    SCBW A 1 A_SeekerMissile (90, 90, SMF_PRECISE)
    SCBW A 1 A_SeekerMissile (90, 90, SMF_PRECISE)
    loop
  Death:
    TNT1 A 0 A_CustomMissile ("SoulCubeReturnSpawner",0,0,0,0,0)
	TNT1 A 0 A_Quake(2,12,0,800)
	TNT1 A 0 A_Explode(175,256)
    TNT1 A -1
    stop
  }
}

actor SoulCubeReturnSpawner
{
  Radius 0
  Height 0
  Scale 0.25
  MONSTER
  +NONSHOOTABLE
  +NOGRAVITY
  -SOLID
  -COUNTKILL
  States
  {
  Spawn:
    SCBW A 0 A_PlaySound ("SoulCube/Slice")
    SCBW AAAAAAAAAAAAAAAA 1
  Missile:
    TNT1 A 0 A_FaceTarget
    TNT1 A 0 A_PlaySound("SoulCube/Use")
    TNT1 A 0 A_CustomMissile ("SoulCubeReturner",0,0,0,0,0)
  Death:
    TNT1 A 0 A_GiveToTarget ("SoulCube")
    TNT1 A 0 A_TakeFromTarget ("CubeAmmo", 50)
    TNT1 A -1
    Stop
  }
}
  
actor SoulCubeReturner : Ammo
{
  radius 13
  height 1
  speed 25
  damage 0
   Scale 0.25
  +MISSILE
  +STEPMISSILE
  +SEEKERMISSILE
  +PAINLESS
  +NONSHOOTABLE
  +NOGRAVITY
  -SOLID
  states
  {
  Spawn:
    SCBW A 1 A_SeekerMissile (90, 90, SMF_PRECISE)
    SCBW A 1 A_SeekerMissile (90, 90, SMF_PRECISE)
    SCBW A 1 A_SeekerMissile (90, 90, SMF_PRECISE)
    SCBW A 1 A_SeekerMissile (90, 90, SMF_PRECISE)
    loop
  Death:
    TNT1 A -1
    stop
  Pickup:
    TNT1 A 0 A_GiveInventory("SoulCube")
    TNT1 A 0 A_TakeInventory("CubeAmmo", 50)
    stop
  }
}
  
actor SoulCubeGenerator : CustomInventory
{
  radius 13
  height 8
  +FLOORCLIP
  +FLOATBOB
  +AUTOACTIVATE
  +INVENTORY.ALWAYSPICKUP
  Inventory.PickupMessage "The mysterious artifact speaks to you... ''We are many. We are one. We are the Praeleanthor. You know us as the \crSoul Cube\c-.'' \cf(\cjSlot 7\cf)"
  Inventory.PickupSound "SoulCube/Pickup" 
  Inventory.MaxAmount 1
   Scale 0.25
  states
  {
  Spawn:
    SCBG A 5
	Loop
  Pickup:
    TNT1 A 0 A_GiveInventory("SoulCube")
    TNT1 A 0 A_TakeInventory("CubeAmmo", 25)
    TNT1 A 0 A_SelectWeapon("SoulCube") 
    stop
  }
}

actor CubeAmmo : Ammo
{
	 Inventory.Amount 1
     Inventory.MaxAmount 50
     Ammo.BackpackAmount 0
     Ammo.BackpackMaxAmount 50
	 Inventory.PickupMessage "The \crSoul Cube\c- feeds on the enemy soul you picked up."
	 Inventory.PickupSound "SoulCube/GetSoul"
	 Scale 0.25
	 Alpha 0.99
	 +FLOATBOB
	 States
	 {
	 Spawn:
	   TERR ABCDE 3 Bright
	   Loop
	 }
}

/*-
Actor SoulSpawner
{
	States
	{
	Spawn:
	  TNT1 A 0 //Needed for this to actually work
	  TNT1 A 0 A_JumpIfInTargetInventory("SoulCube", 1, "SpawnSoul", AAPTR_PLAYER1)
	  Stop
	SpawnSoul:
	  TNT1 A 0 A_SpawnItem("CubeAmmo")
	  Stop
	}
}
*/
//This (unfortunately) does not work.
//I will need to have enemies check for the Soul Cube in the player's inventory for them to drop Soul Cube ammo during their death animation.
//It's hacky, yeah, but it's necessary in order for this to work MetaDoom style (Without the need of ACS or ZScript).