
class BodyCarryEventHandler : EventHandler {
// TODO: Move to player class?
	void walkSlow(){
		if (PlayerInGame[0] && players[0].mo)
		{
			PlayerPawn pawn = PlayerPawn(players[0].mo);
			pawn.ForwardMove2 = 0.3;
			pawn.JumpZ = 0.3;
		}
	}
	
	void walkFast(){
		if (PlayerInGame[0] && players[0].mo)
		{
			PlayerPawn pawn = PlayerPawn(players[0].mo);
			pawn.ForwardMove2 = 1;
			pawn.JumpZ = 7;
		}
	}

	bool checkForToilet() {
		for (let i = BlockThingsIterator.Create(players[0].mo, 20); i.Next();) {
			Actor other = i.thing;
			// TODO: Subclass these
			if(other && (other.GetClassname() == "nutoilet" || other.GetClassname() == "nutoilet2")){
				other.GiveInventory("BodyOnToilet", 1);
				console.printf("you place the woman on the toilet");
				return true;
				break;
			}
		}
		return false;
	}

	bool PlayerHasCorpse() {

		ThinkerIterator CarryFinder = ThinkerIterator.Create("Carry");
		Actor mo;
		while (mo = Carry(CarryFinder.Next())){

			if(players[0].mo.CountInv(mo.GetClassName()) > 0){
				return true;
				break;
			}
		}
		return false;

	}

	override void NetworkProcess(ConsoleEvent e) {
		bool playerHasCorpse = PlayerhasCorpse();

		if (e.Name == "carry_corpse") {
			// TODO: Clean Up Boolean logic
			bool isCarrying = PlayerHasCorpse();
			if(!isCarrying){
				for (let i = BlockThingsIterator.Create(players[0].mo, 100); i.Next();) {
					Actor other = i.thing;
					if(other && other.GetParentClass().GetClassname() == "CarryableCorpse"){
						string corpseClass = other.getClassName();
						let corpse = CarryableCorpse(other);
						string carryClass = corpse.Carry;
						other.Destroy();
						players[0].mo.GiveInventory(carryClass, 1);
						players[0].mo.A_SelectWeapon(carryClass);
						players[0].mo.A_PlaySound("grunt5");
						walkSlow();
						break;
					}
				}
				
			} else {
				
				bool corpseSpawned = false;
				ThinkerIterator CarryFinder = ThinkerIterator.Create("Carry");
				Actor mo;
				while (mo = Carry(CarryFinder.Next()))
				{
					if(mo){
						// not sure why this needs to be done again
						let cc = Carry(mo);
						string corpseToSpawn = cc.Corpse;
						if(!corpseSpawned){
							actor b = Actor.Spawn(
								corpseToSpawn,
								players[0].mo.pos
							);
							corpseSpawned = true;
						}
						// regardless if a corpse is spawned, remove from inventory
						// this is to prevent an edge case if multiple corpses are given to the player (race condition?)
						players[0].mo.TakeInventory(cc.getClassName(), 55);
					}

				}
				players[0].mo.A_PlaySound("bodydump");
				walkFast();
			}
		}
	}
}
