remove mobs on player leave

This commit is contained in:
Simon Pribylski
2023-08-26 10:46:20 +02:00
parent 8e7b446003
commit 5631efcf9e
5 changed files with 39 additions and 2 deletions

View File

@@ -123,6 +123,17 @@ void World::SpawnMobAt(MobID id, MobType type, std::uint8_t level, PlayerID send
GetMobNotifier().NotifyListeners(&MobListener::OnMobSpawn, mob.get());
}
MobPtr World::RemoveMob(MobID mobId) {
auto it = std::find_if(m_Mobs.begin(), m_Mobs.end(), [mobId](MobPtr mob) { return mob->GetMobID() == mobId;});
if (it == m_Mobs.end()) return nullptr;
MobPtr mob = *it;
m_Mobs.erase(it);
return mob;
}
TowerPtr World::PlaceTowerAt(TowerID id, TowerType type, std::int32_t x, std::int32_t y, PlayerID builder) {
TowerPtr tower = TowerFactory::CreateTower(type, id, x, y, builder);
m_Towers.push_back(tower);