mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-23 13:12:49 +00:00
feat: store each named pet's LOT in pet_names
pet_names gets a pet_lot column (mysql 80, sqlite 63). The world writes it whenever it saves a pet name, from the pet entity's LOT, and fills it in for older rows when the owner loads into a world (from the pets the game loads for that character, only where it is still missing). The dashboard's pet name tables read pet_lot instead of scanning the owner's character XML; pets without it yet show as Unknown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -90,24 +90,13 @@ namespace {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds each pet's LOT and kind (its CDClient name) to pet_names rows. pet_names doesn't hold the LOT; the owner's
|
||||
* save does (<pet><p id l/>), so each owner on the page is read once. Pets whose owner is unknown, or who have
|
||||
* left the owner's save, get lot 0.
|
||||
* Adds each pet's kind (its CDClient name) to pet_names rows, from the pet_lot the game writes (lot 0: not known yet).
|
||||
*/
|
||||
std::string WithPetKinds(const std::string& raw) {
|
||||
auto json = nlohmann::json::parse(raw, nullptr, false);
|
||||
if (json.is_discarded() || !json.contains("data") || !json["data"].is_array()) return raw;
|
||||
std::map<LWOOBJID, std::map<LWOOBJID, LOT>> owners;
|
||||
for (auto& row : json["data"]) {
|
||||
const auto owner = GeneralUtils::TryParse<LWOOBJID>(row.value("owner_id", std::string{})).value_or(0);
|
||||
const auto pet = GeneralUtils::TryParse<LWOOBJID>(row.value("id", std::string{})).value_or(0);
|
||||
LOT lot = 0;
|
||||
if (owner && pet) {
|
||||
auto [it, added] = owners.try_emplace(owner);
|
||||
if (added) for (const auto& held : CharacterXml::Pets(Database::Get()->GetCharacterXml(owner))) it->second[held.id] = held.lot;
|
||||
if (const auto found = it->second.find(pet); found != it->second.end()) lot = found->second;
|
||||
}
|
||||
row["lot"] = lot;
|
||||
const LOT lot = row.value("lot", 0);
|
||||
row["kind"] = lot > 0 ? ClientAssets::ItemName(lot) : "";
|
||||
}
|
||||
return json.dump();
|
||||
|
||||
@@ -137,7 +137,7 @@
|
||||
},
|
||||
// A pet's kind: its icon and CDClient name (rows from the pet name tables carry lot and kind)
|
||||
pet: function (lot, kind) {
|
||||
if (!lot) return '<span class="text-body-secondary small" title="The owner\'s save doesn\'t hold this pet">Unknown</span>';
|
||||
if (!lot) return '<span class="text-body-secondary small" title="Not recorded yet: filled in when the owner next loads into a world">Unknown</span>';
|
||||
return '<span class="text-nowrap"><img src="/api/icon/' + esc(lot) + '" width="28" height="28" class="me-1 align-middle" alt="" loading="lazy">' +
|
||||
esc(kind || ('LOT ' + lot)) + ' <span class="small text-body-secondary">(' + esc(lot) + ')</span></span>';
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user