mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-18 22:44:04 +09:00
new item type, "Dynamic Item"; working text terminal
Former-commit-id: 81e6d836f5f1e6490027d38146a32d404cf9ce3e Former-commit-id: af6557340f9cd0ea0b67eb7a8825aeffe75f9d82
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package net.torvald.terrarum.itemproperties
|
||||
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.KVHashMap
|
||||
import net.torvald.terrarum.gameactors.CanBeAnItem
|
||||
import net.torvald.terrarum.gameitem.InventoryItem
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gamemap.GameWorld
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import org.newdawn.slick.GameContainer
|
||||
import java.util.*
|
||||
|
||||
@@ -17,23 +18,30 @@ object ItemPropCodex {
|
||||
|
||||
/**
|
||||
* <ItemID or RefID for Actor, TheItem>
|
||||
* Will return corresponding Actor if ID >= 32768
|
||||
* Will return corresponding Actor if ID >= 16777216
|
||||
*/
|
||||
private lateinit var itemCodex: Array<InventoryItem>
|
||||
private val itemCodex = ArrayList<InventoryItem>()
|
||||
private val dynamicItemDescription = HashMap<Int, KVHashMap>()
|
||||
|
||||
const val ITEM_UNIQUE_MAX = 32768
|
||||
val TILE_MAX = GameWorld.TILES_SUPPORTED
|
||||
val ITEM_TILE_MAX = GameWorld.TILES_SUPPORTED
|
||||
val ITEM_COUNT_MAX = 16777216
|
||||
val ITEM_DYNAMIC_MAX = ITEM_COUNT_MAX - 1
|
||||
val ITEM_STATIC_MAX = 32767
|
||||
val ITEM_DYNAMIC_MIN = ITEM_STATIC_MAX + 1
|
||||
val ITEM_STATIC_MIN = ITEM_TILE_MAX
|
||||
|
||||
init {
|
||||
itemCodex = arrayOf<InventoryItem>()
|
||||
|
||||
// read prop in csv
|
||||
// read prop in csv and fill itemCodex
|
||||
|
||||
// read from save (if applicable) and fill dynamicItemDescription
|
||||
}
|
||||
|
||||
fun getProp(code: Int): InventoryItem {
|
||||
if (code < ITEM_UNIQUE_MAX) // generic item
|
||||
return itemCodex[code]
|
||||
if (code < ITEM_STATIC_MAX) // generic item
|
||||
return itemCodex[code] // from CSV
|
||||
else if (code < ITEM_DYNAMIC_MAX) {
|
||||
TODO("read from dynamicitem description (JSON)")
|
||||
}
|
||||
else {
|
||||
val a = Terrarum.ingame.getActorByID(code) // actor item
|
||||
if (a is CanBeAnItem) return a.itemData
|
||||
@@ -41,4 +49,6 @@ object ItemPropCodex {
|
||||
throw IllegalArgumentException("Attempted to get item data of actor that cannot be an item. ($a)")
|
||||
}
|
||||
}
|
||||
|
||||
fun hasItem(itemID: Int): Boolean = dynamicItemDescription.containsKey(itemID)
|
||||
}
|
||||
Reference in New Issue
Block a user