From bbe668bcec60d3cf1d9999efc7ed73c05c06df7c Mon Sep 17 00:00:00 2001 From: alemidev Date: Thu, 5 May 2022 10:30:57 +0200 Subject: [PATCH] track HP changes --- src/treepuncher/game/state.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/treepuncher/game/state.py b/src/treepuncher/game/state.py index 62bf83e..1e9d15f 100644 --- a/src/treepuncher/game/state.py +++ b/src/treepuncher/game/state.py @@ -102,12 +102,17 @@ class GameState(Scaffold): @self.on_packet(PacketUpdateHealth) async def player_hp_cb(packet:PacketUpdateHealth): died = packet.health != self.hp and packet.health <= 0 + if self.hp != packet.health: + if self.hp < packet.health: + self.logger.info("Healed by %.1f (%.1f HP)", packet.health - self.hp, packet.health) + else: + self.logger.info("Took %.1f damage (%.1f HP)", self.hp - packet.health, packet.health) self.hp = packet.health self.food = packet.food + packet.foodSaturation if died: self.run_callbacks(DeathEvent, DeathEvent()) - self.logger.info("Dead, respawning...") - await asyncio.sleep(0.5) + self.logger.warning("Died, attempting to respawn") + await asyncio.sleep(0.5) # TODO make configurable await self.dispatcher.write( PacketClientCommand(self.dispatcher.proto, actionId=0) # respawn )