sanity check on equipping the item

This commit is contained in:
Song Minjae
2017-04-11 21:12:51 +09:00
parent 8d565a36ba
commit e7f221a499
2 changed files with 15 additions and 5 deletions

View File

@@ -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)

View File

@@ -109,16 +109,18 @@ abstract class InventoryItem : Comparable<InventoryItem> {
open fun effectWhenPickedUp(gc: GameContainer, delta: Int) { }
/**
* Effects applied (continuously or not) while primary button (usually left mouse button) is down
* Apply effects (continuously or not) while primary button (usually left mouse button) is down.
* The item will NOT be consumed, so you will want to consume it yourself by inventory.consumeItem(item)
*
* @return true when use successfully, false otherwise
* @return true when used successfully, false otherwise
*/
open fun primaryUse(gc: GameContainer, delta: Int): Boolean = false
/**
* Effects applied (continuously or not) while secondary button (usually right mouse button) is down
* Apply effects (continuously or not) while secondary button (usually right mouse button) is down
* The item will NOT be consumed, so you will want to consume it yourself by inventory.consumeItem(item)
*
* @return true when use successfully, false otherwise
* @return true when used successfully, false otherwise
*/
open fun secondaryUse(gc: GameContainer, delta: Int): Boolean = false