remove player from team when leaving
This commit is contained in:
@@ -20,6 +20,10 @@ void Game::Tick(std::uint64_t delta) {
|
||||
void Game::Reset() {
|
||||
m_World->Reset();
|
||||
|
||||
for (auto team : m_Teams) {
|
||||
team.ClearPlayers();
|
||||
}
|
||||
|
||||
for (auto& [id, player] : m_Players) {
|
||||
player.SetExp(0);
|
||||
player.SetGold(0);
|
||||
@@ -43,5 +47,20 @@ const Player* Game::GetPlayerById(PlayerID id) const {
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
void Game::RemovePlayer(PlayerID pId) {
|
||||
Player* player = GetPlayerById(pId);
|
||||
|
||||
if (!player) return;
|
||||
|
||||
TeamColor team = player->GetTeamColor();
|
||||
|
||||
GetTeam(team).RemovePlayer(player);
|
||||
auto it = GetPlayers().find(pId);
|
||||
|
||||
if (it == GetPlayers().end()) return;
|
||||
|
||||
GetPlayers().erase(it);
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
} // namespace td
|
||||
|
||||
Reference in New Issue
Block a user