From a4ff66f12a5b540eae82be06f4d7658231d87e5b Mon Sep 17 00:00:00 2001 From: kadeshar Date: Thu, 22 May 2025 22:10:53 +0200 Subject: [PATCH] - [Bugfix] Fixed bug with unequip and item in bags (#1327) --- src/strategy/actions/UnequipAction.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/strategy/actions/UnequipAction.cpp b/src/strategy/actions/UnequipAction.cpp index 3eadbe36..def974bb 100644 --- a/src/strategy/actions/UnequipAction.cpp +++ b/src/strategy/actions/UnequipAction.cpp @@ -46,7 +46,20 @@ void UnequipAction::UnequipItem(FindItemVisitor* visitor) IterateItems(visitor, ITERATE_ALL_ITEMS); std::vector items = visitor->GetResult(); if (!items.empty()) - UnequipItem(*items.begin()); + { + // Prefer equipped item + auto equipped = std::find_if(items.begin(), items.end(), + [](Item* item) + { + uint8 bag = item->GetBagSlot(); + return bag == INVENTORY_SLOT_BAG_0 && item->GetSlot() < EQUIPMENT_SLOT_END; + }); + + if (equipped != items.end()) + UnequipItem(*equipped); + else + UnequipItem(*items.begin()); + } } void UnequipAction::UnequipItem(Item* item)