[Corpses] Add corpse entity variables to DB

- When corpses have entity variables add/remove/modified it will update the database accordingly.
- Corpse loading will pull the database values if they exist.
This commit is contained in:
Trust
2025-06-10 23:10:02 -04:00
committed by Chris Miles
parent dc261bb203
commit be19f85a31
6 changed files with 84 additions and 0 deletions
+42
View File
@@ -32,7 +32,9 @@
#include "../common/repositories/character_corpse_items_repository.h"
#include <iostream>
#include "queryserv.h"
#include "../common/json/json.hpp"
using json = nlohmann::json;
extern EntityList entity_list;
extern Zone *zone;
@@ -674,6 +676,21 @@ bool Corpse::Save()
ce.drakkin_tattoo = drakkin_tattoo;
ce.drakkin_details = drakkin_details;
{
json j;
for (const auto& kv : m_EntityVariables) {
j[kv.first] = kv.second;
}
if (!j.empty()) {
ce.entity_variables = j.dump();
} else {
ce.entity_variables = "{}";
}
LogCorpses("Corpse entity_variables: %s", ce.entity_variables.c_str());
}
for (auto &item: m_item_list) {
CharacterCorpseItemEntry e;
@@ -2428,9 +2445,34 @@ Corpse *Corpse::LoadCharacterCorpse(
c->m_become_npc = false;
c->m_consented_guild_id = cc.guild_consent_id;
if (!cc.entity_variables.empty() && cc.entity_variables != "null") {
json j = json::parse(cc.entity_variables, nullptr, false);
if (!j.is_discarded()) {
for (auto& el : j.items()) {
c->SetEntityVariable(el.key(), el.value().get<std::string>());
}
}
}
c->IsRezzed(cc.is_rezzed);
c->UpdateEquipmentLight();
return c;
}
void Corpse::SyncEntityVariablesToCorpseDB()
{
if (!m_is_player_corpse || m_corpse_db_id == 0) {
return;
}
json j;
for (const auto& [key, value] : m_EntityVariables) {
j[key] = value;
}
std::string serialized = j.dump();
CharacterCorpsesRepository::UpdateEntityVariables(database, m_corpse_db_id, serialized);
}
+2
View File
@@ -244,6 +244,8 @@ public:
const glm::vec4 &position
);
void SyncEntityVariablesToCorpseDB();
protected:
void MoveItemToCorpse(Client *client, EQ::ItemInstance *inst, int16 equipSlot, std::list<uint32> &removedList);
+1
View File
@@ -336,6 +336,7 @@ struct CharacterCorpseEntry
uint32 drakkin_tattoo;
uint32 drakkin_details;
std::vector<CharacterCorpseItemEntry> items;
std::string entity_variables;
};
namespace BeastlordPetData {