From 5a2e05bb1283adcb5c30d3a9d8ebfa4003d62490 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Wed, 4 May 2022 11:31:12 +0200 Subject: [PATCH] More debug for waypoints --- .../Indyuce/mmocore/gui/WaypointViewer.java | 19 +++++++++++-------- .../Indyuce/mmocore/waypoint/Waypoint.java | 7 ++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java b/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java index 5bfa25f6..1f68d5ac 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java +++ b/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java @@ -157,7 +157,7 @@ public class WaypointViewer extends EditableInventory { Waypoint waypoint = inv.waypoints.get(inv.page * inv.getByFunction("waypoint").getSlots().size() + n); holders.register("name", waypoint.getName()); if (!onlyName) { - holders.register("current_cost",inv.paths.get(waypoint).getCost()); + holders.register("current_cost", inv.paths.get(waypoint).getCost()); holders.register("normal_cost", decimal.format(inv.paths.containsKey(waypoint) ? inv.paths.get(waypoint).getCost() : Double.POSITIVE_INFINITY)); holders.register("dynamic_cost", decimal.format(waypoint.getDynamicCost())); holders.register("intermediary_waypoints", inv.paths.containsKey(waypoint) ? inv.paths.get(waypoint).displayIntermediaryWayPoints(inv.waypointCostType.equals(CostType.DYNAMIC_USE)) : "none"); @@ -184,17 +184,20 @@ public class WaypointViewer extends EditableInventory { paths.put(pathInfo.getFinalWaypoint(), pathInfo); } if (current == null) { + + //Iterate through all the dynamic points and find all the points it is linked to and the path + HashMap dynamicPoints = new HashMap<>(); //We first check all the dynamic waypoints for (Waypoint waypoint : waypoints) { - if (waypoint.canHaveDynamicUse(playerData.getPlayer())) - paths.put(waypoint,new Waypoint.PathInfo(waypoint, waypoint.getDynamicCost())); + if (waypoint.canHaveDynamicUse(playerData.getPlayer())) { + paths.put(waypoint, new Waypoint.PathInfo(waypoint, waypoint.getDynamicCost())); + dynamicPoints.put(waypoint, waypoint.getDynamicCost()); + } } - //Iterate through all the dynamic points and find all the points it is linked to and the path - HashSet waypointSet = new HashSet<>(paths.keySet()); - for (Waypoint source : waypointSet) { + for(Waypoint source: dynamicPoints.keySet()){ for (Waypoint.PathInfo target : source.getAllPath()) { - if (!paths.containsKey(target.getFinalWaypoint()) || paths.get(target.getFinalWaypoint()).getCost() > target.getCost()) { - paths.put(target.getFinalWaypoint(), target); + if (!paths.containsKey(target.getFinalWaypoint()) || paths.get(target.getFinalWaypoint()).getCost() > target.getCost()+dynamicPoints.get(source)) { + paths.put(target.getFinalWaypoint(), target.addCost(dynamicPoints.get(source))); } } } diff --git a/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java b/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java index 6c6b7074..b19ca467 100644 --- a/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java +++ b/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java @@ -240,7 +240,7 @@ public class Waypoint implements Unlockable { public static class PathInfo { private final ArrayList waypoints; - private final double cost; + private double cost; public ArrayList getWaypoints() { return waypoints; @@ -261,6 +261,11 @@ public class Waypoint implements Unlockable { this.cost = cost; } + public PathInfo addCost(double cost) { + this.cost+=cost; + return this; + } + public ArrayList addInOrder(ArrayList pathInfos) { int index = 0; while (index < pathInfos.size()) {