mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 12:34:05 +09:00
implemented player 'reach' for items
This commit is contained in:
10
.idea/runConfigurations.xml
generated
10
.idea/runConfigurations.xml
generated
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RunConfigurationProducerService">
|
|
||||||
<option name="ignoredProducers">
|
|
||||||
<set>
|
|
||||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
|
||||||
</set>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -23,10 +23,12 @@
|
|||||||
|
|
||||||
"encumbrance": 1000,
|
"encumbrance": 1000,
|
||||||
"basedefence": 100,
|
"basedefence": 100,
|
||||||
"basereach": 50,
|
"basereach": 56,
|
||||||
|
|
||||||
"toolsize": 15,
|
"toolsize": 15,
|
||||||
|
|
||||||
"intelligent": true
|
"intelligent": true,
|
||||||
|
"barehandactionminheight": 80,
|
||||||
|
"basebarehanddiggingsize": 0.5
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
"toolsize": 40,
|
"toolsize": 40,
|
||||||
|
|
||||||
"intelligent": true
|
"intelligent": true,
|
||||||
|
"barehandactionminheight": 40,
|
||||||
|
"basebarehanddiggingsize": 1.0
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -184,13 +184,13 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
|
|||||||
/**
|
/**
|
||||||
* Event for triggering held item's `startPrimaryUse(Float)`
|
* Event for triggering held item's `startPrimaryUse(Float)`
|
||||||
*/
|
*/
|
||||||
open fun worldPrimaryClickStart(delta: Float) {
|
open fun worldPrimaryClickStart(actor: ActorWithBody, delta: Float) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event for triggering held item's `endPrimaryUse(Float)`
|
* Event for triggering held item's `endPrimaryUse(Float)`
|
||||||
*/
|
*/
|
||||||
open fun worldPrimaryClickEnd(delta: Float) {
|
open fun worldPrimaryClickEnd(actor: ActorWithBody, delta: Float) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import kotlin.math.roundToInt
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Actor with body movable. Base class for every actor that has animated sprites. This includes furnishings, paintings, gadgets, etc.
|
* Actor with body movable; or more like, 'Actor that has defined XY-Position'. Base class for every actor that has animated sprites. This includes furnishings, paintings, gadgets, etc.
|
||||||
* Also has all the usePhysics
|
* Also has all the usePhysics
|
||||||
*
|
*
|
||||||
* @param renderOrder Rendering order (BEHIND, MIDDLE, MIDTOP, FRONT)
|
* @param renderOrder Rendering order (BEHIND, MIDDLE, MIDTOP, FRONT)
|
||||||
@@ -206,6 +206,41 @@ open class ActorWithBody : Actor {
|
|||||||
|
|
||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
var avBaseScale: Double // use canonical "scale" for apparent scale (base * buff)
|
||||||
|
get() = actorValue.getAsDouble(AVKey.SCALE) ?: 1.0
|
||||||
|
set(value) {
|
||||||
|
actorValue[AVKey.SCALE] = value
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Apparent strength. 1 000 is default value
|
||||||
|
*/
|
||||||
|
val avStrength: Double
|
||||||
|
get() = (actorValue.getAsDouble(AVKey.STRENGTH) ?: 1000.0) *
|
||||||
|
(actorValue.getAsDouble(AVKey.STRENGTHBUFF) ?: 1.0) * scale
|
||||||
|
var avBaseStrength: Double?
|
||||||
|
get() = actorValue.getAsDouble(AVKey.STRENGTH)
|
||||||
|
set(value) {
|
||||||
|
actorValue[AVKey.STRENGTH] = value!!
|
||||||
|
}
|
||||||
|
var avBaseMass: Double
|
||||||
|
inline get() = actorValue.getAsDouble(AVKey.BASEMASS) ?: MASS_DEFAULT
|
||||||
|
set(value) {
|
||||||
|
if (value <= 0 || value.isNaN() || value.isInfinite())
|
||||||
|
throw IllegalArgumentException("Tried to set base mass to invalid value ($value)")
|
||||||
|
actorValue[AVKey.BASEMASS] = value
|
||||||
|
}
|
||||||
|
val avAcceleration: Double
|
||||||
|
get() { if (accelMultMovement.isNaN()) println("accelMultMovement: $accelMultMovement")
|
||||||
|
return actorValue.getAsDouble(AVKey.ACCEL)!! *
|
||||||
|
(actorValue.getAsDouble(AVKey.ACCELBUFF) ?: 1.0) *
|
||||||
|
accelMultMovement *
|
||||||
|
scale.sqrt()
|
||||||
|
}
|
||||||
|
val avSpeedCap: Double
|
||||||
|
get() = actorValue.getAsDouble(AVKey.SPEED)!! *
|
||||||
|
(actorValue.getAsDouble(AVKey.SPEEDBUFF) ?: 1.0) *
|
||||||
|
speedMultByTile *
|
||||||
|
scale.sqrt()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flags and Properties
|
* Flags and Properties
|
||||||
@@ -1877,43 +1912,6 @@ open class ActorWithBody : Actor {
|
|||||||
@Transient private val HITBOX_COLOURS1 = Color(0xFFFF0088.toInt())
|
@Transient private val HITBOX_COLOURS1 = Color(0xFFFF0088.toInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
// gameplay-related actorvalue macros
|
|
||||||
|
|
||||||
var avBaseScale: Double // use canonical "scale" for apparent scale (base * buff)
|
|
||||||
get() = actorValue.getAsDouble(AVKey.SCALE) ?: 1.0
|
|
||||||
set(value) {
|
|
||||||
actorValue[AVKey.SCALE] = value
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Apparent strength. 1 000 is default value
|
|
||||||
*/
|
|
||||||
internal val avStrength: Double
|
|
||||||
get() = (actorValue.getAsDouble(AVKey.STRENGTH) ?: 1000.0) *
|
|
||||||
(actorValue.getAsDouble(AVKey.STRENGTHBUFF) ?: 1.0) * scale
|
|
||||||
internal var avBaseStrength: Double?
|
|
||||||
get() = actorValue.getAsDouble(AVKey.STRENGTH)
|
|
||||||
set(value) {
|
|
||||||
actorValue[AVKey.STRENGTH] = value!!
|
|
||||||
}
|
|
||||||
internal var avBaseMass: Double
|
|
||||||
inline get() = actorValue.getAsDouble(AVKey.BASEMASS) ?: MASS_DEFAULT
|
|
||||||
set(value) {
|
|
||||||
if (value <= 0 || value.isNaN() || value.isInfinite())
|
|
||||||
throw IllegalArgumentException("Tried to set base mass to invalid value ($value)")
|
|
||||||
actorValue[AVKey.BASEMASS] = value
|
|
||||||
}
|
|
||||||
internal val avAcceleration: Double
|
|
||||||
get() { if (accelMultMovement.isNaN()) println("accelMultMovement: $accelMultMovement")
|
|
||||||
return actorValue.getAsDouble(AVKey.ACCEL)!! *
|
|
||||||
(actorValue.getAsDouble(AVKey.ACCELBUFF) ?: 1.0) *
|
|
||||||
accelMultMovement *
|
|
||||||
scale.sqrt()
|
|
||||||
}
|
|
||||||
internal val avSpeedCap: Double
|
|
||||||
get() = actorValue.getAsDouble(AVKey.SPEED)!! *
|
|
||||||
(actorValue.getAsDouble(AVKey.SPEEDBUFF) ?: 1.0) *
|
|
||||||
speedMultByTile *
|
|
||||||
scale.sqrt()
|
|
||||||
|
|
||||||
private fun Double.toPositiveRad() = // rad(0..pi, -pi..0) -> rad(0..2pi)
|
private fun Double.toPositiveRad() = // rad(0..pi, -pi..0) -> rad(0..2pi)
|
||||||
if (-Math.PI <= this && this < 0.0)
|
if (-Math.PI <= this && this < 0.0)
|
||||||
|
|||||||
@@ -130,8 +130,8 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
|||||||
// also, some UIs should NOT affect item usage (e.g. quickslot) and ingame's uiOpened property is doing
|
// also, some UIs should NOT affect item usage (e.g. quickslot) and ingame's uiOpened property is doing
|
||||||
// the very job.
|
// the very job.
|
||||||
|
|
||||||
if (Gdx.input.isButtonPressed(App.getConfigInt("config_mouseprimary")) && !worldPrimaryClickLatched) {
|
if (terrarumIngame.actorNowPlaying != null && Gdx.input.isButtonPressed(App.getConfigInt("config_mouseprimary")) && !worldPrimaryClickLatched) {
|
||||||
terrarumIngame.worldPrimaryClickStart(App.UPDATE_RATE)
|
terrarumIngame.worldPrimaryClickStart(terrarumIngame.actorNowPlaying!!, App.UPDATE_RATE)
|
||||||
worldPrimaryClickLatched = true
|
worldPrimaryClickLatched = true
|
||||||
}
|
}
|
||||||
/*if Gdx.input.isButtonPressed(AppLoader.getConfigInt("config_mousesecondary")) {
|
/*if Gdx.input.isButtonPressed(AppLoader.getConfigInt("config_mousesecondary")) {
|
||||||
@@ -219,9 +219,10 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
|
|||||||
if (terrarumIngame.uiContainer.map { if ((it?.isOpening == true || it?.isOpened == true) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
if (terrarumIngame.uiContainer.map { if ((it?.isOpening == true || it?.isOpened == true) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
||||||
|
|
||||||
if (
|
if (
|
||||||
button == App.getConfigInt("config_mouseprimary") ||
|
terrarumIngame.actorNowPlaying != null &&
|
||||||
button == App.getConfigInt("config_mousesecondary")) {
|
(button == App.getConfigInt("config_mouseprimary") ||
|
||||||
terrarumIngame.worldPrimaryClickEnd(App.UPDATE_RATE)
|
button == App.getConfigInt("config_mousesecondary"))) {
|
||||||
|
terrarumIngame.worldPrimaryClickEnd(terrarumIngame.actorNowPlaying!!, App.UPDATE_RATE)
|
||||||
}
|
}
|
||||||
/*if (button == AppLoader.getConfigInt("config_mousesecondary")) {
|
/*if (button == AppLoader.getConfigInt("config_mousesecondary")) {
|
||||||
ingame.worldSecondaryClickEnd(AppLoader.UPDATE_RATE)
|
ingame.worldSecondaryClickEnd(AppLoader.UPDATE_RATE)
|
||||||
|
|||||||
@@ -3,14 +3,16 @@ package net.torvald.terrarum.gameitem
|
|||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.Codex
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.ItemCodex
|
|
||||||
import net.torvald.terrarum.ItemValue
|
|
||||||
import net.torvald.terrarum.ReferencingRanges.PREFIX_DYNAMICITEM
|
import net.torvald.terrarum.ReferencingRanges.PREFIX_DYNAMICITEM
|
||||||
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||||
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.itemproperties.Material
|
import net.torvald.terrarum.itemproperties.Material
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
|
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
|
||||||
|
import org.dyn4j.geometry.Vector2
|
||||||
|
|
||||||
typealias ItemID = String
|
typealias ItemID = String
|
||||||
|
|
||||||
@@ -151,12 +153,12 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
|||||||
/**
|
/**
|
||||||
* Effects applied continuously while in pocket
|
* Effects applied continuously while in pocket
|
||||||
*/
|
*/
|
||||||
open fun effectWhileInPocket(delta: Float) { }
|
open fun effectWhileInPocket(actor: ActorWithBody, delta: Float) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Effects applied immediately only once if picked up
|
* Effects applied immediately only once if picked up
|
||||||
*/
|
*/
|
||||||
open fun effectWhenPickedUp(delta: Float) { }
|
open fun effectWhenPickedUp(actor: ActorWithBody, delta: Float) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply effects (continuously or not) while primary button is down.
|
* Apply effects (continuously or not) while primary button is down.
|
||||||
@@ -174,7 +176,7 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
|||||||
* Consumption function is executed in net.torvald.terrarum.gamecontroller.IngameController,
|
* Consumption function is executed in net.torvald.terrarum.gamecontroller.IngameController,
|
||||||
* in which the function itself is defined in net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
* in which the function itself is defined in net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
||||||
*/
|
*/
|
||||||
open fun startPrimaryUse(delta: Float): Boolean = false
|
open fun startPrimaryUse(actor: ActorWithBody, delta: Float): Boolean = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* I have decided that left and right clicks must do the same thing, so no secondary use from now on. --Torvald on 2019-05-26
|
* I have decided that left and right clicks must do the same thing, so no secondary use from now on. --Torvald on 2019-05-26
|
||||||
@@ -190,23 +192,23 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
|||||||
*/
|
*/
|
||||||
//open fun startSecondaryUse(delta: Float): Boolean = false
|
//open fun startSecondaryUse(delta: Float): Boolean = false
|
||||||
|
|
||||||
open fun endPrimaryUse(delta: Float): Boolean = false
|
open fun endPrimaryUse(actor: ActorWithBody, delta: Float): Boolean = false
|
||||||
open fun endSecondaryUse(delta: Float): Boolean = false
|
open fun endSecondaryUse(actor: ActorWithBody, delta: Float): Boolean = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Effects applied immediately only once if thrown (discarded) from pocket
|
* Effects applied immediately only once if thrown (discarded) from pocket
|
||||||
*/
|
*/
|
||||||
open fun effectWhenThrown(delta: Float) { }
|
open fun effectWhenThrown(actor: ActorWithBody, delta: Float) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Effects applied (continuously or not) when equipped (drawn/pulled out)
|
* Effects applied (continuously or not) when equipped (drawn/pulled out)
|
||||||
*/
|
*/
|
||||||
open fun effectWhenEquipped(delta: Float) { }
|
open fun effectWhenEquipped(actor: ActorWithBody, delta: Float) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Effects applied only once when unequipped
|
* Effects applied only once when unequipped
|
||||||
*/
|
*/
|
||||||
open fun effectOnUnequip(delta: Float) { }
|
open fun effectOnUnequip(actor: ActorWithBody, delta: Float) { }
|
||||||
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
@@ -306,6 +308,7 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
val DURABILITY_NA = 0
|
val DURABILITY_NA = 0
|
||||||
@@ -320,7 +323,15 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fun inInteractableRange(actor: ActorWithBody, action: () -> Boolean): Boolean {
|
||||||
|
val mousePos1 = Vector2(Terrarum.mouseX, Terrarum.mouseY)
|
||||||
|
val mousePos2 = Vector2(Terrarum.mouseX + INGAME.world.width * TILE_SIZED, Terrarum.mouseY)
|
||||||
|
val mousePos3 = Vector2(Terrarum.mouseX - INGAME.world.width * TILE_SIZED, Terrarum.mouseY)
|
||||||
|
val actorPos = actor.centrePosVector
|
||||||
|
val dist = minOf(actorPos.distanceSquared(mousePos1), actorPos.distanceSquared(mousePos2), actorPos.distanceSquared(mousePos3))
|
||||||
|
val distMax = actor.actorValue.getAsInt(AVKey.BASEREACH)!! * actor.scale // perform some error checking here
|
||||||
|
if (dist <= distMax.sqr()) return action() else return false
|
||||||
|
}
|
||||||
fun IntRange.pickRandom() = HQRNG().nextInt(this.endInclusive - this.start + 1) + this.start // count() on 200 million entries? Se on vitun hyvää idea
|
fun IntRange.pickRandom() = HQRNG().nextInt(this.endInclusive - this.start + 1) + this.start // count() on 200 million entries? Se on vitun hyvää idea
|
||||||
fun IntArray.pickRandom(): Int = this[HQRNG().nextInt(this.size)]
|
fun IntArray.pickRandom(): Int = this[HQRNG().nextInt(this.size)]
|
||||||
fun DoubleArray.pickRandom(): Double = this[HQRNG().nextInt(this.size)]
|
fun DoubleArray.pickRandom(): Double = this[HQRNG().nextInt(this.size)]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.torvald.terrarum.itemproperties
|
package net.torvald.terrarum.itemproperties
|
||||||
|
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.sqrt
|
import net.torvald.terrarum.sqrt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,7 +16,7 @@ object Calculate {
|
|||||||
*
|
*
|
||||||
* TODO Newtons as unit?
|
* TODO Newtons as unit?
|
||||||
*/
|
*/
|
||||||
@JvmStatic fun pickaxePower(actor: ActorHumanoid, material: Material): Float {
|
@JvmStatic fun pickaxePower(actor: ActorWithBody, material: Material): Float {
|
||||||
return (4.0 * material.forceMod.toDouble().sqrt() * (actor.avStrength / 1000.0)).toFloat()
|
return (4.0 * material.forceMod.toDouble().sqrt() * (actor.avStrength / 1000.0)).toFloat()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import net.torvald.terrarum.*
|
|||||||
import net.torvald.terrarum.App.IS_DEVELOPMENT_BUILD
|
import net.torvald.terrarum.App.IS_DEVELOPMENT_BUILD
|
||||||
import net.torvald.terrarum.App.printdbg
|
import net.torvald.terrarum.App.printdbg
|
||||||
import net.torvald.terrarum.blockproperties.BlockProp
|
import net.torvald.terrarum.blockproperties.BlockProp
|
||||||
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.modulebasegame.gameitems.BlockBase
|
import net.torvald.terrarum.modulebasegame.gameitems.BlockBase
|
||||||
import net.torvald.terrarum.modulebasegame.imagefont.WatchFont
|
import net.torvald.terrarum.modulebasegame.imagefont.WatchFont
|
||||||
@@ -82,12 +83,12 @@ class EntryPoint : ModuleEntryPoint() {
|
|||||||
equipPosition = EquipPosition.HAND_GRIP
|
equipPosition = EquipPosition.HAND_GRIP
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startPrimaryUse(delta: Float): Boolean {
|
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Boolean {
|
||||||
return BlockBase.blockStartPrimaryUse(this, dynamicID, delta)
|
return BlockBase.blockStartPrimaryUse(actor, this, dynamicID, delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun effectWhenEquipped(delta: Float) {
|
override fun effectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
||||||
BlockBase.blockEffectWhenEquipped(delta)
|
BlockBase.blockEffectWhenEquipped(actor, delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
|||||||
import net.torvald.terrarum.blockproperties.BlockPropUtil
|
import net.torvald.terrarum.blockproperties.BlockPropUtil
|
||||||
import net.torvald.terrarum.blockstats.BlockStats
|
import net.torvald.terrarum.blockstats.BlockStats
|
||||||
import net.torvald.terrarum.blockstats.MinimapComposer
|
import net.torvald.terrarum.blockstats.MinimapComposer
|
||||||
import net.torvald.terrarum.concurrent.ThreadExecutor
|
|
||||||
import net.torvald.terrarum.console.AVTracker
|
import net.torvald.terrarum.console.AVTracker
|
||||||
import net.torvald.terrarum.console.ActorsList
|
import net.torvald.terrarum.console.ActorsList
|
||||||
import net.torvald.terrarum.console.Authenticator
|
import net.torvald.terrarum.console.Authenticator
|
||||||
@@ -48,7 +47,6 @@ import net.torvald.terrarum.worlddrawer.WorldCamera
|
|||||||
import net.torvald.util.CircularArray
|
import net.torvald.util.CircularArray
|
||||||
import org.khelekore.prtree.PRTree
|
import org.khelekore.prtree.PRTree
|
||||||
import java.util.concurrent.locks.ReentrantLock
|
import java.util.concurrent.locks.ReentrantLock
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -482,10 +480,10 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
}// END enter
|
}// END enter
|
||||||
|
|
||||||
override fun worldPrimaryClickStart(delta: Float) {
|
override fun worldPrimaryClickStart(actor: ActorWithBody, delta: Float) {
|
||||||
//println("[Ingame] worldPrimaryClickStart $delta")
|
//println("[Ingame] worldPrimaryClickStart $delta")
|
||||||
|
|
||||||
val itemOnGrip = ItemCodex[actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)]
|
val itemOnGrip = ItemCodex[(actor as Pocketed).inventory.itemEquipped.get(GameItem.EquipPosition.HAND_GRIP)]
|
||||||
// bring up the UIs of the fixtures (e.g. crafting menu from a crafting table)
|
// bring up the UIs of the fixtures (e.g. crafting menu from a crafting table)
|
||||||
var uiOpened = false
|
var uiOpened = false
|
||||||
|
|
||||||
@@ -516,15 +514,15 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
// don't want to open the UI and use the item at the same time, would ya?
|
// don't want to open the UI and use the item at the same time, would ya?
|
||||||
if (!uiOpened) {
|
if (!uiOpened) {
|
||||||
val consumptionSuccessful = itemOnGrip?.startPrimaryUse(delta) ?: false
|
val consumptionSuccessful = itemOnGrip?.startPrimaryUse(actor, delta) ?: false
|
||||||
if (consumptionSuccessful)
|
if (consumptionSuccessful)
|
||||||
actorNowPlaying?.inventory?.consumeItem(itemOnGrip!!)
|
(actor as Pocketed).inventory.consumeItem(itemOnGrip!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun worldPrimaryClickEnd(delta: Float) {
|
override fun worldPrimaryClickEnd(actor: ActorWithBody, delta: Float) {
|
||||||
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
|
val itemOnGrip = (actor as Pocketed).inventory.itemEquipped.get(GameItem.EquipPosition.HAND_GRIP)
|
||||||
ItemCodex[itemOnGrip]?.endPrimaryUse(delta)
|
ItemCodex[itemOnGrip]?.endPrimaryUse(actor, delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
// I have decided that left and right clicks must do the same thing, so no secondary use from now on. --Torvald on 2019-05-26
|
// I have decided that left and right clicks must do the same thing, so no secondary use from now on. --Torvald on 2019-05-26
|
||||||
@@ -897,7 +895,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
*/
|
*/
|
||||||
fun updateActors(delta: Float) {
|
fun updateActors(delta: Float) {
|
||||||
if (false) { // don't multithread this for now, it's SLOWER //if (Terrarum.MULTITHREAD && actorContainerActive.size > Terrarum.THREADS) {
|
if (false) { // don't multithread this for now, it's SLOWER //if (Terrarum.MULTITHREAD && actorContainerActive.size > Terrarum.THREADS) {
|
||||||
ThreadExecutor.renew()
|
/*ThreadExecutor.renew()
|
||||||
|
|
||||||
val actors = actorContainerActive.size.toFloat()
|
val actors = actorContainerActive.size.toFloat()
|
||||||
// set up indices
|
// set up indices
|
||||||
@@ -912,7 +910,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
ThreadExecutor.join()
|
ThreadExecutor.join()
|
||||||
|
|
||||||
actorNowPlaying?.update(delta)
|
actorNowPlaying?.update(delta)*/
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
actorContainerActive.forEach {
|
actorContainerActive.forEach {
|
||||||
@@ -921,9 +919,9 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
if (it is Pocketed) {
|
if (it is Pocketed) {
|
||||||
it.inventory.forEach { inventoryEntry ->
|
it.inventory.forEach { inventoryEntry ->
|
||||||
ItemCodex[inventoryEntry.itm]!!.effectWhileInPocket(delta)
|
ItemCodex[inventoryEntry.itm]!!.effectWhileInPocket(it as ActorWithBody, delta) // kind of an error checking because all Pocketed must be ActorWithBody
|
||||||
if (it.equipped(inventoryEntry.itm)) {
|
if (it.equipped(inventoryEntry.itm)) {
|
||||||
ItemCodex[inventoryEntry.itm]!!.effectWhenEquipped(delta)
|
ItemCodex[inventoryEntry.itm]!!.effectWhenEquipped(it as ActorWithBody, delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import net.torvald.terrarum.gameitem.GameItem
|
|||||||
import net.torvald.terrarum.itemproperties.Material
|
import net.torvald.terrarum.itemproperties.Material
|
||||||
import net.torvald.terrarum.realestate.LandUtil
|
import net.torvald.terrarum.realestate.LandUtil
|
||||||
import org.dyn4j.geometry.Vector2
|
import org.dyn4j.geometry.Vector2
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Humanoid actor class to provide same controlling function (such as work, jump)
|
* Humanoid actor class to provide same controlling function (such as work, jump)
|
||||||
@@ -213,10 +212,10 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
|||||||
// update inventory items
|
// update inventory items
|
||||||
inventory.forEach {
|
inventory.forEach {
|
||||||
if (!inventory.itemEquipped.contains(it.itm)) { // unequipped
|
if (!inventory.itemEquipped.contains(it.itm)) { // unequipped
|
||||||
ItemCodex[it.itm]!!.effectWhileInPocket(delta)
|
ItemCodex[it.itm]!!.effectWhileInPocket(this, delta)
|
||||||
}
|
}
|
||||||
else { // equipped
|
else { // equipped
|
||||||
ItemCodex[it.itm]!!.effectWhenEquipped(delta)
|
ItemCodex[it.itm]!!.effectWhenEquipped(this, delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import net.torvald.terrarum.INGAME
|
|||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gameactors.AIControlled
|
import net.torvald.terrarum.gameactors.AIControlled
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameactors.ai.ActorAI
|
import net.torvald.terrarum.gameactors.ai.ActorAI
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.itemproperties.Material
|
import net.torvald.terrarum.itemproperties.Material
|
||||||
@@ -49,7 +50,7 @@ open class HumanoidNPC : ActorHumanoid, AIControlled, CanBeAnItem {
|
|||||||
override val isDynamic = false
|
override val isDynamic = false
|
||||||
override val material = Material()
|
override val material = Material()
|
||||||
|
|
||||||
override fun startPrimaryUse(delta: Float): Boolean {
|
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Boolean {
|
||||||
try {
|
try {
|
||||||
// place the actor to the world
|
// place the actor to the world
|
||||||
this@HumanoidNPC.setPosition(Terrarum.mouseX, Terrarum.mouseY)
|
this@HumanoidNPC.setPosition(Terrarum.mouseX, Terrarum.mouseY)
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.gameactors
|
package net.torvald.terrarum.modulebasegame.gameactors
|
||||||
|
|
||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
|
import net.torvald.terrarum.ItemCodex
|
||||||
import net.torvald.terrarum.gameactors.ActorValue
|
import net.torvald.terrarum.gameactors.ActorValue
|
||||||
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.gameitem.ItemID
|
import net.torvald.terrarum.gameitem.ItemID
|
||||||
import net.torvald.terrarum.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-01-15.
|
* Created by minjaesong on 2016-01-15.
|
||||||
@@ -35,7 +36,7 @@ interface Pocketed {
|
|||||||
// Relevant Actorvalue is NOT being updated on time
|
// Relevant Actorvalue is NOT being updated on time
|
||||||
// They're being safely handled by UIItemInventoryElem*.touchDown() and ActorInventory.remove
|
// They're being safely handled by UIItemInventoryElem*.touchDown() and ActorInventory.remove
|
||||||
|
|
||||||
item.effectOnUnequip(App.UPDATE_RATE)
|
item.effectOnUnequip(this as ActorWithBody, App.UPDATE_RATE)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unequipItem(itemID: ItemID?) {
|
fun unequipItem(itemID: ItemID?) {
|
||||||
@@ -66,7 +67,7 @@ interface Pocketed {
|
|||||||
|
|
||||||
if (item.equipPosition >= 0) {
|
if (item.equipPosition >= 0) {
|
||||||
inventory.itemEquipped[item.equipPosition] = item.dynamicID
|
inventory.itemEquipped[item.equipPosition] = item.dynamicID
|
||||||
item.effectWhenEquipped(App.UPDATE_RATE)
|
item.effectWhenEquipped(this as ActorWithBody, App.UPDATE_RATE)
|
||||||
}
|
}
|
||||||
// else do nothing
|
// else do nothing
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,10 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.gameactors
|
package net.torvald.terrarum.modulebasegame.gameactors
|
||||||
|
|
||||||
import net.torvald.terrarum.App
|
|
||||||
import net.torvald.terrarum.Terrarum
|
|
||||||
import java.util.concurrent.Callable
|
|
||||||
import net.torvald.terrarum.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-05-25.
|
* Created by minjaesong on 2016-05-25.
|
||||||
*/
|
*/
|
||||||
class ThreadActorUpdate(val startIndex: Int, val endIndex: Int) : Callable<Unit> {
|
class ThreadActorUpdate(val startIndex: Int, val endIndex: Int) : Runnable {
|
||||||
override fun call() {
|
override fun run() {
|
||||||
for (i in startIndex..endIndex) {
|
|
||||||
val it = INGAME.actorContainerActive[i]
|
|
||||||
it.update(App.UPDATE_RATE)
|
|
||||||
|
|
||||||
if (it is Pocketed) {
|
|
||||||
it.inventory.forEach { inventoryEntry ->
|
|
||||||
ItemCodex[inventoryEntry.itm]?.effectWhileInPocket(App.UPDATE_RATE)
|
|
||||||
if (it.equipped(inventoryEntry.itm)) {
|
|
||||||
ItemCodex[inventoryEntry.itm]?.effectWhenEquipped(App.UPDATE_RATE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,11 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.gameitems
|
package net.torvald.terrarum.modulebasegame.gameitems
|
||||||
|
|
||||||
import net.torvald.terrarum.Point2d
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.Point2i
|
|
||||||
import net.torvald.terrarum.Terrarum
|
|
||||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
|
||||||
import net.torvald.terrarum.blockproperties.WireCodex
|
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.gameitem.ItemID
|
import net.torvald.terrarum.gameitem.ItemID
|
||||||
|
import net.torvald.terrarum.gameitem.inInteractableRange
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
import net.torvald.terrarum.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2019-05-02.
|
* Created by minjaesong on 2019-05-02.
|
||||||
@@ -20,7 +16,7 @@ object BlockBase {
|
|||||||
* @param dontEncaseActors when set to true, blocks won't be placed where Actors are. You will want to set it false
|
* @param dontEncaseActors when set to true, blocks won't be placed where Actors are. You will want to set it false
|
||||||
* for wire items, otherwise you want it to be true.
|
* for wire items, otherwise you want it to be true.
|
||||||
*/
|
*/
|
||||||
fun blockStartPrimaryUse(gameItem: GameItem, itemID: ItemID, delta: Float): Boolean {
|
fun blockStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, itemID: ItemID, delta: Float) = inInteractableRange(actor) {
|
||||||
val ingame = Terrarum.ingame!! as TerrarumIngame
|
val ingame = Terrarum.ingame!! as TerrarumIngame
|
||||||
val mousePoint = Point2d(Terrarum.mouseTileX.toDouble(), Terrarum.mouseTileY.toDouble())
|
val mousePoint = Point2d(Terrarum.mouseTileX.toDouble(), Terrarum.mouseTileY.toDouble())
|
||||||
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
|
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
|
||||||
@@ -38,7 +34,7 @@ object BlockBase {
|
|||||||
if (it is ActorWithBody && it.physProp.usePhysics && it.intTilewiseHitbox.intersects(mousePoint))
|
if (it is ActorWithBody && it.physProp.usePhysics && it.intTilewiseHitbox.intersects(mousePoint))
|
||||||
ret1 = false // return is not allowed here
|
ret1 = false // return is not allowed here
|
||||||
}
|
}
|
||||||
if (!ret1) return ret1
|
if (!ret1) return@inInteractableRange ret1
|
||||||
}
|
}
|
||||||
|
|
||||||
// return false if the tile underneath is:
|
// return false if the tile underneath is:
|
||||||
@@ -50,7 +46,7 @@ object BlockBase {
|
|||||||
gameItem.dynamicID == "wall@" + ingame.world.getTileFromWall(mouseTile.x, mouseTile.y) ||
|
gameItem.dynamicID == "wall@" + ingame.world.getTileFromWall(mouseTile.x, mouseTile.y) ||
|
||||||
BlockCodex[ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y)].nameKey.contains("ACTORBLOCK_")
|
BlockCodex[ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y)].nameKey.contains("ACTORBLOCK_")
|
||||||
)
|
)
|
||||||
return false
|
return@inInteractableRange false
|
||||||
|
|
||||||
// filter passed, do the job
|
// filter passed, do the job
|
||||||
// FIXME this is only useful for Player
|
// FIXME this is only useful for Player
|
||||||
@@ -71,21 +67,21 @@ object BlockBase {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun blockEffectWhenEquipped(delta: Float) {
|
fun blockEffectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
||||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
|
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
fun wireStartPrimaryUse(gameItem: GameItem, delta: Float): Boolean {
|
fun wireStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, delta: Float) = inInteractableRange(actor) {
|
||||||
val itemID = gameItem.originalID
|
val itemID = gameItem.originalID
|
||||||
val ingame = Terrarum.ingame!! as TerrarumIngame
|
val ingame = Terrarum.ingame!! as TerrarumIngame
|
||||||
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
|
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
|
||||||
|
|
||||||
// return false if the tile is already there
|
// return false if the tile is already there
|
||||||
if (ingame.world.getAllWiresFrom(mouseTile.x, mouseTile.y)?.searchFor(itemID) != null)
|
if (ingame.world.getAllWiresFrom(mouseTile.x, mouseTile.y)?.searchFor(itemID) != null)
|
||||||
return false
|
return@inInteractableRange false
|
||||||
|
|
||||||
// filter passed, do the job
|
// filter passed, do the job
|
||||||
ingame.world.setTileWire(
|
ingame.world.setTileWire(
|
||||||
@@ -95,7 +91,7 @@ object BlockBase {
|
|||||||
false
|
false
|
||||||
)
|
)
|
||||||
|
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun wireEffectWhenEquipped(gameItem: GameItem, delta: Float) {
|
fun wireEffectWhenEquipped(gameItem: GameItem, delta: Float) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
|
|||||||
import net.torvald.terrarum.CommonResourcePool
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.ModMgr
|
import net.torvald.terrarum.ModMgr
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.gameitem.ItemID
|
import net.torvald.terrarum.gameitem.ItemID
|
||||||
import net.torvald.terrarum.itemproperties.Material
|
import net.torvald.terrarum.itemproperties.Material
|
||||||
@@ -36,18 +37,18 @@ class ItemLogicSignalEmitter(originalID: ItemID) : GameItem(originalID) {
|
|||||||
equipPosition = EquipPosition.HAND_GRIP
|
equipPosition = EquipPosition.HAND_GRIP
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startPrimaryUse(delta: Float): Boolean {
|
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Boolean {
|
||||||
val item = FixtureLogicSignalEmitter()
|
val item = FixtureLogicSignalEmitter()
|
||||||
|
|
||||||
return item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY)
|
return item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY)
|
||||||
// return true when placed, false when cannot be placed
|
// return true when placed, false when cannot be placed
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun effectWhenEquipped(delta: Float) {
|
override fun effectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
||||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "signal"
|
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "signal"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun effectOnUnequip(delta: Float) {
|
override fun effectOnUnequip(actor: ActorWithBody, delta: Float) {
|
||||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
|
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ package net.torvald.terrarum.modulebasegame.gameitems
|
|||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.terrarum.CommonResourcePool
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.gameitem.ItemID
|
import net.torvald.terrarum.gameitem.ItemID
|
||||||
|
import net.torvald.terrarum.gameitem.inInteractableRange
|
||||||
import net.torvald.terrarum.itemproperties.Material
|
import net.torvald.terrarum.itemproperties.Material
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureStorageChest
|
import net.torvald.terrarum.modulebasegame.gameactors.FixtureStorageChest
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
|
import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
|
||||||
@@ -30,10 +32,10 @@ class ItemStorageChest(originalID: ItemID) : GameItem(originalID) {
|
|||||||
equipPosition = EquipPosition.HAND_GRIP
|
equipPosition = EquipPosition.HAND_GRIP
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startPrimaryUse(delta: Float): Boolean {
|
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = inInteractableRange(actor) {
|
||||||
val item = FixtureStorageChest()
|
val item = FixtureStorageChest()
|
||||||
|
|
||||||
return item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)
|
item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)
|
||||||
// return true when placed, false when cannot be placed
|
// return true when placed, false when cannot be placed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
|
|||||||
import net.torvald.terrarum.CommonResourcePool
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.ModMgr
|
import net.torvald.terrarum.ModMgr
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.gameitem.ItemID
|
import net.torvald.terrarum.gameitem.ItemID
|
||||||
|
import net.torvald.terrarum.gameitem.inInteractableRange
|
||||||
import net.torvald.terrarum.itemproperties.Material
|
import net.torvald.terrarum.itemproperties.Material
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
|
import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
@@ -38,11 +40,12 @@ class ItemTikiTorch(originalID: ItemID) : GameItem(originalID) {
|
|||||||
equipPosition = EquipPosition.HAND_GRIP
|
equipPosition = EquipPosition.HAND_GRIP
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startPrimaryUse(delta: Float): Boolean {
|
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = inInteractableRange(actor) {
|
||||||
val item = FixtureTikiTorch()
|
val item = FixtureTikiTorch()
|
||||||
|
|
||||||
return item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)
|
item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)
|
||||||
// return true when placed, false when cannot be placed
|
// return true when placed, false when cannot be placed
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,36 +1,29 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.gameitems
|
package net.torvald.terrarum.modulebasegame.gameitems
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.terrarum.CommonResourcePool
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.Point2d
|
|
||||||
import net.torvald.terrarum.Terrarum
|
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||||
import net.torvald.terrarum.blockproperties.Block
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.gameitem.ItemID
|
import net.torvald.terrarum.gameitem.ItemID
|
||||||
import net.torvald.terrarum.itemproperties.Calculate
|
import net.torvald.terrarum.itemproperties.Calculate
|
||||||
import net.torvald.terrarum.itemproperties.MaterialCodex
|
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem
|
import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem
|
||||||
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.BASE_MASS_AND_SIZE
|
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.BASE_MASS_AND_SIZE
|
||||||
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.TOOL_DURABILITY_BASE
|
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.TOOL_DURABILITY_BASE
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
import net.torvald.terrarum.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2019-03-10.
|
* Created by minjaesong on 2019-03-10.
|
||||||
*/
|
*/
|
||||||
object PickaxeCore {
|
object PickaxeCore {
|
||||||
fun startPrimaryUse(delta: Float, item: GameItem): Boolean {
|
fun startPrimaryUse(actor: ActorWithBody, delta: Float, item: GameItem): Boolean {
|
||||||
val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying ?: return false
|
|
||||||
|
|
||||||
val mouseTileX = Terrarum.mouseTileX
|
val mouseTileX = Terrarum.mouseTileX
|
||||||
val mouseTileY = Terrarum.mouseTileY
|
val mouseTileY = Terrarum.mouseTileY
|
||||||
|
|
||||||
val mousePoint = Point2d(mouseTileX.toDouble(), mouseTileY.toDouble())
|
val mousePoint = Point2d(mouseTileX.toDouble(), mouseTileY.toDouble())
|
||||||
val actorvalue = player.actorValue
|
val actorvalue = actor.actorValue
|
||||||
|
|
||||||
item.using = true
|
item.using = true
|
||||||
|
|
||||||
@@ -53,7 +46,7 @@ object PickaxeCore {
|
|||||||
|
|
||||||
(INGAME.world).inflictTerrainDamage(
|
(INGAME.world).inflictTerrainDamage(
|
||||||
mouseTileX, mouseTileY,
|
mouseTileX, mouseTileY,
|
||||||
Calculate.pickaxePower(player, item.material) * swingDmgToFrameDmg
|
Calculate.pickaxePower(actor, item.material) * swingDmgToFrameDmg
|
||||||
)?.let { tileBroken ->
|
)?.let { tileBroken ->
|
||||||
val drop = BlockCodex[tileBroken].drop
|
val drop = BlockCodex[tileBroken].drop
|
||||||
if (drop.isNotBlank()) {
|
if (drop.isNotBlank()) {
|
||||||
@@ -64,13 +57,11 @@ object PickaxeCore {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun endPrimaryUse(delta: Float, item: GameItem): Boolean {
|
fun endPrimaryUse(actor: ActorWithBody, delta: Float, item: GameItem): Boolean {
|
||||||
val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
|
|
||||||
if (player == null) return false
|
|
||||||
|
|
||||||
item.using = false
|
item.using = false
|
||||||
// reset action timer to zero
|
// reset action timer to zero
|
||||||
player.actorValue.set(AVKey.__ACTION_TIMER, 0.0)
|
actor.actorValue.set(AVKey.__ACTION_TIMER, 0.0)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,8 +92,8 @@ class PickaxeCopper(originalID: ItemID) : GameItem(originalID) {
|
|||||||
super.name = "Copper Pickaxe"
|
super.name = "Copper Pickaxe"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startPrimaryUse(delta: Float) = PickaxeCore.startPrimaryUse(delta, this)
|
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = PickaxeCore.startPrimaryUse(actor, delta, this)
|
||||||
override fun endPrimaryUse(delta: Float) = PickaxeCore.endPrimaryUse(delta, this)
|
override fun endPrimaryUse(actor: ActorWithBody, delta: Float) = PickaxeCore.endPrimaryUse(actor, delta, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,8 +119,8 @@ class PickaxeIron(originalID: ItemID) : GameItem(originalID) {
|
|||||||
super.name = "Iron Pickaxe"
|
super.name = "Iron Pickaxe"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startPrimaryUse(delta: Float) = PickaxeCore.startPrimaryUse(delta, this)
|
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = PickaxeCore.startPrimaryUse(actor , delta, this)
|
||||||
override fun endPrimaryUse(delta: Float) = PickaxeCore.endPrimaryUse(delta, this)
|
override fun endPrimaryUse(actor: ActorWithBody, delta: Float) = PickaxeCore.endPrimaryUse(actor, delta, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -155,6 +146,6 @@ class PickaxeSteel(originalID: ItemID) : GameItem(originalID) {
|
|||||||
super.name = "Steel Pickaxe"
|
super.name = "Steel Pickaxe"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startPrimaryUse(delta: Float) = PickaxeCore.startPrimaryUse(delta, this)
|
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = PickaxeCore.startPrimaryUse(actor, delta, this)
|
||||||
override fun endPrimaryUse(delta: Float) = PickaxeCore.endPrimaryUse(delta, this)
|
override fun endPrimaryUse(actor: ActorWithBody, delta: Float) = PickaxeCore.endPrimaryUse(actor, delta, this)
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,10 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
|
|||||||
import net.torvald.terrarum.CommonResourcePool
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.Point2i
|
import net.torvald.terrarum.Point2i
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.gameitem.ItemID
|
import net.torvald.terrarum.gameitem.ItemID
|
||||||
|
import net.torvald.terrarum.gameitem.inInteractableRange
|
||||||
import net.torvald.terrarum.itemproperties.Material
|
import net.torvald.terrarum.itemproperties.Material
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
|
|
||||||
@@ -32,22 +34,23 @@ class WireCutterAll(originalID: ItemID) : GameItem(originalID) {
|
|||||||
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
|
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startPrimaryUse(delta: Float): Boolean {
|
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = inInteractableRange(actor) {
|
||||||
val ingame = Terrarum.ingame!! as TerrarumIngame
|
val ingame = Terrarum.ingame!! as TerrarumIngame
|
||||||
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
|
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
|
||||||
val wires = ingame.world.getAllWiresFrom(mouseTile.x, mouseTile.y)?.cloneToList()
|
val wires = ingame.world.getAllWiresFrom(mouseTile.x, mouseTile.y)?.cloneToList()
|
||||||
|
|
||||||
wires?.forEach {
|
wires?.forEach {
|
||||||
ingame.world.removeTileWire(mouseTile.x, mouseTile.y, it, false)
|
ingame.world.removeTileWire(mouseTile.x, mouseTile.y, it, false)
|
||||||
} ?: return false
|
} ?: return@inInteractableRange false
|
||||||
return true
|
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun effectWhenEquipped(delta: Float) {
|
override fun effectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
||||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "wire_render_all"
|
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "wire_render_all"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun effectOnUnequip(delta: Float) {
|
override fun effectOnUnequip(actor: ActorWithBody, delta: Float) {
|
||||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
|
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,11 +4,10 @@ import com.badlogic.gdx.graphics.Color
|
|||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.EMDASH
|
import net.torvald.EMDASH
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.blockproperties.WireCodex
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameactors.BlockMarkerActor
|
import net.torvald.terrarum.gameactors.BlockMarkerActor
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.gameitem.ItemID
|
import net.torvald.terrarum.gameitem.ItemID
|
||||||
import net.torvald.terrarum.itemproperties.MaterialCodex
|
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
|
|
||||||
class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) {
|
class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) {
|
||||||
@@ -32,7 +31,7 @@ class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) {
|
|||||||
private val sb = StringBuilder()
|
private val sb = StringBuilder()
|
||||||
private val blockMarker = CommonResourcePool.get("blockmarking_actor") as BlockMarkerActor
|
private val blockMarker = CommonResourcePool.get("blockmarking_actor") as BlockMarkerActor
|
||||||
|
|
||||||
override fun effectWhenEquipped(delta: Float) {
|
override fun effectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
||||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "wire_render_all"
|
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "wire_render_all"
|
||||||
|
|
||||||
blockMarker.shape = 3
|
blockMarker.shape = 3
|
||||||
@@ -70,7 +69,7 @@ class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun effectOnUnequip(delta: Float) {
|
override fun effectOnUnequip(actor: ActorWithBody, delta: Float) {
|
||||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
|
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
|
||||||
(Terrarum.ingame!! as TerrarumIngame).setTooltipMessage(null)
|
(Terrarum.ingame!! as TerrarumIngame).setTooltipMessage(null)
|
||||||
blockMarker.isVisible = false
|
blockMarker.isVisible = false
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package net.torvald.terrarum.modulebasegame.gameitems
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.terrarum.CommonResourcePool
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.blockproperties.Wire
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.gameitem.ItemID
|
import net.torvald.terrarum.gameitem.ItemID
|
||||||
import net.torvald.terrarum.itemproperties.Material
|
import net.torvald.terrarum.itemproperties.Material
|
||||||
@@ -30,15 +30,15 @@ class WirePieceSignalWire(originalID: ItemID, private val atlasID: String, priva
|
|||||||
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
|
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startPrimaryUse(delta: Float): Boolean {
|
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Boolean {
|
||||||
return BlockBase.wireStartPrimaryUse(this, delta)
|
return BlockBase.wireStartPrimaryUse(actor,this, delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun effectWhenEquipped(delta: Float) {
|
override fun effectWhenEquipped(actor: ActorWithBody, delta: Float) {
|
||||||
BlockBase.wireEffectWhenEquipped(this, delta)
|
BlockBase.wireEffectWhenEquipped(this, delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun effectOnUnequip(delta: Float) {
|
override fun effectOnUnequip(actor: ActorWithBody, delta: Float) {
|
||||||
BlockBase.wireEffectWhenUnequipped(this, delta)
|
BlockBase.wireEffectWhenUnequipped(this, delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user