RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
SimplePathChecker.java
1package com.osroyale.game.world.pathfinding.path;
2
3import com.osroyale.game.world.Interactable;
4import com.osroyale.game.world.entity.mob.Mob;
5import com.osroyale.game.world.position.Position;
6import com.osroyale.util.Utility;
7
51
52public class SimplePathChecker extends PathFinder {
53 private static final SimplePathChecker SIMPLE_PATH_CHECKER = new SimplePathChecker();
54
55 @Override
56 public Path find(Mob source, Position end, int targetWidth, int targetLength) {
57 /* empty path */
58 return new Path(null);
59 }
60
61 public static boolean checkLine(Interactable source, Interactable target) {
62 Position targetPosition = Utility.findBestInside(source, target);
63 return SIMPLE_PATH_CHECKER.check(source.getPosition(), targetPosition, source.width(), false);
64 }
65
66 public static boolean checkLine(Interactable source, Position target) {
67 return SIMPLE_PATH_CHECKER.check(source.getPosition(), target, source.width(), false);
68 }
69
70 public static boolean checkProjectile(Interactable source, Interactable target) {
71 Position targetPosition = Utility.findBestInside(source, target);
72 return SIMPLE_PATH_CHECKER.check(source.getPosition(), targetPosition, Math.max(1, Math.max(source.width(), source.length())), true);
73 }
74
84 private boolean check(Position start, Position end, int size, boolean projectile) {
85 int dx = end.getX() - start.getX();
86 int dy = end.getY() - start.getY();
87 int xSignum = Integer.signum(dx);
88 int ySignum = Integer.signum(dy);
89 int height = start.getHeight();
90 int nextX = start.getX();
91 int nextY = start.getY();
92 int currentX = nextX;
93 int currentY = nextY;
94
95 while (true) {
96 if (dx == 0) {
97 nextY += ySignum;
98 } else if (dy == 0) {
99 nextX += xSignum;
100 } else if (nextX != end.getX()) {
101 int pointSlope = (nextX + xSignum - start.getX()) * dy / dx + start.getY();
102
103 if (Math.abs(pointSlope - currentY) > 1) {
104 nextY += ySignum;
105 } else {
106 nextX += xSignum;
107 nextY = pointSlope;
108 }
109 }
110
111 Position current = new Position(currentX, currentY, height);
112 Position next = new Position(nextX, nextY, height);
113
114 if (projectile && !projectileCheck(current, next)) {
115 return false;
116 }
117
118 if (!projectile && !traversable(current, next, size)) {
119 return false;
120 }
121
122 if (nextX == end.getX() && nextY == end.getY()) {
123 break;
124 }
125
126 currentX = nextX;
127 currentY = nextY;
128 }
129 return true;
130 }
131
132}
boolean projectileCheck(Position current, Position going)
boolean traversable(Position current, int size, Direction... directions)
Path find(Mob source, Position end, int targetWidth, int targetLength)