DEADSOFTWARE

Inventory class
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / model / item / InventoryItem.kt
index 6c1598315cb5037813c8a385ddb06f5f062846ea..aa646cbe8fb88437cae365ea8c4c724fd335319d 100644 (file)
@@ -31,6 +31,21 @@ class InventoryItem @JvmOverloads constructor(
         item = gameItemsHolder.getItem(itemKey)
     }
 
+    @JvmOverloads
+    fun add(count: Int = 1) {
+        amount += count
+    }
+
+    @JvmOverloads
+    fun subtract(count: Int = 1) {
+        add(-count)
+    }
+
+    @JvmOverloads
+    fun canBeAdded(count: Int = 1): Boolean {
+        return !item.isTool() && amount + count <= item.params.maxStack
+    }
+
     private fun drawAmountText(spriteBatch: SpriteBatch, text: String,  x: Float, y: Float) {
         spriteBatch.drawString(text, x + 1, y + 1, Color.BLACK)
         spriteBatch.drawString(text, x, y, Color.WHITE)