fix(inventory): deleting more than the stack holds does nothing, as the client

LWOInventoryComponent_Common::msgRemoveItemFromInventory (0x00d203b0)
counts the item (GetInvItemCount) and does nothing when it holds fewer
than iStackCount; a request for an item with no count takes the whole
stack. The server cut the request down to the stack and deleted it, and
deleted nothing for a count of 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-10-02 10:22:17 -05:00
parent 5bf637b02e
commit 9497d20027
2 changed files with 33 additions and 1 deletions

View File

@@ -5,6 +5,7 @@
#include "CDItemComponentTable.h"
#include "Entity.h"
#include "InventoryComponent.h"
#include "InventoryMessages.h"
#include "Item.h"
#include "eReplicaComponentType.h"
@@ -85,3 +86,31 @@ TEST_F(ItemRemovalTests, RetiredItemsAreFreedWithTheInventory) {
// Freed by the inventory's destructor (checked by sanitizer builds)
entity.reset();
}
namespace {
GameMessages::RemoveItemFromInventory Delete(const Item& item, const uint32_t count) {
GameMessages::RemoveItemFromInventory msg;
msg.bConfirmed = true;
msg.eInvType = eInventoryType::ITEMS;
msg.eLootTypeSource = GeneralUtils::ToUnderlying(eLootSourceType::DELETION);
msg.iObjID = item.GetId();
msg.iObjTemplate = item.GetLot();
msg.iStackCount = count;
return msg;
}
}
// LWOInventoryComponent_Common::msgRemoveItemFromInventory (0x00d203b0): a stack holding fewer than asked is left
// alone, and no count means the whole stack
TEST_F(ItemRemovalTests, DeletingMoreThanTheStackHoldsDoesNothing) {
auto* const item = Give(3);
inventoryComponent->OnRemoveItemFromInventory(Delete(*item, 4));
EXPECT_EQ(item->GetCount(), 3u);
inventoryComponent->OnRemoveItemFromInventory(Delete(*item, 2));
EXPECT_EQ(item->GetCount(), 1u);
auto* const other = Give(5);
inventoryComponent->OnRemoveItemFromInventory(Delete(*other, 0));
EXPECT_EQ(other->GetCount(), 0u);
}