//// CUSTOM ACTORS


class spectrimp:doomimp
{
    states
	{
    spawn:
        TNT1 A 0 nodelay A_JumpIf(cursector.lightlevel<113,"spawnspookyimp");
        goto super::spawn;
    spawnspookyimp:
		TNT1 A 0 A_Jump(80, "DarkImp");
        TNT1 A 0 A_SpawnItemEx("Shadow");
        stop;
	DarkImp:	
		TNT1 A 0 A_SpawnItemEx("DarkImpSpawner");
		stop;
    }
}

class LITPlayer : PlayerPawn
{

////// FOOTSTEPS
        //Checks to make this work
        double wait; //time between each footstep
        double speed;
        double volume; //this is going to be affected by speed

        //setup sound to play when 'getStepSound' is played
        private String getStepSound()
            {
                if((acs_scriptcall("CheckArmorType") ==1)) return "HFOOT";
				else if ((acs_scriptcall("CheckArmorType") ==2)) return "MFOOT";
				else if ((acs_scriptcall("CheckArmorType") ==3)) return "LFOOT";
				else if ((acs_scriptcall("CheckArmorType") ==4)) return "UFOOT";
                else return "null";
            }

        //is on floor or object
        bool bIsOnFloor(void)
            {
                
                return (Pos.Z == FloorZ || bOnMObj );
        
            }
  
    Override void Tick()
        {
            speed = clamp(vel.xY.length(),0.0,10.0); 
            //speed equals the player velocity but is clamped at a max 12.0
            //this can be adjusted to alter the footstep timings.    
            if (bIsOnFloor())//only make sounds on floor, but this can be expanded to water etc
            volume = speed*0.1;
            {
                if (speed > 1.5)//don't make a sound if you're moving slowly
                    {
                        if (wait <= 0.0) //wait counts down to zero, this is when it makes a sound. 
                        {    
                            A_SpawnItemEx("FootStep6", 0, 0, 8, 0, 0, 0, 0, SXF_SETMASTER );
                            A_StartSound(getStepSound(), CHAN_Auto, 0,volume);
                            wait = 21 - speed;
                        }
                --wait;
                    }
            }
            super.tick();
        }
///// FOOTSTEPS - end
    override int DamageMobj(Actor inflictor, Actor source, int damage, Name mod, int flags, double angle)
    {
        if (mod == 'Bleeding' || mod == "LitPoison" && !((player.cheats & CF_GODMODE) || bInvulnerable))
        {
            flags |= DMG_FORCED;
        }
	      
        return Super.DamageMobj(inflictor, source, damage, mod, flags, angle);
    }
	
   override void CheatGive (String name, int amount)
   {
      super.CheatGive(name, amount);
      
      if (name ~== "all" || name ~== "armor")
      {
         CheatTake("armor", 1);
         super.CheatGive("heavyarmornew", 1);
      }
	  
	   if (name ~== "all" || name ~== "ammo")
      {
         CheatTake("usedstamina", 5000);
         super.CheatGive("backpack", 1);
      }
   }
}

class LITWeapon : DoomWeapon
{
    override Inventory CreateTossable( int amt )
    {
        // disallow dropping if weapon isn't ready for switching
        if ( (Owner.player.ReadyWeapon == self) && (!(Owner.player.WeaponState&WF_WEAPONSWITCHOK) || (Owner.player.WeaponState&WF_DISABLESWITCH)) )
            return null;
        return Super.CreateTossable(amt);
    }
	
	override void ownerdied()
  {  super.ownerdied();
      A_ClearOverlays(1,999,true);
  }
		
	Action void A_WeaponReadyLit() //Universal check for universal weapon states
		{
			A_WeaponReady(WRF_allowreload|WRF_ALLOWUSER4|WRF_ALLOWUSER3); //reload / unload or mag check / toss throwable
			State StartSprint = player.ReadyWeapon.FindState('StartSprint');
			If(StartSprint != NULL && CountInv("IsTacticalClass") == 1 && player.cmd.buttons & BT_FORWARD && player.cmd.buttons & BT_SPEED) 
				{
				player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('StartSprint')); 
				}
			
