feat(Core/World): Implement DoForAllPlayers() helper for all online p… (#18060)

* feat(Core/World): Implement DoForAllPlayers() helper for all online players

* Update src/server/game/World/World.cpp

Co-authored-by: Winfidonarleyan <dowlandtop@yandex.com>

* Update src/server/game/World/World.cpp

Co-authored-by: Winfidonarleyan <dowlandtop@yandex.com>

* rename

* Update WorldMock.h

* Update WorldMock.h

---------

Co-authored-by: Winfidonarleyan <dowlandtop@yandex.com>
This commit is contained in:
Andrew
2024-01-01 09:57:57 -03:00
committed by GitHub
parent adccad8499
commit e3fd42f3d4
5 changed files with 24 additions and 4 deletions

View File

@@ -608,6 +608,7 @@ public:
[[nodiscard]] virtual std::string const& GetRealmName() const = 0;
virtual void SetRealmName(std::string name) = 0;
virtual void RemoveOldCorpses() = 0;
virtual void DoForAllOnlinePlayers(std::function<void(Player*)> exec) = 0;
};
#endif //AZEROTHCORE_IWORLD_H

View File

@@ -3253,6 +3253,23 @@ void World::RemoveOldCorpses()
_timers[WUPDATE_CORPSES].SetCurrent(_timers[WUPDATE_CORPSES].GetInterval());
}
void World::DoForAllOnlinePlayers(std::function<void(Player*)> exec)
{
std::shared_lock lock(*HashMapHolder<Player>::GetLock());
for (auto const& it : ObjectAccessor::GetPlayers())
{
if (Player* player = it.second)
{
if (!player->IsInWorld())
{
continue;
}
exec(player);
}
}
}
bool World::IsPvPRealm() const
{
return getIntConfig(CONFIG_GAME_TYPE) == REALM_TYPE_PVP || getIntConfig(CONFIG_GAME_TYPE) == REALM_TYPE_RPPVP || getIntConfig(CONFIG_GAME_TYPE) == REALM_TYPE_FFA_PVP;

View File

@@ -349,6 +349,8 @@ public:
void RemoveOldCorpses() override;
void DoForAllOnlinePlayers(std::function<void(Player*)> exec) override;
protected:
void _UpdateGameTime();
// callback for UpdateRealmCharacters