working sledgehammer item to take down walls

This commit is contained in:
minjaesong
2023-09-05 22:47:40 +09:00
parent 274be20e25
commit 70b9cebbd0
9 changed files with 212 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ id;classname
1;net.torvald.terrarum.modulebasegame.gameitems.PickaxeCopper
2;net.torvald.terrarum.modulebasegame.gameitems.PickaxeIron
3;net.torvald.terrarum.modulebasegame.gameitems.PickaxeSteel
4;net.torvald.terrarum.modulebasegame.gameitems.SledgehammerIron
5;net.torvald.terrarum.modulebasegame.gameitems.ItemTikiTorch
6;net.torvald.terrarum.modulebasegame.gameitems.ItemStorageChest
7;net.torvald.terrarum.modulebasegame.gameitems.WireGraphDebugger
@@ -9,6 +10,9 @@ id;classname
9;net.torvald.terrarum.modulebasegame.gameitems.WireCutterAll
10;net.torvald.terrarum.modulebasegame.gameitems.ItemTypewriter
11;net.torvald.terrarum.modulebasegame.gameitems.ItemWallCalendar
12;net.torvald.terrarum.modulebasegame.gameitems.SledgehammerCopper
13;net.torvald.terrarum.modulebasegame.gameitems.SledgehammerSteel
256;net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorOak
257;net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorEbony
1 id classname
2 1 net.torvald.terrarum.modulebasegame.gameitems.PickaxeCopper
3 2 net.torvald.terrarum.modulebasegame.gameitems.PickaxeIron
4 3 net.torvald.terrarum.modulebasegame.gameitems.PickaxeSteel
5 4 net.torvald.terrarum.modulebasegame.gameitems.SledgehammerIron
6 5 net.torvald.terrarum.modulebasegame.gameitems.ItemTikiTorch
7 6 net.torvald.terrarum.modulebasegame.gameitems.ItemStorageChest
8 7 net.torvald.terrarum.modulebasegame.gameitems.WireGraphDebugger
10 9 net.torvald.terrarum.modulebasegame.gameitems.WireCutterAll
11 10 net.torvald.terrarum.modulebasegame.gameitems.ItemTypewriter
12 11 net.torvald.terrarum.modulebasegame.gameitems.ItemWallCalendar
13 12 net.torvald.terrarum.modulebasegame.gameitems.SledgehammerCopper
14 13 net.torvald.terrarum.modulebasegame.gameitems.SledgehammerSteel
15 256 net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorOak
16 256 257 net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorOak net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorEbony
17 257 258 net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorEbony net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorBirch
18 258 259 net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorBirch net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorRosewood

Binary file not shown.

View File

@@ -5,6 +5,12 @@
"ITEM_CALENDAR": "Calendar",
"ITEM_LOGIC_SIGNAL_EMITTER": "Logic Signal Emitter",
"ITEM_PICK_COPPER": "Copper Pickaxe",
"ITEM_PICK_IRON": "Iron Pickaxe",
"ITEM_PICK_STEEL": "Steel Pickaxe",
"ITEM_SLEDGEHAMMER_COPPER": "Copper Sledgehammer",
"ITEM_SLEDGEHAMMER_IRON": "Iron Sledgehammer",
"ITEM_SLEDGEHAMMER_STEEL": "Steel Sledgehammer",
"ITEM_STORAGE_CHEST": "Storage Chest",
"ITEM_TIKI_TORCH": "Tiki Torch",
"ITEM_TYPEWRITER": "Typewriter",

View File

@@ -5,6 +5,12 @@
"ITEM_CALENDAR": "달력",
"ITEM_LOGIC_SIGNAL_EMITTER": "신호발생기",
"ITEM_PICK_COPPER": "구리 곡괭이",
"ITEM_PICK_IRON": "철 곡괭이",
"ITEM_PICK_STEEL": "강철 곡괭이",
"ITEM_SLEDGEHAMMER_COPPER": "구리 해머",
"ITEM_SLEDGEHAMMER_IRON": "철 해머",
"ITEM_SLEDGEHAMMER_STEEL": "강철 해머",
"ITEM_STORAGE_CHEST": "보관상자",
"ITEM_TIKI_TORCH": "티키 토치",
"ITEM_TYPEWRITER": "타자기",

View File

