inventoryItem -> gameItem

This commit is contained in:
Song Minjae
2017-04-29 23:11:54 +09:00
parent 9a7885fc80
commit c9c761598a
17 changed files with 84 additions and 100 deletions

View File

@@ -1,14 +1,14 @@
|Range|Description| |Range|Description|
|-----|-----------| |-----|-----------|
|0..4095|Tiles| |0..4095|Tiles (4096 possible)|
|4096..8191|Walls| |4096..8191|Walls (4096 possible)|
|8192..8447|Wires| |8192..8447|Wires (256 possible)|
|8448..32767|Items (static)| |8448..32767|Items (static) (24320 possible)|
|32768..0x0FFF_FFFF|Items (dynamic\*)| |32768..0x0FFF_FFFF|Items (dynamic\*) (268M possible)|
|0x1000_0000..0x7FFF_FFFF|Actors| |0x1000_0000..0x7FFF_FFFF|Actors|
|-2147483648..-1 (all negative numbers)|Faction| |-2147483648..-1 (all negative numbers)|Faction|
* dynamic items can have their own properties that will persist through savegame. * dynamic items have own properties that will persist through savegame.
Actors range in-depth Actors range in-depth

View File

@@ -1,4 +1,4 @@
import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.itemproperties.Material
import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable import org.jetbrains.annotations.Nullable
@@ -7,9 +7,9 @@ import org.jetbrains.annotations.Nullable
* Created by SKYHi14 on 2017-04-28. * Created by SKYHi14 on 2017-04-28.
*/ */
static InventoryItem invoke(int id) { static GameItem invoke(int id) {
return new InventoryItem() { return new GameItem() {
@Override @Override
int getDynamicID() { int getDynamicID() {
return 0 return 0

View File

@@ -9,23 +9,21 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWithPhysics import net.torvald.terrarum.gameactors.ActorWithPhysics
import net.torvald.terrarum.itemproperties.Calculate import net.torvald.terrarum.itemproperties.Calculate
import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.Block
// following two are NOT UNUSED! // following two are NOT UNUSED!
import net.torvald.terrarum.itemproperties.InventoryItem.EquipPosition
import net.torvald.terrarum.itemproperties.InventoryItem.Category
import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.NotNull
import org.newdawn.slick.GameContainer import org.newdawn.slick.GameContainer
static InventoryItem invoke(int id) { static GameItem invoke(int id) {
return new TestPick(id) return new TestPick(id)
} }
class TestPick extends InventoryItem { class TestPick extends GameItem {
int originalID int originalID
int dynamicID int dynamicID

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum package net.torvald.terrarum
import net.torvald.terrarum.gameactors.ActorHumanoid import net.torvald.terrarum.gameactors.ActorHumanoid
import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.ui.UIVitalMetre import net.torvald.terrarum.ui.UIVitalMetre
/** /**
@@ -10,7 +10,7 @@ import net.torvald.terrarum.ui.UIVitalMetre
object AmmoMeterProxy { object AmmoMeterProxy {
operator fun invoke(actor: ActorHumanoid, meter: UIVitalMetre) { operator fun invoke(actor: ActorHumanoid, meter: UIVitalMetre) {
val currentItem = actor.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP] val currentItem = actor.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]
if (currentItem == null) { if (currentItem == null) {
meter.vitalGetterMax = { null } meter.vitalGetterMax = { null }
@@ -18,7 +18,7 @@ object AmmoMeterProxy {
} }
else { else {
meter.vitalGetterVal = { meter.vitalGetterVal = {
if (currentItem.stackable && currentItem.maxDurability == InventoryItem.DURABILITY_NA) { if (currentItem.stackable && currentItem.maxDurability == GameItem.DURABILITY_NA) {
actor.inventory.getByDynamicID(currentItem.dynamicID)!!.amount.toFloat() actor.inventory.getByDynamicID(currentItem.dynamicID)!!.amount.toFloat()
} }
else else
@@ -26,7 +26,7 @@ object AmmoMeterProxy {
} }
meter.vitalGetterMax = { meter.vitalGetterMax = {
if (currentItem.stackable && currentItem.maxDurability == InventoryItem.DURABILITY_NA) if (currentItem.stackable && currentItem.maxDurability == GameItem.DURABILITY_NA)
500f 500f
else else
currentItem.maxDurability.toFloat() currentItem.maxDurability.toFloat()

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum package net.torvald.terrarum
import net.torvald.CSVFetcher import net.torvald.CSVFetcher
import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
@@ -103,7 +103,7 @@ object ModMgr {
/*val engine = ScriptEngineManager().getEngineByExtension("groovy")!! /*val engine = ScriptEngineManager().getEngineByExtension("groovy")!!
engine.eval(FileReader(getFile("basegame", "/items/testpick.groovy"))) engine.eval(FileReader(getFile("basegame", "/items/testpick.groovy")))
val newPick = (engine as Invocable).invokeFunction("invoke", 8449) as InventoryItem val newPick = (engine as Invocable).invokeFunction("invoke", 8449) as GameItem
ItemCodex[8449] = newPick*/ ItemCodex[8449] = newPick*/
} }
@@ -157,7 +157,7 @@ object ModMgr {
val itemID = it["id"].toInt() val itemID = it["id"].toInt()
groovyEngine.eval(script) groovyEngine.eval(script)
ItemCodex[itemID] = groovyInvocable.invokeFunction("invoke", itemID) as InventoryItem ItemCodex[itemID] = groovyInvocable.invokeFunction("invoke", itemID) as GameItem
} }
} }
} }

View File

@@ -2,7 +2,7 @@ package net.torvald.terrarum
import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.itemproperties.IVKey import net.torvald.terrarum.itemproperties.IVKey
import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.Block
@@ -46,7 +46,7 @@ class StateUITest : BasicGameState() {
// Item properties must be pre-composed using CSV/JSON, and read and made into the item instance // Item properties must be pre-composed using CSV/JSON, and read and made into the item instance
// using factory/builder pattern. @see ItemCodex // using factory/builder pattern. @see ItemCodex
actor.inventory.add(object : InventoryItem() { actor.inventory.add(object : GameItem() {
init { init {
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.HAMMER itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.HAMMER
} }
@@ -56,7 +56,7 @@ class StateUITest : BasicGameState() {
override var originalName: String = "Test tool" override var originalName: String = "Test tool"
override var baseMass: Double = 12.0 override var baseMass: Double = 12.0
override var baseToolSize: Double? = 8.0 override var baseToolSize: Double? = 8.0
override var inventoryCategory: String = InventoryItem.Category.TOOL override var inventoryCategory: String = GameItem.Category.TOOL
override var maxDurability: Int = 143 override var maxDurability: Int = 143
override var durability: Float = 64f override var durability: Float = 64f
override var stackable = false override var stackable = false
@@ -65,7 +65,7 @@ class StateUITest : BasicGameState() {
}) })
actor.inventory.getByDynamicID(5656)!!.item.name = "Test tool" actor.inventory.getByDynamicID(5656)!!.item.name = "Test tool"
actor.inventory.add(object : InventoryItem() { actor.inventory.add(object : GameItem() {
init { init {
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.ARTEFACT itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.ARTEFACT
} }
@@ -75,7 +75,7 @@ class StateUITest : BasicGameState() {
override var originalName: String = "CONTEXT_ITEM_QUEST_NOUN" override var originalName: String = "CONTEXT_ITEM_QUEST_NOUN"
override var baseMass: Double = 1.4 override var baseMass: Double = 1.4
override var baseToolSize: Double? = null override var baseToolSize: Double? = null
override var inventoryCategory: String = InventoryItem.Category.MISC override var inventoryCategory: String = GameItem.Category.MISC
override var stackable = false override var stackable = false
override val isDynamic = false override val isDynamic = false
override val material = Material(0,0,0,0,0,0,0,0,0,0.0) override val material = Material(0,0,0,0,0,0,0,0,0,0.0)

View File

@@ -2,8 +2,7 @@ package net.torvald.terrarum
import net.torvald.colourutil.CIELabUtil.darkerLab import net.torvald.colourutil.CIELabUtil.darkerLab
import net.torvald.terrarum.gamecontroller.Key import net.torvald.terrarum.gamecontroller.Key
import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIInventory import net.torvald.terrarum.ui.UIInventory
import net.torvald.terrarum.ui.UIItem import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarum.ui.UIItemTextButton import net.torvald.terrarum.ui.UIItemTextButton
@@ -22,7 +21,7 @@ class UIItemInventoryElem(
override var posX: Int, override var posX: Int,
override var posY: Int, override var posY: Int,
override val width: Int, override val width: Int,
var item: InventoryItem?, var item: GameItem?,
var amount: Int, var amount: Int,
var itemImage: Image?, var itemImage: Image?,
val mouseOverTextCol: Color = Color(0xfff066), val mouseOverTextCol: Color = Color(0xfff066),

View File

@@ -4,7 +4,7 @@ import com.jme3.math.FastMath
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.faction.Faction import net.torvald.terrarum.gameactors.faction.Faction
import net.torvald.terrarum.gamecontroller.Key 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.itemproperties.Material
import net.torvald.terrarum.realestate.LandUtil import net.torvald.terrarum.realestate.LandUtil
import net.torvald.terrarum.ui.UIInventory import net.torvald.terrarum.ui.UIInventory
@@ -138,7 +138,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
get() = this == Terrarum.ingame!!.player get() = this == Terrarum.ingame!!.player
private val nullItem = object : InventoryItem() { private val nullItem = object : GameItem() {
override var dynamicID: Int = 0 override var dynamicID: Int = 0
override val originalID = dynamicID override val originalID = dynamicID
override val isUnique: Boolean = false override val isUnique: Boolean = false
@@ -480,7 +480,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
// ONLY FOR HAND_GRIPs!! // ONLY FOR HAND_GRIPs!!
val quickBarItem = inventory.getQuickBar(actorValue.getAsInt(key)!!)?.item 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) equipItem(quickBarItem)
} }

View File

@@ -2,12 +2,11 @@ package net.torvald.terrarum.gameactors
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.BlockCodex 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
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_WALLS import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_WALLS
import net.torvald.terrarum.itemproperties.ItemID import net.torvald.terrarum.itemproperties.ItemID
import net.torvald.terrarum.ui.UIInventory
import java.util.* import java.util.*
import java.util.concurrent.locks.Lock import java.util.concurrent.locks.Lock
import java.util.concurrent.locks.ReentrantLock 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.) * 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. * 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(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") println("[ActorInventory] add $item, $count")
// not wall-able walls // not wall-able walls
if (item.inventoryCategory == InventoryItem.Category.WALL && if (item.inventoryCategory == GameItem.Category.WALL &&
!BlockCodex[item.dynamicID - ITEM_WALLS.start].isWallable) { !BlockCodex[item.dynamicID - ITEM_WALLS.start].isWallable) {
throw IllegalArgumentException("Wall ID ${item.dynamicID - ITEM_WALLS.start} is not wall-able.") 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) fun remove(itemID: ItemID, count: Int) = remove(ItemCodex[itemID], count)
/** Will check existence of the item using its Dynamic ID; careful with command order! /** Will check existence of the item using its Dynamic ID; careful with command order!
* e.g. re-assign after this operation */ * 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") 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]) fun getQuickBar(slot: Int): InventoryPair? = getByDynamicID(quickBar[slot])
/** /**
* HashMap<InventoryItem, Amounts> * HashMap<GameItem, Amounts>
*/ */
fun forEach(consumer: (InventoryPair) -> Unit) = itemList.forEach(consumer) fun forEach(consumer: (InventoryPair) -> Unit) = itemList.forEach(consumer)
@@ -169,12 +168,12 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
false false
fun consumeItem(actor: Actor, item: InventoryItem) { fun consumeItem(actor: Actor, item: GameItem) {
if (item.stackable && !item.isDynamic) { if (item.stackable && !item.isDynamic) {
remove(item, 1) remove(item, 1)
} }
else { else {
val newItem: InventoryItem val newItem: GameItem
// unpack newly-made dynamic item (e.g. any weapon, floppy disk) // unpack newly-made dynamic item (e.g. any weapon, floppy disk)
if (item.isDynamic && item.originalID == item.dynamicID) { 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) = fun contains(id: ItemID) =
if (itemList.size == 0) if (itemList.size == 0)
false 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)

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.gameactors package net.torvald.terrarum.gameactors
import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.GameItem
/** /**
* Created by minjaesong on 16-01-31. * Created by minjaesong on 16-01-31.
@@ -13,6 +13,6 @@ interface CanBeAnItem {
fun resumeUpdateAndDraw() fun resumeUpdateAndDraw()
var itemData: InventoryItem var itemData: GameItem
} }

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.gameactors 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.itemproperties.ItemCodex
import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.blockproperties.BlockCodex
import org.newdawn.slick.GameContainer import org.newdawn.slick.GameContainer
@@ -9,7 +9,7 @@ import org.newdawn.slick.Graphics
/** /**
* Created by minjaesong on 16-03-15. * 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 { init {
if (item.dynamicID >= ItemCodex.ACTORID_MIN) if (item.dynamicID >= ItemCodex.ACTORID_MIN)

View File

@@ -1,24 +1,13 @@
package net.torvald.terrarum.gameactors package net.torvald.terrarum.gameactors
import net.torvald.terrarum.Terrarum 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.ActorAI
import net.torvald.terrarum.gameactors.ai.LuaAIWrapper import net.torvald.terrarum.gameactors.ai.LuaAIWrapper
import net.torvald.terrarum.gamecontroller.mouseX import net.torvald.terrarum.gamecontroller.mouseX
import net.torvald.terrarum.gamecontroller.mouseY 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 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.GameContainer
import org.newdawn.slick.Input
import java.io.InputStreamReader
import java.io.Reader
/** /**
* @param ai AI class. Use LuaAIWrapper for Lua script * @param ai AI class. Use LuaAIWrapper for Lua script
@@ -42,8 +31,8 @@ open class HumanoidNPC(
collisionType = DEFAULT_COLLISION_TYPE collisionType = DEFAULT_COLLISION_TYPE
} }
// we're having InventoryItem data so that this class could be somewhat universal // we're having GameItem data so that this class could be somewhat universal
override var itemData: InventoryItem = object : InventoryItem() { override var itemData: GameItem = object : GameItem() {
override var dynamicID = referenceID override var dynamicID = referenceID
override val originalID = dynamicID override val originalID = dynamicID
override val isUnique = true override val isUnique = true

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum.gameactors package net.torvald.terrarum.gameactors
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex 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. * 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 == 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") throw Error("Unequipping the item that cannot be equipped in the first place")
if (!inventory.contains(item)) { if (!inventory.contains(item)) {
@@ -32,7 +32,7 @@ interface Pocketed {
// no need for equipSlot(Int) // no need for equipSlot(Int)
fun unequipSlot(slot: 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") throw IllegalArgumentException("Slot index out of range: $slot")
unequipItem(inventory.itemEquipped[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. * 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)) { if (!inventory.contains(item)) {
println("[Pocketed] Item does not exist; adding one before equipped") println("[Pocketed] Item does not exist; adding one before equipped")
inventory.add(item) inventory.add(item)
@@ -54,26 +54,26 @@ interface Pocketed {
// else do nothing // else do nothing
} }
fun equipped(item: InventoryItem): Boolean { fun equipped(item: GameItem): Boolean {
return inventory.itemEquipped[item.equipPosition] == item return inventory.itemEquipped[item.equipPosition] == item
} }
fun addItem(itemID: Int, count: Int = 1) = inventory.add(ItemCodex[itemID], count) 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(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 hasItem(id: Int) = inventory.contains(id)
fun consumePrimary(item: InventoryItem) { fun consumePrimary(item: GameItem) {
if (item.primaryUse(Terrarum.appgc, Terrarum.delta)) { if (item.primaryUse(Terrarum.appgc, Terrarum.delta)) {
inventory.consumeItem(this as Actor, item) // consume on successful inventory.consumeItem(this as Actor, item) // consume on successful
} }
} }
fun consumeSecondary(item: InventoryItem) { fun consumeSecondary(item: GameItem) {
if (item.secondaryUse(Terrarum.appgc, Terrarum.delta)) if (item.secondaryUse(Terrarum.appgc, Terrarum.delta))
inventory.consumeItem(this as Actor, item) // consume on successful inventory.consumeItem(this as Actor, item) // consume on successful
} }

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum.gamecontroller
import net.torvald.terrarum.worlddrawer.FeaturesDrawer import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.worlddrawer.WorldCamera import net.torvald.terrarum.worlddrawer.WorldCamera
import org.newdawn.slick.GameContainer import org.newdawn.slick.GameContainer
import org.newdawn.slick.Input import org.newdawn.slick.Input
@@ -65,7 +65,7 @@ object GameController {
// Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP) // Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP)
if (ingame.player != null && ingame.canPlayerControl) { if (ingame.player != null && ingame.canPlayerControl) {
if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary")) || input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) { if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary")) || input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) {
val itemOnGrip = ingame.player!!.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP] val itemOnGrip = ingame.player!!.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]
if (itemOnGrip != null) { if (itemOnGrip != null) {
if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary"))) { if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary"))) {
@@ -130,7 +130,7 @@ object GameController {
val ingame = Terrarum.ingame!! val ingame = Terrarum.ingame!!
// don't separate Player from this! Physics will break, esp. airborne manoeuvre // don't separate Player from this! Physics will break, esp. airborne manoeuvre
if (ingame.player != null && ingame.canPlayerControl) { if (ingame.player != null && ingame.canPlayerControl) {
val itemOnGrip = ingame.player!!.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP] val itemOnGrip = ingame.player!!.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]
if (itemOnGrip != null) { if (itemOnGrip != null) {
if (button == Terrarum.getConfigInt("mousePrimary")) { if (button == Terrarum.getConfigInt("mousePrimary")) {

View File

@@ -5,7 +5,6 @@ import net.torvald.terrarum.ItemValue
import net.torvald.terrarum.gameactors.ActorInventory import net.torvald.terrarum.gameactors.ActorInventory
import net.torvald.terrarum.gameactors.Pocketed import net.torvald.terrarum.gameactors.Pocketed
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import org.newdawn.slick.Color import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer import org.newdawn.slick.GameContainer
@@ -15,7 +14,7 @@ typealias ItemID = Int
/** /**
* Created by minjaesong on 16-01-16. * Created by minjaesong on 16-01-16.
*/ */
abstract class InventoryItem : Comparable<InventoryItem>, Cloneable { abstract class GameItem : Comparable<GameItem>, Cloneable {
abstract var dynamicID: ItemID abstract var dynamicID: ItemID
/** /**
@@ -110,7 +109,7 @@ abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
open var scale: Double = 1.0 open var scale: Double = 1.0
/** /**
* Set to zero (InventoryItem.DURABILITY_NA) if durability not applicable * Set to zero (GameItem.DURABILITY_NA) if durability not applicable
*/ */
open var maxDurability: Int = 0 open var maxDurability: Int = 0
@@ -183,7 +182,7 @@ abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (other == null) return false if (other == null) return false
return dynamicID == (other as InventoryItem).dynamicID return dynamicID == (other as GameItem).dynamicID
} }
fun unsetCustomName() { fun unsetCustomName() {
@@ -192,7 +191,7 @@ abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
nameColour = Color.white nameColour = Color.white
} }
override fun compareTo(other: InventoryItem): Int = (this.dynamicID - other.dynamicID).sign() override fun compareTo(other: GameItem): Int = (this.dynamicID - other.dynamicID).sign()
fun Int.sign(): Int = if (this > 0) 1 else if (this < 0) -1 else 0 fun Int.sign(): Int = if (this > 0) 1 else if (this < 0) -1 else 0
@@ -243,17 +242,17 @@ abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
@JvmStatic val MISC = "misc" @JvmStatic val MISC = "misc"
} }
override public fun clone(): InventoryItem { override public fun clone(): GameItem {
val clonedItem = super.clone() val clonedItem = super.clone()
// properly clone ItemValue // properly clone ItemValue
(clonedItem as InventoryItem).itemProperties = this.itemProperties.clone() (clonedItem as GameItem).itemProperties = this.itemProperties.clone()
return clonedItem return clonedItem
} }
fun generateUniqueDynamicID(inventory: ActorInventory): InventoryItem { fun generateUniqueDynamicID(inventory: ActorInventory): GameItem {
dynamicID = InventoryItem.generateUniqueDynamicID(inventory) dynamicID = GameItem.generateUniqueDynamicID(inventory)
return this return this
} }

View File

@@ -24,7 +24,7 @@ object ItemCodex {
* <ItemID or RefID for Actor, TheItem> * <ItemID or RefID for Actor, TheItem>
* Will return corresponding Actor if ID >= ACTORID_MIN * Will return corresponding Actor if ID >= ACTORID_MIN
*/ */
private val itemCodex = HashMap<ItemID, InventoryItem>() private val itemCodex = HashMap<ItemID, GameItem>()
private val dynamicItemDescription = HashMap<ItemID, KVHashMap>() private val dynamicItemDescription = HashMap<ItemID, KVHashMap>()
val ITEM_TILES = 0..GameWorld.TILES_SUPPORTED - 1 val ITEM_TILES = 0..GameWorld.TILES_SUPPORTED - 1
@@ -42,7 +42,7 @@ object ItemCodex {
// blocks.csvs are loaded by ModMgr beforehand // blocks.csvs are loaded by ModMgr beforehand
// block items (blocks and walls are the same thing basically) // block items (blocks and walls are the same thing basically)
for (i in ITEM_TILES + ITEM_WALLS) { for (i in ITEM_TILES + ITEM_WALLS) {
itemCodex[i] = object : InventoryItem() { itemCodex[i] = object : GameItem() {
override val originalID = i override val originalID = i
override var dynamicID = i override var dynamicID = i
override val isUnique: Boolean = false override val isUnique: Boolean = false
@@ -108,7 +108,7 @@ object ItemCodex {
} }
// test copper pickaxe // test copper pickaxe
/*itemCodex[ITEM_STATIC.first] = object : InventoryItem() { /*itemCodex[ITEM_STATIC.first] = object : GameItem() {
override val originalID = ITEM_STATIC.first override val originalID = ITEM_STATIC.first
override var dynamicID = originalID override var dynamicID = originalID
override val isUnique = false override val isUnique = false
@@ -173,7 +173,7 @@ object ItemCodex {
/** /**
* Returns clone of the item in the Codex * Returns clone of the item in the Codex
*/ */
operator fun get(code: ItemID): InventoryItem { operator fun get(code: ItemID): GameItem {
if (code <= ITEM_STATIC.endInclusive) // generic item if (code <= ITEM_STATIC.endInclusive) // generic item
return itemCodex[code]!!.clone() // from CSV return itemCodex[code]!!.clone() // from CSV
else if (code <= ITEM_DYNAMIC.endInclusive) { else if (code <= ITEM_DYNAMIC.endInclusive) {
@@ -190,11 +190,11 @@ object ItemCodex {
/** /**
* Mainly used by GameItemLoader * Mainly used by GameItemLoader
*/ */
operator fun set(code: ItemID, item: InventoryItem) { operator fun set(code: ItemID, item: GameItem) {
itemCodex[code] = item itemCodex[code] = item
} }
fun getItemImage(item: InventoryItem): Image { fun getItemImage(item: GameItem): Image {
// terrain // terrain
if (item.originalID in ITEM_TILES) { if (item.originalID in ITEM_TILES) {
return BlocksDrawer.tilesTerrain.getSubImage( return BlocksDrawer.tilesTerrain.getSubImage(

View File

@@ -5,7 +5,7 @@ import net.torvald.terrarum.Terrarum.joypadLabelNinA
import net.torvald.terrarum.Terrarum.joypadLabelNinY import net.torvald.terrarum.Terrarum.joypadLabelNinY
import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER import net.torvald.terrarum.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER
import net.torvald.terrarum.itemproperties.InventoryItem import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import org.newdawn.slick.* import org.newdawn.slick.*
@@ -35,15 +35,15 @@ class UIInventory(
val defaultTextColour = Color(0xeaeaea) val defaultTextColour = Color(0xeaeaea)
init { init {
catButtonsToCatIdent.put("GAME_INVENTORY_WEAPONS", InventoryItem.Category.WEAPON) catButtonsToCatIdent.put("GAME_INVENTORY_WEAPONS", GameItem.Category.WEAPON)
catButtonsToCatIdent.put("CONTEXT_ITEM_TOOL_PLURAL", InventoryItem.Category.TOOL) catButtonsToCatIdent.put("CONTEXT_ITEM_TOOL_PLURAL", GameItem.Category.TOOL)
catButtonsToCatIdent.put("CONTEXT_ITEM_ARMOR", InventoryItem.Category.ARMOUR) catButtonsToCatIdent.put("CONTEXT_ITEM_ARMOR", GameItem.Category.ARMOUR)
catButtonsToCatIdent.put("GAME_INVENTORY_INGREDIENTS", InventoryItem.Category.GENERIC) catButtonsToCatIdent.put("GAME_INVENTORY_INGREDIENTS", GameItem.Category.GENERIC)
catButtonsToCatIdent.put("GAME_INVENTORY_POTIONS", InventoryItem.Category.POTION) catButtonsToCatIdent.put("GAME_INVENTORY_POTIONS", GameItem.Category.POTION)
catButtonsToCatIdent.put("CONTEXT_ITEM_MAGIC", InventoryItem.Category.MAGIC) catButtonsToCatIdent.put("CONTEXT_ITEM_MAGIC", GameItem.Category.MAGIC)
catButtonsToCatIdent.put("GAME_INVENTORY_BLOCKS", InventoryItem.Category.BLOCK) catButtonsToCatIdent.put("GAME_INVENTORY_BLOCKS", GameItem.Category.BLOCK)
catButtonsToCatIdent.put("GAME_INVENTORY_WALLS", InventoryItem.Category.WALL) catButtonsToCatIdent.put("GAME_INVENTORY_WALLS", GameItem.Category.WALL)
catButtonsToCatIdent.put("GAME_GENRE_MISC", InventoryItem.Category.MISC) catButtonsToCatIdent.put("GAME_GENRE_MISC", GameItem.Category.MISC)
// special filter // special filter
catButtonsToCatIdent.put("MENU_LABEL_ALL", "__all__") catButtonsToCatIdent.put("MENU_LABEL_ALL", "__all__")