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()) {