mirror of
https://github.com/minetest/minetest.git
synced 2025-01-12 00:07:35 +01:00
No damage effects on hp_max change (#11846)
This commit is contained in:
parent
3eafcab64e
commit
f4a53f7ee6
@ -493,6 +493,7 @@ void Client::step(float dtime)
|
|||||||
ClientEvent *event = new ClientEvent();
|
ClientEvent *event = new ClientEvent();
|
||||||
event->type = CE_PLAYER_DAMAGE;
|
event->type = CE_PLAYER_DAMAGE;
|
||||||
event->player_damage.amount = damage;
|
event->player_damage.amount = damage;
|
||||||
|
event->player_damage.effect = true;
|
||||||
m_client_event_queue.push(event);
|
m_client_event_queue.push(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,7 @@ struct ClientEvent
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
u16 amount;
|
u16 amount;
|
||||||
|
bool effect;
|
||||||
} player_damage;
|
} player_damage;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -2605,6 +2605,9 @@ void Game::handleClientEvent_PlayerDamage(ClientEvent *event, CameraOrientation
|
|||||||
if (client->modsLoaded())
|
if (client->modsLoaded())
|
||||||
client->getScript()->on_damage_taken(event->player_damage.amount);
|
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
|
// Damage flash and hurt tilt are not used at death
|
||||||
if (client->getHP() > 0) {
|
if (client->getHP() > 0) {
|
||||||
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
||||||
|
@ -570,6 +570,10 @@ void Client::handleCommand_HP(NetworkPacket *pkt)
|
|||||||
|
|
||||||
u16 hp;
|
u16 hp;
|
||||||
*pkt >> hp;
|
*pkt >> hp;
|
||||||
|
bool damage_effect = true;
|
||||||
|
try {
|
||||||
|
*pkt >> damage_effect;
|
||||||
|
} catch (PacketError &e) {};
|
||||||
|
|
||||||
player->hp = hp;
|
player->hp = hp;
|
||||||
|
|
||||||
@ -581,6 +585,7 @@ void Client::handleCommand_HP(NetworkPacket *pkt)
|
|||||||
ClientEvent *event = new ClientEvent();
|
ClientEvent *event = new ClientEvent();
|
||||||
event->type = CE_PLAYER_DAMAGE;
|
event->type = CE_PLAYER_DAMAGE;
|
||||||
event->player_damage.amount = oldhp - hp;
|
event->player_damage.amount = oldhp - hp;
|
||||||
|
event->player_damage.effect = damage_effect;
|
||||||
m_client_event_queue.push(event);
|
m_client_event_queue.push(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ void read_object_properties(lua_State *L, int index,
|
|||||||
prop->hp_max = (u16)rangelim(hp_max, 0, U16_MAX);
|
prop->hp_max = (u16)rangelim(hp_max, 0, U16_MAX);
|
||||||
|
|
||||||
if (prop->hp_max < sao->getHP()) {
|
if (prop->hp_max < sao->getHP()) {
|
||||||
PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP);
|
PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP_MAX);
|
||||||
sao->setHP(prop->hp_max, reason);
|
sao->setHP(prop->hp_max, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1107,7 +1107,7 @@ PlayerSAO* Server::StageTwoClientInit(session_t peer_id)
|
|||||||
SendInventory(playersao, false);
|
SendInventory(playersao, false);
|
||||||
|
|
||||||
// Send HP
|
// Send HP
|
||||||
SendPlayerHP(playersao);
|
SendPlayerHP(playersao, false);
|
||||||
|
|
||||||
// Send death screen
|
// Send death screen
|
||||||
if (playersao->isDead())
|
if (playersao->isDead())
|
||||||
@ -1374,7 +1374,7 @@ void Server::SendMovement(session_t peer_id)
|
|||||||
void Server::HandlePlayerHPChange(PlayerSAO *playersao, const PlayerHPChangeReason &reason)
|
void Server::HandlePlayerHPChange(PlayerSAO *playersao, const PlayerHPChangeReason &reason)
|
||||||
{
|
{
|
||||||
m_script->player_event(playersao, "health_changed");
|
m_script->player_event(playersao, "health_changed");
|
||||||
SendPlayerHP(playersao);
|
SendPlayerHP(playersao, reason.type != PlayerHPChangeReason::SET_HP_MAX);
|
||||||
|
|
||||||
// Send to other clients
|
// Send to other clients
|
||||||
playersao->sendPunchCommand();
|
playersao->sendPunchCommand();
|
||||||
@ -1383,15 +1383,15 @@ void Server::HandlePlayerHPChange(PlayerSAO *playersao, const PlayerHPChangeReas
|
|||||||
HandlePlayerDeath(playersao, reason);
|
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);
|
NetworkPacket pkt(TOCLIENT_HP, 3, peer_id);
|
||||||
pkt << hp;
|
pkt << hp << effect;
|
||||||
Send(&pkt);
|
Send(&pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ public:
|
|||||||
void printToConsoleOnly(const std::string &text);
|
void printToConsoleOnly(const std::string &text);
|
||||||
|
|
||||||
void HandlePlayerHPChange(PlayerSAO *sao, const PlayerHPChangeReason &reason);
|
void HandlePlayerHPChange(PlayerSAO *sao, const PlayerHPChangeReason &reason);
|
||||||
void SendPlayerHP(PlayerSAO *sao);
|
void SendPlayerHP(PlayerSAO *sao, bool effect);
|
||||||
void SendPlayerBreath(PlayerSAO *sao);
|
void SendPlayerBreath(PlayerSAO *sao);
|
||||||
void SendInventory(PlayerSAO *playerSAO, bool incremental);
|
void SendInventory(PlayerSAO *playerSAO, bool incremental);
|
||||||
void SendMovePlayer(session_t peer_id);
|
void SendMovePlayer(session_t peer_id);
|
||||||
@ -439,7 +439,7 @@ private:
|
|||||||
void init();
|
void init();
|
||||||
|
|
||||||
void SendMovement(session_t peer_id);
|
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 SendBreath(session_t peer_id, u16 breath);
|
||||||
void SendAccessDenied(session_t peer_id, AccessDeniedCode reason,
|
void SendAccessDenied(session_t peer_id, AccessDeniedCode reason,
|
||||||
const std::string &custom_reason, bool reconnect = false);
|
const std::string &custom_reason, bool reconnect = false);
|
||||||
|
@ -495,7 +495,7 @@ void PlayerSAO::setHP(s32 target_hp, const PlayerHPChangeReason &reason, bool fr
|
|||||||
m_hp = hp;
|
m_hp = hp;
|
||||||
m_env->getGameDef()->HandlePlayerHPChange(this, reason);
|
m_env->getGameDef()->HandlePlayerHPChange(this, reason);
|
||||||
} else if (from_client)
|
} else if (from_client)
|
||||||
m_env->getGameDef()->SendPlayerHP(this);
|
m_env->getGameDef()->SendPlayerHP(this, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerSAO::setBreath(const u16 breath, bool send)
|
void PlayerSAO::setBreath(const u16 breath, bool send)
|
||||||
|
@ -235,6 +235,7 @@ struct PlayerHPChangeReason
|
|||||||
enum Type : u8
|
enum Type : u8
|
||||||
{
|
{
|
||||||
SET_HP,
|
SET_HP,
|
||||||
|
SET_HP_MAX, // internal type to allow distinguishing hp reset and damage (for effects)
|
||||||
PLAYER_PUNCH,
|
PLAYER_PUNCH,
|
||||||
FALL,
|
FALL,
|
||||||
NODE_DAMAGE,
|
NODE_DAMAGE,
|
||||||
@ -277,6 +278,7 @@ struct PlayerHPChangeReason
|
|||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PlayerHPChangeReason::SET_HP:
|
case PlayerHPChangeReason::SET_HP:
|
||||||
|
case PlayerHPChangeReason::SET_HP_MAX:
|
||||||
return "set_hp";
|
return "set_hp";
|
||||||
case PlayerHPChangeReason::PLAYER_PUNCH:
|
case PlayerHPChangeReason::PLAYER_PUNCH:
|
||||||
return "punch";
|
return "punch";
|
||||||
|
Loading…
Reference in New Issue
Block a user