summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7bb128a)
raw | patch | inline | side by side (parent: 7bb128a)
author | fredboy <fredboy@protonmail.com> | |
Fri, 10 May 2024 17:16:29 +0000 (00:16 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Fri, 10 May 2024 17:16:29 +0000 (00:16 +0700) |
core/src/ru/deadsoftware/cavedroid/game/mobs/player/Inventory.kt | patch | blob | history | |
core/src/ru/deadsoftware/cavedroid/game/objects/drop/Drop.kt | patch | blob | history |
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 c6dea8bc878f0d523be0fc447979961080fc94df..3012d6675a3346bed978a5183b342120d31ab0b9 100644 (file)
for (i in _items.indices) {
val inventoryItem = _items[i]
- if (item == inventoryItem.item && inventoryItem.canBeAdded(drop.amount)) {
+ if (item == inventoryItem.item && inventoryItem.canBeAdded()) {
return i
}
}
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()
}
+ drop.pickedUp = true
}
-
- drop.pickedUp = true
}
fun addItem(item: Item) {
diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/drop/Drop.kt b/core/src/ru/deadsoftware/cavedroid/game/objects/drop/Drop.kt
index 9099864b39f8c12db0f2362d41a2eecd2739d393..edb3c81ff657a63fd41b865e4dbaea9a7dc01230 100644 (file)
x: Float,
y: Float,
_item: Item,
- val amount: Int = 1,
+ _amount: Int = 1,
) : Rectangle(x, y, DROP_SIZE, DROP_SIZE) {
+ var amount: Int = _amount
+ private set
+
val itemKey = _item.params.key
val velocity = getInitialVelocity()
var pickedUp = false
return Intersector.overlaps(magnetArea, rectangle)
}
+ @JvmOverloads
+ fun subtract(count: Int = 1) {
+ if (count < 0) {
+ throw IllegalArgumentException("Can't subtract negative amount")
+ }
+
+ amount -= count
+ }
+
private fun getMagnetArea(): Rectangle {
return Rectangle(
/* x = */ x - MAGNET_DISTANCE,