|
10 | 10 | import io.luna.game.model.collision.CollisionManager; |
11 | 11 | import io.luna.game.model.path.AStarPathfindingAlgorithm; |
12 | 12 | import io.luna.game.model.path.EuclideanHeuristic; |
| 13 | +import io.luna.game.model.path.PathfindingAlgorithm; |
13 | 14 | import io.luna.game.model.path.SimplePathfindingAlgorithm; |
14 | 15 | import io.luna.util.RandomUtils; |
15 | 16 | import org.apache.logging.log4j.LogManager; |
16 | 17 | import org.apache.logging.log4j.Logger; |
17 | 18 |
|
18 | | -import java.util.ArrayDeque; |
19 | | -import java.util.Arrays; |
20 | | -import java.util.Deque; |
21 | | -import java.util.Objects; |
22 | | -import java.util.Optional; |
23 | | -import java.util.Queue; |
| 19 | +import java.util.*; |
24 | 20 |
|
25 | 21 | /** |
26 | 22 | * A model representing an implementation of the walking queue. |
@@ -124,16 +120,7 @@ public int getY() { |
124 | 120 | * The collision manager. |
125 | 121 | */ |
126 | 122 | private final CollisionManager collisionManager; |
127 | | - |
128 | | - /** |
129 | | - * The simple pathfinder. |
130 | | - */ |
131 | | - private final SimplePathfindingAlgorithm simplePathfinder; |
132 | | - |
133 | | - /** |
134 | | - * The A* pathfinder. |
135 | | - */ |
136 | | - private final AStarPathfindingAlgorithm astarPathfinder; |
| 123 | + private final PathfindingAlgorithm pathfindingAlgorithm; |
137 | 124 |
|
138 | 125 | /** |
139 | 126 | * The mob. |
@@ -163,8 +150,11 @@ public int getY() { |
163 | 150 | public WalkingQueue(Mob mob) { |
164 | 151 | this.mob = mob; |
165 | 152 | collisionManager = mob.getWorld().getCollisionManager(); |
166 | | - simplePathfinder = new SimplePathfindingAlgorithm(collisionManager); |
167 | | - astarPathfinder = new AStarPathfindingAlgorithm(collisionManager, new EuclideanHeuristic()); |
| 153 | + if (mob instanceof Player) { |
| 154 | + this.pathfindingAlgorithm = new AStarPathfindingAlgorithm(collisionManager, new EuclideanHeuristic()); |
| 155 | + } else { |
| 156 | + this.pathfindingAlgorithm = new SimplePathfindingAlgorithm(collisionManager); |
| 157 | + } |
168 | 158 | } |
169 | 159 |
|
170 | 160 | /** |
@@ -265,7 +255,7 @@ public void walk(Position destination) { |
265 | 255 | */ |
266 | 256 | public void walkUntilReached(Entity target) { |
267 | 257 | Deque<Step> newPath = new ArrayDeque<>(); |
268 | | - Deque<Position> path = astarPathfinder.find(mob.getPosition(), target.getPosition()); |
| 258 | + Deque<Position> path = pathfindingAlgorithm.find(mob.getPosition(), target.getPosition()); |
269 | 259 | Position lastPosition = mob.getPosition(); |
270 | 260 | for (; ; ) { |
271 | 261 | Position nextPosition = path.poll(); |
@@ -507,8 +497,7 @@ private void incrementRunEnergy() { |
507 | 497 | * @return The path. |
508 | 498 | */ |
509 | 499 | private Deque<Step> findPath(Position target) { |
510 | | - Deque<Position> positionPath = mob.getType() == EntityType.PLAYER ? astarPathfinder.find(mob.getPosition(), target) : |
511 | | - simplePathfinder.find(mob.getPosition(), target); |
| 500 | + Deque<Position> positionPath = pathfindingAlgorithm.find(mob.getPosition(), target); |
512 | 501 | Deque<Step> stepPath = new ArrayDeque<>(positionPath.size()); |
513 | 502 | for (; ; ) { |
514 | 503 | // TODO remove step class? |
|
0 commit comments