From 0cb1e53f671385cf83c35fb1eae2cc4a8f2338d7 Mon Sep 17 00:00:00 2001 From: ceikry Date: Wed, 25 Aug 2021 17:55:42 -0500 Subject: [PATCH] Add entity passthrough to destination overrides --- .../java/core/game/interaction/MovementPulse.java | 7 ++++--- .../core/game/interaction/npc/NPCTradePlugin.kt | 2 +- .../events/supriseexam/SupriseExamListeners.kt | 2 +- .../quest/members/waterfall/WaterfallListeners.kt | 2 +- .../rs09/game/interaction/InteractionListener.kt | 7 ++++--- .../rs09/game/interaction/InteractionListeners.kt | 15 ++++++++------- .../rs09/game/interaction/npc/NPCTalkListener.kt | 2 +- .../object/canoestation/CanoeStationListener.kt | 4 ++-- .../region/rellekka/JatizsoListeners.kt | 2 +- 9 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Server/src/main/java/core/game/interaction/MovementPulse.java b/Server/src/main/java/core/game/interaction/MovementPulse.java index 3a9e8b2aa..40b5a1a7b 100644 --- a/Server/src/main/java/core/game/interaction/MovementPulse.java +++ b/Server/src/main/java/core/game/interaction/MovementPulse.java @@ -14,6 +14,7 @@ import core.net.packet.PacketRepository; import core.net.packet.context.PlayerContext; import core.net.packet.out.ClearMinimapFlag; import kotlin.jvm.functions.Function1; +import kotlin.jvm.functions.Function2; import rs09.game.system.SystemLogger; import java.util.Deque; @@ -75,7 +76,7 @@ public abstract class MovementPulse extends Pulse { */ private boolean near; - private Function1 overrideMethod; + private Function2 overrideMethod; /** * Constructs a new {@code MovementPulse} {@code Object}. @@ -145,7 +146,7 @@ public abstract class MovementPulse extends Pulse { this.destinationFlag = destinationFlag; } - public MovementPulse(Entity mover, Node destination, DestinationFlag destinationFlag, Function1 method){ + public MovementPulse(Entity mover, Node destination, DestinationFlag destinationFlag, Function2 method){ this(mover,destination,null,false); this.destinationFlag = destinationFlag; this.overrideMethod = method; @@ -241,7 +242,7 @@ public abstract class MovementPulse extends Pulse { loc = destinationFlag.getDestination(mover, destination); } if(overrideMethod != null){ - loc = overrideMethod.invoke(destination); + loc = overrideMethod.invoke(mover,destination); if(loc == destination.getLocation()) loc = destinationFlag.getDestination(mover,destination); } if (loc == null && optionHandler != null) { diff --git a/Server/src/main/java/core/game/interaction/npc/NPCTradePlugin.kt b/Server/src/main/java/core/game/interaction/npc/NPCTradePlugin.kt index 6adf59936..8a2930716 100644 --- a/Server/src/main/java/core/game/interaction/npc/NPCTradePlugin.kt +++ b/Server/src/main/java/core/game/interaction/npc/NPCTradePlugin.kt @@ -45,7 +45,7 @@ class NPCTradePlugin : InteractionListener() { } override fun defineDestinationOverrides() { - setDest(NPC,"trade","shop"){node -> + setDest(NPC,"trade","shop"){_,node -> val npc = node as NPC if (npc.getAttribute("facing_booth", false)) { val offsetX = npc.direction.stepX shl 1 diff --git a/Server/src/main/kotlin/rs09/game/content/ame/events/supriseexam/SupriseExamListeners.kt b/Server/src/main/kotlin/rs09/game/content/ame/events/supriseexam/SupriseExamListeners.kt index 88a7cd7c0..8d8b241ef 100644 --- a/Server/src/main/kotlin/rs09/game/content/ame/events/supriseexam/SupriseExamListeners.kt +++ b/Server/src/main/kotlin/rs09/game/content/ame/events/supriseexam/SupriseExamListeners.kt @@ -53,7 +53,7 @@ class SupriseExamListeners : InteractionListener() { } override fun defineDestinationOverrides() { - setDest(NPC,MORDAUT){_ -> + setDest(NPC,MORDAUT){_,_ -> return@setDest Location.create(1886, 5025, 0) } } diff --git a/Server/src/main/kotlin/rs09/game/content/quest/members/waterfall/WaterfallListeners.kt b/Server/src/main/kotlin/rs09/game/content/quest/members/waterfall/WaterfallListeners.kt index ee140a00e..a2d187a89 100644 --- a/Server/src/main/kotlin/rs09/game/content/quest/members/waterfall/WaterfallListeners.kt +++ b/Server/src/main/kotlin/rs09/game/content/quest/members/waterfall/WaterfallListeners.kt @@ -15,7 +15,7 @@ class WaterfallListeners : InteractionListener(){ } override fun defineDestinationOverrides() { - setDest(NPC,HUDON){ + setDest(NPC,HUDON){_,_ -> return@setDest Location.create(2512, 3481, 0) } } diff --git a/Server/src/main/kotlin/rs09/game/interaction/InteractionListener.kt b/Server/src/main/kotlin/rs09/game/interaction/InteractionListener.kt index 6f93c9334..ffc9ae3c3 100644 --- a/Server/src/main/kotlin/rs09/game/interaction/InteractionListener.kt +++ b/Server/src/main/kotlin/rs09/game/interaction/InteractionListener.kt @@ -1,6 +1,7 @@ package rs09.game.interaction import core.game.node.Node +import core.game.node.entity.Entity import core.game.node.entity.player.Player import core.game.world.map.Location @@ -38,14 +39,14 @@ abstract class InteractionListener : Listener{ open fun defineDestinationOverrides(){} - fun setDest(type: Int, id: Int,handler: (Node) -> Location){ + fun setDest(type: Int, id: Int,handler: (Entity, Node) -> Location){ InteractionListeners.addDestOverride(type,id,handler) } - fun setDest(type:Int, vararg options: String, handler: (Node) -> Location){ + fun setDest(type:Int, vararg options: String, handler: (Entity, Node) -> Location){ InteractionListeners.addDestOverrides(type,options,handler) } - fun setDest(type: Int, ids: IntArray, vararg options: String, handler: (Node) -> Location){ + fun setDest(type: Int, ids: IntArray, vararg options: String, handler: (Entity, Node) -> Location){ InteractionListeners.addDestOverrides(type,ids,options,handler) } diff --git a/Server/src/main/kotlin/rs09/game/interaction/InteractionListeners.kt b/Server/src/main/kotlin/rs09/game/interaction/InteractionListeners.kt index 65fdcac52..cf71dc195 100644 --- a/Server/src/main/kotlin/rs09/game/interaction/InteractionListeners.kt +++ b/Server/src/main/kotlin/rs09/game/interaction/InteractionListeners.kt @@ -4,13 +4,14 @@ import core.game.interaction.DestinationFlag import core.game.interaction.MovementPulse import core.game.interaction.Option import core.game.node.Node +import core.game.node.entity.Entity import core.game.node.entity.player.Player import core.game.world.map.Location object InteractionListeners { private val listeners = HashMap Boolean>(1000) private val useWithListeners = HashMap Boolean>(1000) - private val destinationOverrides = HashMap Location>(100) + private val destinationOverrides = HashMap Location>(100) private val equipListeners = HashMap Boolean>(10) @JvmStatic @@ -89,19 +90,19 @@ object InteractionListeners { } @JvmStatic - fun addDestOverride(type: Int, id: Int, method: (Node) -> Location){ + fun addDestOverride(type: Int, id: Int, method: (Entity,Node) -> Location){ destinationOverrides["$type:$id"] = method } @JvmStatic - fun addDestOverrides(type: Int,options: Array, method: (Node) -> Location){ + fun addDestOverrides(type: Int,options: Array, method: (Entity,Node) -> Location){ for(opt in options){ destinationOverrides["$type:${opt.toLowerCase()}"] = method } } @JvmStatic - fun addDestOverrides(type: Int, ids: IntArray,options: Array, method: (Node) -> Location){ + fun addDestOverrides(type: Int, ids: IntArray,options: Array, method: (Entity,Node) -> Location){ for(id in ids){ for(opt in options){ destinationOverrides["$type:$id:${opt.toLowerCase()}"] = method @@ -110,17 +111,17 @@ object InteractionListeners { } @JvmStatic - fun getOverride(type: Int, id:Int, option: String): ((Node) -> Location)?{ + fun getOverride(type: Int, id:Int, option: String): ((Entity, Node) -> Location)?{ return destinationOverrides["$type:$id:${option.toLowerCase()}"] } @JvmStatic - fun getOverride(type: Int,id: Int): ((Node) -> Location)?{ + fun getOverride(type: Int,id: Int): ((Entity,Node) -> Location)?{ return destinationOverrides["$type:$id"] } @JvmStatic - fun getOverride(type: Int,option: String): ((Node) -> Location)?{ + fun getOverride(type: Int,option: String): ((Entity,Node) -> Location)?{ return destinationOverrides["$type:$option"] } diff --git a/Server/src/main/kotlin/rs09/game/interaction/npc/NPCTalkListener.kt b/Server/src/main/kotlin/rs09/game/interaction/npc/NPCTalkListener.kt index 59317ac0c..8bea79755 100644 --- a/Server/src/main/kotlin/rs09/game/interaction/npc/NPCTalkListener.kt +++ b/Server/src/main/kotlin/rs09/game/interaction/npc/NPCTalkListener.kt @@ -40,7 +40,7 @@ class NPCTalkListener : InteractionListener() { } override fun defineDestinationOverrides() { - setDest(NPC,"talk","talk-to"){node -> + setDest(NPC,"talk","talk-to"){_,node -> val npc = node as NPC if (npc.getAttribute("facing_booth", false)) { val offsetX = npc.direction.stepX shl 1 diff --git a/Server/src/main/kotlin/rs09/game/interaction/object/canoestation/CanoeStationListener.kt b/Server/src/main/kotlin/rs09/game/interaction/object/canoestation/CanoeStationListener.kt index 259ccb37d..857ba683e 100644 --- a/Server/src/main/kotlin/rs09/game/interaction/object/canoestation/CanoeStationListener.kt +++ b/Server/src/main/kotlin/rs09/game/interaction/object/canoestation/CanoeStationListener.kt @@ -19,10 +19,10 @@ class CanoeStationListener : InteractionListener() { private val FLOAT = Animation(3304) override fun defineDestinationOverrides() { - setDest(SCENERY,STATION_IDs,"chop-down"){ node -> + setDest(SCENERY,STATION_IDs,"chop-down"){ _,node -> return@setDest CanoeUtils.getChopLocation(node.location) } - setDest(SCENERY,STATION_IDs,"shape-canoe","float canoe","float log","float waka"){ node -> + setDest(SCENERY,STATION_IDs,"shape-canoe","float canoe","float log","float waka"){ _,node -> return@setDest CanoeUtils.getCraftFloatLocation(node.location) } } diff --git a/Server/src/main/kotlin/rs09/game/interaction/region/rellekka/JatizsoListeners.kt b/Server/src/main/kotlin/rs09/game/interaction/region/rellekka/JatizsoListeners.kt index ef36111a2..38d366122 100644 --- a/Server/src/main/kotlin/rs09/game/interaction/region/rellekka/JatizsoListeners.kt +++ b/Server/src/main/kotlin/rs09/game/interaction/region/rellekka/JatizsoListeners.kt @@ -137,7 +137,7 @@ class JatizsoListeners : InteractionListener() { return@on true } - setDest(NPC, NPCs.MAGNUS_GRAM_5488){_ -> + setDest(NPC, NPCs.MAGNUS_GRAM_5488){_,_ -> return@setDest Location.create(2416, 3801, 0) }