Skip to content

Commit 61ae094

Browse files
committed
feat: introduce shortest path integration
1 parent 7057a45 commit 61ae094

2 files changed

Lines changed: 72 additions & 4 deletions

File tree

src/main/java/io/github/mmagicala/gnomeRestaurant/GnomeRestaurantConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,13 @@ default boolean showHintArrow() {
7777
default boolean showWorldMapPoint() {
7878
return true;
7979
}
80+
81+
@ConfigItem(
82+
keyName = GnomeRestaurantPlugin.USE_SHORTEST_PATH,
83+
name = "Use Shortest Path",
84+
description = "Configures whether to use shortest path plugin integration"
85+
)
86+
default boolean useShortestPath() {
87+
return true;
88+
}
8089
}

src/main/java/io/github/mmagicala/gnomeRestaurant/GnomeRestaurantPlugin.java

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import net.runelite.api.Client;
3838
import net.runelite.api.ItemContainer;
3939
import net.runelite.api.NPC;
40+
import net.runelite.api.coords.WorldPoint;
4041
import net.runelite.api.events.ItemContainerChanged;
4142
import net.runelite.api.events.NpcDespawned;
4243
import net.runelite.api.events.NpcSpawned;
@@ -46,8 +47,10 @@
4647
import net.runelite.api.gameval.VarbitID;
4748
import net.runelite.client.callback.ClientThread;
4849
import net.runelite.client.config.ConfigManager;
50+
import net.runelite.client.eventbus.EventBus;
4951
import net.runelite.client.eventbus.Subscribe;
5052
import net.runelite.client.events.ConfigChanged;
53+
import net.runelite.client.events.PluginMessage;
5154
import net.runelite.client.game.ItemManager;
5255
import net.runelite.client.plugins.Plugin;
5356
import net.runelite.client.plugins.PluginDescriptor;
@@ -63,7 +66,9 @@
6366
import javax.inject.Inject;
6467
import java.time.temporal.ChronoUnit;
6568
import java.util.ArrayList;
69+
import java.util.HashMap;
6670
import java.util.List;
71+
import java.util.Map;
6772

6873
@PluginDescriptor(name = "Gnome Restaurant")
6974
public class GnomeRestaurantPlugin extends Plugin {
@@ -91,6 +96,9 @@ public class GnomeRestaurantPlugin extends Plugin {
9196
@Inject
9297
private WorldMapPointManager worldMapPointManager;
9398

99+
@Inject
100+
private EventBus eventBus;
101+
94102
// UI
95103

96104
private Timer timer;
@@ -128,6 +136,7 @@ private void resetPlugin() {
128136
removeOverlay();
129137
removeWorldMapPoint();
130138
client.clearHintArrow();
139+
removeShortestPath();
131140

132141
stepIdx = 0;
133142

@@ -218,6 +227,10 @@ private void setupUI() {
218227
if (config.showWorldMapPoint()) {
219228
showWorldMapPoint();
220229
}
230+
231+
if (config.useShortestPath()) {
232+
showShortestPath();
233+
}
221234
}
222235

223236
private void setupOverlay() {
@@ -287,28 +300,60 @@ private boolean setHintArrowToCustomer() {
287300
return false;
288301
}
289302

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+
290329
@Subscribe
291330
public void onNpcSpawned(final NpcSpawned event) {
292331
var npc = event.getNpc();
293332

294-
if (order == null || !config.showHintArrow()) {
333+
if (order == null || npc.getId() != customer.getNpcTypeId(client)) {
295334
return;
296335
}
297-
if (npc.getId() == customer.getNpcTypeId(client)) {
336+
if (config.showHintArrow()) {
298337
client.setHintArrow(npc);
299338
}
339+
if (config.useShortestPath()) {
340+
setShortestPath(npc.getWorldLocation());
341+
}
300342
}
301343

302344
@Subscribe
303345
public void onNpcDespawned(final NpcDespawned event) {
304346
var npc = event.getNpc();
305347

306-
if (order == null || !config.showHintArrow()) {
348+
if (order == null || npc.getId() != customer.getNpcTypeId(client)) {
307349
return;
308350
}
309-
if (npc.getId() == customer.getNpcTypeId(client)) {
351+
if (config.showHintArrow()) {
310352
client.setHintArrow(customer.getLocation(client));
311353
}
354+
if (config.useShortestPath()) {
355+
setShortestPath(customer.getLocation(client));
356+
}
312357
}
313358

314359
@Subscribe
@@ -377,6 +422,9 @@ public void onItemContainerChanged(ItemContainerChanged event) {
377422
if (updateOrderStep()) {
378423
updateOverlayHeader();
379424
rebuildOverlayTables();
425+
if (config.useShortestPath()) {
426+
showShortestPath();
427+
}
380428
} else {
381429
updateOverlayTables();
382430
}
@@ -436,6 +484,7 @@ GnomeRestaurantConfig provideConfig(ConfigManager configManager) {
436484
public static final String SHOW_OVERLAY = "showOverlay";
437485
public static final String SHOW_HINT_ARROW = "showHintArrow";
438486
public static final String SHOW_WORLD_MAP_POINT = "showWorldMapPoint";
487+
public static final String USE_SHORTEST_PATH = "useShortestPath";
439488

440489
/**
441490
* Monitor changes to plugin config and update the plugin accordingly
@@ -468,6 +517,12 @@ public void onConfigChanged(ConfigChanged event) {
468517
} else {
469518
showWorldMapPoint();
470519
}
520+
} else if (event.getKey().equals(USE_SHORTEST_PATH)) {
521+
if (event.getNewValue().equals("false")) {
522+
removeShortestPath();
523+
} else {
524+
showShortestPath();
525+
}
471526
}
472527
} else {
473528
if (!event.getGroup().equals("gnomerestaurant")) {
@@ -499,6 +554,10 @@ private void removeWorldMapPoint() {
499554
worldMapPoint = null;
500555
}
501556

557+
private void removeShortestPath() {
558+
eventBus.post(new PluginMessage("shortestpath", "clear"));
559+
}
560+
502561
private void clearOverlayTables() {
503562
stepIngredientsOverlayTable.clear();
504563
nextRawIngredientsOverlayTable.clear();

0 commit comments

Comments
 (0)