item is useable (wall is not!); tile breakage works confirmed

This commit is contained in:
minjaesong
2021-02-24 16:46:37 +09:00
parent b6a688c484
commit ed0bec0ee8
4 changed files with 12 additions and 139 deletions

View File

@@ -239,7 +239,7 @@ object ModMgr {
val internalID: Int = it["id"].toInt()
val itemName: String = "item@$module:$internalID"
printdbg(this, "Reading item #$internalID with className $className")
printdbg(this, "Reading item ${itemName} <<- internal #$internalID with className $className")
val loadedClass = Class.forName(className)
val loadedClassConstructor = loadedClass.getConstructor(ItemID::class.java)

View File

@@ -39,133 +39,6 @@ object ItemCodex {
private val itemImagePlaceholder: TextureRegion
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_24") // copper pickaxe
init {
//val ingame = Terrarum.ingame!! as Ingame // WARNING you can't put this here, ExceptionInInitializerError
println("[ItemCodex] recording item ID ")
// test copper pickaxe
/*itemCodex[ITEM_STATIC.first] = object : GameItem() {
override val originalID = ITEM_STATIC.first
override var dynamicID = originalID
override val isUnique = false
override val originalName = ""
override var baseMass = 10.0
override var baseToolSize: Double? = 10.0
override var stackable = true
override var maxDurability = 147//606
override var durability = maxDurability.toFloat()
override var equipPosition = EquipPosition.HAND_GRIP
override var inventoryCategory = Category.TOOL
override val isDynamic = true
override val material = Material(0,0,0,0,0,0,0,0,1,0.0)
init {
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.PICK
name = "Stone pickaxe"
}
override fun startPrimaryUse(delta: Float): Boolean {
val mousePoint = Point2d(Terrarum.mouseTileX.toDouble(), Terrarum.mouseTileY.toDouble())
val actorvalue = ingame.actorNowPlaying.actorValue
using = true
// linear search filter (check for intersection with tilewise mouse point and tilewise hitbox)
// return false if hitting actors
ingame.actorContainerActive.forEach {
if (it is ActorWBMovable && it.hIntTilewiseHitbox.intersects(mousePoint))
return false
}
// return false if there's no tile
if (Block.AIR == ingame.world.getTileFromTerrain(Terrarum.mouseTileX, Terrarum.mouseTileY))
return false
// filter passed, do the job
val swingDmgToFrameDmg = delta.toDouble() / actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
ingame.world.inflictTerrainDamage(
Terrarum.mouseTileX,
Terrarum.mouseTileY,
Calculate.pickaxePower(ingame.actorNowPlaying, material) * swingDmgToFrameDmg
)
return true
}
override fun endPrimaryUse(delta: Float): Boolean {
using = false
// reset action timer to zero
ingame.actorNowPlaying.actorValue[AVKey.__ACTION_TIMER] = 0.0
return true
}
}*/
// test water bucket
/*itemCodex[9000] = object : GameItem(9000) {
override val isUnique: Boolean = true
override val originalName: String = "Infinite Water Bucket"
override var baseMass: Double = 1000.0
override var baseToolSize: Double? = null
override var inventoryCategory: String = "tool"
override var stackable: Boolean = false
override val isDynamic: Boolean = false
override val material: Material = Material()
init {
equipPosition = EquipPosition.HAND_GRIP
}
override fun startPrimaryUse(delta: Float): Boolean {
val ingame = Terrarum.ingame!! as TerrarumIngame // must be in here
ingame.world.setFluid(Terrarum.mouseTileX, Terrarum.mouseTileY, Fluid.WATER, 4f)
return true
}
}
// test lava bucket
itemCodex[9001] = object : GameItem(9001) {
override val isUnique: Boolean = true
override val originalName: String = "Infinite Lava Bucket"
override var baseMass: Double = 1000.0
override var baseToolSize: Double? = null
override var inventoryCategory: String = "tool"
override var stackable: Boolean = false
override val isDynamic: Boolean = false
override val material: Material = Material()
init {
equipPosition = EquipPosition.HAND_GRIP
}
override fun startPrimaryUse(delta: Float): Boolean {
val ingame = Terrarum.ingame!! as TerrarumIngame // must be in here
ingame.world.setFluid(Terrarum.mouseTileX, Terrarum.mouseTileY, Fluid.LAVA, 4f)
return true
}
}*/
// read from save (if applicable) and fill dynamicItemDescription
println()
}
/**
* @param: dynamicID string of "dyn:<random id>"
*/
@@ -194,7 +67,7 @@ object ItemCodex {
//throw IllegalArgumentException("Attempted to get item data of actor that cannot be an item. ($a)")
}
else // generic item
return itemCodex[code]!!.clone() // from CSV
return itemCodex[code]?.clone() // from CSV
}
fun dynamicToStaticID(dynamicID: ItemID) = dynamicToStaticTable[dynamicID]!!
@@ -225,7 +98,7 @@ object ItemCodex {
}
// item
else if (itemID.startsWith("item@")) {
return getItemImage(itemID)
return itemCodex[itemID]?.itemImage
}
// TODO: wires
// wall

View File

@@ -45,7 +45,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
init {
}
fun add(itemID: ItemID, count: Int = 1) = add(ItemCodex[itemID]!!, count)
fun add(itemID: ItemID, count: Int = 1) = if (ItemCodex[itemID] == null) throw NullPointerException("Item not found: "+itemID) else add(ItemCodex[itemID]!!, count)
fun add(item: GameItem, count: Int = 1) {
println("[ActorInventory] add $item, $count")

View File

@@ -84,13 +84,13 @@ object PlayerBuilderSigrid {
}
// item ids are defined in <module>/items/itemid.csv
/*
inventory.add("item@basegame:0", 16) // copper pick
inventory.add("item@basegame:1") // iron pick
inventory.add("item@basegame:2") // steel pick
inventory.add("item@basegame:3", 9995) // wire piece
inventory.add("item@basegame:4", 385930603) // test tiki torch
inventory.add("item@basegame:5", 95) // crafting table
*/
inventory.add("item@basegame:1", 16) // copper pick
inventory.add("item@basegame:2") // iron pick
inventory.add("item@basegame:3") // steel pick
inventory.add("item@basegame:4", 9995) // wire piece
inventory.add("item@basegame:5", 385930603) // test tiki torch
//inventory.add("item@basegame:6", 95) // crafting table
}
}