@@ -146,7 +146,10 @@ class BlockCodex {
}
try {
return blockProps[blockID]!!
return if (blockID.startsWith("wall@"))
blockProps[blockID.substring(5)]!!
else
blockProps[blockID]!!
}
catch (e: NullPointerException) {
throw NullPointerException("Blockprop with id $blockID does not exist.")

View File

@@ -112,7 +112,7 @@ object PickaxeCore {
class PickaxeCopper(originalID: ItemID) : GameItem(originalID) {
internal constructor() : this("-uninitialised-")
override val originalName = "COPPER_PICK"
override val originalName = "ITEM_PICK_COPPER"
override var baseToolSize: Double? = BASE_MASS_AND_SIZE
override var stackable = true
override var inventoryCategory = Category.TOOL
@@ -127,7 +127,6 @@ class PickaxeCopper(originalID: ItemID) : GameItem(originalID) {
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
super.maxDurability = (TOOL_DURABILITY_BASE * material.enduranceMod).roundToInt()
super.durability = maxDurability.toFloat()
super.name = "Copper Pickaxe"
super.tags.add("PICK")
}
@@ -142,7 +141,7 @@ class PickaxeCopper(originalID: ItemID) : GameItem(originalID) {
class PickaxeIron(originalID: ItemID) : GameItem(originalID) {
internal constructor() : this("-uninitialised-")
override val originalName = "IRON_PICK"
override val originalName = "ITEM_PICK_IRON"
override var baseToolSize: Double? = BASE_MASS_AND_SIZE
override var stackable = true
override var inventoryCategory = Category.TOOL
@@ -157,7 +156,6 @@ class PickaxeIron(originalID: ItemID) : GameItem(originalID) {
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
super.maxDurability = (TOOL_DURABILITY_BASE * material.enduranceMod).roundToInt()
super.durability = maxDurability.toFloat()
super.name = "Iron Pickaxe"
super.tags.add("PICK")
}
@@ -172,7 +170,7 @@ class PickaxeIron(originalID: ItemID) : GameItem(originalID) {
class PickaxeSteel(originalID: ItemID) : GameItem(originalID) {
internal constructor() : this("-uninitialised-")
override val originalName = "STEEL_PICK"
override val originalName = "ITEM_PICK_STEEL"
override var baseToolSize: Double? = BASE_MASS_AND_SIZE
override var stackable = true
override var inventoryCategory = Category.TOOL
@@ -187,7 +185,6 @@ class PickaxeSteel(originalID: ItemID) : GameItem(originalID) {
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
super.maxDurability = (TOOL_DURABILITY_BASE * material.enduranceMod).roundToInt()
super.durability = maxDurability.toFloat()
super.name = "Steel Pickaxe"
super.tags.add("PICK")
}

View File

@@ -0,0 +1,185 @@
package net.torvald.terrarum.modulebasegame.gameitems
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.*
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.mouseInInteractableRangeTools
import net.torvald.terrarum.itemproperties.Calculate
import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem
import net.torvald.terrarum.modulebasegame.gameitems.SledgehammerCore.BASE_MASS_AND_SIZE
import net.torvald.terrarum.modulebasegame.gameitems.SledgehammerCore.TOOL_DURABILITY_BASE
import kotlin.math.roundToInt
/**
* Created by minjaesong on 2023-09-05.
*/
object SledgehammerCore {
/**
* @param mx centre position of the digging
* @param my centre position of the digging
* @param mw width of the digging
* @param mh height of the digging
*/
fun startPrimaryUse(
actor: ActorWithBody, delta: Float, item: GameItem?, mx: Int, my: Int,
dropProbability: Double = 1.0, mw: Int = 1, mh: Int = 1
) = mouseInInteractableRangeTools(actor, item) {
// un-round the mx
val ww = INGAME.world.width
val hpww = ww * TerrarumAppConfiguration.TILE_SIZE / 2
val apos = actor.centrePosPoint
val mx = if (apos.x - mx * TerrarumAppConfiguration.TILE_SIZE < -hpww) mx - ww
else if (apos.x - mx * TerrarumAppConfiguration.TILE_SIZE >= hpww) mx + ww
else mx
var xoff = -(mw / 2) // implicit flooring
var yoff = -(mh / 2) // implicit flooring
// if mw or mh is even number, make it closer toward the actor
if (mw % 2 == 0 && apos.x > mx * TerrarumAppConfiguration.TILE_SIZE) xoff += 1
if (mh % 2 == 0 && apos.y > my * TerrarumAppConfiguration.TILE_SIZE) yoff += 1
var usageStatus = false
for (oy in 0 until mh) for (ox in 0 until mw) {
val x = mx + xoff + ox
val y = my + yoff + oy
val mousePoint = Point2d(x.toDouble(), y.toDouble())
val actorvalue = actor.actorValue
val tile = INGAME.world.getTileFromWall(x, y)
val tileTerrain = INGAME.world.getTileFromTerrain(x, y)
item?.using = true
// linear search filter (check for intersection with tilewise mouse point and tilewise hitbox)
// return false if hitting actors
// ** below is commented out -- don't make actors obstruct the way of digging **
/*var ret1 = true
INGAME.actorContainerActive.forEach {
if (it is ActorWBMovable && it.hIntTilewiseHitbox.intersects(mousePoint))
ret1 = false // return is not allowed here
}
if (!ret1) return ret1*/
// return false if here's no tile, or if the wall is covered by a solid tile
if (Block.AIR == tile || BlockCodex[tile].isActorBlock || BlockCodex[tileTerrain].isSolid) {
usageStatus = usageStatus or false
continue
}
// filter passed, do the job
val swingDmgToFrameDmg = delta.toDouble() / actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
INGAME.world.inflictWallDamage(
x, y,
Calculate.pickaxePower(actor, item?.material) * swingDmgToFrameDmg
)?.let { tileBroken ->
if (Math.random() < dropProbability) {
val drop = BlockCodex[tileBroken].drop
if (drop.isNotBlank()) {
INGAME.queueActorAddition(DroppedItem("wall@$drop", x * TerrarumAppConfiguration.TILE_SIZED, y * TerrarumAppConfiguration.TILE_SIZED))
}
}
}
usageStatus = usageStatus or true
}
usageStatus
}
fun endPrimaryUse(actor: ActorWithBody, delta: Float, item: GameItem): Boolean {
item.using = false
// reset action timer to zero
actor.actorValue.set(AVKey.__ACTION_TIMER, 0.0)
return true
}
const val BASE_MASS_AND_SIZE = 20.0 // of iron sledgehammer
const val TOOL_DURABILITY_BASE = 480 // of iron sledgehammer
}
class SledgehammerCopper(originalID: ItemID) : GameItem(originalID) {
internal constructor() : this("-uninitialised-")
override val originalName = "ITEM_SLEDGEHAMMER_COPPER"
override var baseToolSize: Double? = BASE_MASS_AND_SIZE
override var stackable = true
override var inventoryCategory = Category.TOOL
override val isUnique = false
override val isDynamic = true
override val materialId = "CUPR"
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(6,0)
init {
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
super.maxDurability = (TOOL_DURABILITY_BASE * material.enduranceMod).roundToInt()
super.durability = maxDurability.toFloat()
super.tags.add("HAMR")
}
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) =
if (SledgehammerCore.startPrimaryUse(actor, delta, this, Terrarum.mouseTileX, Terrarum.mouseTileY)) 0L else -1L
override fun endPrimaryUse(actor: ActorWithBody, delta: Float) = SledgehammerCore.endPrimaryUse(actor, delta, this)
}
class SledgehammerIron(originalID: ItemID) : GameItem(originalID) {
internal constructor() : this("-uninitialised-")
override val originalName = "ITEM_SLEDGEHAMMER_IRON"
override var baseToolSize: Double? = BASE_MASS_AND_SIZE
override var stackable = true
override var inventoryCategory = Category.TOOL
override val isUnique = false
override val isDynamic = true
override val materialId = "IRON"
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(7,0)
init {
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
super.maxDurability = (TOOL_DURABILITY_BASE * material.enduranceMod).roundToInt()
super.durability = maxDurability.toFloat()
super.tags.add("HAMR")
}
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) =
if (SledgehammerCore.startPrimaryUse(actor , delta, this, Terrarum.mouseTileX, Terrarum.mouseTileY)) 0L else -1L
override fun endPrimaryUse(actor: ActorWithBody, delta: Float) = SledgehammerCore.endPrimaryUse(actor, delta, this)
}
class SledgehammerSteel(originalID: ItemID) : GameItem(originalID) {
internal constructor() : this("-uninitialised-")
override val originalName = "ITEM_SLEDGEHAMMER_STEEL"
override var baseToolSize: Double? = BASE_MASS_AND_SIZE
override var stackable = true
override var inventoryCategory = Category.TOOL
override val isUnique = false
override val isDynamic = true
override val materialId = "STAL"
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(8,0)
init {
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
super.maxDurability = (TOOL_DURABILITY_BASE * material.enduranceMod).roundToInt()
super.durability = maxDurability.toFloat()
super.tags.add("HAMR")
}
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) =
if (SledgehammerCore.startPrimaryUse(actor, delta, this, Terrarum.mouseTileX, Terrarum.mouseTileY)) 0L else -1L
override fun endPrimaryUse(actor: ActorWithBody, delta: Float) = SledgehammerCore.endPrimaryUse(actor, delta, this)
}

View File

@@ -83,7 +83,7 @@ fun getKeycapFkeys(n: Int) = when (n) {
fun List<Int>.toJavaString(): String {
val sb = StringBuilder()
this.forEach {
this.subList(0, this.size).forEach {
if (it > 65535) {
val u = it - 65536
sb.append((0xD800 or (u ushr 10).and(1023)).toChar())