1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Send Player HP when setHP (or a setHP caller) is called instead of looping and testing the state change.

This commit is contained in:
Loic Blot 2015-03-02 17:31:31 +01:00
parent 056e8f7839
commit 64ff966bae
6 changed files with 54 additions and 42 deletions

View file

@ -893,12 +893,7 @@ void Server::handleCommand_Damage(NetworkPacket* pkt)
<< std::endl;
playersao->setHP(playersao->getHP() - damage);
if (playersao->getHP() == 0 && playersao->m_hp_not_sent)
DiePlayer(pkt->getPeerId());
if (playersao->m_hp_not_sent)
SendPlayerHP(pkt->getPeerId());
SendPlayerHPOrDie(playersao->getPeerID(), playersao->getHP() == 0);
}
}
@ -1048,8 +1043,8 @@ void Server::handleCommand_Respawn(NetworkPacket* pkt)
RespawnPlayer(pkt->getPeerId());
actionstream<<player->getName()<<" respawns at "
<<PP(player->getPosition()/BS)<<std::endl;
actionstream << player->getName() << " respawns at "
<< PP(player->getPosition()/BS) << std::endl;
// ActiveObject is added to environment in AsyncRunStep after
// the previous addition has been succesfully removed
@ -1234,8 +1229,24 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
).normalize();
float time_from_last_punch =
playersao->resetTimeFromLastPunch();
s16 src_original_hp = pointed_object->getHP();
s16 dst_origin_hp = playersao->getHP();
pointed_object->punch(dir, &toolcap, playersao,
time_from_last_punch);
// If the object is a player and its HP changed
if (src_original_hp != pointed_object->getHP() &&
pointed_object->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
SendPlayerHPOrDie(((PlayerSAO*)pointed_object)->getPeerID(),
pointed_object->getHP() == 0);
}
// If the puncher is a player and its HP changed
if (dst_origin_hp != playersao->getHP()) {
SendPlayerHPOrDie(playersao->getPeerID(), playersao->getHP() == 0);
}
}
} // action == 0