diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index 28ac0fb93..644d50fa3 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -2236,6 +2236,9 @@ void InventoryComponent::OnRemoveItemFromInventory(const GameMessages::RemoveIte const auto iStackCount = msg.iStackCount == 0 ? item->GetCount() : msg.iStackCount; if (item->GetCount() < iStackCount) return; + // DoRemoveItemFromInventory (0x00d1fb50) skips equipped items when deleting + if (msg.eLootTypeSource == GeneralUtils::ToUnderlying(eLootSourceType::DELETION) && item->IsEquipped()) return; + if (msg.bConfirmed && !CanDelete(*item)) { LOG("%llu tried to delete %llu (LOT %i), which its deletion restriction does not allow", m_Parent->GetObjectID(), item->GetId(), item->GetLot()); return; diff --git a/tests/dGameTests/dComponentsTests/ItemRemovalTests.cpp b/tests/dGameTests/dComponentsTests/ItemRemovalTests.cpp index ad34fee5a..9b099b684 100644 --- a/tests/dGameTests/dComponentsTests/ItemRemovalTests.cpp +++ b/tests/dGameTests/dComponentsTests/ItemRemovalTests.cpp @@ -114,3 +114,21 @@ TEST_F(ItemRemovalTests, DeletingMoreThanTheStackHoldsDoesNothing) { inventoryComponent->OnRemoveItemFromInventory(Delete(*other, 0)); EXPECT_EQ(other->GetCount(), 0u); } + +// LWOInventoryComponent_Common::DoRemoveItemFromInventory (0x00d1fb50) skips equipped items when deleting +TEST_F(ItemRemovalTests, AnEquippedItemIsNotDeleted) { + auto* const item = Give(1); + inventoryComponent->UpdateSlot("hair", { item->GetId(), item->GetLot(), item->GetCount(), item->GetSlot() }); + ASSERT_TRUE(item->IsEquipped()); + + inventoryComponent->OnRemoveItemFromInventory(Delete(*item, 1)); + EXPECT_EQ(item->GetCount(), 1u); + + // Removed for any other reason it goes (one of a stack, so it stays equipped) + auto* const stack = Give(2); + inventoryComponent->UpdateSlot("hat", { stack->GetId(), stack->GetLot(), stack->GetCount(), stack->GetSlot() }); + auto msg = Delete(*stack, 1); + msg.eLootTypeSource = GeneralUtils::ToUnderlying(eLootSourceType::NONE); + inventoryComponent->OnRemoveItemFromInventory(msg); + EXPECT_EQ(stack->GetCount(), 1u); +}