|
37 | 37 | import net.runelite.api.Client; |
38 | 38 | import net.runelite.api.ItemContainer; |
39 | 39 | import net.runelite.api.NPC; |
| 40 | +import net.runelite.api.coords.WorldPoint; |
40 | 41 | import net.runelite.api.events.ItemContainerChanged; |
41 | 42 | import net.runelite.api.events.NpcDespawned; |
42 | 43 | import net.runelite.api.events.NpcSpawned; |
|
46 | 47 | import net.runelite.api.gameval.VarbitID; |
47 | 48 | import net.runelite.client.callback.ClientThread; |
48 | 49 | import net.runelite.client.config.ConfigManager; |
| 50 | +import net.runelite.client.eventbus.EventBus; |
49 | 51 | import net.runelite.client.eventbus.Subscribe; |
50 | 52 | import net.runelite.client.events.ConfigChanged; |
| 53 | +import net.runelite.client.events.PluginMessage; |
51 | 54 | import net.runelite.client.game.ItemManager; |
52 | 55 | import net.runelite.client.plugins.Plugin; |
53 | 56 | import net.runelite.client.plugins.PluginDescriptor; |
|
63 | 66 | import javax.inject.Inject; |
64 | 67 | import java.time.temporal.ChronoUnit; |
65 | 68 | import java.util.ArrayList; |
| 69 | +import java.util.HashMap; |
66 | 70 | import java.util.List; |
| 71 | +import java.util.Map; |
67 | 72 |
|
68 | 73 | @PluginDescriptor(name = "Gnome Restaurant") |
69 | 74 | public class GnomeRestaurantPlugin extends Plugin { |
@@ -91,6 +96,9 @@ public class GnomeRestaurantPlugin extends Plugin { |
91 | 96 | @Inject |
92 | 97 | private WorldMapPointManager worldMapPointManager; |
93 | 98 |
|
| 99 | + @Inject |
| 100 | + private EventBus eventBus; |
| 101 | + |
94 | 102 | // UI |
95 | 103 |
|
96 | 104 | private Timer timer; |
@@ -128,6 +136,7 @@ private void resetPlugin() { |
128 | 136 | removeOverlay(); |
129 | 137 | removeWorldMapPoint(); |
130 | 138 | client.clearHintArrow(); |
| 139 | + removeShortestPath(); |
131 | 140 |
|
132 | 141 | stepIdx = 0; |
133 | 142 |
|
@@ -218,6 +227,10 @@ private void setupUI() { |
218 | 227 | if (config.showWorldMapPoint()) { |
219 | 228 | showWorldMapPoint(); |
220 | 229 | } |
| 230 | + |
| 231 | + if (config.useShortestPath()) { |
| 232 | + showShortestPath(); |
| 233 | + } |
221 | 234 | } |
222 | 235 |
|
223 | 236 | private void setupOverlay() { |
@@ -287,28 +300,60 @@ private boolean setHintArrowToCustomer() { |
287 | 300 | return false; |
288 | 301 | } |
289 | 302 |
|
| 303 | + private void showShortestPath() { |
| 304 | + if (!setShortestPathToCustomer()) { |
| 305 | + // NPC not in sight |
| 306 | + // Set destination to approximate location |
| 307 | + setShortestPath(customer.getLocation(client)); |
| 308 | + } |
| 309 | + } |
| 310 | + |
| 311 | + private boolean setShortestPathToCustomer() { |
| 312 | + var npcs = client.getTopLevelWorldView().npcs(); |
| 313 | + |
| 314 | + for (NPC npc : npcs) { |
| 315 | + if (npc.getId() == customer.getNpcTypeId(client)) { |
| 316 | + setShortestPath(npc.getWorldLocation()); |
| 317 | + return true; |
| 318 | + } |
| 319 | + } |
| 320 | + return false; |
| 321 | + } |
| 322 | + |
| 323 | + private void setShortestPath(final WorldPoint destination) { |
| 324 | + Map<String, Object> data = new HashMap<>(); |
| 325 | + data.put("target", destination); |
| 326 | + eventBus.post(new PluginMessage("shortestpath", "path", data)); |
| 327 | + } |
| 328 | + |
290 | 329 | @Subscribe |
291 | 330 | public void onNpcSpawned(final NpcSpawned event) { |
292 | 331 | var npc = event.getNpc(); |
293 | 332 |
|
294 | | - if (order == null || !config.showHintArrow()) { |
| 333 | + if (order == null || npc.getId() != customer.getNpcTypeId(client)) { |
295 | 334 | return; |
296 | 335 | } |
297 | | - if (npc.getId() == customer.getNpcTypeId(client)) { |
| 336 | + if (config.showHintArrow()) { |
298 | 337 | client.setHintArrow(npc); |
299 | 338 | } |
| 339 | + if (config.useShortestPath()) { |
| 340 | + setShortestPath(npc.getWorldLocation()); |
| 341 | + } |
300 | 342 | } |
301 | 343 |
|
302 | 344 | @Subscribe |
303 | 345 | public void onNpcDespawned(final NpcDespawned event) { |
304 | 346 | var npc = event.getNpc(); |
305 | 347 |
|
306 | | - if (order == null || !config.showHintArrow()) { |
| 348 | + if (order == null || npc.getId() != customer.getNpcTypeId(client)) { |
307 | 349 | return; |
308 | 350 | } |
309 | | - if (npc.getId() == customer.getNpcTypeId(client)) { |
| 351 | + if (config.showHintArrow()) { |
310 | 352 | client.setHintArrow(customer.getLocation(client)); |
311 | 353 | } |
| 354 | + if (config.useShortestPath()) { |
| 355 | + setShortestPath(customer.getLocation(client)); |
| 356 | + } |
312 | 357 | } |
313 | 358 |
|
314 | 359 | @Subscribe |
@@ -377,6 +422,9 @@ public void onItemContainerChanged(ItemContainerChanged event) { |
377 | 422 | if (updateOrderStep()) { |
378 | 423 | updateOverlayHeader(); |
379 | 424 | rebuildOverlayTables(); |
| 425 | + if (config.useShortestPath()) { |
| 426 | + showShortestPath(); |
| 427 | + } |
380 | 428 | } else { |
381 | 429 | updateOverlayTables(); |
382 | 430 | } |
@@ -436,6 +484,7 @@ GnomeRestaurantConfig provideConfig(ConfigManager configManager) { |
436 | 484 | public static final String SHOW_OVERLAY = "showOverlay"; |
437 | 485 | public static final String SHOW_HINT_ARROW = "showHintArrow"; |
438 | 486 | public static final String SHOW_WORLD_MAP_POINT = "showWorldMapPoint"; |
| 487 | + public static final String USE_SHORTEST_PATH = "useShortestPath"; |
439 | 488 |
|
440 | 489 | /** |
441 | 490 | * Monitor changes to plugin config and update the plugin accordingly |
@@ -468,6 +517,12 @@ public void onConfigChanged(ConfigChanged event) { |
468 | 517 | } else { |
469 | 518 | showWorldMapPoint(); |
470 | 519 | } |
| 520 | + } else if (event.getKey().equals(USE_SHORTEST_PATH)) { |
| 521 | + if (event.getNewValue().equals("false")) { |
| 522 | + removeShortestPath(); |
| 523 | + } else { |
| 524 | + showShortestPath(); |
| 525 | + } |
471 | 526 | } |
472 | 527 | } else { |
473 | 528 | if (!event.getGroup().equals("gnomerestaurant")) { |
@@ -499,6 +554,10 @@ private void removeWorldMapPoint() { |
499 | 554 | worldMapPoint = null; |
500 | 555 | } |
501 | 556 |
|
| 557 | + private void removeShortestPath() { |
| 558 | + eventBus.post(new PluginMessage("shortestpath", "clear")); |
| 559 | + } |
| 560 | + |
502 | 561 | private void clearOverlayTables() { |
503 | 562 | stepIngredientsOverlayTable.clear(); |
504 | 563 | nextRawIngredientsOverlayTable.clear(); |
|
0 commit comments