Add entity passthrough to destination overrides

This commit is contained in:
ceikry 2021-08-25 17:55:42 -05:00
parent cd641fdaaf
commit 0cb1e53f67
9 changed files with 23 additions and 20 deletions

View file

@ -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<Node,Location> overrideMethod;
private Function2<Entity,Node,Location> 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<Node,Location> method){
public MovementPulse(Entity mover, Node destination, DestinationFlag destinationFlag, Function2<Entity,Node,Location> 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) {

View file

@ -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

View file

@ -53,7 +53,7 @@ class SupriseExamListeners : InteractionListener() {
}
override fun defineDestinationOverrides() {
setDest(NPC,MORDAUT){_ ->
setDest(NPC,MORDAUT){_,_ ->
return@setDest Location.create(1886, 5025, 0)
}
}

View file

@ -15,7 +15,7 @@ class WaterfallListeners : InteractionListener(){
}
override fun defineDestinationOverrides() {
setDest(NPC,HUDON){
setDest(NPC,HUDON){_,_ ->
return@setDest Location.create(2512, 3481, 0)
}
}

View file

@ -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)
}

View file

@ -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<String,(Player, Node) -> Boolean>(1000)
private val useWithListeners = HashMap<String,(Player,Node,Node) -> Boolean>(1000)
private val destinationOverrides = HashMap<String,(Node) -> Location>(100)
private val destinationOverrides = HashMap<String,(Entity, Node) -> Location>(100)
private val equipListeners = HashMap<String,(Player,Node) -> 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<out String>, method: (Node) -> Location){
fun addDestOverrides(type: Int,options: Array<out String>, method: (Entity,Node) -> Location){
for(opt in options){
destinationOverrides["$type:${opt.toLowerCase()}"] = method
}
}
@JvmStatic
fun addDestOverrides(type: Int, ids: IntArray,options: Array<out String>, method: (Node) -> Location){
fun addDestOverrides(type: Int, ids: IntArray,options: Array<out String>, 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"]
}

View file

@ -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

View file

@ -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)
}
}

View file

@ -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)
}