remove towers on player leave

This commit is contained in:
Simon Pribylski
2023-08-26 10:25:52 +02:00
parent 1f94ae2586
commit 51ec035490
3 changed files with 19 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ public:
virtual void OnGameClose() override;
virtual void OnPlayerJoin(game::PlayerID id) override;
virtual void OnPlayerLeave(game::PlayerID id) override;
private:
void BalanceTeams();
void InitPlayerStats();

View File

@@ -219,7 +219,9 @@ public:
const TeamList& GetTeams() const;
TowerList& GetTowers() { return m_Towers; }
const TowerList& GetTowers() const { return m_Towers; }
TowerPtr GetTowerById(TowerID tower);
const Player* GetPlayerById(PlayerID id) const;

View File

@@ -2,6 +2,7 @@
#include "server/Server.h"
#include "td/protocol/packets/DisconnectPacket.h"
#include "td/protocol/packets/RemoveTowerPacket.h"
#include "td/protocol/packets/UpdatePlayerTeamPacket.h"
#include "td/protocol/packets/UpdateGameStatePacket.h"
#include "td/protocol/packets/UpdateMoneyPacket.h"
@@ -139,5 +140,20 @@ void ServerGame::OnPlayerJoin(game::PlayerID id){
BalanceTeams();
}
void ServerGame::OnPlayerLeave(game::PlayerID playerId){
// temporary fix
auto& towerList = GetWorld()->GetTowers();
for(std::size_t i = 0; i < towerList.size(); i++) {
auto tower = towerList.at(i);
if(tower->GetBuilder() == playerId) {
protocol::RemoveTowerPacket packet(tower->GetID());
m_Server->BroadcastPacket(&packet);
towerList.erase(towerList.begin() + i);
}
}
}
} // namespace game
} // namespace td