diff --git a/core/src/main/kotlin/com/last/commit/inventory/Inventory.kt b/core/src/main/kotlin/com/last/commit/inventory/Inventory.kt index 892aeee..e17ee62 100644 --- a/core/src/main/kotlin/com/last/commit/inventory/Inventory.kt +++ b/core/src/main/kotlin/com/last/commit/inventory/Inventory.kt @@ -1,7 +1,5 @@ package com.last.commit.inventory -import com.last.commit.GameState - class Inventory() { val items: MutableList = ArrayList() @@ -12,28 +10,25 @@ class Inventory() { * @param name the name of the subtexture loaded from xml * @return wether the item was added */ - fun add(name: String, state: GameState): Boolean { - if (this.items.find { it.name == name } == null) { - if (this.items.size < 8) { - items.add(InventoryItem(name)) - this.updated = true + fun add(name: String) { + items.add(InventoryItem(name)) + this.updated = true + } - return true - } - } else { - // Item is already in inventory - state.dialogStage.setTexts("You already have this item.") - state.dialogStage.show() - } - return false + fun hasItem(name: String): Boolean { + return this.items.find { it.name == name } == null + } + + fun isFull(): Boolean { + return items.size >= 7 } fun remove(name: String) { items.removeIf() { item -> item.name == name } } - + fun checkVictoryCondition(): Boolean { - return requiredItems.all {itemName -> + return requiredItems.all { itemName -> items.find { it.name == itemName } != null } } diff --git a/core/src/main/kotlin/com/last/commit/map/Collectible.kt b/core/src/main/kotlin/com/last/commit/map/Collectible.kt index a294225..fb8e2ea 100644 --- a/core/src/main/kotlin/com/last/commit/map/Collectible.kt +++ b/core/src/main/kotlin/com/last/commit/map/Collectible.kt @@ -26,8 +26,13 @@ class Collectible( override fun interact(otherCollider: Rectangle, state: GameState) { println("Interacting with item $name") state.soundEngine.play(GameSoundEffect.GRAB) - if (state.inventory.add(this.name, state)) { - state.map?.collectibles?.remove(this) + if (state.inventory.hasItem(this.name)) { + state.dialogStage.setTexts("You already have this item.") + state.dialogStage.show() + } else if (state.inventory.isFull()) { + state.dialogStage.setTexts("You can't carry anymore items.") + } else { + state.inventory.add(this.name) } }