From b92125c039efea56d017559742c792334e78e64d Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 28 Apr 2022 09:18:16 +0200 Subject: [PATCH 1/5] Add files --- .../java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java b/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java index 686b78a3..c33637e8 100644 --- a/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java +++ b/src/main/java/net/Indyuce/mmocore/skill/cast/listener/KeyCombos.java @@ -111,6 +111,7 @@ public class KeyCombos implements Listener { return; } + // Adding pressed key CustomSkillCastingHandler casting = (CustomSkillCastingHandler) playerData.getSkillCasting(); casting.current.registerKey(event.getPressed()); From 41720d90486b07fa655fd1076daacbd840199838 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 28 Apr 2022 13:43:33 +0200 Subject: [PATCH 2/5] Use PersistentDataCContainer instead of NBT, change the system of WayPoints with Djikstra Algorithm --- .../Indyuce/mmocore/gui/WaypointViewer.java | 24 ++- .../Indyuce/mmocore/waypoint/Waypoint.java | 148 +++++++++++++++++- src/main/resources/default/gui/waypoints.yml | 1 + 3 files changed, 164 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 385db1ce..c8f59612 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java +++ b/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java @@ -1,7 +1,5 @@ package net.Indyuce.mmocore.gui; -import io.lumine.mythic.lib.api.item.ItemTag; -import io.lumine.mythic.lib.api.item.NBTItem; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerActivity; import net.Indyuce.mmocore.api.player.PlayerData; @@ -15,13 +13,16 @@ import net.Indyuce.mmocore.waypoint.Waypoint; import net.Indyuce.mmocore.waypoint.WaypointOption; import org.apache.commons.lang.Validate; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; import java.util.ArrayList; import java.util.List; -import java.util.Objects; public class WaypointViewer extends EditableInventory { public WaypointViewer() { @@ -103,13 +104,16 @@ public class WaypointViewer extends EditableInventory { return locked.display(inv, n); // Waypoints are not linked - if (inv.current != null && !inv.current.hasDestination(waypoint)) + if (inv.current != null && inv.current.getPath(waypoint)==null) return notLinked.display(inv, n); // Not dynamic waypoint if (inv.current == null && !waypoint.hasOption(WaypointOption.DYNAMIC)) return notDynamic.display(inv, n); + //Dynamic waypoint + if(waypoint.hasOption(WaypointOption.DYNAMIC)&&inv.current==null) + // Stellium cost if (waypoint.getCost(inv.current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE) > inv.getPlayerData().getStellium()) return noStellium.display(inv, n); @@ -129,7 +133,11 @@ public class WaypointViewer extends EditableInventory { // If a player can teleport to another waypoint given his location Waypoint waypoint = inv.waypoints.get(inv.page * inv.getEditable().getByFunction("waypoint").getSlots().size() + n); - return NBTItem.get(disp).addTag(new ItemTag("waypointId", waypoint.getId())).toItem(); + ItemMeta meta=disp.getItemMeta(); + PersistentDataContainer container=meta.getPersistentDataContainer(); + container.set(new NamespacedKey(MMOCore.plugin,"waypointId"),PersistentDataType.STRING,waypoint.getId()); + disp.setItemMeta(meta); + return disp; } @Override @@ -149,6 +157,7 @@ public class WaypointViewer extends EditableInventory { public class WaypointViewerInventory extends GeneratedInventory { private final List waypoints = new ArrayList<>(MMOCore.plugin.waypointManager.getAll()); private final Waypoint current; + private final ArrayList paths; private final CostType waypointCostType; private int page; @@ -157,6 +166,7 @@ public class WaypointViewer extends EditableInventory { super(playerData, editable); this.current = current; + paths=current!=null? current.getAllPath() : null; this.waypointCostType = current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE; } @@ -180,7 +190,9 @@ public class WaypointViewer extends EditableInventory { } if (item.getFunction().equals("waypoint")) { - String tag = NBTItem.get(event.getCurrentItem()).getString("waypointId"); + PersistentDataContainer container =event.getCurrentItem().getItemMeta().getPersistentDataContainer(); + String tag =container.get(new NamespacedKey(MMOCore.plugin,"wayPointId"), PersistentDataType.STRING); + if (tag.equals("")) return; diff --git a/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java b/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java index f6d609b7..c33058e5 100644 --- a/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java +++ b/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java @@ -1,11 +1,13 @@ package net.Indyuce.mmocore.waypoint; +import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.player.Unlockable; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.craftbukkit.libs.jline.internal.Nullable; import org.bukkit.entity.Player; import java.util.*; @@ -21,7 +23,7 @@ public class Waypoint implements Unlockable { *

