52public abstract class Waypoint
extends Task {
53 protected final Mob mob;
63 protected abstract void onDestination();
65 protected int getRadius() {
69 protected boolean withinDistance() {
70 if (target instanceof
final GameObject object) {
71 Position position = mob.getPosition();
72 int x = position.
getX();
73 int y = position.getY();
76 int walkingFlag = definition.getWalkingFlag();
79 int rotation =
object.getDirection().getId();
80 if (rotation % 2 != 0) {
85 walkingFlag = (walkingFlag << rotation & 0xF) + (walkingFlag >> 4 - rotation);
87 if (sizeX != 0 && sizeY != 0) {
88 Position targetPosition = target.getPosition();
89 int destX = targetPosition.
getX();
90 int destY = targetPosition.
getY();
95 int cornerX = destX + sizeX - 1;
96 int cornerY = destY + sizeY - 1;
98 if (destX <= x && cornerX >= x && y >= destY && y <= cornerY) {
101 if (x == destX - 1 && destY <= y && y <= cornerY && (0x8 & flag) == 0 && (0x8 & walkingFlag) == 0) {
104 if (x == cornerX + 1 && destY <= y && cornerY >= y && (flag & 0x80) == 0 && (0x2 & walkingFlag) == 0) {
107 if (y == destY - 1 && destX <= x && cornerX >= x && (0x2 & flag) == 0 && (0x4 & walkingFlag) == 0) {
110 if (y == cornerY + 1 && destX <= x && cornerX >= x && (flag & 0x20) == 0 && (0x1 & walkingFlag) == 0) {
115 return Utility.getDistance(mob, target) <= getRadius() && !mob.movement.needsPlacement();
120 if (mob.locking.locked(
PacketType.MOVEMENT)) {
124 if (target instanceof
Mob) {
125 mob.interact((
Mob) target);
128 if (!withinDistance()) {
135 if (target instanceof
Mob &&
Utility.inside(mob, target)) {
137 && !mob.movement.needsPlacement()) {
138 Mob targetMob = (
Mob) target;
139 if (targetMob.hasPriorityIndex(mob)
140 || (!targetMob.isFixingInside() && !targetMob.movement.needsPlacement())) {
141 Utility.fixInsidePosition(mob, target);
146 mob.setFixingInside(
false);
149 if (withinDistance()) {
154 if (target instanceof
GameObject gameObject && mob.isPlayer()) {
155 if (gameObject.distance() > 1 && withinDistance(mob.getPosition().getX(), mob.getPosition().getY(), target.getPosition().getX(), target.getPosition().getY(), target.width(), gameObject.length(), gameObject.distance())) {
161 if (target.getPosition().equals(lastPosition)) {
165 if (mob.locking.locked(
PacketType.MOVEMENT)) {
169 lastPosition = target.getPosition();
173 private void findRoute() {
174 if (target instanceof
Player && mob.equals(((
Player) target).pet)) {
175 int distance =
Utility.getDistance(mob, target);
176 if (distance >
Region.VIEW_DISTANCE) {
177 Npc pet = mob.getNpc();
179 pet.instance = ((
Player) target).instance;
182 pet.follow((
Player) target);
194 boolean smart = mob.isPlayer() || (mob.isNpc() && !(
this instanceof CombatWaypoint));
196 if (smart && mob.movement.dijkstraPath(target)) {
205 mob.getPlayer().send(
new SendMessage(
"I can't reach that!"));
215 if (target instanceof
Mob other) {
216 other.attributes.remove(
"mob-following");
221 public boolean equals(Object obj) {
222 if (obj ==
this)
return true;
223 if (obj instanceof
Waypoint other) {
224 return Objects.equals(mob, other.mob)
225 && Objects.equals(target, other.target);
231 public String toString() {
232 return getClass().getSimpleName() +
"{" +
241 public void onChange() {
246 boolean withinDistance(
int x,
int y,
int x2,
int y2,
int width,
int height,
int distance) {
248 x2 += Math.min(width, x - x2) - 1;
251 y2 += Math.min(height, y - y2) - 1;
253 return Math.abs(x - x2) <= distance && Math.abs(y - y2) <= distance;