1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-27 17:28:41 +00:00

Allow detection of damage greater than HP (#15160)

Co-authored-by: Gregor Parzefall <gregor.parzefall@posteo.de>
This commit is contained in:
sfence 2024-09-27 21:34:52 +02:00 committed by GitHub
parent fbb0e82679
commit 610ddaba7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 77 additions and 15 deletions

View file

@ -519,12 +519,13 @@ void PlayerSAO::rightClick(ServerActiveObject *clicker)
void PlayerSAO::setHP(s32 target_hp, const PlayerHPChangeReason &reason, bool from_client)
{
target_hp = rangelim(target_hp, 0, U16_MAX);
if (target_hp == m_hp)
if (target_hp == m_hp || (m_hp == 0 && target_hp < 0))
return; // Nothing to do
s32 hp_change = m_env->getScriptIface()->on_player_hpchange(this, target_hp - (s32)m_hp, reason);
// Protect against overflow.
s32 hp_change = std::max<s64>((s64)target_hp - (s64)m_hp, S32_MIN);
hp_change = m_env->getScriptIface()->on_player_hpchange(this, hp_change, reason);
hp_change = std::min<s32>(hp_change, U16_MAX); // Protect against overflow
s32 hp = (s32)m_hp + hp_change;