[Bugfix] Load zone variables before encounter_load. (#4846)

This commit is contained in:
zimp-wow 2025-04-09 20:59:19 -05:00 committed by GitHub
parent b883888a19
commit 4fc0ffd173
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 12 deletions

View File

@ -1191,6 +1191,11 @@ bool Zone::Init(bool is_static) {
RespawnTimesRepository::ClearExpiredRespawnTimers(database);
// Loading zone variables so they're available for things like encounter_load
if (RuleB(Zone, StateSavingOnShutdown)) {
zone->LoadZoneVariablesState();
}
// make sure that anything that needs to be loaded prior to scripts is loaded before here
// this is to ensure that the scripts have access to the data they need
parse->ReloadQuests(true);

View File

@ -476,6 +476,7 @@ public:
inline uint32 GetZoneServerId() const { return m_zone_server_id; }
// zone state
bool LoadZoneVariablesState();
bool LoadZoneState(
std::unordered_map<uint32, uint32> spawn_times,
std::vector<Spawn2DisabledRepository::Spawn2Disabled> disabled_spawns

View File

@ -381,6 +381,31 @@ inline void LoadZoneVariables(Zone *z, const std::string &variables)
}
}
bool Zone::LoadZoneVariablesState()
{
auto spawn_states = ZoneStateSpawnsRepository::GetWhere(
database,
fmt::format(
"zone_id = {} AND instance_id = {} AND is_zone = 1 ORDER BY spawn2_id",
zoneid,
zone->GetInstanceID()
)
);
if (spawn_states.empty()) {
return false;
}
for (auto &s: spawn_states) {
if (s.is_zone) {
LoadZoneVariables(zone, s.entity_variables);
return true;
}
}
return false;
}
bool Zone::LoadZoneState(
std::unordered_map<uint32, uint32> spawn_times,
std::vector<Spawn2DisabledRepository::Spawn2Disabled> disabled_spawns
@ -389,18 +414,19 @@ bool Zone::LoadZoneState(
auto spawn_states = ZoneStateSpawnsRepository::GetWhere(
database,
fmt::format(
"zone_id = {} AND instance_id = {} ORDER BY spawn2_id",
"zone_id = {} AND instance_id = {} AND is_zone = 0 ORDER BY spawn2_id",
zoneid,
zone->GetInstanceID()
)
);
LogInfo("Loading zone state spawns for zone [{}] spawns [{}]", GetShortName(), spawn_states.size());
if (spawn_states.empty()) {
LogInfo("No zone state spawns found for zone [{}] instance [{}]", GetShortName(), zone->GetInstanceID());
return false;
}
LogInfo("Loading zone state spawns for zone [{}] instance [{}] spawns [{}]", GetShortName(), zone->GetInstanceID(), spawn_states.size());
if (!IsZoneStateValid(spawn_states)) {
LogZoneState("Invalid zone state data for zone [{}]", GetShortName());
ClearZoneState(zoneid, zone->GetInstanceID());
@ -414,16 +440,8 @@ bool Zone::LoadZoneState(
zone->initgrids_timer.Trigger();
zone->Process();
// load zone variables first
int count = 0;
for (auto &s: spawn_states) {
if (s.is_zone) {
LoadZoneVariables(zone, s.entity_variables);
break;
}
}
// spawn2
int count = 0;
for (auto &s: spawn_states) {
if (s.spawngroup_id == 0 || s.is_corpse || s.is_zone) {
continue;