mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-30 17:13:47 +00:00
refactor(Core/World): Move various worldstate related functions to worldstate class. (#22086)
This commit is contained in:
@@ -564,9 +564,6 @@ public:
|
||||
[[nodiscard]] virtual float getFloatConfig(WorldFloatConfigs index) const = 0;
|
||||
virtual void setIntConfig(WorldIntConfigs index, uint32 value) = 0;
|
||||
[[nodiscard]] virtual uint32 getIntConfig(WorldIntConfigs index) const = 0;
|
||||
virtual void setWorldState(uint32 index, uint64 value) = 0;
|
||||
[[nodiscard]] virtual uint64 getWorldState(uint32 index) const = 0;
|
||||
virtual void LoadWorldStates() = 0;
|
||||
[[nodiscard]] virtual bool IsPvPRealm() const = 0;
|
||||
[[nodiscard]] virtual bool IsFFAPvPRealm() const = 0;
|
||||
virtual uint32 GetNextWhoListUpdateDelaySecs() = 0;
|
||||
|
||||
@@ -1753,8 +1753,9 @@ void World::SetInitialWorldSettings()
|
||||
LOG_INFO("server.loading", "Loading Creature Formations...");
|
||||
sFormationMgr->LoadCreatureFormations();
|
||||
|
||||
LOG_INFO("server.loading", "Loading World States..."); // must be loaded before battleground, outdoor PvP and conditions
|
||||
LoadWorldStates();
|
||||
LOG_INFO("server.loading", "Loading WorldStates..."); // must be loaded before battleground, outdoor PvP and conditions
|
||||
sWorldState->LoadWorldStates();
|
||||
sWorldState->Load();
|
||||
|
||||
LOG_INFO("server.loading", "Loading Conditions...");
|
||||
sConditionMgr->LoadConditions();
|
||||
@@ -1896,9 +1897,6 @@ void World::SetInitialWorldSettings()
|
||||
LOG_INFO("server.loading", "Loading Active Arena Season...");
|
||||
sArenaSeasonMgr->LoadActiveSeason();
|
||||
|
||||
LOG_INFO("server.loading", "Loading WorldState...");
|
||||
sWorldState->Load();
|
||||
|
||||
sTicketMgr->Initialize();
|
||||
|
||||
///- Initialize Battlegrounds
|
||||
@@ -2517,67 +2515,67 @@ void World::_UpdateRealmCharCount(PreparedQueryResult resultCharCount,uint32 acc
|
||||
|
||||
void World::InitWeeklyQuestResetTime()
|
||||
{
|
||||
Seconds wstime = Seconds(sWorld->getWorldState(WORLD_STATE_CUSTOM_WEEKLY_QUEST_RESET_TIME));
|
||||
Seconds wstime = Seconds(sWorldState->getWorldState(WORLD_STATE_CUSTOM_WEEKLY_QUEST_RESET_TIME));
|
||||
_nextWeeklyQuestReset = wstime > 0s ? wstime : Seconds(Acore::Time::GetNextTimeWithDayAndHour(4, 6));
|
||||
|
||||
if (wstime == 0s)
|
||||
{
|
||||
sWorld->setWorldState(WORLD_STATE_CUSTOM_WEEKLY_QUEST_RESET_TIME, _nextWeeklyQuestReset.count());
|
||||
sWorldState->setWorldState(WORLD_STATE_CUSTOM_WEEKLY_QUEST_RESET_TIME, _nextWeeklyQuestReset.count());
|
||||
}
|
||||
}
|
||||
|
||||
void World::InitDailyQuestResetTime()
|
||||
{
|
||||
Seconds wstime = Seconds(sWorld->getWorldState(WORLD_STATE_CUSTOM_DAILY_QUEST_RESET_TIME));
|
||||
Seconds wstime = Seconds(sWorldState->getWorldState(WORLD_STATE_CUSTOM_DAILY_QUEST_RESET_TIME));
|
||||
_nextDailyQuestReset = wstime > 0s ? wstime : Seconds(Acore::Time::GetNextTimeWithDayAndHour(-1, 6));
|
||||
|
||||
if (wstime == 0s)
|
||||
{
|
||||
sWorld->setWorldState(WORLD_STATE_CUSTOM_DAILY_QUEST_RESET_TIME, _nextDailyQuestReset.count());
|
||||
sWorldState->setWorldState(WORLD_STATE_CUSTOM_DAILY_QUEST_RESET_TIME, _nextDailyQuestReset.count());
|
||||
}
|
||||
}
|
||||
|
||||
void World::InitMonthlyQuestResetTime()
|
||||
{
|
||||
Seconds wstime = Seconds(sWorld->getWorldState(WORLD_STATE_CUSTOM_MONTHLY_QUEST_RESET_TIME));
|
||||
Seconds wstime = Seconds(sWorldState->getWorldState(WORLD_STATE_CUSTOM_MONTHLY_QUEST_RESET_TIME));
|
||||
_nextMonthlyQuestReset = wstime > 0s ? wstime : Seconds(Acore::Time::GetNextTimeWithDayAndHour(-1, 6));
|
||||
|
||||
if (wstime == 0s)
|
||||
{
|
||||
sWorld->setWorldState(WORLD_STATE_CUSTOM_MONTHLY_QUEST_RESET_TIME, _nextMonthlyQuestReset.count());
|
||||
sWorldState->setWorldState(WORLD_STATE_CUSTOM_MONTHLY_QUEST_RESET_TIME, _nextMonthlyQuestReset.count());
|
||||
}
|
||||
}
|
||||
|
||||
void World::InitRandomBGResetTime()
|
||||
{
|
||||
Seconds wstime = Seconds(sWorld->getWorldState(WORLD_STATE_CUSTOM_BG_DAILY_RESET_TIME));
|
||||
Seconds wstime = Seconds(sWorldState->getWorldState(WORLD_STATE_CUSTOM_BG_DAILY_RESET_TIME));
|
||||
_nextRandomBGReset = wstime > 0s ? wstime : Seconds(Acore::Time::GetNextTimeWithDayAndHour(-1, 6));
|
||||
|
||||
if (wstime == 0s)
|
||||
{
|
||||
sWorld->setWorldState(WORLD_STATE_CUSTOM_BG_DAILY_RESET_TIME, _nextRandomBGReset.count());
|
||||
sWorldState->setWorldState(WORLD_STATE_CUSTOM_BG_DAILY_RESET_TIME, _nextRandomBGReset.count());
|
||||
}
|
||||
}
|
||||
|
||||
void World::InitCalendarOldEventsDeletionTime()
|
||||
{
|
||||
Seconds currentDeletionTime = Seconds(getWorldState(WORLD_STATE_CUSTOM_DAILY_CALENDAR_DELETION_OLD_EVENTS_TIME));
|
||||
Seconds currentDeletionTime = Seconds(sWorldState->getWorldState(WORLD_STATE_CUSTOM_DAILY_CALENDAR_DELETION_OLD_EVENTS_TIME));
|
||||
Seconds nextDeletionTime = currentDeletionTime > 0s ? currentDeletionTime : Seconds(Acore::Time::GetNextTimeWithDayAndHour(-1, getIntConfig(CONFIG_CALENDAR_DELETE_OLD_EVENTS_HOUR)));
|
||||
|
||||
if (currentDeletionTime == 0s)
|
||||
{
|
||||
sWorld->setWorldState(WORLD_STATE_CUSTOM_DAILY_CALENDAR_DELETION_OLD_EVENTS_TIME, nextDeletionTime.count());
|
||||
sWorldState->setWorldState(WORLD_STATE_CUSTOM_DAILY_CALENDAR_DELETION_OLD_EVENTS_TIME, nextDeletionTime.count());
|
||||
}
|
||||
}
|
||||
|
||||
void World::InitGuildResetTime()
|
||||
{
|
||||
Seconds wstime = Seconds(getWorldState(WORLD_STATE_CUSTOM_GUILD_DAILY_RESET_TIME));
|
||||
Seconds wstime = Seconds(sWorldState->getWorldState(WORLD_STATE_CUSTOM_GUILD_DAILY_RESET_TIME));
|
||||
_nextGuildReset = wstime > 0s ? wstime : Seconds(Acore::Time::GetNextTimeWithDayAndHour(-1, 6));
|
||||
|
||||
if (wstime == 0s)
|
||||
{
|
||||
sWorld->setWorldState(WORLD_STATE_CUSTOM_GUILD_DAILY_RESET_TIME, _nextGuildReset.count());
|
||||
sWorldState->setWorldState(WORLD_STATE_CUSTOM_GUILD_DAILY_RESET_TIME, _nextGuildReset.count());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2592,7 +2590,7 @@ void World::ResetDailyQuests()
|
||||
itr->second->GetPlayer()->ResetDailyQuestStatus();
|
||||
|
||||
_nextDailyQuestReset = Seconds(Acore::Time::GetNextTimeWithDayAndHour(-1, 6));
|
||||
sWorld->setWorldState(WORLD_STATE_CUSTOM_DAILY_QUEST_RESET_TIME, _nextDailyQuestReset.count());
|
||||
sWorldState->setWorldState(WORLD_STATE_CUSTOM_DAILY_QUEST_RESET_TIME, _nextDailyQuestReset.count());
|
||||
|
||||
// change available dailies
|
||||
sPoolMgr->ChangeDailyQuests();
|
||||
@@ -2628,7 +2626,7 @@ void World::ResetWeeklyQuests()
|
||||
itr->second->GetPlayer()->ResetWeeklyQuestStatus();
|
||||
|
||||
_nextWeeklyQuestReset = Seconds(Acore::Time::GetNextTimeWithDayAndHour(4, 6));
|
||||
sWorld->setWorldState(WORLD_STATE_CUSTOM_WEEKLY_QUEST_RESET_TIME, _nextWeeklyQuestReset.count());
|
||||
sWorldState->setWorldState(WORLD_STATE_CUSTOM_WEEKLY_QUEST_RESET_TIME, _nextWeeklyQuestReset.count());
|
||||
|
||||
// change available weeklies
|
||||
sPoolMgr->ChangeWeeklyQuests();
|
||||
@@ -2647,7 +2645,7 @@ void World::ResetMonthlyQuests()
|
||||
itr->second->GetPlayer()->ResetMonthlyQuestStatus();
|
||||
|
||||
_nextMonthlyQuestReset = Seconds(Acore::Time::GetNextTimeWithMonthAndHour(-1, 6));
|
||||
sWorld->setWorldState(WORLD_STATE_CUSTOM_MONTHLY_QUEST_RESET_TIME, _nextMonthlyQuestReset.count());
|
||||
sWorldState->setWorldState(WORLD_STATE_CUSTOM_MONTHLY_QUEST_RESET_TIME, _nextMonthlyQuestReset.count());
|
||||
}
|
||||
|
||||
void World::ResetEventSeasonalQuests(uint16 event_id)
|
||||
@@ -2675,7 +2673,7 @@ void World::ResetRandomBG()
|
||||
itr->second->GetPlayer()->SetRandomWinner(false);
|
||||
|
||||
_nextRandomBGReset = Seconds(Acore::Time::GetNextTimeWithDayAndHour(-1, 6));
|
||||
sWorld->setWorldState(WORLD_STATE_CUSTOM_BG_DAILY_RESET_TIME, _nextRandomBGReset.count());
|
||||
sWorldState->setWorldState(WORLD_STATE_CUSTOM_BG_DAILY_RESET_TIME, _nextRandomBGReset.count());
|
||||
}
|
||||
|
||||
void World::CalendarDeleteOldEvents()
|
||||
@@ -2683,7 +2681,7 @@ void World::CalendarDeleteOldEvents()
|
||||
LOG_INFO("server.worldserver", "Calendar deletion of old events.");
|
||||
|
||||
_nextCalendarOldEventsDeletionTime = Seconds(Acore::Time::GetNextTimeWithDayAndHour(-1, getIntConfig(CONFIG_CALENDAR_DELETE_OLD_EVENTS_HOUR)));
|
||||
sWorld->setWorldState(WORLD_STATE_CUSTOM_DAILY_CALENDAR_DELETION_OLD_EVENTS_TIME, _nextCalendarOldEventsDeletionTime.count());
|
||||
sWorldState->setWorldState(WORLD_STATE_CUSTOM_DAILY_CALENDAR_DELETION_OLD_EVENTS_TIME, _nextCalendarOldEventsDeletionTime.count());
|
||||
sCalendarMgr->DeleteOldEvents();
|
||||
}
|
||||
|
||||
@@ -2692,7 +2690,7 @@ void World::ResetGuildCap()
|
||||
LOG_INFO("server.worldserver", "Guild Daily Cap reset.");
|
||||
|
||||
_nextGuildReset = Seconds(Acore::Time::GetNextTimeWithDayAndHour(-1, 6));
|
||||
sWorld->setWorldState(WORLD_STATE_CUSTOM_GUILD_DAILY_RESET_TIME, _nextGuildReset.count());
|
||||
sWorldState->setWorldState(WORLD_STATE_CUSTOM_GUILD_DAILY_RESET_TIME, _nextGuildReset.count());
|
||||
|
||||
sGuildMgr->ResetTimes();
|
||||
}
|
||||
@@ -2725,57 +2723,6 @@ void World::UpdateAreaDependentAuras()
|
||||
}
|
||||
}
|
||||
|
||||
void World::LoadWorldStates()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
QueryResult result = CharacterDatabase.Query("SELECT entry, value FROM worldstates");
|
||||
|
||||
if (!result)
|
||||
{
|
||||
LOG_WARN("server.loading", ">> Loaded 0 world states. DB table `worldstates` is empty!");
|
||||
LOG_INFO("server.loading", " ");
|
||||
return;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
_worldstates[fields[0].Get<uint32>()] = fields[1].Get<uint32>();
|
||||
} while (result->NextRow());
|
||||
|
||||
LOG_INFO("server.loading", ">> Loaded {} World States in {} ms", _worldstates.size(), GetMSTimeDiffToNow(oldMSTime));
|
||||
LOG_INFO("server.loading", " ");
|
||||
}
|
||||
|
||||
// Setting a worldstate will save it to DB
|
||||
void World::setWorldState(uint32 index, uint64 timeValue)
|
||||
{
|
||||
auto const& it = _worldstates.find(index);
|
||||
if (it != _worldstates.end())
|
||||
{
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_WORLDSTATE);
|
||||
stmt->SetData(0, uint32(timeValue));
|
||||
stmt->SetData(1, index);
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
else
|
||||
{
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_WORLDSTATE);
|
||||
stmt->SetData(0, index);
|
||||
stmt->SetData(1, uint32(timeValue));
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
|
||||
_worldstates[index] = timeValue;
|
||||
}
|
||||
|
||||
uint64 World::getWorldState(uint32 index) const
|
||||
{
|
||||
auto const& itr = _worldstates.find(index);
|
||||
return itr != _worldstates.end() ? itr->second : 0;
|
||||
}
|
||||
|
||||
void World::ProcessQueryCallbacks()
|
||||
{
|
||||
_queryProcessor.ProcessReadyCallbacks();
|
||||
|
||||
@@ -241,10 +241,6 @@ public:
|
||||
return index < INT_CONFIG_VALUE_COUNT ? _int_configs[index] : 0;
|
||||
}
|
||||
|
||||
void setWorldState(uint32 index, uint64 value) override;
|
||||
[[nodiscard]] uint64 getWorldState(uint32 index) const override;
|
||||
void LoadWorldStates() override;
|
||||
|
||||
/// Are we on a "Player versus Player" server?
|
||||
[[nodiscard]] bool IsPvPRealm() const override;
|
||||
[[nodiscard]] bool IsFFAPvPRealm() const override;
|
||||
@@ -318,8 +314,6 @@ private:
|
||||
uint32 _int_configs[INT_CONFIG_VALUE_COUNT];
|
||||
bool _bool_configs[BOOL_CONFIG_VALUE_COUNT];
|
||||
float _float_configs[FLOAT_CONFIG_VALUE_COUNT];
|
||||
typedef std::map<uint32, uint64> WorldStatesMap;
|
||||
WorldStatesMap _worldstates;
|
||||
AccountTypes _allowedSecurityLevel;
|
||||
LocaleConstant _defaultDbcLocale; // from config for one from loaded DBC locales
|
||||
uint32 _availableDbcLocaleMask; // by loaded DBC
|
||||
|
||||
@@ -95,6 +95,57 @@ void WorldState::Load()
|
||||
HandleSunsReachSubPhaseTransition(m_sunsReachData.m_subphaseMask, true);
|
||||
}
|
||||
|
||||
void WorldState::LoadWorldStates()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
QueryResult result = CharacterDatabase.Query("SELECT entry, value FROM worldstates");
|
||||
|
||||
if (!result)
|
||||
{
|
||||
LOG_WARN("server.loading", ">> Loaded 0 world states. DB table `worldstates` is empty!");
|
||||
LOG_INFO("server.loading", " ");
|
||||
return;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
_worldstates[fields[0].Get<uint32>()] = fields[1].Get<uint32>();
|
||||
} while (result->NextRow());
|
||||
|
||||
LOG_INFO("server.loading", ">> Loaded {} World States in {} ms", _worldstates.size(), GetMSTimeDiffToNow(oldMSTime));
|
||||
LOG_INFO("server.loading", " ");
|
||||
}
|
||||
|
||||
// Setting a worldstate will save it to DB
|
||||
void WorldState::setWorldState(uint32 index, uint64 timeValue)
|
||||
{
|
||||
auto const& it = _worldstates.find(index);
|
||||
if (it != _worldstates.end())
|
||||
{
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_WORLDSTATE);
|
||||
stmt->SetData(0, uint32(timeValue));
|
||||
stmt->SetData(1, index);
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
else
|
||||
{
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_WORLDSTATE);
|
||||
stmt->SetData(0, index);
|
||||
stmt->SetData(1, uint32(timeValue));
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
|
||||
_worldstates[index] = timeValue;
|
||||
}
|
||||
|
||||
uint64 WorldState::getWorldState(uint32 index) const
|
||||
{
|
||||
auto const& itr = _worldstates.find(index);
|
||||
return itr != _worldstates.end() ? itr->second : 0;
|
||||
}
|
||||
|
||||
void WorldState::Save(WorldStateSaveIds saveId)
|
||||
{
|
||||
switch (saveId)
|
||||
@@ -233,6 +284,7 @@ void WorldState::HandlePlayerEnterZone(Player* player, WorldStateZoneId zoneId)
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
void WorldState::HandlePlayerLeaveZone(Player* player, WorldStateZoneId zoneId)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_mutex);
|
||||
|
||||
@@ -177,6 +177,9 @@ class WorldState
|
||||
virtual ~WorldState();
|
||||
static WorldState* instance();
|
||||
void Load();
|
||||
void LoadWorldStates();
|
||||
void setWorldState(uint32 index, uint64 value);
|
||||
[[nodiscard]] uint64 getWorldState(uint32 index) const;
|
||||
void Save(WorldStateSaveIds saveId);
|
||||
void SaveHelper(std::string& stringToSave, WorldStateSaveIds saveId);
|
||||
void HandlePlayerEnterZone(Player* player, WorldStateZoneId zoneId);
|
||||
@@ -195,6 +198,8 @@ class WorldState
|
||||
void HandleSunwellGateTransition(uint32 newGate);
|
||||
void SetSunwellGateCounter(SunwellGateCounters index, uint32 value);
|
||||
private:
|
||||
typedef std::map<uint32, uint64> WorldStatesMap;
|
||||
WorldStatesMap _worldstates;
|
||||
void SendWorldstateUpdate(std::mutex& mutex, GuidVector const& guids, uint32 value, uint32 worldStateId);
|
||||
void StopSunsReachPhase(bool forward);
|
||||
void StartSunsReachPhase(bool initial = false);
|
||||
|
||||
Reference in New Issue
Block a user