Skip to content

Commit

Permalink
fix: health and death sync bug
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed Feb 22, 2022
1 parent f7e41cd commit 126edee
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Code/client/Events/HealthChangeEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ struct HealthChangeEvent
{
HealthChangeEvent(uint32_t aHitteeId, float aDeltaHealth)
: HitteeId(aHitteeId), DeltaHealth(aDeltaHealth)
{}
{
}

uint32_t HitteeId;
float DeltaHealth;
Expand Down
5 changes: 3 additions & 2 deletions Code/server/GameServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,12 @@ void GameServer::SendToLoaded(const ServerMessage& acServerMessage) const
}
}

void GameServer::SendToPlayers(const ServerMessage& acServerMessage) const
void GameServer::SendToPlayers(const ServerMessage& acServerMessage, const Player* apExcludeSender) const
{
for (auto pPlayer : m_pWorld->GetPlayerManager())
{
pPlayer->Send(acServerMessage);
if (pPlayer != apExcludeSender)
pPlayer->Send(acServerMessage);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Code/server/GameServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct GameServer final : Server
void Send(ConnectionId_t aConnectionId, const ServerMessage& acServerMessage) const;
void Send(ConnectionId_t aConnectionId, const ServerAdminMessage& acServerMessage) const;
void SendToLoaded(const ServerMessage& acServerMessage) const;
void SendToPlayers(const ServerMessage& acServerMessage) const;
void SendToPlayers(const ServerMessage& acServerMessage, const Player* apExcludeSender = nullptr) const;
void SendToPlayersInRange(const ServerMessage& acServerMessage, const entt::entity acOrigin) const;

const Info& GetInfo() const noexcept
Expand Down
12 changes: 4 additions & 8 deletions Code/server/Services/ActorValueService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ void ActorValueService::OnActorValueChanges(const PacketEvent<RequestActorValueC
notify.Id = acMessage.Packet.Id;
notify.Values = acMessage.Packet.Values;

const entt::entity cEntity = static_cast<entt::entity>(message.Id);
GameServer::Get()->SendToPlayersInRange(notify, cEntity);
GameServer::Get()->SendToPlayers(notify, acMessage.pPlayer);
}

void ActorValueService::OnActorMaxValueChanges(const PacketEvent<RequestActorMaxValueChanges>& acMessage) const noexcept
Expand All @@ -74,8 +73,7 @@ void ActorValueService::OnActorMaxValueChanges(const PacketEvent<RequestActorMax
notify.Id = message.Id;
notify.Values = message.Values;

const entt::entity cEntity = static_cast<entt::entity>(message.Id);
GameServer::Get()->SendToPlayersInRange(notify, cEntity);
GameServer::Get()->SendToPlayers(notify, acMessage.pPlayer);
}

void ActorValueService::OnHealthChangeBroadcast(const PacketEvent<RequestHealthChangeBroadcast>& acMessage) const noexcept
Expand All @@ -86,8 +84,7 @@ void ActorValueService::OnHealthChangeBroadcast(const PacketEvent<RequestHealthC
notify.Id = message.Id;
notify.DeltaHealth = message.DeltaHealth;

const entt::entity cEntity = static_cast<entt::entity>(message.Id);
GameServer::Get()->SendToPlayersInRange(notify, cEntity);
GameServer::Get()->SendToPlayers(notify, acMessage.pPlayer);
}

void ActorValueService::OnDeathStateChange(const PacketEvent<RequestDeathStateChange>& acMessage) const noexcept
Expand All @@ -110,7 +107,6 @@ void ActorValueService::OnDeathStateChange(const PacketEvent<RequestDeathStateCh
notify.Id = message.Id;
notify.IsDead = message.IsDead;

const entt::entity cEntity = static_cast<entt::entity>(message.Id);
GameServer::Get()->SendToPlayersInRange(notify, cEntity);
GameServer::Get()->SendToPlayers(notify, acMessage.pPlayer);
}

0 comments on commit 126edee

Please sign in to comment.