mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-16 05:24:06 +09:00
@@ -138,7 +138,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
|
||||
|
||||
|
||||
private val nullItem = object : InventoryItem() {
|
||||
override val id: Int = 0
|
||||
override var id: Int = 0
|
||||
override val isUnique: Boolean = false
|
||||
override var baseMass: Double = 0.0
|
||||
override var baseToolSize: Double? = null
|
||||
|
||||
@@ -44,12 +44,18 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
||||
// If we already have the item, increment the amount
|
||||
// If not, add item with specified amount
|
||||
val existingItem = getByID(item.id)
|
||||
|
||||
if (existingItem != null) { // if the item already exists
|
||||
val newCount = getByID(item.id)!!.amount + count
|
||||
itemList.remove(existingItem)
|
||||
itemList.add(InventoryPair(existingItem.item, newCount))
|
||||
}
|
||||
else {
|
||||
else { // new item
|
||||
if (item.isDynamic) {
|
||||
// assign new ID
|
||||
item.originalID = item.id
|
||||
item.id = InventoryItem.generateNewDynamicID(this)
|
||||
}
|
||||
itemList.add(InventoryPair(item, count))
|
||||
}
|
||||
insertionSortLastElem(itemList)
|
||||
@@ -121,12 +127,18 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
||||
false
|
||||
|
||||
|
||||
fun consumeItem(item: InventoryItem) {
|
||||
fun consumeItem(actor: Actor, item: InventoryItem) {
|
||||
if (item.consumable) {
|
||||
remove(item, 1)
|
||||
}
|
||||
else {
|
||||
item.durability -= 1f
|
||||
val baseDamagePerSwing = if (actor is ActorHumanoid)
|
||||
actor.avStrength / 1000.0
|
||||
else
|
||||
1.0 // TODO variable: scale, strength
|
||||
val swingDmgToFrameDmg = Terrarum.delta.toDouble() / actor.actorValue.getAsDouble(AVKey.ACTION_INTERVAL)!!
|
||||
|
||||
item.durability -= (baseDamagePerSwing * swingDmgToFrameDmg).toFloat()
|
||||
if (item.durability <= 0)
|
||||
remove(item, 1)
|
||||
}
|
||||
|
||||
@@ -107,9 +107,9 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
||||
}
|
||||
@Transient val MASS_LOWEST = 0.1 // Kilograms
|
||||
/** Apparent mass. Use "avBaseMass" for base mass */
|
||||
var mass: Double
|
||||
val mass: Double
|
||||
get() = actorValue.getAsDouble(AVKey.BASEMASS) ?: MASS_DEFAULT * Math.pow(scale, 3.0)
|
||||
set(value) {
|
||||
/*set(value) { // use "var avBaseMass: Double"
|
||||
if (value <= 0)
|
||||
throw IllegalArgumentException("mass cannot be less than or equal to zero.")
|
||||
else if (value < MASS_LOWEST) {
|
||||
@@ -118,7 +118,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
||||
}
|
||||
|
||||
actorValue[AVKey.BASEMASS] = value / Math.pow(scale, 3.0)
|
||||
}
|
||||
}*/
|
||||
@Transient private val MASS_DEFAULT: Double = 60.0
|
||||
/** Valid range: [0, 1] */
|
||||
var elasticity: Double = 0.0
|
||||
@@ -232,7 +232,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
||||
protected val gameContainer: GameContainer
|
||||
get() = Terrarum.appgc
|
||||
protected val updateDelta: Int
|
||||
get() = Terrarum.UPDATE_DELTA
|
||||
get() = Terrarum.delta
|
||||
|
||||
/**
|
||||
* true: This actor had just made collision
|
||||
@@ -1286,15 +1286,12 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
||||
set(value) {
|
||||
actorValue[AVKey.SCALE] = value
|
||||
}
|
||||
/** Apparent strength */
|
||||
var avStrength: Double
|
||||
get() = (actorValue.getAsDouble(AVKey.STRENGTH) ?: 0.0) *
|
||||
(actorValue.getAsDouble(AVKey.STRENGTHBUFF) ?: 0.0) * scale
|
||||
set(value) {
|
||||
actorValue[AVKey.STRENGTH] =
|
||||
value /
|
||||
((actorValue.getAsDouble(AVKey.STRENGTHBUFF) ?: 1.0) * (avBaseStrength ?: 1.0))
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
@@ -17,7 +17,7 @@ class DroppedItem(private val item: InventoryItem) : ActorWithPhysics(Actor.Rend
|
||||
|
||||
isVisible = true
|
||||
|
||||
mass = if (item.id < TileCodex.TILE_UNIQUE_MAX)
|
||||
avBaseMass = if (item.id < TileCodex.TILE_UNIQUE_MAX)
|
||||
TileCodex[item.id].density / 1000.0
|
||||
else
|
||||
ItemCodex[item.id].mass
|
||||
|
||||
@@ -20,7 +20,7 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, maxLifeTime: Int? = null
|
||||
/** Will NOT actually delete from the CircularArray */
|
||||
@Volatile var flagDespawn = false
|
||||
|
||||
override fun run() = update(Terrarum.appgc, Terrarum.UPDATE_DELTA)
|
||||
override fun run() = update(Terrarum.appgc, Terrarum.delta)
|
||||
|
||||
var isNoSubjectToGrav = false
|
||||
var dragCoefficient = 3.0
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.newdawn.slick.Image
|
||||
class ParticleTestRain(posX: Double, posY: Double) : ParticleBase(Actor.RenderOrder.BEHIND, 6000) {
|
||||
|
||||
init {
|
||||
body = Image("./assets/graphics/weathers/raindrop.tga")
|
||||
body = Image("./assets/modules/basegame/weathers/raindrop.tga")
|
||||
val w = body.width.toDouble()
|
||||
val h = body.height.toDouble()
|
||||
hitbox.setFromWidthHeight(
|
||||
|
||||
@@ -16,7 +16,7 @@ class PhysTestBall : ActorWithPhysics(Actor.RenderOrder.MIDDLE, immobileBody = t
|
||||
|
||||
init {
|
||||
setHitboxDimension(16, 16, 0, 0)
|
||||
mass = 10.0
|
||||
avBaseMass = 10.0
|
||||
density = 200.0
|
||||
|
||||
color = RoguelikeRandomiser.composeColourFrom(RoguelikeRandomiser.POTION_PRIMARY_COLSET)
|
||||
|
||||
@@ -25,7 +25,7 @@ interface Pocketed {
|
||||
}
|
||||
|
||||
inventory.itemEquipped[item.equipPosition] = null
|
||||
item.effectOnUnequip(Terrarum.appgc, Terrarum.UPDATE_DELTA)
|
||||
item.effectOnUnequip(Terrarum.appgc, Terrarum.delta)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ interface Pocketed {
|
||||
|
||||
if (item.equipPosition >= 0) {
|
||||
inventory.itemEquipped[item.equipPosition] = item
|
||||
item.effectWhenEquipped(Terrarum.appgc, Terrarum.UPDATE_DELTA)
|
||||
item.effectWhenEquipped(Terrarum.appgc, Terrarum.delta)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,12 +55,13 @@ interface Pocketed {
|
||||
|
||||
|
||||
fun consumePrimary(item: InventoryItem) {
|
||||
if (item.primaryUse(Terrarum.appgc, Terrarum.UPDATE_DELTA))
|
||||
inventory.consumeItem(item) // consume on successful
|
||||
if (item.primaryUse(Terrarum.appgc, Terrarum.delta)) {
|
||||
inventory.consumeItem(this as Actor, item) // consume on successful
|
||||
}
|
||||
}
|
||||
|
||||
fun consumeSecondary(item: InventoryItem) {
|
||||
if (item.secondaryUse(Terrarum.appgc, Terrarum.UPDATE_DELTA))
|
||||
inventory.consumeItem(item) // consume on successful
|
||||
if (item.secondaryUse(Terrarum.appgc, Terrarum.delta))
|
||||
inventory.consumeItem(this as Actor, item) // consume on successful
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user