mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-16 13:34:06 +09:00
quickslot works, new event for actor "actorValueChanged"
- "unpacking" fresh new tool would un-register quickslot desig. - priority issue on "equipped by quickslot change" and "equipped by inventory UI"
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.ActorValue
|
||||
import net.torvald.terrarum.gameactors.ActorValue
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex.ACTORID_MIN
|
||||
@@ -37,7 +37,7 @@ abstract class Actor(val renderOrder: RenderOrder) : Comparable<Actor>, Runnable
|
||||
* @return Reference ID. (16777216-0x7FFF_FFFF)
|
||||
*/
|
||||
open var referenceID: ActorID = generateUniqueReferenceID()
|
||||
var actorValue = ActorValue()
|
||||
var actorValue = ActorValue(this)
|
||||
@Volatile var flagDespawn = false
|
||||
|
||||
override fun equals(other: Any?) = referenceID == (other as Actor).referenceID
|
||||
@@ -79,4 +79,10 @@ abstract class Actor(val renderOrder: RenderOrder) : Comparable<Actor>, Runnable
|
||||
return ret
|
||||
}
|
||||
|
||||
/**
|
||||
* ActorValue change event handler
|
||||
*
|
||||
* @param value null if the key is deleted
|
||||
*/
|
||||
abstract fun actorValueChanged(key: String, value: Any?)
|
||||
}
|
||||
@@ -473,6 +473,21 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
|
||||
}
|
||||
}
|
||||
|
||||
override fun actorValueChanged(key: String, value: Any?) {
|
||||
// quickslot implementation
|
||||
if (key == AVKey.__PLAYER_QUICKSLOTSEL && value != null) {
|
||||
// ONLY FOR HAND_GRIPs!!
|
||||
val quickBarItem = inventory.getQuickBar(actorValue.getAsInt(key)!!)?.item
|
||||
|
||||
if (quickBarItem == null) {
|
||||
unequipSlot(InventoryItem.EquipPosition.HAND_GRIP)
|
||||
}
|
||||
else if (quickBarItem.equipPosition == InventoryItem.EquipPosition.HAND_GRIP) {
|
||||
equipItem(quickBarItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun isNoClip(): Boolean {
|
||||
return noClip
|
||||
}
|
||||
|
||||
29
src/net/torvald/terrarum/gameactors/ActorValue.kt
Normal file
29
src/net/torvald/terrarum/gameactors/ActorValue.kt
Normal file
@@ -0,0 +1,29 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.terrarum.KVHashMap
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-04-28.
|
||||
*/
|
||||
class ActorValue(val actor: Actor) : KVHashMap() {
|
||||
|
||||
private constructor(actor: Actor, newMap: HashMap<String, Any>): this(actor) {
|
||||
hashMap = newMap
|
||||
}
|
||||
|
||||
override fun set(key: String, value: Any) {
|
||||
super.set(key, value)
|
||||
actor.actorValueChanged(key, value) // fire the event handler
|
||||
}
|
||||
|
||||
override fun remove(key: String) {
|
||||
if (hashMap[key] != null) {
|
||||
hashMap.remove(key, hashMap[key]!!)
|
||||
actor.actorValueChanged(key, null)
|
||||
}
|
||||
}
|
||||
|
||||
fun clone(newActor: Actor): ActorValue {
|
||||
return ActorValue(newActor, hashMap)
|
||||
}
|
||||
}
|
||||
@@ -1124,6 +1124,13 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
||||
}
|
||||
}
|
||||
|
||||
override fun actorValueChanged(key: String, value: Any?) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private fun clampW(x: Double): Double =
|
||||
if (x < TILE_SIZE + nextHitbox.width / 2) {
|
||||
TILE_SIZE + nextHitbox.width / 2
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.*
|
||||
/**
|
||||
* Created by minjaesong on 16-06-17.
|
||||
*/
|
||||
class FixtureTikiTorch : FixtureBase(), Luminous {
|
||||
internal class FixtureTikiTorch : FixtureBase(), Luminous {
|
||||
|
||||
override var luminosity: Int
|
||||
get() = BlockCodex[Block.TORCH].luminosity
|
||||
|
||||
@@ -4,7 +4,7 @@ import net.torvald.JsonFetcher
|
||||
import net.torvald.random.Fudge3
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import com.google.gson.JsonObject
|
||||
import net.torvald.terrarum.ActorValue
|
||||
import net.torvald.terrarum.gameactors.ActorValue
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import org.newdawn.slick.SlickException
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.terrarum.ui.UIQuickBar
|
||||
import org.newdawn.slick.GameContainer
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.terrarum.ActorValue
|
||||
import net.torvald.terrarum.gameactors.ActorValue
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.gameactors.faction.FactionFactory
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
@@ -28,7 +28,6 @@ object PlayerBuilderSigrid {
|
||||
p.spriteGlow!!.delay = 200
|
||||
p.spriteGlow!!.setRowsAndFrames(1, 1)
|
||||
|
||||
p.actorValue = ActorValue()
|
||||
p.actorValue[AVKey.SCALE] = 1.0
|
||||
p.actorValue[AVKey.SPEED] = 4.0
|
||||
p.actorValue[AVKey.SPEEDBUFF] = 1.0
|
||||
|
||||
@@ -14,7 +14,9 @@ interface Pocketed {
|
||||
/**
|
||||
* Equips an item. If the item is not in the inventory, an error will be thrown.
|
||||
*/
|
||||
fun unequipItem(item: InventoryItem) {
|
||||
fun unequipItem(item: InventoryItem?) {
|
||||
if (item == null) return
|
||||
|
||||
if (item.equipPosition == InventoryItem.EquipPosition.NULL)
|
||||
throw Error("Unequipping the item that cannot be equipped in the first place")
|
||||
|
||||
@@ -28,6 +30,14 @@ interface Pocketed {
|
||||
item.effectOnUnequip(Terrarum.appgc, Terrarum.delta)
|
||||
}
|
||||
|
||||
// no need for equipSlot(Int)
|
||||
fun unequipSlot(slot: Int) {
|
||||
if (slot < 0 || slot > InventoryItem.EquipPosition.INDEX_MAX)
|
||||
throw IllegalArgumentException("Slot index out of range: $slot")
|
||||
|
||||
unequipItem(inventory.itemEquipped[slot])
|
||||
}
|
||||
|
||||
/**
|
||||
* Equips an item. If the item is not in the inventory, adds the item first.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user