mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 19:14:05 +09:00
sanity check on equipping the item
This commit is contained in:
@@ -11,7 +11,9 @@ interface Pocketed {
|
|||||||
|
|
||||||
var inventory: ActorInventory
|
var inventory: ActorInventory
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Equips an item. If the item is not in the inventory, an error will be thrown.
|
||||||
|
*/
|
||||||
fun unequipItem(item: InventoryItem) {
|
fun unequipItem(item: InventoryItem) {
|
||||||
if (item.equipPosition == InventoryItem.EquipPosition.NULL)
|
if (item.equipPosition == InventoryItem.EquipPosition.NULL)
|
||||||
throw Error("Unequipping the item that cannot be equipped")
|
throw Error("Unequipping the item that cannot be equipped")
|
||||||
@@ -23,7 +25,13 @@ interface Pocketed {
|
|||||||
item.effectOnUnequip(Terrarum.appgc, Terrarum.UPDATE_DELTA)
|
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) {
|
fun equipItem(item: InventoryItem) {
|
||||||
|
if (!inventory.hasItem(item))
|
||||||
|
inventory.add(item)
|
||||||
|
|
||||||
if (item.equipPosition >= 0) {
|
if (item.equipPosition >= 0) {
|
||||||
inventory.itemEquipped[item.equipPosition] = item
|
inventory.itemEquipped[item.equipPosition] = item
|
||||||
item.effectWhenEquipped(Terrarum.appgc, Terrarum.UPDATE_DELTA)
|
item.effectWhenEquipped(Terrarum.appgc, Terrarum.UPDATE_DELTA)
|
||||||
|
|||||||
@@ -109,16 +109,18 @@ abstract class InventoryItem : Comparable<InventoryItem> {
|
|||||||
open fun effectWhenPickedUp(gc: GameContainer, delta: Int) { }
|
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
|
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
|
open fun secondaryUse(gc: GameContainer, delta: Int): Boolean = false
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user