diff --git a/assets/mods/basegame/items/itemid.csv b/assets/mods/basegame/items/itemid.csv index c85baee9e..32f715ec0 100644 --- a/assets/mods/basegame/items/itemid.csv +++ b/assets/mods/basegame/items/itemid.csv @@ -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 diff --git a/assets/mods/basegame/items/items.tga b/assets/mods/basegame/items/items.tga index f744177e6..cd09e1805 100644 --- a/assets/mods/basegame/items/items.tga +++ b/assets/mods/basegame/items/items.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:080a23fe059d163a1632b84a280e4460c57436411f67c6b1343e38371162859c +oid sha256:deae4cfa1393231a4d6eb92c38608ea67e36a1082ff1260d7a91318a47b63ce0 size 2408466 diff --git a/assets/mods/basegame/locales/en/items.json b/assets/mods/basegame/locales/en/items.json index 2a281c653..849122b4e 100644 --- a/assets/mods/basegame/locales/en/items.json +++ b/assets/mods/basegame/locales/en/items.json @@ -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", diff --git a/assets/mods/basegame/locales/koKR/items.json b/assets/mods/basegame/locales/koKR/items.json index 1d1cf966b..dbb05de54 100644 --- a/assets/mods/basegame/locales/koKR/items.json +++ b/assets/mods/basegame/locales/koKR/items.json @@ -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": "타자기", diff --git a/src/net/torvald/terrarum/blockproperties/BlockCodex.kt b/src/net/torvald/terrarum/blockproperties/BlockCodex.kt index 2110d28df..67088144a 100644 --- a/src/net/torvald/terrarum/blockproperties/BlockCodex.kt +++ b/src/net/torvald/terrarum/blockproperties/BlockCodex.kt @@ -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.") diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt index dd76da6ce..362d8f01d 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt @@ -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") } diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/SledgehammerCore.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/SledgehammerCore.kt new file mode 100644 index 000000000..b069cd9ec --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/SledgehammerCore.kt @@ -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) +} \ No newline at end of file diff --git a/src/net/torvald/unicode/UniTextShortcuts.kt b/src/net/torvald/unicode/UniTextShortcuts.kt index 6a83b8c70..4b6d7a2c3 100644 --- a/src/net/torvald/unicode/UniTextShortcuts.kt +++ b/src/net/torvald/unicode/UniTextShortcuts.kt @@ -83,7 +83,7 @@ fun getKeycapFkeys(n: Int) = when (n) { fun List.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()) diff --git a/work_files/graphics/items/basegame_items.kra b/work_files/graphics/items/basegame_items.kra index bdc809e62..54e33ec67 100644 --- a/work_files/graphics/items/basegame_items.kra +++ b/work_files/graphics/items/basegame_items.kra @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2ba327d06abcd284606612ee7d7c2369248b09bf85cdeadbec3b4675758e72ce -size 166383 +oid sha256:bfb72dd1e0ac1ff1337a49f31dc09a59035208475935084b98a0e77b451d29ea +size 168739