Pathfinder now correctly paths to the closest accessible tile of an object, not the closest tile numerically. This should fix instances where you end up running around an object before interacting with it.

This commit is contained in:
Ceikry
2022-06-11 12:35:16 +00:00
committed by Ryan
parent 7249aaed5e
commit 5c28375c3b
5 changed files with 121 additions and 11 deletions
@@ -5,6 +5,7 @@ import core.game.node.entity.Entity;
import core.game.node.entity.impl.WalkingQueue;
import core.game.node.entity.npc.NPC;
import core.game.node.entity.player.Player;
import core.game.node.scenery.Scenery;
import core.game.system.task.Pulse;
import core.game.world.map.Direction;
import core.game.world.map.Location;
@@ -241,26 +242,33 @@ public abstract class MovementPulse extends Pulse {
if (last != null && last.equals(destination.getLocation()) && !inside) {
return;
}
Location loc = null;
if (destinationFlag != null && overrideMethod == null) {
loc = destinationFlag.getDestination(mover, destination);
}
if(overrideMethod != null){
else if(overrideMethod != null){
loc = overrideMethod.invoke(mover,destination);
if(loc == destination.getLocation()) loc = destinationFlag.getDestination(mover,destination);
}
if (loc == null && optionHandler != null) {
loc = optionHandler.getDestination(mover, destination);
}
if (loc == null && useHandler != null) {
loc = useHandler.getDestination((Player) mover, destination);
}
if (loc == null && inside) {
loc = findBorderLocation();
if (loc == null) {
if (optionHandler != null) {
loc = optionHandler.getDestination(mover, destination);
}
else if (useHandler != null) {
loc = useHandler.getDestination((Player) mover, destination);
}
else if (inside) {
loc = findBorderLocation();
}
}
if (destination == null) {
return;
}
Location ml = mover.getLocation();
Location dl = destination.getLocation();
// Lead the target if they're walking/running, unless they're already within interaction range
@@ -10,6 +10,11 @@ import core.game.node.entity.player.Player;
import core.game.system.task.Pulse;
import core.game.world.map.Direction;
import core.game.world.map.Location;
import org.jetbrains.annotations.NotNull;
import rs09.game.system.SystemLogger;
import java.util.ArrayList;
import java.util.List;
/**
* Represents a scenery.
@@ -30,7 +35,7 @@ public class Scenery extends Node {
/**
* The rotation.
*/
private final int rotation;
private int rotation;
/**
* The object's definition.
@@ -309,6 +314,10 @@ public class Scenery extends Node {
return rotation;
}
public void setRotation(int rot) {
rotation = rot;
}
/**
* @return the location
*/
@@ -426,4 +435,37 @@ public class Scenery extends Node {
this.wrapper = wrapper;
}
@SuppressWarnings("SuspiciousNameCombination")
@NotNull
public List<Location> getOccupiedTiles() {
List<Location> occupied = new ArrayList<>();
occupied.add(location);
int sizeX = getSizeX();
int sizeY = getSizeY();
if (rotation % 2 == 1) {
int tmp = sizeX;
sizeX = sizeY;
sizeY = tmp;
}
boolean sub = rotation >= 2;
if (sizeX > 1) {
for (int i = 1; i < sizeX; i++) {
int modifier = sub ? -i : i;
occupied.add(location.transform(modifier, 0, 0));
}
}
if (sizeY > 1) {
for (int i = 1; i < sizeY; i++) {
int modifier = sub ? -i : i;
occupied.add(location.transform(0, modifier, 0));
}
}
return occupied;
}
}
@@ -207,7 +207,7 @@ object InteractionListeners {
val flag = when(type){
3 -> DestinationFlag.ITEM
2 -> DestinationFlag.ENTITY
1 -> DestinationFlag.OBJECT
1 -> null
else -> DestinationFlag.OBJECT
}
@@ -149,6 +149,13 @@ object ManagementEvents {
}
is FriendUpdate -> {
val remove = event.type == FriendUpdate.Type.REMOVE
val f = Repository.getPlayerByName(event.friend)
val p = Repository.getPlayerByName(event.username)
val world = if (f != null) GameWorld.settings!!.worldId else 0
}
is PrivateMessage -> {
val sender = Repository.getPlayerByName(event.sender)
val receiver = Repository.getPlayerByName(event.receiver)