mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-14 23:56:07 +09:00
:PunchTrees:
This commit is contained in:
@@ -26,7 +26,7 @@ object Calculate {
|
||||
}
|
||||
|
||||
@JvmStatic fun hatchetPower(actor: ActorWithBody, material: Material?): Float {
|
||||
return (8.0 * (material?.forceMod?.toDouble() ?: 1.0).sqrt() * (actor.avStrength / 1000.0)).toFloat()
|
||||
return (1.0 * (material?.forceMod?.toDouble() ?: 1.0).sqrt() * (actor.avStrength / 1000.0)).toFloat()
|
||||
}
|
||||
|
||||
private val fallDamageDampenMult = (32.0 / 1176.0).sqr()
|
||||
|
||||
13
src/net/torvald/terrarum/itemproperties/Item.kt
Normal file
13
src/net/torvald/terrarum/itemproperties/Item.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package net.torvald.terrarum.itemproperties
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2023-11-13.
|
||||
*/
|
||||
object Item {
|
||||
|
||||
const val TREE_STICK = "item@basegame:18"
|
||||
|
||||
const val TREE_SEED_OAK = "item@basegame:160"
|
||||
const val TREE_LOGS_OAK = "item@basegame:168"
|
||||
|
||||
}
|
||||
@@ -1422,7 +1422,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
val punchSize = actor.scale * actor.actorValue.getAsDouble(AVKey.BAREHAND_BASE_DIGSIZE)!!
|
||||
val punchBlockSize = punchSize.div(TILE_SIZED).floorToInt()
|
||||
|
||||
val mouseUnderPunchableTreeTrunk = BlockCodex[world.getTileFromTerrain(mtx, mty)].hasAllTagOf("TREETRUNK", "TREESMALL")
|
||||
val mouseUnderPunchableTree = BlockCodex[world.getTileFromTerrain(mtx, mty)].hasAnyTagOf("LEAVES", "TREESMALL")
|
||||
|
||||
// if there are attackable actor or fixtures
|
||||
val actorsUnderMouse: List<ActorWithBody> = getActorsAtVicinity(mwx, mwy, punchSize / 2.0).sortedBy {
|
||||
@@ -1462,8 +1462,8 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO punch a small tree/shrub
|
||||
else if (mouseUnderPunchableTreeTrunk) {
|
||||
// punch a small tree/shrub
|
||||
else if (mouseUnderPunchableTree) {
|
||||
barehandAxeInUse = true
|
||||
AxeCore.startPrimaryUse(actor, delta, null, mtx, mty, punchBlockSize.coerceAtLeast(1), punchBlockSize.coerceAtLeast(1), listOf("TREESMALL"))
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.gameitems
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
@@ -10,6 +11,7 @@ import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.gameitems.mouseInInteractableRangeTools
|
||||
import net.torvald.terrarum.gameparticles.createRandomBlockParticle
|
||||
import net.torvald.terrarum.itemproperties.Calculate
|
||||
import net.torvald.terrarum.itemproperties.Item
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem
|
||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
||||
@@ -24,6 +26,8 @@ object AxeCore {
|
||||
actor: ActorWithBody, delta: Float, item: GameItem?, mx: Int, my: Int,
|
||||
mw: Int = 1, mh: Int = 1, additionalCheckTags: List<String> = listOf()
|
||||
) = mouseInInteractableRangeTools(actor, item) {
|
||||
val mh = 1
|
||||
|
||||
// un-round the mx
|
||||
val ww = INGAME.world.width
|
||||
val hpww = ww * TerrarumAppConfiguration.TILE_SIZE / 2
|
||||
@@ -40,6 +44,8 @@ object AxeCore {
|
||||
|
||||
var usageStatus = false
|
||||
|
||||
val branchSize = if (item == null) 3 else 4
|
||||
|
||||
for (oy in 0 until mh) for (ox in 0 until mw) {
|
||||
val x = mx + xoff + ox
|
||||
val y = my + yoff + oy
|
||||
@@ -60,8 +66,8 @@ object AxeCore {
|
||||
if (!ret1) return ret1*/
|
||||
|
||||
|
||||
// check if tile under mouse is a tree
|
||||
if (BlockCodex[tile].hasAllTag(listOf("TREE", "TREETRUNK") + additionalCheckTags)) {
|
||||
// check if tile under mouse is leaves
|
||||
if (BlockCodex[tile].hasTag("LEAVES")) {
|
||||
val actionInterval = actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
|
||||
val swingDmgToFrameDmg = delta.toDouble() / actionInterval
|
||||
|
||||
@@ -71,14 +77,62 @@ object AxeCore {
|
||||
).let { tileBroken ->
|
||||
// tile busted
|
||||
if (tileBroken != null) {
|
||||
var upCtr = 0
|
||||
removeLeaf(x, y, tileBroken.substringAfter(':').toInt() - 112)
|
||||
PickaxeCore.makeDust(tile, x, y, 9)
|
||||
}
|
||||
// tile not busted
|
||||
if (Math.random() < actionInterval) {
|
||||
PickaxeCore.makeDust(tile, x, y, 1)
|
||||
}
|
||||
}
|
||||
|
||||
usageStatus = usageStatus or true
|
||||
}
|
||||
// check if tile under mouse is a tree
|
||||
else if (BlockCodex[tile].hasAllTag(listOf("TREE", "TREETRUNK") + additionalCheckTags)) {
|
||||
val actionInterval = actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
|
||||
val swingDmgToFrameDmg = delta.toDouble() / actionInterval
|
||||
|
||||
INGAME.world.inflictTerrainDamage(
|
||||
x, y,
|
||||
Calculate.hatchetPower(actor, item?.material) * swingDmgToFrameDmg
|
||||
).let { tileBroken ->
|
||||
// tile busted
|
||||
if (tileBroken != null) {
|
||||
var upCtr = 1
|
||||
var thisLeaf: ItemID? = null
|
||||
while (true) {
|
||||
val tileHere = INGAME.world.getTileFromTerrain(x, y - upCtr)
|
||||
val propHere = BlockCodex[tileHere]
|
||||
|
||||
if (BlockCodex[tileHere].hasTag("TREETRUNK")) {
|
||||
PickaxeCore.dropItem(tileHere, x, y - upCtr) // todo use log item
|
||||
if (propHere.hasTag("TREETRUNK")) {
|
||||
INGAME.world.setTileTerrain(x, y - upCtr, Block.AIR, false)
|
||||
PickaxeCore.dropItem(tileHere, x, y - upCtr) // todo use log item if applicable
|
||||
}
|
||||
else { // TODO check for leaves
|
||||
else if (propHere.hasTag("LEAVES")) {
|
||||
if (thisLeaf == null) thisLeaf = tileHere
|
||||
// only remove leaves that matches the species
|
||||
// scan horizontally left
|
||||
for (l in -1 downTo -branchSize) {
|
||||
val tileBranch = INGAME.world.getTileFromTerrain(x + l, y - upCtr)
|
||||
if (tileBranch == thisLeaf)
|
||||
removeLeaf(x + l, y - upCtr, thisLeaf.substringAfter(':').toInt() - 112)
|
||||
else break
|
||||
}
|
||||
// scan horizontally right
|
||||
for (l in 1 .. branchSize) {
|
||||
val tileBranch = INGAME.world.getTileFromTerrain(x + l, y - upCtr)
|
||||
if (tileBranch == thisLeaf)
|
||||
removeLeaf(x + l, y - upCtr, thisLeaf.substringAfter(':').toInt() - 112)
|
||||
else break
|
||||
}
|
||||
// deal with the current tile
|
||||
val tileBranch = INGAME.world.getTileFromTerrain(x, y - upCtr)
|
||||
if (tileBranch == thisLeaf)
|
||||
removeLeaf(x, y - upCtr, thisLeaf.substringAfter(':').toInt() - 112)
|
||||
else break
|
||||
}
|
||||
else {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -106,6 +160,18 @@ object AxeCore {
|
||||
usageStatus
|
||||
}
|
||||
|
||||
private fun removeLeaf(x: Int, y: Int, species: Int) {
|
||||
INGAME.world.setTileTerrain(x, y, Block.AIR, false)
|
||||
// drop items
|
||||
when (Math.random()) {
|
||||
in 0.0..0.10 -> Item.TREE_STICK
|
||||
in 0.20..0.26 -> "item@basegame:${160+species}"
|
||||
else -> null
|
||||
}?.let {
|
||||
PickaxeCore.dropItem(it, x, y)
|
||||
}
|
||||
}
|
||||
|
||||
fun endPrimaryUse(actor: ActorWithBody, item: GameItem?): Boolean {
|
||||
item?.using = false
|
||||
// reset action timer to zero
|
||||
|
||||
@@ -37,7 +37,7 @@ class ItemOakLogs(originalID: ItemID) : OreItemBase(originalID) {
|
||||
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(0,10)
|
||||
}
|
||||
|
||||
class ItemOakSEED(originalID: ItemID) : OreItemBase(originalID) {
|
||||
class ItemOakSeed(originalID: ItemID) : OreItemBase(originalID) {
|
||||
override var originalName = "ITEM_ACORN_OAK"
|
||||
override val materialId = "WOOD"
|
||||
override val itemImage: TextureRegion
|
||||
|
||||
Reference in New Issue
Block a user