[Zone] State Save Improvements (#4765)

* [Zone] State saving improvements

* Make sure we load spawn enabled off of the state row

* Update npc.h

* Update spawn2.cpp

* Update database_instances.cpp

* Update database_instances.cpp
This commit is contained in:
Chris Miles
2025-03-08 03:15:42 -06:00
committed by GitHub
parent 53610c2f0f
commit a8fea95eab
5 changed files with 59 additions and 10 deletions
+28
View File
@@ -608,6 +608,34 @@ public:
inline void SetResumedFromZoneSuspend(bool state = true) { m_resumed_from_zone_suspend = state; }
inline bool IsResumedFromZoneSuspend() { return m_resumed_from_zone_suspend; }
inline void LoadBuffsFromState(std::vector<Buffs_Struct> in_buffs) {
int i = 0;
for (auto &b: in_buffs) {
buffs[i].spellid = b.spellid;
buffs[i].casterlevel = b.casterlevel;
buffs[i].casterid = b.casterid;
strncpy(buffs[i].caster_name, b.caster_name, 64);
buffs[i].ticsremaining = b.ticsremaining;
buffs[i].counters = b.counters;
buffs[i].hit_number = b.hit_number;
buffs[i].melee_rune = b.melee_rune;
buffs[i].magic_rune = b.magic_rune;
buffs[i].dot_rune = b.dot_rune;
buffs[i].caston_x = b.caston_x;
buffs[i].caston_y = b.caston_y;
buffs[i].caston_z = b.caston_z;
buffs[i].ExtraDIChance = b.ExtraDIChance;
buffs[i].RootBreakChance = b.RootBreakChance;
buffs[i].instrument_mod = b.instrument_mod;
buffs[i].virus_spread_time = b.virus_spread_time;
buffs[i].persistant_buff = b.persistant_buff;
buffs[i].client = b.client;
buffs[i].UpdateClient = b.UpdateClient;
i++;
}
CalcBonuses();
}
protected:
void HandleRoambox();
+7 -1
View File
@@ -198,7 +198,13 @@ bool Spawn2::Process() {
}
//have the spawn group pick an NPC for us
uint32 npcid = currentnpcid && currentnpcid > 0 ? currentnpcid : spawn_group->GetNPCType(condition_value);
uint32 npcid = 0;
if (RuleB(Zone, StateSavingOnShutdown) && currentnpcid && currentnpcid > 0) {
npcid = currentnpcid;
} else {
npcid = spawn_group->GetNPCType(condition_value);
}
if (npcid == 0) {
LogSpawns("Spawn2 [{}]: Spawn group [{}] did not yeild an NPC! not spawning", spawn2_id, spawngroup_id_);
+15 -8
View File
@@ -171,6 +171,10 @@ inline std::string GetLootSerialized(Corpse *c)
inline void LoadNPCEntityVariables(NPC *n, const std::string &entity_variables)
{
if (!RuleB(Zone, StateSaveEntityVariables)) {
return;
}
if (!Strings::IsValidJson(entity_variables)) {
LogZoneState("Invalid JSON data for NPC [{}]", n->GetNPCTypeID());
return;
@@ -196,6 +200,10 @@ inline void LoadNPCEntityVariables(NPC *n, const std::string &entity_variables)
inline void LoadNPCBuffs(NPC *n, const std::string &buffs)
{
if (!RuleB(Zone, StateSaveBuffs)) {
return;
}
if (!Strings::IsValidJson(buffs)) {
LogZoneState("Invalid JSON data for NPC [{}]", n->GetNPCTypeID());
return;
@@ -214,10 +222,7 @@ inline void LoadNPCBuffs(NPC *n, const std::string &buffs)
return;
}
for (const auto &b: valid_buffs) {
// int AddBuff(Mob *caster, const uint16 spell_id, int duration = 0, int32 level_override = -1, bool disable_buff_overwrite = false);
n->AddBuff(n, b.spellid, b.ticsremaining, b.casterlevel, false);
}
n->LoadBuffsFromState(valid_buffs);
}
inline std::vector<uint32_t> GetLootdropIds(const std::vector<ZoneStateSpawnsRepository::ZoneStateSpawns> &spawn_states)
@@ -225,7 +230,8 @@ inline std::vector<uint32_t> GetLootdropIds(const std::vector<ZoneStateSpawnsRep
LogInfo("Loading lootdrop ids for zone state spawns");
std::vector<uint32_t> lootdrop_ids;
for (auto &s: spawn_states) {
for (auto &s: spawn_states) {
if (s.loot_data.empty()) {
continue;
}
@@ -347,7 +353,7 @@ bool Zone::LoadZoneState(
(bool) s.path_when_zone_idle,
s.condition_id,
s.condition_min_value,
spawn_enabled,
(s.enabled && spawn_enabled),
(EmuAppearance) s.anim
);
@@ -415,7 +421,8 @@ inline void SaveNPCState(NPC *n, ZoneStateSpawnsRepository::ZoneStateSpawns &s)
{
// entity variables
std::map<std::string, std::string> variables;
for (const auto &k: n->GetEntityVariables()) {
for (const auto &k: n->GetEntityVariables()) {
variables[k] = n->GetEntityVariable(k);
}
@@ -503,7 +510,7 @@ void Zone::SaveZoneState()
s.created_at = std::time(nullptr);
auto n = sp->GetNPC();
if (n) {
if (n && entity_list.GetNPCByID(n->GetID())) {
SaveNPCState(n, s);
}