diff --git a/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt b/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt index 6a658a8f8..76460b07f 100644 --- a/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt +++ b/src/net/torvald/terrarum/gameactors/ActorHumanoid.kt @@ -134,9 +134,9 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null) private val nullItem = object : InventoryItem() { override val id: Int = 0 - override val equipPosition: Int = EquipPosition.NULL - override var mass: Double = 0.0 override var scale: Double = 1.0 + override var baseMass: Double = 0.0 + override var baseToolSize: Double? = null } override fun update(gc: GameContainer, delta: Int) { diff --git a/src/net/torvald/terrarum/gameactors/ActorWithSprite.kt b/src/net/torvald/terrarum/gameactors/ActorWithSprite.kt index 8d4a94a10..2a304f814 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithSprite.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithSprite.kt @@ -510,8 +510,8 @@ open class ActorWithSprite(renderOrder: ActorOrder, val immobileBody: Boolean = // the actor is hitting the wall // FIXME balls are stuck in this - if (referenceID != 321321321) - println("$this trying to reflectX") + //if (referenceID != 321321321) + // println("$this trying to reflectX") hitAndReflectX() } } @@ -548,29 +548,37 @@ open class ActorWithSprite(renderOrder: ActorOrder, val immobileBody: Boolean = } private fun hitAndReflectX() { - if ((externalForce.x * elasticity).abs() >= MINIMUM_BOUNCE_THRESHOLD) { // > Epsilon.E) { - externalForce.x *= -elasticity - if (this is Controllable) walkX *= -elasticity - } - else { - externalForce.x = 0.0 - if (this is Controllable) walkX = 0.0 - } + // when it sticks, externalForce.x goes back and forth + /* +1123921356 trying to reflectX +1123921356 -1.3677473305837262 +1123921356 trying to reflectX +1123921356 0.8150659571934893 +1123921356 trying to reflectX +1123921356 -0.48545419966417575 +1123921356 trying to reflectX +1123921356 0.28939570979162116 +1123921356 trying to reflectX +1123921356 -0.17225986626214265 +1123921356 trying to reflectX +1123921356 0.1027945259506898 +1123921356 trying to reflectX +1123921356 -0.06108288092971576 + */ + + externalForce.x *= -elasticity + if (this is Controllable) walkX *= -elasticity + + println("$this\t${externalForce.x}") } private fun hitAndReflectY() { - if (externalForce.y.abs() >= MINIMUM_BOUNCE_THRESHOLD) { //> Epsilon.E) { - externalForce.y *= -elasticity - if (this is Controllable) walkY *= -elasticity - } - else { - externalForce.y = 0.0 - if (this is Controllable) walkY *= 0.0 - } + externalForce.y *= -elasticity + if (this is Controllable) walkY *= -elasticity } @Transient private val CEILING_HIT_ELASTICITY = 0.3 - @Transient private val MINIMUM_BOUNCE_THRESHOLD = 0.1 + @Transient private val MINIMUM_BOUNCE_THRESHOLD = 1.0 /** * prevents sticking to the ceiling diff --git a/src/net/torvald/terrarum/gameitem/DynamicItem.kt b/src/net/torvald/terrarum/gameitem/DynamicItem.kt index f0b1c0f8b..0008cd0a4 100644 --- a/src/net/torvald/terrarum/gameitem/DynamicItem.kt +++ b/src/net/torvald/terrarum/gameitem/DynamicItem.kt @@ -12,7 +12,7 @@ import org.newdawn.slick.GameContainer * * Created by minjaesong on 16-09-08. */ -open class DynamicItem(val baseItemID: Int?, newMass: Double? = null, newScale: Double? = null) +open abstract class DynamicItem(val baseItemID: Int?, newMass: Double? = null, newScale: Double? = null) : InventoryItem() { /** @@ -24,13 +24,6 @@ open class DynamicItem(val baseItemID: Int?, newMass: Double? = null, newScale: */ override val id: Int = generateUniqueDynamicItemID() - override val equipPosition: Int = // default to HAND_GRIP if no baseItemID given - if (baseItemID != null) - ItemCodex[baseItemID].equipPosition - else - EquipPosition.HAND_GRIP - - private fun generateUniqueDynamicItemID(): Int { var ret: Int do { diff --git a/src/net/torvald/terrarum/gameitem/InventoryItem.kt b/src/net/torvald/terrarum/gameitem/InventoryItem.kt index b676441fc..1b547cbb8 100644 --- a/src/net/torvald/terrarum/gameitem/InventoryItem.kt +++ b/src/net/torvald/terrarum/gameitem/InventoryItem.kt @@ -1,5 +1,6 @@ package net.torvald.terrarum.gameitem +import net.torvald.terrarum.itemproperties.Material import org.newdawn.slick.GameContainer /** @@ -15,16 +16,38 @@ abstract class InventoryItem { */ abstract val id: Int + abstract var baseMass: Double + + abstract var baseToolSize: Double? + /** * Where to equip the item */ - abstract val equipPosition: Int + var equipPosition: Int = EquipPosition.NULL + + var material: Material? = null /** - * Base mass of the item. Real mass must be calculated from - * mass * scale^3 + * Apparent mass of the item. (basemass * scale^3) */ - abstract var mass: Double + open var mass: Double + get() = baseMass * scale * scale * scale + set(value) { baseMass = value / (scale * scale * scale) } + + /** + * Apparent tool size (or weight in kg). (baseToolSize * scale^3) + */ + open var toolSize: Double? + get() = if (baseToolSize != null) baseToolSize!! * scale * scale * scale else null + set(value) { + if (value != null) + if (baseToolSize != null) + baseToolSize = value / (scale * scale * scale) + else + throw NullPointerException("baseToolSize is null; this item is not a tool or you're doing it wrong") + else + throw NullPointerException("null input; nullify baseToolSize instead :p") + } /** * Scale of the item. diff --git a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt index 1a226b0a9..aac8f86d7 100644 --- a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt +++ b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt @@ -38,9 +38,9 @@ object ItemCodex { for (i in 0..ITEM_TILE_MAX) { itemCodex[i] = object : InventoryItem() { override val id: Int = i - override val equipPosition = EquipPosition.HAND_GRIP - override var mass: Double = TileCodex[i].density / 1000.0 + override var baseMass: Double = TileCodex[i].density / 1000.0 override var scale: Double = 1.0 // no need to set setter as scale would not change + override var baseToolSize: Double? = null override fun primaryUse(gc: GameContainer, delta: Int) { // TODO base punch attack diff --git a/src/net/torvald/terrarum/itemproperties/Material.kt b/src/net/torvald/terrarum/itemproperties/Material.kt index 46260e4bd..bfff25ac2 100644 --- a/src/net/torvald/terrarum/itemproperties/Material.kt +++ b/src/net/torvald/terrarum/itemproperties/Material.kt @@ -1,10 +1,36 @@ package net.torvald.terrarum.itemproperties /** + * To be used with items AND TILES (electricity resistance, thermal conductivity) + * * Created by minjaesong on 16-03-18. */ -internal data class Material ( - var maxEdge: Int, - var hardness: Int, - var density: Int +data class Material ( + //var maxEdge: Int, // i think weapSharpnessMod would cut it // arbitrary unit + var hardness: Int, // arbitrary unit + var density: Int, // grams per litre + + // impact force: force applied by sudden strike, e.g. hammer/axe/sword strike + var impactRigidness: Int, // arbitrary unit (rigid <-> soft) a weapon made of soft material will inflict less damage + var impactFractureForce: Int, // pascal (N/m^2); if the item (e.g. sword) receives a force that exceeds this value, the item will be destroyed + + // compressive force: force applied by exerting pressure on an object, e.g. sword/spear stab + var compressiveRigidness: Int, // arbitrary unit (rigid <-> soft) a weapon made of soft material will inflict less damage + var compressiveFractureForce: Int, // pascal (N/m^2); if the item (e.g. sword) receives a force that exceeds this value, the item will be destroyed + + // remarks: + // we won't need elasticity, even if we have glass + // some examples: + // - glass sword works as the material has high compressive fracture, but prone to shatter + // (hit mobs 5-6 times and it's gone) as it shatters easily as it has low impact fracture + + + + var electricityResistance: Int, // ohm + var thermalConductivity: Int, // pascal (N/m^2); if the item (e.g. sword) receives a force that exceeds this value, the item will be destroyed + + + // must be a item properties + var weapSharpnessMod: Double, // multiplier + var armourMod: Double // multiplier ) \ No newline at end of file