feat: implement consume item behavior (#1098)

* feature: implement consume item behavior

* Cleanup

* tested with skill 456 and fixed some things

* remove logs
This commit is contained in:
Aaron Kimbrell
2023-11-14 19:38:52 -06:00
committed by GitHub
parent 8a9883c224
commit 8cd5bf7b8d
6 changed files with 63 additions and 22 deletions

View File

@@ -300,38 +300,26 @@ void InventoryComponent::AddItem(
}
}
void InventoryComponent::RemoveItem(const LOT lot, const uint32_t count, eInventoryType inventoryType, const bool ignoreBound) {
bool InventoryComponent::RemoveItem(const LOT lot, const uint32_t count, eInventoryType inventoryType, const bool ignoreBound, const bool silent) {
if (count == 0) {
LOG("Attempted to remove 0 of item (%i) from the inventory!", lot);
return;
return false;
}
if (inventoryType == INVALID) {
inventoryType = Inventory::FindInventoryTypeForLot(lot);
}
if (inventoryType == INVALID) inventoryType = Inventory::FindInventoryTypeForLot(lot);
auto* inventory = GetInventory(inventoryType);
if (inventory == nullptr) {
return;
}
if (!inventory) return false;
auto left = std::min<uint32_t>(count, inventory->GetLotCount(lot));
if (left != count) return false;
while (left > 0) {
auto* item = FindItemByLot(lot, inventoryType, false, ignoreBound);
if (item == nullptr) {
break;
}
if (!item) break;
const auto delta = std::min<uint32_t>(left, item->GetCount());
item->SetCount(item->GetCount() - delta);
item->SetCount(item->GetCount() - delta, silent);
left -= delta;
}
return true;
}
void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType inventory, const uint32_t count, const bool showFlyingLot, bool isModMoveAndEquip, const bool ignoreEquipped, const int32_t preferredSlot) {