feat(inventory): items can carry where they came from to the client

Live servers put _Metric_ keys in AddItemToInventoryClientSync's extra info,
after the item's own config, saying where the items came from: the source
object's LOT (_Metric_Souce_LOT_Int, misspelt as live had it), the mission,
activity, coins paid, mail or trade. LootMetrics holds them and writes them
with the key names and name value types live used (the mail ID as type 8,
the trade ID as type 9). AddItem, ReceiveItem (its options), the new item
constructor and Item::SetCount pass them through to the message; the item
does not keep them.

RemoveItem and Item::SetCount can also say what took items away
(ItemRemovalSource), filling RemoveItemFromInventory's loot source and
source object instead of none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-30 07:45:50 -05:00
parent 3018312f29
commit a1ee18fce7
9 changed files with 112 additions and 16 deletions

View File

@@ -228,7 +228,8 @@ void InventoryComponent::AddItem(
const eInventoryType inventorySourceType,
const int32_t sourceType,
const bool bound,
int32_t preferredSlot) {
int32_t preferredSlot,
const LootMetrics& metrics) {
if (count == 0) {
LOG("Attempted to add 0 of item (%i) to the inventory!", lot);
@@ -262,7 +263,7 @@ void InventoryComponent::AddItem(
return;
}
auto* item = new Item(lot, inventory, slot, count, config, parent, showFlyingLoot, isModMoveAndEquip, subKey, bound, lootSourceType);
auto* item = new Item(lot, inventory, slot, count, config, parent, showFlyingLoot, isModMoveAndEquip, subKey, bound, lootSourceType, metrics);
if (missions != nullptr && !IsTransferInventory(inventoryType)) {
missions->Progress(eMissionTaskType::GATHER, lot, LWOOBJID_EMPTY, "", count, IsTransferInventory(inventorySourceType));
@@ -295,7 +296,7 @@ void InventoryComponent::AddItem(
left -= delta;
existing->SetCount(existing->GetCount() + delta, false, true, showFlyingLoot, lootSourceType);
existing->SetCount(existing->GetCount() + delta, false, true, showFlyingLoot, lootSourceType, metrics);
if (isModMoveAndEquip) {
existing->Equip();
@@ -348,7 +349,7 @@ void InventoryComponent::AddItem(
continue;
}
auto* item = new Item(lot, inventory, slot, size, {}, parent, showFlyingLoot, isModMoveAndEquip, subKey, false, lootSourceType);
auto* item = new Item(lot, inventory, slot, size, {}, parent, showFlyingLoot, isModMoveAndEquip, subKey, false, lootSourceType, metrics);
isModMoveAndEquip = false;
}
@@ -374,6 +375,7 @@ ReceivedItem InventoryComponent::ReceiveItem(const LWOOBJID id, const LOT lot, c
GameMessages::AddItemToInventoryClientSync addItem;
addItem.target = m_Parent->GetObjectID();
addItem.SetItem(*item);
addItem.AddMetrics(options.metrics);
addItem.eLootTypeSource = lootSourceType;
addItem.iSubkey = subKey;
addItem.itemCount = static_cast<int>(count);
@@ -398,7 +400,7 @@ ReceivedItem InventoryComponent::ReceiveItem(const LWOOBJID id, const LOT lot, c
for (const auto& [itemId, item] : inventory->GetItems()) {
if (item->GetLot() == lot) before[itemId] = item->GetCount();
}
AddItem(lot, count, lootSourceType, inventoryType, config, LWOOBJID_EMPTY, options.showFlyingLoot, options.equip, subKey, options.sourceInventory, 0, bound, options.preferredSlot);
AddItem(lot, count, lootSourceType, inventoryType, config, LWOOBJID_EMPTY, options.showFlyingLoot, options.equip, subKey, options.sourceInventory, 0, bound, options.preferredSlot, options.metrics);
LWOOBJID receivedBy = LWOOBJID_EMPTY;
int64_t largestGain = 0;
@@ -420,7 +422,7 @@ bool InventoryComponent::IsUniqueLot(const LOT lot) {
return !isBrick && info.stackSize <= 1;
}
bool InventoryComponent::RemoveItem(const LOT lot, const uint32_t count, eInventoryType inventoryType, const bool ignoreBound, const bool silent) {
bool InventoryComponent::RemoveItem(const LOT lot, const uint32_t count, eInventoryType inventoryType, const bool ignoreBound, const bool silent, const ItemRemovalSource& removalSource) {
if (count == 0) {
LOG("Attempted to remove 0 of item (%i) from the inventory!", lot);
return false;
@@ -437,7 +439,7 @@ bool InventoryComponent::RemoveItem(const LOT lot, const uint32_t count, eInvent
auto* item = FindItemByLot(lot, inventoryType, false, ignoreBound);
if (!item) break;
const auto delta = std::min<uint32_t>(left, item->GetCount());
item->SetCount(item->GetCount() - delta, silent);
item->SetCount(item->GetCount() - delta, silent, true, true, eLootSourceType::NONE, {}, removalSource);
left -= delta;
}
return true;
@@ -448,7 +450,7 @@ bool InventoryComponent::RemoveItem(const LOT lot, const uint32_t count, eInvent
auto* item = inventory->FindItemByLot(lot, false, ignoreBound);
if (!item) break;
const auto delta = std::min<uint32_t>(item->GetCount(), left);
item->SetCount(item->GetCount() - delta, silent);
item->SetCount(item->GetCount() - delta, silent, true, true, eLootSourceType::NONE, {}, removalSource);
left -= delta;
}
}

View File

@@ -23,6 +23,7 @@
#include "eReplicaComponentType.h"
#include "eLootSourceType.h"
#include "Loot.h"
#include "LootMetrics.h"
class Entity;
class ItemSet;
@@ -57,6 +58,7 @@ struct ReceiveItemOptions {
bool equip = false;
int32_t preferredSlot = -1;
eInventoryType sourceInventory = INVALID; // set when moving between the player's own inventories
LootMetrics metrics{}; // where the items came from, sent with them (e.g. the mail or trade ID)
};
// Which item or stack ReceiveItem put the items in
@@ -153,6 +155,7 @@ public:
* @param bound whether this item is bound
* @param preferredSlot the preferred slot to store this item
* @param lootSourceType The source of the loot. Defaults to none.
* @param metrics where the items came from (source LOT, mission, activity...), sent with them and not kept
*/
void AddItem(
LOT lot,
@@ -167,7 +170,8 @@ public:
eInventoryType inventorySourceType = INVALID,
int32_t sourceType = 0,
bool bound = false,
int32_t preferredSlot = -1
int32_t preferredSlot = -1,
const LootMetrics& metrics = {}
);
/**
@@ -190,8 +194,9 @@ public:
* @param inventoryType optional inventory type to remove the item from
* @param ignoreBound ignores bound items
* @param silent silently remove the item
* @param removalSource what took the items, sent with the removal (e.g. a quickbuild taking its item cost)
*/
bool RemoveItem(LOT lot, uint32_t count, eInventoryType inventoryType = INVALID, bool ignoreBound = false, bool silent = false);
bool RemoveItem(LOT lot, uint32_t count, eInventoryType inventoryType = INVALID, bool ignoreBound = false, bool silent = false, const ItemRemovalSource& removalSource = {});
/**
* Moves an existing item to an inventory of the entity