mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-19 15:04:05 +09:00
inventoryItem -> gameItem
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.itemproperties.InventoryItem
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
|
||||
/**
|
||||
@@ -14,10 +14,10 @@ interface Pocketed {
|
||||
/**
|
||||
* Equips an item. If the item is not in the inventory, an error will be thrown.
|
||||
*/
|
||||
fun unequipItem(item: InventoryItem?) {
|
||||
fun unequipItem(item: GameItem?) {
|
||||
if (item == null) return
|
||||
|
||||
if (item.equipPosition == InventoryItem.EquipPosition.NULL)
|
||||
if (item.equipPosition == GameItem.EquipPosition.NULL)
|
||||
throw Error("Unequipping the item that cannot be equipped in the first place")
|
||||
|
||||
if (!inventory.contains(item)) {
|
||||
@@ -32,7 +32,7 @@ interface Pocketed {
|
||||
|
||||
// no need for equipSlot(Int)
|
||||
fun unequipSlot(slot: Int) {
|
||||
if (slot < 0 || slot > InventoryItem.EquipPosition.INDEX_MAX)
|
||||
if (slot < 0 || slot > GameItem.EquipPosition.INDEX_MAX)
|
||||
throw IllegalArgumentException("Slot index out of range: $slot")
|
||||
|
||||
unequipItem(inventory.itemEquipped[slot])
|
||||
@@ -41,7 +41,7 @@ interface Pocketed {
|
||||
/**
|
||||
* Equips an item. If the item is not in the inventory, adds the item first.
|
||||
*/
|
||||
fun equipItem(item: InventoryItem) {
|
||||
fun equipItem(item: GameItem) {
|
||||
if (!inventory.contains(item)) {
|
||||
println("[Pocketed] Item does not exist; adding one before equipped")
|
||||
inventory.add(item)
|
||||
@@ -54,26 +54,26 @@ interface Pocketed {
|
||||
// else do nothing
|
||||
}
|
||||
|
||||
fun equipped(item: InventoryItem): Boolean {
|
||||
fun equipped(item: GameItem): Boolean {
|
||||
return inventory.itemEquipped[item.equipPosition] == item
|
||||
}
|
||||
|
||||
fun addItem(itemID: Int, count: Int = 1) = inventory.add(ItemCodex[itemID], count)
|
||||
fun addItem(item: InventoryItem, count: Int = 1) = inventory.add(item, count)
|
||||
fun addItem(item: GameItem, count: Int = 1) = inventory.add(item, count)
|
||||
fun removeItem(itemID: Int, count: Int = 1) = inventory.remove(ItemCodex[itemID], count)
|
||||
fun removeItem(item: InventoryItem, count: Int = 1) = inventory.remove(item, count)
|
||||
fun removeItem(item: GameItem, count: Int = 1) = inventory.remove(item, count)
|
||||
|
||||
fun hasItem(item: InventoryItem) = inventory.contains(item.dynamicID)
|
||||
fun hasItem(item: GameItem) = inventory.contains(item.dynamicID)
|
||||
fun hasItem(id: Int) = inventory.contains(id)
|
||||
|
||||
|
||||
fun consumePrimary(item: InventoryItem) {
|
||||
fun consumePrimary(item: GameItem) {
|
||||
if (item.primaryUse(Terrarum.appgc, Terrarum.delta)) {
|
||||
inventory.consumeItem(this as Actor, item) // consume on successful
|
||||
}
|
||||
}
|
||||
|
||||
fun consumeSecondary(item: InventoryItem) {
|
||||
fun consumeSecondary(item: GameItem) {
|
||||
if (item.secondaryUse(Terrarum.appgc, Terrarum.delta))
|
||||
inventory.consumeItem(this as Actor, item) // consume on successful
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user