diff --git a/zone/zone.cpp b/zone/zone.cpp index 448373156..97d6973cd 100644 --- a/zone/zone.cpp +++ b/zone/zone.cpp @@ -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); diff --git a/zone/zone.h b/zone/zone.h index d7de16f9b..3a130818a 100755 --- a/zone/zone.h +++ b/zone/zone.h @@ -476,6 +476,7 @@ public: inline uint32 GetZoneServerId() const { return m_zone_server_id; } // zone state + bool LoadZoneVariablesState(); bool LoadZoneState( std::unordered_map spawn_times, std::vector disabled_spawns diff --git a/zone/zone_save_state.cpp b/zone/zone_save_state.cpp index c0adaaf12..f5e97a571 100644 --- a/zone/zone_save_state.cpp +++ b/zone/zone_save_state.cpp @@ -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 spawn_times, std::vector 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;