mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-17 22:14:05 +09:00
sanity check on equipping the item
This commit is contained in:
@@ -11,7 +11,9 @@ interface Pocketed {
|
||||
|
||||
var inventory: ActorInventory
|
||||
|
||||
|
||||
/**
|
||||
* Equips an item. If the item is not in the inventory, an error will be thrown.
|
||||
*/
|
||||
fun unequipItem(item: InventoryItem) {
|
||||
if (item.equipPosition == InventoryItem.EquipPosition.NULL)
|
||||
throw Error("Unequipping the item that cannot be equipped")
|
||||
@@ -23,7 +25,13 @@ interface Pocketed {
|
||||
item.effectOnUnequip(Terrarum.appgc, Terrarum.UPDATE_DELTA)
|
||||
}
|
||||
|
||||
/**
|
||||
* Equips an item. If the item is not in the inventory, adds the item first.
|
||||
*/
|
||||
fun equipItem(item: InventoryItem) {
|
||||
if (!inventory.hasItem(item))
|
||||
inventory.add(item)
|
||||
|
||||
if (item.equipPosition >= 0) {
|
||||
inventory.itemEquipped[item.equipPosition] = item
|
||||
item.effectWhenEquipped(Terrarum.appgc, Terrarum.UPDATE_DELTA)
|
||||
|
||||
Reference in New Issue
Block a user