1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00

Don't call on_dieplayer callback two times (#11874)

This commit is contained in:
savilli 2022-01-15 17:44:55 +01:00 committed by GitHub
parent 76e97e85a0
commit 72b14bd994
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 60 deletions

View file

@ -463,36 +463,33 @@ void PlayerSAO::rightClick(ServerActiveObject *clicker)
m_env->getScriptIface()->on_rightclickplayer(this, clicker);
}
void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason, bool send)
void PlayerSAO::setHP(s32 target_hp, const PlayerHPChangeReason &reason, bool from_client)
{
if (hp == (s32)m_hp)
target_hp = rangelim(target_hp, 0, U16_MAX);
if (target_hp == m_hp)
return; // Nothing to do
if (m_hp <= 0 && hp < (s32)m_hp)
return; // Cannot take more damage
s32 hp_change = m_env->getScriptIface()->on_player_hpchange(this, target_hp - (s32)m_hp, reason);
{
s32 hp_change = m_env->getScriptIface()->on_player_hpchange(this, hp - m_hp, reason);
if (hp_change == 0)
return;
s32 hp = (s32)m_hp + std::min(hp_change, U16_MAX); // Protection against s32 overflow
hp = rangelim(hp, 0, U16_MAX);
hp = m_hp + hp_change;
}
if (hp > m_prop.hp_max)
hp = m_prop.hp_max;
s32 oldhp = m_hp;
hp = rangelim(hp, 0, m_prop.hp_max);
if (hp < oldhp && isImmortal())
return; // Do not allow immortal players to be damaged
m_hp = hp;
if (hp < m_hp && isImmortal())
hp = m_hp; // Do not allow immortal players to be damaged
// Update properties on death
if ((hp == 0) != (oldhp == 0))
if ((hp == 0) != (m_hp == 0))
m_properties_sent = false;
if (send)
m_env->getGameDef()->SendPlayerHPOrDie(this, reason);
if (hp != m_hp) {
m_hp = hp;
m_env->getGameDef()->HandlePlayerHPChange(this, reason);
} else if (from_client)
m_env->getGameDef()->SendPlayerHP(this);
}
void PlayerSAO::setBreath(const u16 breath, bool send)