diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/player/Inventory.kt b/core/src/ru/deadsoftware/cavedroid/game/mobs/player/Inventory.kt
index c5e10d06b30600a2c4aaac74ebedd9a97d67a781..43f298c876e9702fb5e675e5b429602b22fbf13d 100644 (file)
}
}
}
}
- private fun getItemPickSlot(item: Item): Int {
+ private fun getItemPickSlot(drop: Drop): Int {
+ val item = drop.item
+
for (i in _items.indices) {
val inventoryItem = _items[i]
for (i in _items.indices) {
val inventoryItem = _items[i]
return -1
}
return -1
}
- fun canPickItem(item: Item): Boolean {
- return getItemPickSlot(item) >= 0
+ fun canPickItem(drop: Drop): Boolean {
+ return getItemPickSlot(drop) >= 0
}
fun pickDrop(drop: Drop) {
}
fun pickDrop(drop: Drop) {
- val slot = getItemPickSlot(drop.item).takeIf { it >= 0 } ?: return
+ val slot = getItemPickSlot(drop).takeIf { it >= 0 } ?: return
val inventoryItem = _items[slot]
if (inventoryItem.item == drop.item) {
val inventoryItem = _items[slot]
if (inventoryItem.item == drop.item) {
- inventoryItem.add(drop.amount)
+ if (inventoryItem.canBeAdded(drop.amount)) {
+ inventoryItem.add(drop.amount)
+ drop.pickedUp = true
+ } else {
+ val addCount = inventoryItem.item.params.maxStack - inventoryItem.amount
+ inventoryItem.add(addCount)
+ drop.subtract(addCount)
+ pickDrop(drop)
+ }
} else {
_items[slot] = drop.item.toInventoryItem(drop.amount)
if (slot == activeSlot) {
showCurrentItemTooltip()
}
} else {
_items[slot] = drop.item.toInventoryItem(drop.amount)
if (slot == activeSlot) {
showCurrentItemTooltip()
}
+ drop.pickedUp = true
}
}
-
- drop.pickedUp = true
}
fun addItem(item: Item) {
}
fun addItem(item: Item) {
fun decreaseCurrentItemAmount(count: Int = 1) {
decreaseItemAmount(activeSlot, count)
}
fun decreaseCurrentItemAmount(count: Int = 1) {
decreaseItemAmount(activeSlot, count)
}
+
+ fun clear() {
+ for (i in _items.indices) {
+ _items[i] = fallbackItem
+ }
+ }
}
\ No newline at end of file
}
\ No newline at end of file