1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51: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

@ -1095,11 +1095,12 @@ PlayerSAO* Server::StageTwoClientInit(session_t peer_id)
// Send inventory
SendInventory(playersao, false);
// Send HP or death screen
// Send HP
SendPlayerHP(playersao);
// Send death screen
if (playersao->isDead())
SendDeathscreen(peer_id, false, v3f(0,0,0));
else
SendPlayerHP(peer_id);
// Send Breath
SendPlayerBreath(playersao);
@ -1365,18 +1366,21 @@ void Server::SendMovement(session_t peer_id)
Send(&pkt);
}
void Server::SendPlayerHPOrDie(PlayerSAO *playersao, const PlayerHPChangeReason &reason)
void Server::HandlePlayerHPChange(PlayerSAO *playersao, const PlayerHPChangeReason &reason)
{
if (playersao->isImmortal())
return;
m_script->player_event(playersao, "health_changed");
SendPlayerHP(playersao);
session_t peer_id = playersao->getPeerID();
bool is_alive = !playersao->isDead();
// Send to other clients
playersao->sendPunchCommand();
if (is_alive)
SendPlayerHP(peer_id);
else
DiePlayer(peer_id, reason);
if (playersao->isDead())
HandlePlayerDeath(playersao, reason);
}
void Server::SendPlayerHP(PlayerSAO *playersao)
{
SendHP(playersao->getPeerID(), playersao->getHP());
}
void Server::SendHP(session_t peer_id, u16 hp)
@ -1810,18 +1814,6 @@ void Server::SendTimeOfDay(session_t peer_id, u16 time, f32 time_speed)
}
}
void Server::SendPlayerHP(session_t peer_id)
{
PlayerSAO *playersao = getPlayerSAO(peer_id);
assert(playersao);
SendHP(peer_id, playersao->getHP());
m_script->player_event(playersao,"health_changed");
// Send to other clients
playersao->sendPunchCommand();
}
void Server::SendPlayerBreath(PlayerSAO *sao)
{
assert(sao);
@ -2750,23 +2742,18 @@ void Server::sendDetachedInventories(session_t peer_id, bool incremental)
Something random
*/
void Server::DiePlayer(session_t peer_id, const PlayerHPChangeReason &reason)
void Server::HandlePlayerDeath(PlayerSAO *playersao, const PlayerHPChangeReason &reason)
{
PlayerSAO *playersao = getPlayerSAO(peer_id);
assert(playersao);
infostream << "Server::DiePlayer(): Player "
<< playersao->getPlayer()->getName()
<< " dies" << std::endl;
playersao->setHP(0, reason);
playersao->clearParentAttachment();
// Trigger scripted stuff
m_script->on_dieplayer(playersao, reason);
SendPlayerHP(peer_id);
SendDeathscreen(peer_id, false, v3f(0,0,0));
SendDeathscreen(playersao->getPeerID(), false, v3f(0,0,0));
}
void Server::RespawnPlayer(session_t peer_id)
@ -2787,8 +2774,6 @@ void Server::RespawnPlayer(session_t peer_id)
// setPos will send the new position to client
playersao->setPos(findSpawnPos());
}
SendPlayerHP(peer_id);
}