fix(inventory): a save in build mode keeps the equipment from before it

Entering build mode pushes the equipped items (PushEquippedItems); the
thinking hat and a model picked up off the property are then equipped
until PopEquippedItems puts the old equipment back. A character save in
between (the world's periodic save, a disconnect, a zone change) wrote
what was equipped at that moment, so a carried brick built model (LOT
6662) was saved in MODELS with eq="true" and equipped again on every
load. While the equipment is pushed, the save now writes the pushed
equipment as equipped instead. Nothing is dropped from the save.

In game: on a property, pick up a brick built model and carry it, wait
for a save (or log out) while carrying it, log back in: the model is in
the Models bag, not equipped, and your normal gear is worn. Characters
already saved with an equipped model keep it until it is put away or
the save is cleaned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-28 23:33:58 -05:00
parent b5e92ce97c
commit 107437e72f
4 changed files with 112 additions and 1 deletions

View File

@@ -826,6 +826,13 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument& document) {
items->DeleteChildren();
// Saved while the equipped items are pushed (build mode, possibly carrying a model): the character's equipment is
// the pushed state, which PopEquippedItems puts back, not the temporary items equipped since.
const auto& savedEquipment = m_HasPushed ? m_Pushed : m_Equipped;
const auto isSavedEquipped = [&savedEquipment](const LWOOBJID id) {
return std::ranges::any_of(savedEquipment, [id](const auto& slot) { return slot.second.id == id; });
};
for (auto* inventory : inventoriesToSave) {
if (inventory->GetSize() == 0) {
continue;
@@ -845,7 +852,7 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument& document) {
itemElement->SetAttribute("s", static_cast<unsigned int>(item->GetSlot()));
itemElement->SetAttribute("c", static_cast<unsigned int>(item->GetCount()));
itemElement->SetAttribute("b", item->GetBound());
itemElement->SetAttribute("eq", item->IsEquipped());
itemElement->SetAttribute("eq", isSavedEquipped(item->GetId()));
itemElement->SetAttribute("sk", item->GetSubKey());
// Begin custom xml
@@ -1197,6 +1204,7 @@ void InventoryComponent::RemoveBuff(Item* item) const {
void InventoryComponent::PushEquippedItems() {
m_Pushed = m_Equipped;
m_HasPushed = true;
m_Dirty = true;
}
@@ -1225,6 +1233,7 @@ void InventoryComponent::PopEquippedItems() {
}
m_Pushed.clear();
m_HasPushed = false;
auto destroyableComponent = m_Parent->GetComponent<DestroyableComponent>();