ClientEvent *event = new ClientEvent();
event->type = CE_PLAYER_DAMAGE;
event->player_damage.amount = damage;
+ event->player_damage.effect = true;
m_client_event_queue.push(event);
}
}
struct
{
u16 amount;
+ bool effect;
} player_damage;
struct
{
if (client->modsLoaded())
client->getScript()->on_damage_taken(event->player_damage.amount);
+ if (!event->player_damage.effect)
+ return;
+
// Damage flash and hurt tilt are not used at death
if (client->getHP() > 0) {
LocalPlayer *player = client->getEnv().getLocalPlayer();
u16 hp;
*pkt >> hp;
+ bool damage_effect = true;
+ try {
+ *pkt >> damage_effect;
+ } catch (PacketError &e) {};
player->hp = hp;
ClientEvent *event = new ClientEvent();
event->type = CE_PLAYER_DAMAGE;
event->player_damage.amount = oldhp - hp;
+ event->player_damage.effect = damage_effect;
m_client_event_queue.push(event);
}
}
prop->hp_max = (u16)rangelim(hp_max, 0, U16_MAX);
if (prop->hp_max < sao->getHP()) {
- PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP);
+ PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP_MAX);
sao->setHP(prop->hp_max, reason);
}
}
SendInventory(playersao, false);
// Send HP
- SendPlayerHP(playersao);
+ SendPlayerHP(playersao, false);
// Send death screen
if (playersao->isDead())
void Server::HandlePlayerHPChange(PlayerSAO *playersao, const PlayerHPChangeReason &reason)
{
m_script->player_event(playersao, "health_changed");
- SendPlayerHP(playersao);
+ SendPlayerHP(playersao, reason.type != PlayerHPChangeReason::SET_HP_MAX);
// Send to other clients
playersao->sendPunchCommand();
HandlePlayerDeath(playersao, reason);
}
-void Server::SendPlayerHP(PlayerSAO *playersao)
+void Server::SendPlayerHP(PlayerSAO *playersao, bool effect)
{
- SendHP(playersao->getPeerID(), playersao->getHP());
+ SendHP(playersao->getPeerID(), playersao->getHP(), effect);
}
-void Server::SendHP(session_t peer_id, u16 hp)
+void Server::SendHP(session_t peer_id, u16 hp, bool effect)
{
- NetworkPacket pkt(TOCLIENT_HP, 1, peer_id);
- pkt << hp;
+ NetworkPacket pkt(TOCLIENT_HP, 3, peer_id);
+ pkt << hp << effect;
Send(&pkt);
}
void printToConsoleOnly(const std::string &text);
void HandlePlayerHPChange(PlayerSAO *sao, const PlayerHPChangeReason &reason);
- void SendPlayerHP(PlayerSAO *sao);
+ void SendPlayerHP(PlayerSAO *sao, bool effect);
void SendPlayerBreath(PlayerSAO *sao);
void SendInventory(PlayerSAO *playerSAO, bool incremental);
void SendMovePlayer(session_t peer_id);
void init();
void SendMovement(session_t peer_id);
- void SendHP(session_t peer_id, u16 hp);
+ void SendHP(session_t peer_id, u16 hp, bool effect);
void SendBreath(session_t peer_id, u16 breath);
void SendAccessDenied(session_t peer_id, AccessDeniedCode reason,
const std::string &custom_reason, bool reconnect = false);
m_hp = hp;
m_env->getGameDef()->HandlePlayerHPChange(this, reason);
} else if (from_client)
- m_env->getGameDef()->SendPlayerHP(this);
+ m_env->getGameDef()->SendPlayerHP(this, true);
}
void PlayerSAO::setBreath(const u16 breath, bool send)
enum Type : u8
{
SET_HP,
+ SET_HP_MAX, // internal type to allow distinguishing hp reset and damage (for effects)
PLAYER_PUNCH,
FALL,
NODE_DAMAGE,
{
switch (type) {
case PlayerHPChangeReason::SET_HP:
+ case PlayerHPChangeReason::SET_HP_MAX:
return "set_hp";
case PlayerHPChangeReason::PLAYER_PUNCH:
return "punch";