mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-25 06:02:49 +00:00
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:
@@ -3,7 +3,8 @@ set(DGAME_DINVENTORY_SOURCES
|
||||
"Inventory.cpp"
|
||||
"Item.cpp"
|
||||
"ItemSet.cpp"
|
||||
"ItemSetPassiveAbility.cpp")
|
||||
"ItemSetPassiveAbility.cpp"
|
||||
"LootMetrics.cpp")
|
||||
|
||||
add_library(dInventory OBJECT ${DGAME_DINVENTORY_SOURCES})
|
||||
target_include_directories(dInventory PUBLIC "."
|
||||
|
||||
@@ -82,7 +82,8 @@ Item::Item(
|
||||
bool isModMoveAndEquip,
|
||||
LWOOBJID subKey,
|
||||
bool bound,
|
||||
eLootSourceType lootSourceType) {
|
||||
eLootSourceType lootSourceType,
|
||||
const LootMetrics& metrics) {
|
||||
if (!Inventory::IsValidItem(lot)) {
|
||||
return;
|
||||
}
|
||||
@@ -113,6 +114,7 @@ Item::Item(
|
||||
GameMessages::AddItemToInventoryClientSync addItem;
|
||||
addItem.target = entity->GetObjectID();
|
||||
addItem.SetItem(*this);
|
||||
addItem.AddMetrics(metrics);
|
||||
addItem.eLootTypeSource = lootSourceType;
|
||||
addItem.iSubkey = subKey;
|
||||
addItem.itemCount = static_cast<int>(this->count);
|
||||
@@ -178,7 +180,7 @@ PreconditionExpression* Item::GetPreconditionExpression() const {
|
||||
return preconditions;
|
||||
}
|
||||
|
||||
void Item::SetCount(const uint32_t value, const bool silent, const bool disassemble, const bool showFlyingLoot, eLootSourceType lootSourceType) {
|
||||
void Item::SetCount(const uint32_t value, const bool silent, const bool disassemble, const bool showFlyingLoot, eLootSourceType lootSourceType, const LootMetrics& metrics, const ItemRemovalSource& removalSource) {
|
||||
if (value == count) {
|
||||
return;
|
||||
}
|
||||
@@ -202,6 +204,7 @@ void Item::SetCount(const uint32_t value, const bool silent, const bool disassem
|
||||
GameMessages::AddItemToInventoryClientSync addItem;
|
||||
addItem.target = entity->GetObjectID();
|
||||
addItem.SetItem(*this);
|
||||
addItem.AddMetrics(metrics);
|
||||
addItem.eLootTypeSource = lootSourceType;
|
||||
addItem.itemCount = delta;
|
||||
addItem.newObjID = id;
|
||||
@@ -213,7 +216,8 @@ void Item::SetCount(const uint32_t value, const bool silent, const bool disassem
|
||||
removeItem.target = entity->GetObjectID();
|
||||
removeItem.bConfirmed = true;
|
||||
removeItem.eInvType = inventory->GetType();
|
||||
removeItem.eLootTypeSource = LOOTTYPE_NONE;
|
||||
removeItem.eLootTypeSource = static_cast<int32_t>(removalSource.type);
|
||||
removeItem.iLootTypeSource = removalSource.object;
|
||||
removeItem.iObjID = id;
|
||||
removeItem.iObjTemplate = lot;
|
||||
removeItem.iStackCount = delta;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "Preconditions.h"
|
||||
#include "eInventoryType.h"
|
||||
#include "eLootSourceType.h"
|
||||
#include "LootMetrics.h"
|
||||
|
||||
namespace tinyxml2 {
|
||||
class XMLElement;
|
||||
@@ -58,6 +59,7 @@ public:
|
||||
* @param isModMoveAndEquip equips the item
|
||||
* @param subKey optional subkey for this item, e.g. for pets
|
||||
* @param bound if the item should be bound
|
||||
* @param metrics where the items came from, sent with the item (not kept)
|
||||
*/
|
||||
explicit Item(
|
||||
LOT lot,
|
||||
@@ -70,7 +72,8 @@ public:
|
||||
bool isModMoveAndEquip = false,
|
||||
LWOOBJID subKey = LWOOBJID_EMPTY,
|
||||
bool bound = false,
|
||||
eLootSourceType lootSourceType = eLootSourceType::NONE
|
||||
eLootSourceType lootSourceType = eLootSourceType::NONE,
|
||||
const LootMetrics& metrics = {}
|
||||
);
|
||||
|
||||
~Item();
|
||||
@@ -93,8 +96,10 @@ public:
|
||||
* @param silent if true, the client will not be notified of the change with GMs
|
||||
* @param disassemble if items were removed, this returns all the sub parts of the item individually if it had assembly part lots
|
||||
* @param showFlyingLoot shows flying loot to the client, if not silent
|
||||
* @param metrics where added items came from, sent with them (not kept)
|
||||
* @param removalSource what took removed items away, sent with the removal
|
||||
*/
|
||||
void SetCount(uint32_t value, bool silent = false, bool disassemble = true, bool showFlyingLoot = true, eLootSourceType lootSourceType = eLootSourceType::NONE);
|
||||
void SetCount(uint32_t value, bool silent = false, bool disassemble = true, bool showFlyingLoot = true, eLootSourceType lootSourceType = eLootSourceType::NONE, const LootMetrics& metrics = {}, const ItemRemovalSource& removalSource = {});
|
||||
|
||||
/**
|
||||
* Returns the number of items this item represents (e.g. for stacks)
|
||||
|
||||
27
dGame/dInventory/LootMetrics.cpp
Normal file
27
dGame/dInventory/LootMetrics.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "LootMetrics.h"
|
||||
|
||||
#include "LDFFormat.h"
|
||||
|
||||
namespace {
|
||||
template<typename T>
|
||||
void Append(std::u16string& out, const char16_t* key, const std::optional<T>& value) {
|
||||
if (!value) return;
|
||||
if (!out.empty()) out += u',';
|
||||
out += GeneralUtils::ASCIIToUTF16(LDFData<T>(key, *value).GetString());
|
||||
}
|
||||
}
|
||||
|
||||
bool LootMetrics::Empty() const {
|
||||
return !sourceLot && !missionId && !activityId && !currencyDelta && !mailId && !transactionId;
|
||||
}
|
||||
|
||||
std::u16string LootMetrics::ToExtraInfo() const {
|
||||
std::u16string out;
|
||||
Append<int32_t>(out, u"_Metric_Souce_LOT_Int", sourceLot);
|
||||
Append<int32_t>(out, u"_Metric_Mission_ID_Int", missionId);
|
||||
Append<int32_t>(out, u"_Metric_Activity_ID_Int", activityId);
|
||||
Append<int32_t>(out, u"_Metric_Currency_Delta_Int", currencyDelta);
|
||||
Append<uint64_t>(out, u"_Metric_Mail_ID_Int64", mailId);
|
||||
Append<LWOOBJID>(out, u"_Metric_Transaction_ID_Int64", transactionId);
|
||||
return out;
|
||||
}
|
||||
39
dGame/dInventory/LootMetrics.h
Normal file
39
dGame/dInventory/LootMetrics.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "dCommonVars.h"
|
||||
#include "eLootSourceType.h"
|
||||
|
||||
/**
|
||||
* Where added items came from, as live servers put it in the extra info of AddItemToInventoryClientSync next to the
|
||||
* item's own config. Only the message carries these keys; the item does not keep them.
|
||||
* Live: a picked up drop had _Metric_Souce_LOT_Int (the source object's LOT, 1 for a player sourced
|
||||
* drop) on all 2,344 pickups of a DropClientLoot; mission and achievement rewards the mission ID and source LOT 1;
|
||||
* activity rewards the activity ID and the activity object's LOT; vendor purchases the vendor's LOT and the coins paid
|
||||
* (negative); mail the mail ID; trades the trade ID. Package contents had none.
|
||||
*/
|
||||
struct LootMetrics {
|
||||
std::optional<LOT> sourceLot; // _Metric_Souce_LOT_Int (the key is misspelt in live's data)
|
||||
std::optional<int32_t> missionId; // _Metric_Mission_ID_Int
|
||||
std::optional<int32_t> activityId; // _Metric_Activity_ID_Int
|
||||
std::optional<int32_t> currencyDelta; // _Metric_Currency_Delta_Int
|
||||
std::optional<uint64_t> mailId; // _Metric_Mail_ID_Int64, name value type 8
|
||||
std::optional<LWOOBJID> transactionId; // _Metric_Transaction_ID_Int64, name value type 9
|
||||
|
||||
[[nodiscard]] bool Empty() const;
|
||||
|
||||
/**
|
||||
* The keys as name value text (key=type:value), comma separated like an item's config in the extra info.
|
||||
* Empty when there are none.
|
||||
*/
|
||||
[[nodiscard]] std::u16string ToExtraInfo() const;
|
||||
};
|
||||
|
||||
// What took items away, for RemoveItemFromInventory's loot source fields (e.g. a quickbuild taking its item cost)
|
||||
struct ItemRemovalSource {
|
||||
eLootSourceType type = eLootSourceType::NONE;
|
||||
LWOOBJID object = LWOOBJID_EMPTY;
|
||||
};
|
||||
Reference in New Issue
Block a user