mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-16 05:24:06 +09:00
inventoryItem -> gameItem
This commit is contained in:
@@ -4,7 +4,7 @@ import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.faction.Faction
|
||||
import net.torvald.terrarum.gamecontroller.Key
|
||||
import net.torvald.terrarum.itemproperties.InventoryItem
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.Material
|
||||
import net.torvald.terrarum.realestate.LandUtil
|
||||
import net.torvald.terrarum.ui.UIInventory
|
||||
@@ -138,7 +138,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
|
||||
get() = this == Terrarum.ingame!!.player
|
||||
|
||||
|
||||
private val nullItem = object : InventoryItem() {
|
||||
private val nullItem = object : GameItem() {
|
||||
override var dynamicID: Int = 0
|
||||
override val originalID = dynamicID
|
||||
override val isUnique: Boolean = false
|
||||
@@ -480,7 +480,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
|
||||
// ONLY FOR HAND_GRIPs!!
|
||||
val quickBarItem = inventory.getQuickBar(actorValue.getAsInt(key)!!)?.item
|
||||
|
||||
if (quickBarItem != null && quickBarItem.equipPosition == InventoryItem.EquipPosition.HAND_GRIP) {
|
||||
if (quickBarItem != null && quickBarItem.equipPosition == GameItem.EquipPosition.HAND_GRIP) {
|
||||
equipItem(quickBarItem)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,11 @@ package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.itemproperties.InventoryItem
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_WALLS
|
||||
import net.torvald.terrarum.itemproperties.ItemID
|
||||
import net.torvald.terrarum.ui.UIInventory
|
||||
import java.util.*
|
||||
import java.util.concurrent.locks.Lock
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
@@ -27,7 +26,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
||||
/**
|
||||
* List of all equipped items (tools, armours, rings, necklaces, etc.)
|
||||
*/
|
||||
val itemEquipped = Array<InventoryItem?>(InventoryItem.EquipPosition.INDEX_MAX, { null })
|
||||
val itemEquipped = Array<GameItem?>(GameItem.EquipPosition.INDEX_MAX, { null })
|
||||
|
||||
/**
|
||||
* Sorted by referenceID.
|
||||
@@ -39,13 +38,13 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
||||
}
|
||||
|
||||
fun add(itemID: ItemID, count: Int = 1) = add(ItemCodex[itemID], count)
|
||||
fun add(item: InventoryItem, count: Int = 1) {
|
||||
fun add(item: GameItem, count: Int = 1) {
|
||||
|
||||
println("[ActorInventory] add $item, $count")
|
||||
|
||||
|
||||
// not wall-able walls
|
||||
if (item.inventoryCategory == InventoryItem.Category.WALL &&
|
||||
if (item.inventoryCategory == GameItem.Category.WALL &&
|
||||
!BlockCodex[item.dynamicID - ITEM_WALLS.start].isWallable) {
|
||||
throw IllegalArgumentException("Wall ID ${item.dynamicID - ITEM_WALLS.start} is not wall-able.")
|
||||
}
|
||||
@@ -86,7 +85,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
||||
fun remove(itemID: ItemID, count: Int) = remove(ItemCodex[itemID], count)
|
||||
/** Will check existence of the item using its Dynamic ID; careful with command order!
|
||||
* e.g. re-assign after this operation */
|
||||
fun remove(item: InventoryItem, count: Int = 1) {
|
||||
fun remove(item: GameItem, count: Int = 1) {
|
||||
|
||||
println("[ActorInventory] remove $item, $count")
|
||||
|
||||
@@ -128,7 +127,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
||||
fun getQuickBar(slot: Int): InventoryPair? = getByDynamicID(quickBar[slot])
|
||||
|
||||
/**
|
||||
* HashMap<InventoryItem, Amounts>
|
||||
* HashMap<GameItem, Amounts>
|
||||
*/
|
||||
fun forEach(consumer: (InventoryPair) -> Unit) = itemList.forEach(consumer)
|
||||
|
||||
@@ -169,12 +168,12 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
||||
false
|
||||
|
||||
|
||||
fun consumeItem(actor: Actor, item: InventoryItem) {
|
||||
fun consumeItem(actor: Actor, item: GameItem) {
|
||||
if (item.stackable && !item.isDynamic) {
|
||||
remove(item, 1)
|
||||
}
|
||||
else {
|
||||
val newItem: InventoryItem
|
||||
val newItem: GameItem
|
||||
|
||||
// unpack newly-made dynamic item (e.g. any weapon, floppy disk)
|
||||
if (item.isDynamic && item.originalID == item.dynamicID) {
|
||||
@@ -219,7 +218,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
||||
|
||||
|
||||
|
||||
fun contains(item: InventoryItem) = contains(item.dynamicID)
|
||||
fun contains(item: GameItem) = contains(item.dynamicID)
|
||||
fun contains(id: ItemID) =
|
||||
if (itemList.size == 0)
|
||||
false
|
||||
@@ -288,4 +287,4 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
||||
}
|
||||
}
|
||||
|
||||
data class InventoryPair(val item: InventoryItem, var amount: Int)
|
||||
data class InventoryPair(val item: GameItem, var amount: Int)
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.terrarum.itemproperties.InventoryItem
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-31.
|
||||
@@ -13,6 +13,6 @@ interface CanBeAnItem {
|
||||
|
||||
fun resumeUpdateAndDraw()
|
||||
|
||||
var itemData: InventoryItem
|
||||
var itemData: GameItem
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.terrarum.itemproperties.InventoryItem
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import org.newdawn.slick.GameContainer
|
||||
@@ -9,7 +9,7 @@ import org.newdawn.slick.Graphics
|
||||
/**
|
||||
* Created by minjaesong on 16-03-15.
|
||||
*/
|
||||
class DroppedItem(private val item: InventoryItem) : ActorWithPhysics(Actor.RenderOrder.MIDTOP) {
|
||||
class DroppedItem(private val item: GameItem) : ActorWithPhysics(Actor.RenderOrder.MIDTOP) {
|
||||
|
||||
init {
|
||||
if (item.dynamicID >= ItemCodex.ACTORID_MIN)
|
||||
|
||||
@@ -1,24 +1,13 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.gameactors.ai.AILuaAPI
|
||||
import net.torvald.terrarum.gameactors.ai.ActorAI
|
||||
import net.torvald.terrarum.gameactors.ai.LuaAIWrapper
|
||||
import net.torvald.terrarum.gamecontroller.mouseX
|
||||
import net.torvald.terrarum.gamecontroller.mouseY
|
||||
import net.torvald.terrarum.itemproperties.InventoryItem
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.Material
|
||||
import org.luaj.vm2.*
|
||||
import org.luaj.vm2.compiler.LuaC
|
||||
import org.luaj.vm2.lib.*
|
||||
import org.luaj.vm2.lib.jse.JseBaseLib
|
||||
import org.luaj.vm2.lib.jse.JseMathLib
|
||||
import org.luaj.vm2.lib.jse.JsePlatform
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Input
|
||||
import java.io.InputStreamReader
|
||||
import java.io.Reader
|
||||
|
||||
/**
|
||||
* @param ai AI class. Use LuaAIWrapper for Lua script
|
||||
@@ -42,8 +31,8 @@ open class HumanoidNPC(
|
||||
collisionType = DEFAULT_COLLISION_TYPE
|
||||
}
|
||||
|
||||
// we're having InventoryItem data so that this class could be somewhat universal
|
||||
override var itemData: InventoryItem = object : InventoryItem() {
|
||||
// we're having GameItem data so that this class could be somewhat universal
|
||||
override var itemData: GameItem = object : GameItem() {
|
||||
override var dynamicID = referenceID
|
||||
override val originalID = dynamicID
|
||||
override val isUnique = true
|
||||
|
||||
@@ -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