* If it's empty it can access any waypoint. */ - private final Set destinations = new HashSet<>(); + private final Map destinations = new HashMap<>(); /** * Waypoint options saved here. @@ -46,7 +48,14 @@ public class Waypoint implements Unlockable { for (WaypointOption option : WaypointOption.values()) options.put(option, config.getBoolean("option." + option.getPath(), option.getDefaultValue())); - destinations.addAll(config.getStringList("linked")); + //We load all the linked WayPoints + ConfigurationSection section=config.getConfigurationSection("linked"); + for(String key: section.getKeys(false)) { + destinations.put(key,config.getInt(key)); + } + + + //destinations.addAll(config.getStringList("linked")); } public String getId() { @@ -61,14 +70,90 @@ public class Waypoint implements Unlockable { return loc; } + /** * @param other Another waypoint * @return If any player standing on that waypoint can teleport to given waypoint */ + @Deprecated public boolean hasDestination(Waypoint other) { - return destinations.isEmpty() || destinations.contains(other.getId()); + return destinations.isEmpty() || destinations.keySet().contains(other.getId()); } + /** + * Checks directly if the waypoint is directly linked to the current one + * + * @return Integer.POSITIVE_INFINITY if the way point is not linked + */ + public int getSimpleCostDestination(Waypoint waypoint) { + if (!destinations.keySet().contains(waypoint.getId())) + return Integer.MAX_VALUE; + return destinations.get(waypoint.getId()); + } + + + public ArrayList getAllPath() { + //All the WayPoints that have been registered + ArrayList checkedPoints = new ArrayList<>(); + //All the path + ArrayList paths = new ArrayList(); + ArrayList pointsToCheck = new ArrayList<>(); + pointsToCheck.add(new PathInfo(this)); + + while (pointsToCheck.size() != 0) { + PathInfo checked = pointsToCheck.get(0); + pointsToCheck.remove(0); + paths.add(checked); + checkedPoints.add(checked.getFinalWaypoint()); + + for (String wayPointId : checked.getFinalWaypoint().destinations.keySet()) { + Waypoint toCheck = MMOCore.plugin.waypointManager.get(wayPointId); + if (!checkedPoints.contains(toCheck)) { + PathInfo toCheckInfo = checked.addWayPoint(toCheck); + //We keep pointsToCheck ordered + pointsToCheck = toCheckInfo.addInOrder(pointsToCheck); + } + } + } + return paths; + + } + + + @Nullable + public PathInfo getPath(Waypoint targetWaypoint) { + //All the WayPoints that have been registered + ArrayList checkedPoints = new ArrayList<>(); + //All the path + ArrayList paths = new ArrayList(); + ArrayList pointsToCheck = new ArrayList<>(); + pointsToCheck.add(new PathInfo(this)); + + while (pointsToCheck.size() != 0) { + PathInfo checked = pointsToCheck.get(0); + pointsToCheck.remove(0); + paths.add(checked); + checkedPoints.add(checked.getFinalWaypoint()); + + if(checked.getFinalWaypoint().equals(targetWaypoint)) + return checked; + + for (String wayPointId : checked.getFinalWaypoint().destinations.keySet()) { + Waypoint toCheck = MMOCore.plugin.waypointManager.get(wayPointId); + if (!checkedPoints.contains(toCheck)) { + PathInfo toCheckInfo = checked.addWayPoint(toCheck); + //We keep pointsToCheck ordered + pointsToCheck = toCheckInfo.addInOrder(pointsToCheck); + } + } + } + + //If no path has been found we return null + return null; + + } + + public double getCost(CostType type) { return costs.getOrDefault(type, 0d); } @@ -118,4 +203,61 @@ public class Waypoint implements Unlockable { return new Location(world, x, y, z, yaw, pitch); } + + public class PathInfo { + private final ArrayList waypoints; + private final int cost; + + public ArrayList getWaypoints() { + return waypoints; + } + + public int getCost() { + return cost; + } + + public PathInfo(Waypoint waypoint) { + this.waypoints = (ArrayList) Arrays.asList(waypoint); + cost = 0; + } + + + public ArrayList addInOrder(ArrayList pathInfos) { + int index = 0; + while (index < pathInfos.size()) { + if (cost < pathInfos.get(index).cost) { + pathInfos.set(index, this); + return pathInfos; + } + } + //If index==pathInfos.size() we add the waypoint at the end + pathInfos.add(this); + return pathInfos; + } + + + + public PathInfo(ArrayList waypoints, int cost) { + this.waypoints = waypoints; + this.cost = cost; + } + + public PathInfo addWayPoint(Waypoint waypoint) { + Validate.isTrue(!waypoints.contains(waypoint), "You can't create cyclic path"); + ArrayList newWaypoints = new ArrayList<>(); + newWaypoints.addAll(waypoints); + newWaypoints.add(waypoint); + int cost=this.cost+getFinalWaypoint().getSimpleCostDestination(waypoint); + return new PathInfo(newWaypoints,cost); + } + + + public Waypoint getInitialWaypoint() { + return waypoints.get(0); + } + + public Waypoint getFinalWaypoint() { + return waypoints.get(waypoints.size() - 1); + } + } } \ No newline at end of file diff --git a/src/main/resources/default/gui/waypoints.yml b/src/main/resources/default/gui/waypoints.yml index 074e6aca..10bf393d 100644 --- a/src/main/resources/default/gui/waypoints.yml +++ b/src/main/resources/default/gui/waypoints.yml @@ -61,6 +61,7 @@ items: lore: - '&7You can teleport to this waypoint.' + - '&7 Intermediary waypoints : {intermediary_waypoints}' - '&7Click to teleport for &b{current_cost} &7Stellium.' next: From c8096765b4401afd25b3927bceb01fa86ceb360c Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 28 Apr 2022 14:34:42 +0200 Subject: [PATCH 3/5] Changes in PlayerData for warp fonction and in WayPointViewer / gui/waypoints.yml --- .../mmocore/api/player/PlayerData.java | 12 ++-- .../Indyuce/mmocore/gui/WaypointViewer.java | 59 ++++++++++++------- .../Indyuce/mmocore/waypoint/Waypoint.java | 43 ++++++++++---- src/main/resources/default/gui/waypoints.yml | 6 +- 4 files changed, 78 insertions(+), 42 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 0fae0302..dc9b8359 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -457,9 +457,9 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc * Teleports the player to a specific waypoint. This applies * the stellium waypoint cost and plays the teleport animation. * - * @param waypoint Target waypoint + * @param target Target waypoint */ - public void warp(Waypoint waypoint, CostType costType) { + public void warp(Waypoint source, Waypoint target, CostType costType) { /* * This cooldown is only used internally to make sure the player is not @@ -467,8 +467,10 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc * player waypoints data */ setLastActivity(PlayerActivity.USE_WAYPOINT); + Validate.isTrue(source!=null||costType!=CostType.NORMAL_USE,"You must precise a source to use normal waypoint" ); + final double cost = costType == CostType.DYNAMIC_USE ? target.getDynamicCost() : source.getCost(target); + - final double cost = waypoint.getCost(costType); giveStellium(-cost, PlayerResourceUpdateEvent.UpdateReason.USE_WAYPOINT); new BukkitRunnable() { @@ -491,7 +493,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc MMOCore.plugin.configManager.getSimpleMessage("warping-comencing", "left", "" + ((120 - t) / 20)).send(getPlayer()); if (t++ >= 100) { - getPlayer().teleport(waypoint.getLocation()); + getPlayer().teleport(target.getLocation()); getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1, false, false)); MMOCore.plugin.soundManager.getSound(SoundEvent.WARP_TELEPORT).playTo(getPlayer()); cancel(); @@ -869,7 +871,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc * checks if they could potentially upgrade to one of these * * @return If the player can change its current class to - * a subclass + * a subclass */ public boolean canChooseSubclass() { for (Subclass subclass : getProfess().getSubclasses()) diff --git a/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java b/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java index c8f59612..f913b127 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java +++ b/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java @@ -22,7 +22,9 @@ import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class WaypointViewer extends EditableInventory { public WaypointViewer() { @@ -65,8 +67,8 @@ public class WaypointViewer extends EditableInventory { } public class WaypointItem extends SimplePlaceholderItem { - private final SimplePlaceholderItem noWaypoint, locked; - private final WaypointItemHandler availWaypoint, notLinked, notDynamic, noStellium; + private final SimplePlaceholderItem noWaypoint, locked,notLinked,notDynamic; + private final WaypointItemHandler availWaypoint,noStellium; public WaypointItem(ConfigurationSection config) { super(Material.BARRIER, config); @@ -80,8 +82,8 @@ public class WaypointViewer extends EditableInventory { noWaypoint = new SimplePlaceholderItem(config.getConfigurationSection("no-waypoint")); locked = new SimplePlaceholderItem(config.getConfigurationSection("locked")); - notLinked = new WaypointItemHandler(config.getConfigurationSection("not-a-destination")); - notDynamic = new WaypointItemHandler(config.getConfigurationSection("not-dynamic")); + notLinked = new SimplePlaceholderItem(config.getConfigurationSection("not-a-destination")); + notDynamic = new SimplePlaceholderItem(config.getConfigurationSection("not-dynamic")); noStellium = new WaypointItemHandler(config.getConfigurationSection("not-enough-stellium")); availWaypoint = new WaypointItemHandler(config.getConfigurationSection("display")); } @@ -104,20 +106,23 @@ public class WaypointViewer extends EditableInventory { return locked.display(inv, n); // Waypoints are not linked - if (inv.current != null && inv.current.getPath(waypoint)==null) + if (inv.current != null && !inv.paths.containsKey(waypoint)) return notLinked.display(inv, n); // Not dynamic waypoint if (inv.current == null && !waypoint.hasOption(WaypointOption.DYNAMIC)) return notDynamic.display(inv, n); - //Dynamic waypoint - if(waypoint.hasOption(WaypointOption.DYNAMIC)&&inv.current==null) - // Stellium cost - if (waypoint.getCost(inv.current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE) > inv.getPlayerData().getStellium()) + //Dynamic waypoint + if (waypoint.hasOption(WaypointOption.DYNAMIC) && inv.current == null && waypoint.getDynamicCost() > inv.getPlayerData().getStellium()) return noStellium.display(inv, n); + //Normal cost + if (inv.current != null && inv.paths.get(waypoint).getCost() > inv.getPlayerData().getStellium()) + return noStellium.display(inv, n); + + return availWaypoint.display(inv, n); } } @@ -133,9 +138,9 @@ public class WaypointViewer extends EditableInventory { // If a player can teleport to another waypoint given his location Waypoint waypoint = inv.waypoints.get(inv.page * inv.getEditable().getByFunction("waypoint").getSlots().size() + n); - ItemMeta meta=disp.getItemMeta(); - PersistentDataContainer container=meta.getPersistentDataContainer(); - container.set(new NamespacedKey(MMOCore.plugin,"waypointId"),PersistentDataType.STRING,waypoint.getId()); + ItemMeta meta = disp.getItemMeta(); + PersistentDataContainer container = meta.getPersistentDataContainer(); + container.set(new NamespacedKey(MMOCore.plugin, "waypointId"), PersistentDataType.STRING, waypoint.getId()); disp.setItemMeta(meta); return disp; } @@ -146,9 +151,10 @@ public class WaypointViewer extends EditableInventory { Waypoint waypoint = inv.waypoints.get(inv.page * inv.getByFunction("waypoint").getSlots().size() + n); holders.register("name", waypoint.getName()); - holders.register("current_cost", decimal.format(waypoint.getCost(inv.waypointCostType))); - holders.register("normal_cost", decimal.format(waypoint.getCost(CostType.NORMAL_USE))); - holders.register("dynamic_cost", decimal.format(waypoint.getCost(CostType.DYNAMIC_USE))); + holders.register("current_cost", decimal.format(inv.waypointCostType.equals(CostType.DYNAMIC_USE) ? waypoint.getDynamicCost() : inv.paths.get(waypoint).getCost())); + holders.register("normal_cost", decimal.format(inv.paths.get(waypoint).getCost())); + holders.register("dynamic_cost", decimal.format(waypoint.getDynamicCost())); + holders.register("intermediary_waypoints", inv.paths.get(waypoint).displayIntermediaryWayPoints()); return holders; } @@ -157,7 +163,7 @@ public class WaypointViewer extends EditableInventory { public class WaypointViewerInventory extends GeneratedInventory { private final List waypoints = new ArrayList<>(MMOCore.plugin.waypointManager.getAll()); private final Waypoint current; - private final ArrayList paths; + private final Map paths = new HashMap<>(); private final CostType waypointCostType; private int page; @@ -166,7 +172,11 @@ public class WaypointViewer extends EditableInventory { super(playerData, editable); this.current = current; - paths=current!=null? current.getAllPath() : null; + if (current != null) { + for (Waypoint.PathInfo pathInfo : current.getAllPath()) + paths.put(pathInfo.getFinalWaypoint(), pathInfo); + } + this.waypointCostType = current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE; } @@ -190,8 +200,8 @@ public class WaypointViewer extends EditableInventory { } if (item.getFunction().equals("waypoint")) { - PersistentDataContainer container =event.getCurrentItem().getItemMeta().getPersistentDataContainer(); - String tag =container.get(new NamespacedKey(MMOCore.plugin,"wayPointId"), PersistentDataType.STRING); + PersistentDataContainer container = event.getCurrentItem().getItemMeta().getPersistentDataContainer(); + String tag = container.get(new NamespacedKey(MMOCore.plugin, "wayPointId"), PersistentDataType.STRING); if (tag.equals("")) return; @@ -210,7 +220,7 @@ public class WaypointViewer extends EditableInventory { } // Waypoint does not have target as destination - if (current != null && !current.hasDestination(waypoint)) { + if (current != null && current.getPath(waypoint)==null) { MMOCore.plugin.configManager.getSimpleMessage("cannot-teleport-to").send(player); return; } @@ -223,7 +233,8 @@ public class WaypointViewer extends EditableInventory { // Stellium cost CostType costType = current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE; - double left = waypoint.getCost(costType) - playerData.getStellium(); + double withdraw = current == null ? waypoint.getDynamicCost() : paths.get(waypoint).getCost(); + double left = withdraw - playerData.getStellium(); if (left > 0) { MMOCore.plugin.configManager.getSimpleMessage("not-enough-stellium", "more", decimal.format(left)).send(player); return; @@ -233,7 +244,11 @@ public class WaypointViewer extends EditableInventory { return; player.closeInventory(); - playerData.warp(waypoint, costType); + if (current == null) + playerData.warp(null, waypoint, costType); + else + playerData.warp(current, waypoint, costType); + } } } diff --git a/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java b/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java index c33058e5..da7696f5 100644 --- a/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java +++ b/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java @@ -33,8 +33,21 @@ public class Waypoint implements Unlockable { /** * Stellium cost for each action (0 being the default cost) */ + private final double dynamicCost,setSpawnCost; private final Map costs = new HashMap<>(); + public double getDynamicCost() { + return dynamicCost; + } + + public double getSetSpawnCost() { + return setSpawnCost; + } + + public double getCost(Waypoint waypoint) { + return getPath(waypoint).cost; + } + public Waypoint(ConfigurationSection config) { id = Objects.requireNonNull(config, "Could not load config section").getName(); name = Objects.requireNonNull(config.getString("name"), "Could not load waypoint name"); @@ -42,8 +55,9 @@ public class Waypoint implements Unlockable { loc = readLocation(Objects.requireNonNull(config.getString("location"), "Could not read location")); radiusSquared = Math.pow(config.getDouble("radius"), 2); - for (CostType costType : CostType.values()) - costs.put(costType, config.getDouble("cost." + costType.getPath())); + dynamicCost=config.getDouble("cost.dynamic-use"); + setSpawnCost=config.getDouble("cost.set-spawnpoint"); + for (WaypointOption option : WaypointOption.values()) options.put(option, config.getBoolean("option." + option.getPath(), option.getDefaultValue())); @@ -85,7 +99,7 @@ public class Waypoint implements Unlockable { * * @return Integer.POSITIVE_INFINITY if the way point is not linked */ - public int getSimpleCostDestination(Waypoint waypoint) { + private int getSimpleCostDestination(Waypoint waypoint) { if (!destinations.keySet().contains(waypoint.getId())) return Integer.MAX_VALUE; return destinations.get(waypoint.getId()); @@ -153,11 +167,6 @@ public class Waypoint implements Unlockable { } - - public double getCost(CostType type) { - return costs.getOrDefault(type, 0d); - } - public boolean hasOption(WaypointOption option) { return options.get(option); } @@ -206,13 +215,13 @@ public class Waypoint implements Unlockable { public class PathInfo { private final ArrayList waypoints; - private final int cost; + private final double cost; public ArrayList getWaypoints() { return waypoints; } - public int getCost() { + public double getCost() { return cost; } @@ -237,17 +246,27 @@ public class Waypoint implements Unlockable { - public PathInfo(ArrayList waypoints, int cost) { + public PathInfo(ArrayList waypoints, double cost) { this.waypoints = waypoints; this.cost = cost; } + public String displayIntermediaryWayPoints() { + if(waypoints.size()<=2) + return ""; + String result=""; + for(int i=1;i newWaypoints = new ArrayList<>(); newWaypoints.addAll(waypoints); newWaypoints.add(waypoint); - int cost=this.cost+getFinalWaypoint().getSimpleCostDestination(waypoint); + double cost=this.cost+getFinalWaypoint().getSimpleCostDestination(waypoint); return new PathInfo(newWaypoints,cost); } diff --git a/src/main/resources/default/gui/waypoints.yml b/src/main/resources/default/gui/waypoints.yml index 10bf393d..aa696e33 100644 --- a/src/main/resources/default/gui/waypoints.yml +++ b/src/main/resources/default/gui/waypoints.yml @@ -34,7 +34,7 @@ items: lore: - '&7You cannot teleport as the two waypoints are not linked.' - - '&7Teleporting costs &b&l{normal_cost}&7/&b&l{dynamic_cost} &7Stellium.' + # When you cannot teleport to a non dynamic waypoint not-dynamic: @@ -43,9 +43,9 @@ items: lore: - '&7You cannot teleport as you are not standing on a waypoint.' - - '&7Teleporting costs &b&l{normal_cost}&7/&b&l{dynamic_cost} &7Stellium.' - # When you cannot teleport to a non dynamic waypoint + + # When you don't have enough stellium not-enough-stellium: name: '&a{name}' item: ENDER_PEARL From e41749135e15c7cfd3836b50c85ecb71e643743c Mon Sep 17 00:00:00 2001 From: Guillaume Date: Wed, 4 May 2022 11:22:00 +0200 Subject: [PATCH 4/5] Debug waypoints Added Luck and did changes on roolChestTier for LootChest Added possibility to have conditions on dynamic waypoints Added intermediary waypoints even when using dynamic waypoints. --- .../mmocore/api/load/DefaultMMOLoader.java | 9 +- .../mmocore/api/player/PlayerData.java | 6 +- .../mmocore/api/player/stats/StatType.java | 1 + .../Indyuce/mmocore/gui/WaypointViewer.java | 82 +++++++++++------ .../mmocore/loot/chest/LootChestRegion.java | 21 +++-- .../condition/DistanceCondition.java | 39 ++++++++ .../Indyuce/mmocore/waypoint/Waypoint.java | 91 ++++++++++++++----- src/main/resources/default/gui/waypoints.yml | 9 +- .../resources/default/professions/fishing.yml | 2 +- src/main/resources/default/stats.yml | 5 + src/main/resources/default/waypoints.yml | 21 +++-- 11 files changed, 209 insertions(+), 77 deletions(-) create mode 100644 src/main/java/net/Indyuce/mmocore/loot/droptable/condition/DistanceCondition.java diff --git a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java index 7b8857b7..074b123d 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java @@ -1,16 +1,12 @@ package net.Indyuce.mmocore.api.load; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; +import net.Indyuce.mmocore.loot.droptable.condition.*; import org.bukkit.configuration.ConfigurationSection; import net.Indyuce.mmocore.api.block.BlockType; import net.Indyuce.mmocore.api.block.SkullBlockType; import net.Indyuce.mmocore.api.block.VanillaBlockType; -import net.Indyuce.mmocore.loot.droptable.condition.BiomeCondition; -import net.Indyuce.mmocore.loot.droptable.condition.Condition; -import net.Indyuce.mmocore.loot.droptable.condition.LevelCondition; -import net.Indyuce.mmocore.loot.droptable.condition.PermissionCondition; -import net.Indyuce.mmocore.loot.droptable.condition.WorldCondition; import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem; import net.Indyuce.mmocore.loot.droptable.dropitem.DropTableDropItem; import net.Indyuce.mmocore.loot.droptable.dropitem.GoldDropItem; @@ -109,6 +105,9 @@ public class DefaultMMOLoader extends MMOLoader { @Override public Condition loadCondition(MMOLineConfig config) { + if(config.getKey().equals("distance")) + return new DistanceCondition(config); + if (config.getKey().equals("world")) return new WorldCondition(config); diff --git a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index dc9b8359..75c9d6bc 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -459,7 +459,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc * * @param target Target waypoint */ - public void warp(Waypoint source, Waypoint target, CostType costType) { + public void warp(Waypoint target, double cost) { /* * This cooldown is only used internally to make sure the player is not @@ -467,10 +467,6 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc * player waypoints data */ setLastActivity(PlayerActivity.USE_WAYPOINT); - Validate.isTrue(source!=null||costType!=CostType.NORMAL_USE,"You must precise a source to use normal waypoint" ); - final double cost = costType == CostType.DYNAMIC_USE ? target.getDynamicCost() : source.getCost(target); - - giveStellium(-cost, PlayerResourceUpdateEvent.UpdateReason.USE_WAYPOINT); new BukkitRunnable() { diff --git a/src/main/java/net/Indyuce/mmocore/api/player/stats/StatType.java b/src/main/java/net/Indyuce/mmocore/api/player/stats/StatType.java index cfc69000..9f66f9bf 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/stats/StatType.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/stats/StatType.java @@ -61,6 +61,7 @@ public enum StatType { // Utility ADDITIONAL_EXPERIENCE, COOLDOWN_REDUCTION, + CHANCE, // Damage-type based stats MAGIC_DAMAGE, diff --git a/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java b/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java index f913b127..5bfa25f6 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java +++ b/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java @@ -12,6 +12,7 @@ import net.Indyuce.mmocore.waypoint.CostType; import net.Indyuce.mmocore.waypoint.Waypoint; import net.Indyuce.mmocore.waypoint.WaypointOption; import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.configuration.ConfigurationSection; @@ -21,10 +22,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class WaypointViewer extends EditableInventory { public WaypointViewer() { @@ -67,8 +65,9 @@ public class WaypointViewer extends EditableInventory { } public class WaypointItem extends SimplePlaceholderItem { - private final SimplePlaceholderItem noWaypoint, locked,notLinked,notDynamic; - private final WaypointItemHandler availWaypoint,noStellium; + private final SimplePlaceholderItem noWaypoint, locked; + private final WaypointItemHandler availWaypoint, noStellium, notLinked, notDynamic, currentWayPoint; + public WaypointItem(ConfigurationSection config) { super(Material.BARRIER, config); @@ -77,15 +76,18 @@ public class WaypointViewer extends EditableInventory { Validate.notNull(config.getConfigurationSection("locked"), "Could not load 'locked' config"); Validate.notNull(config.getConfigurationSection("not-a-destination"), "Could not load 'not-a-destination' config"); Validate.notNull(config.getConfigurationSection("not-dynamic"), "Could not load 'not-dynamic' config"); + Validate.notNull(config.getConfigurationSection("current-waypoint"), "Could not load 'current-waypoint' config"); Validate.notNull(config.getConfigurationSection("not-enough-stellium"), "Could not load 'not-enough-stellium' config"); Validate.notNull(config.getConfigurationSection("display"), "Could not load 'display' config"); + noWaypoint = new SimplePlaceholderItem(config.getConfigurationSection("no-waypoint")); locked = new SimplePlaceholderItem(config.getConfigurationSection("locked")); - notLinked = new SimplePlaceholderItem(config.getConfigurationSection("not-a-destination")); - notDynamic = new SimplePlaceholderItem(config.getConfigurationSection("not-dynamic")); - noStellium = new WaypointItemHandler(config.getConfigurationSection("not-enough-stellium")); - availWaypoint = new WaypointItemHandler(config.getConfigurationSection("display")); + notLinked = new WaypointItemHandler(config.getConfigurationSection("not-a-destination"), true); + notDynamic = new WaypointItemHandler(config.getConfigurationSection("not-dynamic"), true); + currentWayPoint = new WaypointItemHandler(config.getConfigurationSection("current-waypoint"), true); + noStellium = new WaypointItemHandler(config.getConfigurationSection("not-enough-stellium"), false); + availWaypoint = new WaypointItemHandler(config.getConfigurationSection("display"), false); } @Override @@ -102,6 +104,10 @@ public class WaypointViewer extends EditableInventory { // Locked waypoint? Waypoint waypoint = inv.waypoints.get(index); + if (inv.current != null && inv.current.equals(waypoint)) + return currentWayPoint.display(inv, n); + + if (!inv.getPlayerData().hasWaypoint(waypoint)) return locked.display(inv, n); @@ -109,17 +115,13 @@ public class WaypointViewer extends EditableInventory { if (inv.current != null && !inv.paths.containsKey(waypoint)) return notLinked.display(inv, n); + // Not dynamic waypoint - if (inv.current == null && !waypoint.hasOption(WaypointOption.DYNAMIC)) + if (inv.current == null && !inv.paths.containsKey(waypoint)) return notDynamic.display(inv, n); - - //Dynamic waypoint - if (waypoint.hasOption(WaypointOption.DYNAMIC) && inv.current == null && waypoint.getDynamicCost() > inv.getPlayerData().getStellium()) - return noStellium.display(inv, n); - //Normal cost - if (inv.current != null && inv.paths.get(waypoint).getCost() > inv.getPlayerData().getStellium()) + if (inv.paths.get(waypoint).getCost() > inv.getPlayerData().getStellium()) return noStellium.display(inv, n); @@ -128,8 +130,11 @@ public class WaypointViewer extends EditableInventory { } public class WaypointItemHandler extends InventoryItem { - public WaypointItemHandler(ConfigurationSection config) { + private final boolean onlyName; + + public WaypointItemHandler(ConfigurationSection config, boolean onlyName) { super(config); + this.onlyName = onlyName; } @Override @@ -151,10 +156,12 @@ public class WaypointViewer extends EditableInventory { Waypoint waypoint = inv.waypoints.get(inv.page * inv.getByFunction("waypoint").getSlots().size() + n); holders.register("name", waypoint.getName()); - holders.register("current_cost", decimal.format(inv.waypointCostType.equals(CostType.DYNAMIC_USE) ? waypoint.getDynamicCost() : inv.paths.get(waypoint).getCost())); - holders.register("normal_cost", decimal.format(inv.paths.get(waypoint).getCost())); - holders.register("dynamic_cost", decimal.format(waypoint.getDynamicCost())); - holders.register("intermediary_waypoints", inv.paths.get(waypoint).displayIntermediaryWayPoints()); + if (!onlyName) { + 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"); + } return holders; } @@ -176,6 +183,23 @@ public class WaypointViewer extends EditableInventory { for (Waypoint.PathInfo pathInfo : current.getAllPath()) paths.put(pathInfo.getFinalWaypoint(), pathInfo); } + if (current == null) { + //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())); + } + //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.PathInfo target : source.getAllPath()) { + if (!paths.containsKey(target.getFinalWaypoint()) || paths.get(target.getFinalWaypoint()).getCost() > target.getCost()) { + paths.put(target.getFinalWaypoint(), target); + } + } + } + + } this.waypointCostType = current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE; } @@ -201,7 +225,8 @@ public class WaypointViewer extends EditableInventory { if (item.getFunction().equals("waypoint")) { PersistentDataContainer container = event.getCurrentItem().getItemMeta().getPersistentDataContainer(); - String tag = container.get(new NamespacedKey(MMOCore.plugin, "wayPointId"), PersistentDataType.STRING); + String tag = container.has(new NamespacedKey(MMOCore.plugin, "waypointId"), PersistentDataType.STRING) ? + container.get(new NamespacedKey(MMOCore.plugin, "waypointId"), PersistentDataType.STRING) : ""; if (tag.equals("")) return; @@ -220,20 +245,20 @@ public class WaypointViewer extends EditableInventory { } // Waypoint does not have target as destination - if (current != null && current.getPath(waypoint)==null) { + if (current != null && current.getPath(waypoint) == null) { MMOCore.plugin.configManager.getSimpleMessage("cannot-teleport-to").send(player); return; } // Not dynamic waypoint - if (current == null && !waypoint.hasOption(WaypointOption.DYNAMIC)) { + if (current == null && !paths.containsKey(waypoint)) { MMOCore.plugin.configManager.getSimpleMessage("not-dynamic-waypoint").send(player); return; } // Stellium cost CostType costType = current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE; - double withdraw = current == null ? waypoint.getDynamicCost() : paths.get(waypoint).getCost(); + double withdraw = paths.get(waypoint).getCost(); double left = withdraw - playerData.getStellium(); if (left > 0) { MMOCore.plugin.configManager.getSimpleMessage("not-enough-stellium", "more", decimal.format(left)).send(player); @@ -244,10 +269,7 @@ public class WaypointViewer extends EditableInventory { return; player.closeInventory(); - if (current == null) - playerData.warp(null, waypoint, costType); - else - playerData.warp(current, waypoint, costType); + playerData.warp(waypoint, withdraw); } } diff --git a/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java b/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java index ef7e8217..6e265a3b 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java +++ b/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java @@ -4,6 +4,7 @@ import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.event.LootChestSpawnEvent; import net.Indyuce.mmocore.api.player.PlayerActivity; import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.player.stats.StatType; import net.Indyuce.mmocore.loot.LootBuilder; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; @@ -85,7 +86,7 @@ public class LootChestRegion { player.setLastActivity(PlayerActivity.LOOT_CHEST_SPAWN); // First randomly determine the chest tier - ChestTier tier = rollTier(); + ChestTier tier = rollTier(player); // Find a random location, 20 trials max Location location = getRandomLocation(player.getPlayer().getLocation()); @@ -116,14 +117,22 @@ public class LootChestRegion { MMOCore.plugin.lootChests.register(lootChest); } - // TODO stat to increase chance to get higher tiers? - public ChestTier rollTier() { + public ChestTier rollTier(PlayerData player) { + double chance = player.getStats().getStat(StatType.CHANCE); - double s = 0; + //chance=0 ->the tier.chance remains the same + //chance ->+inf -> the tier.chance becomes the same for everyone, uniform law + //chance=8-> tierChance=sqrt(tierChance) + double sum = 0; for (ChestTier tier : tiers) { - if (random.nextDouble() < tier.chance / (1 - s)) + sum += Math.pow(tier.chance, 1 / Math.pow((1 + chance),1/3)); + } + + double s=0; + for (ChestTier tier : tiers) { + s+=Math.pow(tier.chance, 1 / Math.pow((1 + chance),1/3))/sum; + if (random.nextDouble() < s) return tier; - s += tier.chance; } return tiers.stream().findAny().orElse(null); diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/DistanceCondition.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/DistanceCondition.java new file mode 100644 index 00000000..486ce977 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/DistanceCondition.java @@ -0,0 +1,39 @@ +package net.Indyuce.mmocore.loot.droptable.condition; + +import io.lumine.mythic.lib.api.MMOLineConfig; +import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.generator.WorldInfo; + + +import java.util.stream.Collectors; + +public class DistanceCondition extends Condition{ + private final Location location; + private final double distance; + + public DistanceCondition(MMOLineConfig config) { + super(config); + Validate.isTrue(config.contains("world")); + Validate.isTrue(config.contains("x")); + Validate.isTrue(config.contains("y")); + Validate.isTrue(config.contains("z")); + Validate.isTrue(config.contains("distance")); + Validate.isTrue(Bukkit.getWorld(config.getString("world"))!=null,"This world doesn't exist"); + location=new Location(Bukkit.getWorld(config.getString("world")),config.getDouble("x"), + config.getDouble("y"),config.getDouble("z")); + distance=config.getDouble("distance"); + } + + @Override + public boolean isMet(ConditionInstance entity) { + Entity entity1=entity.getEntity(); + return entity1.getWorld().equals(location.getWorld())&&location.distance(entity1.getLocation()) dynamicUseConditions = new ArrayList<>(); + private final Map costs = new HashMap<>(); public double getDynamicCost() { @@ -55,21 +62,39 @@ public class Waypoint implements Unlockable { loc = readLocation(Objects.requireNonNull(config.getString("location"), "Could not read location")); radiusSquared = Math.pow(config.getDouble("radius"), 2); - dynamicCost=config.getDouble("cost.dynamic-use"); - setSpawnCost=config.getDouble("cost.set-spawnpoint"); + dynamicCost = config.getDouble("cost.dynamic-use"); + setSpawnCost = config.getDouble("cost.set-spawnpoint"); for (WaypointOption option : WaypointOption.values()) options.put(option, config.getBoolean("option." + option.getPath(), option.getDefaultValue())); //We load all the linked WayPoints - ConfigurationSection section=config.getConfigurationSection("linked"); - for(String key: section.getKeys(false)) { - destinations.put(key,config.getInt(key)); + if (config.contains("linked")) { + ConfigurationSection section = config.getConfigurationSection("linked"); + for (String key : section.getKeys(false)) { + destinations.put(key, section.getInt(key)); + } } + if (config.contains("conditions")) { + List conditions = config.getStringList("conditions"); + for (String condition : conditions) { + dynamicUseConditions.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(condition))); + } - //destinations.addAll(config.getStringList("linked")); + } + } + + public boolean canHaveDynamicUse(Player player) { + if (!options.get(WaypointOption.DYNAMIC)) + return false; + + for (Condition condition : dynamicUseConditions) { + if (!condition.isMet(new ConditionInstance(player))) + return false; + } + return true; } public String getId() { @@ -149,7 +174,7 @@ public class Waypoint implements Unlockable { paths.add(checked); checkedPoints.add(checked.getFinalWaypoint()); - if(checked.getFinalWaypoint().equals(targetWaypoint)) + if (checked.getFinalWaypoint().equals(targetWaypoint)) return checked; for (String wayPointId : checked.getFinalWaypoint().destinations.keySet()) { @@ -213,7 +238,7 @@ public class Waypoint implements Unlockable { return new Location(world, x, y, z, yaw, pitch); } - public class PathInfo { + public static class PathInfo { private final ArrayList waypoints; private final double cost; @@ -226,10 +251,15 @@ public class Waypoint implements Unlockable { } public PathInfo(Waypoint waypoint) { - this.waypoints = (ArrayList) Arrays.asList(waypoint); + this.waypoints = new ArrayList<>(); + this.waypoints.add(waypoint); cost = 0; } - + public PathInfo(Waypoint waypoint,double cost) { + this.waypoints = new ArrayList<>(); + this.waypoints.add(waypoint); + this.cost = cost; + } public ArrayList addInOrder(ArrayList pathInfos) { int index = 0; @@ -238,6 +268,7 @@ public class Waypoint implements Unlockable { pathInfos.set(index, this); return pathInfos; } + index++; } //If index==pathInfos.size() we add the waypoint at the end pathInfos.add(this); @@ -245,29 +276,43 @@ public class Waypoint implements Unlockable { } - - public PathInfo(ArrayList waypoints, double cost) { - this.waypoints = waypoints; + public PathInfo(List waypoints, double cost) { + this.waypoints = new ArrayList<>(waypoints); this.cost = cost; } - public String displayIntermediaryWayPoints() { - if(waypoints.size()<=2) - return ""; - String result=""; - for(int i=1;i newWaypoints = new ArrayList<>(); newWaypoints.addAll(waypoints); newWaypoints.add(waypoint); - double cost=this.cost+getFinalWaypoint().getSimpleCostDestination(waypoint); - return new PathInfo(newWaypoints,cost); + double cost = this.cost + getFinalWaypoint().getSimpleCostDestination(waypoint); + return new PathInfo(newWaypoints, cost); } diff --git a/src/main/resources/default/gui/waypoints.yml b/src/main/resources/default/gui/waypoints.yml index aa696e33..ff58f2c2 100644 --- a/src/main/resources/default/gui/waypoints.yml +++ b/src/main/resources/default/gui/waypoints.yml @@ -45,6 +45,13 @@ items: - '&7You cannot teleport as you are not standing on a waypoint.' + current-waypoint: + name: '&a{name}' + item: ENDER_PEARL + + lore: + - '&7The waypoint you are standing at.' + # When you don't have enough stellium not-enough-stellium: name: '&a{name}' @@ -61,7 +68,7 @@ items: lore: - '&7You can teleport to this waypoint.' - - '&7 Intermediary waypoints : {intermediary_waypoints}' + - '&7Intermediary waypoints : {intermediary_waypoints}' - '&7Click to teleport for &b{current_cost} &7Stellium.' next: diff --git a/src/main/resources/default/professions/fishing.yml b/src/main/resources/default/professions/fishing.yml index c26e6a6a..ed2b9985 100644 --- a/src/main/resources/default/professions/fishing.yml +++ b/src/main/resources/default/professions/fishing.yml @@ -22,7 +22,7 @@ exp-sources: {} on-fish: overriding-drop-table: conditions: - - 'region{name=swamp}' + - 'biome{name=swamp}' # When drop table is read, one of these # items will be selected randomly. diff --git a/src/main/resources/default/stats.yml b/src/main/resources/default/stats.yml index 1c9ef218..21fdee82 100644 --- a/src/main/resources/default/stats.yml +++ b/src/main/resources/default/stats.yml @@ -58,6 +58,11 @@ default: COOLDOWN_REDUCTION: base: 0 per-level: 0 + + #Increases chance to have rare loot chests + CHANCE: + base: 0 + per-level: 0 # Dealt by skills SKILL_DAMAGE: diff --git a/src/main/resources/default/waypoints.yml b/src/main/resources/default/waypoints.yml index 59999359..1de64a36 100644 --- a/src/main/resources/default/waypoints.yml +++ b/src/main/resources/default/waypoints.yml @@ -17,8 +17,6 @@ spawn: # Stellium cost in order to use the waypoint. # Stellium is like stamina however it's not used # by skills and regens much slower than mana. - normal-use: 3 - # Cost when not standing on any waypoint. dynamic-use: 5 @@ -42,12 +40,12 @@ spawn: default: true # All the waypoints you can teleport to when standing - # on that waypoint. If that list is empty you are able + # on that waypoint. And the cost needed to travel to his pointIf that list is empty you are able # to teleport to any waypoint linked: - - spawn1 - - spawn2 - - forest + spawn1: 4 + spawn2: 5 + spawn1: name: Spawn1 @@ -62,6 +60,15 @@ spawn1: # on any waypoint (waypoint must be unlocked). dynamic: true + ##Not necessary if the waypoint doesn't allow dynamic use + ##The conditions for the dynamic-use of the waypoint + conditions: + - 'distance{world=world;x=69;y=71;z=163;distance=500}' + + + linked: + spawn: 4 + spawn2: name: Spawn2 location: 'world 69 71 136 136 0' @@ -70,3 +77,5 @@ spawn2: normal-use: 3 option: enable-menu: false + linked: + spawn: 3 From 5a2e05bb1283adcb5c30d3a9d8ebfa4003d62490 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Wed, 4 May 2022 11:31:12 +0200 Subject: [PATCH 5/5] 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()) {