/** * Remove one given item from the player's inventory. */ bool MenuInventory::remove(int item) { if(!inventory[CARRIED].remove(item)) { if (!inventory[EQUIPMENT].remove(item)) { return false; } else { applyEquipment(); } } return true; }
/** * Remove an equipped item from the player's inventory. */ void MenuInventory::removeEquipped(int item) { inventory[EQUIPMENT].remove(item); applyEquipment(inventory[EQUIPMENT].storage); }
/** * Remove one given item from the player's inventory. */ void MenuInventory::remove(int item) { if( !inventory[CARRIED].remove(item)) { inventory[EQUIPMENT].remove(item); applyEquipment(inventory[EQUIPMENT].storage); } }
/** * Insert item into first available carried slot, preferably in the optionnal specified slot * * @param ItemStack Stack of items * @param area Area number where it will try to store the item * @param slot Slot number where it will try to store the item */ bool MenuInventory::add(ItemStack stack, int area, int slot, bool play_sound, bool auto_equip) { if (stack.empty()) return true; bool success = true; if (play_sound) items->playSound(stack.item); if (auto_equip && AUTO_EQUIP) { int equip_slot = getEquipSlotFromItem(stack.item, true); if (equip_slot >= 0 && inventory[EQUIPMENT].slots[equip_slot]->enabled) { area = EQUIPMENT; slot = equip_slot; } } if (area == CARRIED) { ItemStack leftover = inventory[CARRIED].add(stack, slot); if (!leftover.empty()) { pc->logMsg(msg->get("Inventory is full."), true); drop_stack.push(leftover); success = false; } } else if (area == EQUIPMENT) { ItemStack &dest = inventory[EQUIPMENT].storage[slot]; ItemStack leftover; leftover.item = stack.item; if (!dest.empty() && dest.item != stack.item) { // items don't match, so just add the stack to the carried area leftover.quantity = stack.quantity; } else if (dest.quantity + stack.quantity > items->items[stack.item].max_quantity) { // items match, so attempt to merge the stacks. Any leftover will be added to the carried area leftover.quantity = dest.quantity + stack.quantity - items->items[stack.item].max_quantity; stack.quantity = items->items[stack.item].max_quantity - dest.quantity; if (stack.quantity > 0) { add(stack, EQUIPMENT, slot, false, false); } } else { // put the item in the appropriate equipment slot inventory[EQUIPMENT].add(stack, slot); updateEquipment(slot); leftover.clear(); } if (!leftover.empty()) { add(leftover, CARRIED, -1, false, false); } applyEquipment(); } // if this item has a power, place it on the action bar if possible if (success && items->items[stack.item].type == "consumable" && items->items[stack.item].power > 0) { menu_act->addPower(items->items[stack.item].power, 0); } drag_prev_src = -1; return success; }