add destination overrides for canoe system

This commit is contained in:
Ceikry
2021-03-15 16:38:19 -05:00
parent df40fbb32d
commit 30576b9eb4
4 changed files with 64 additions and 9 deletions
@@ -35,4 +35,8 @@ abstract class InteractionListener : Listener{
fun setDest(type:Int, vararg options: String, handler: (Node) -> Location){ fun setDest(type:Int, vararg options: String, handler: (Node) -> Location){
InteractionListeners.addDestOverrides(type,options,handler) InteractionListeners.addDestOverrides(type,options,handler)
} }
fun setDest(type: Int, ids: IntArray, vararg options: String, handler: (Node) -> Location){
InteractionListeners.addDestOverrides(type,ids,options,handler)
}
} }
@@ -78,6 +78,20 @@ object InteractionListeners {
} }
} }
@JvmStatic
fun addDestOverrides(type: Int, ids: IntArray,options: Array<out String>, method: (Node) -> Location){
for(id in ids){
for(opt in options){
destinationOverrides["$type:$id:${opt.toLowerCase()}"] = method
}
}
}
@JvmStatic
fun getOverride(type: Int, id:Int, option: String): ((Node) -> Location)?{
return destinationOverrides["$type:$id:${option.toLowerCase()}"]
}
@JvmStatic @JvmStatic
fun getOverride(type: Int,id: Int): ((Node) -> Location)?{ fun getOverride(type: Int,id: Int): ((Node) -> Location)?{
return destinationOverrides["$type:$id"] return destinationOverrides["$type:$id"]
@@ -130,7 +144,7 @@ object InteractionListeners {
if(player.locks.isInteractionLocked) return false if(player.locks.isInteractionLocked) return false
val method = get(id,type,option) ?: get(option,type) ?: return false val method = get(id,type,option) ?: get(option,type) ?: return false
val destOverride = getOverride(type,node.id) ?: getOverride(type,option.toLowerCase()) val destOverride = getOverride(type, id, option) ?: getOverride(type,node.id) ?: getOverride(type,option.toLowerCase())
if(type != 0) { if(type != 0) {
if(player.locks.isMovementLocked) return false if(player.locks.isMovementLocked) return false
@@ -10,22 +10,27 @@ import rs09.game.interaction.InteractionListener
class CanoeStationListener : InteractionListener() { class CanoeStationListener : InteractionListener() {
val STATION_IDs = intArrayOf(12140, 12141, 12142, 12143, 12145, 12146, 12147, 12148, 12151, 12152, 12153, 12154, 12155, 12156, 12157, 12158, 12144, 12146, 12149, 12150, 12157) private val STATION_IDs = intArrayOf(12140, 12141, 12142, 12143, 12144, 12145, 12146, 12147, 12148, 12151, 12152, 12153, 12154, 12155, 12156, 12157, 12158, 12144, 12146, 12149, 12150, 12157)
val CHOP_STATION = intArrayOf(12144) private val STAGE_TREE_NONINTERACTABLE = 9
val STAGE_TREE_NONINTERACTABLE = 9 private val STAGE_LOG_CHOPPED = 10
val STAGE_LOG_CHOPPED = 10
private val SHAPING_INTERFACE = Components.CANOE_52 private val SHAPING_INTERFACE = Components.CANOE_52
private val PUSH = Animation(3301) private val PUSH = Animation(3301)
private val ROW = Animation(3302)
private val FALL = Animation(3303) private val FALL = Animation(3303)
private val FLOAT = Animation(3304) private val FLOAT = Animation(3304)
private val SINK = Animation(3305)
override fun defineDestinationOverrides() {
setDest(OBJECT,STATION_IDs,"chop-down"){node ->
return@setDest CanoeUtils.getChopLocation(node.location)
}
setDest(OBJECT,STATION_IDs,"shape-canoe","float canoe","float log","float waka"){node ->
return@setDest CanoeUtils.getCraftFloatLocation(node.location)
}
}
override fun defineListeners() { override fun defineListeners() {
on(CHOP_STATION,OBJECT,"chop-down"){player, node -> on(STATION_IDs,OBJECT,"chop-down"){player, node ->
val axe: SkillingTool? = SkillingTool.getHatchet(player) val axe: SkillingTool? = SkillingTool.getHatchet(player)
val varbit = node.asObject().definition.configFile val varbit = node.asObject().definition.configFile
if(varbit.getValue(player) != 0){ if(varbit.getValue(player) != 0){
player.varpManager.setVarbit(varbit,0) player.varpManager.setVarbit(varbit,0)
} }
@@ -39,6 +44,8 @@ class CanoeStationListener : InteractionListener() {
return@on true return@on true
} }
player.lock() player.lock()
player.varpManager.get(varbit.configId).clearBitRange(0,31)
player.faceLocation(CanoeUtils.getFaceLocation(player.location))
player.animate(axe.animation) player.animate(axe.animation)
player.varpManager.setVarbit(varbit,STAGE_TREE_NONINTERACTABLE) player.varpManager.setVarbit(varbit,STAGE_TREE_NONINTERACTABLE)
player.pulseManager.run(object : Pulse(4){ player.pulseManager.run(object : Pulse(4){
@@ -59,6 +66,7 @@ class CanoeStationListener : InteractionListener() {
player.varpManager.setVarbit(varbit,0) player.varpManager.setVarbit(varbit,0)
return@on true return@on true
} }
player.faceLocation(CanoeUtils.getFaceLocation(player.location))
player.interfaceManager.open(Component(SHAPING_INTERFACE)) player.interfaceManager.open(Component(SHAPING_INTERFACE))
player.setAttribute("canoe-varbit",varbit) player.setAttribute("canoe-varbit",varbit)
return@on true return@on true
@@ -69,6 +77,7 @@ class CanoeStationListener : InteractionListener() {
val canoe = CanoeUtils.getCanoeFromVarbit(player,varbit) val canoe = CanoeUtils.getCanoeFromVarbit(player,varbit)
player.animator.animate(PUSH) player.animator.animate(PUSH)
player.lock() player.lock()
player.faceLocation(CanoeUtils.getFaceLocation(player.location))
player.pulseManager.run(object : Pulse(){ player.pulseManager.run(object : Pulse(){
override fun pulse(): Boolean { override fun pulse(): Boolean {
player.varpManager.setVarbit(varbit,CanoeUtils.getCraftValue(canoe,true)) player.varpManager.setVarbit(varbit,CanoeUtils.getCraftValue(canoe,true))
@@ -59,4 +59,32 @@ object CanoeUtils {
} }
} }
fun getFaceLocation(location: Location): Location{
return when(getStationIndex(location)){
1 -> location.transform(0,-1,0)
0,2,3 -> location.transform(-1,0,0)
else -> location
}
}
fun getChopLocation(location: Location): Location{
return when(getStationIndex(location)){
0 -> Location.create(3243, 3235, 0)
1 -> Location.create(3204, 3343, 0)
2 -> Location.create(3112, 3409, 0)
3 -> Location.create(3132, 3508, 0)
else -> Location.create(0,0)
}
}
fun getCraftFloatLocation(location: Location): Location{
return when(getStationIndex(location)){
0 -> Location.create(3243, 3237, 0)
1 -> Location.create(3202, 3343, 0)
2 -> Location.create(3112, 3411, 0)
3 -> Location.create(3132, 3510, 0)
else -> Location.create(0,0)
}
}
} }