			If(player.cmd.buttons & BT_USE) { player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('UseAttack')); }
			//////////
			if (CountInv("weargasmask") == 1) { player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('goingtoaction')); }
			if (CountInv("removegasmask") == 1) { player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('goingtoaction')); }
			if (CountInv("repairtoken") == 1) { player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('goingtoaction')); }
			if (CountInv("battledrugtoken") == 1) { player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('goingtoaction')); }
			if (CountInv("BANDAGETOKEN") == 1) { player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('goingtoaction')); }
			if (CountInv("throwtoken") == 1) { player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('Quickthrow')); }
			if (CountInv("slashtoken") == 1) { player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('Quickslash')); }
			if (CountInv("flaretoken") == 1) { player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('TossFlare')); }
			if (CountInv("Taunting") == 1) { player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('Taunt')); }
			if (CountInv("Salute1") == 1 || CountInv("Salute2") == 1) { player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('Salute')); }
			if (CountInv("ExecuteDownedEnemy") == 1) { player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('DoExecution')); }
		}
		
		Action void A_InspectReady() 
			{
			If(player.cmd.buttons & BT_ATTACK) { player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('InspectCancel')); }
			If(player.cmd.buttons & BT_ALTATTACK) { player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('InspectCancel')); }
			//////////
			if (CountInv("kicking") == 1) { player.SetPSprite(PSP_WEAPON,player.ReadyWeapon.FindState('InspectCancel')); }
			}
}

class ControlToken : Inventory
{
    Default
    {
        inventory.maxamount 1;
        +INVENTORY.UNDROPPABLE
        +INVENTORY.UNTOSSABLE
    }   
    override void Tick() {} 
}

class HealthEffects : ControlToken
 {//1
  override void DoEffect() 
  {//2
  
	if (CVar.GetCVar("staminahealthHUD", players[consoleplayer]).GetInt())
	{//3
		if (owner is "MiseryDoomer")
		{//4
			let stamina = owner.findinventory("usedstamina",true);
				if (owner.health <= 40 && owner.health > 0 && stamina && owner.countinv("usedstamina") > 1400)
					{ owner.A_StartSound("TIREHURT", 500, CHANF_LOOPING,0.4,0,0.8); }
				else if (owner.health <= 40 && owner.health > 0) 
					{ owner.A_StartSound("HURTCUE", 500, CHANF_LOOPING,0.4,0,0.8); }
				else if (stamina && owner.countinv("usedstamina") > 1400 && owner.health > 0)
					{ owner.A_StartSound("TIREDCUE", 500, CHANF_LOOPING,0.4,0,0.8); }
			else 
			{ owner.a_stopsound(500); }	
		}//4
		Else
		{//5
			let stamina = owner.findinventory("usedstamina",true);
				if (owner.health <= 40 && owner.health > 0 && stamina && owner.countinv("usedstamina") >= 70) 
					{ owner.A_StartSound("TIREHURT", 500, CHANF_LOOPING,0.4,0,0.8); }
				else if (owner.health <= 40 && owner.health > 0)
					{ owner.A_StartSound("HURTCUE", 500, CHANF_LOOPING,0.4,0,0.8); }
				else if (stamina && owner.countinv("usedstamina") >= 70 && owner.health > 0)
					{ owner.A_StartSound("TIREDCUE", 500, CHANF_LOOPING,0.4,0,0.8); }
				else 
					{ owner.a_stopsound(500); }
		}//5
	  }//3
	Else
	{ owner.a_stopsound(500); }			
   }//2
}//1

Class StickyChild : Actor
{
  protected bool dead;
  override void Tick()
  {
    super.Tick();
    if (!dead && (!master || master.health <= 0))
    {
      dead = true;
      SetStateLabel("Deadmaster");
    }
  }
}