From 6dd27017ed2b82bc53bd8764d34b8ec73ccbc169 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Mon, 17 Oct 2022 07:11:14 +0200 Subject: [PATCH] Modifications for class based skill tree --- .../mmocore/api/player/PlayerData.java | 35 +++++++++++++++++-- .../player/profess/SavedClassInformation.java | 23 +++++++++--- .../experience/droptable/ExperienceTable.java | 9 ----- .../Indyuce/mmocore/tree/SkillTreeNode.java | 22 ++++++++---- 4 files changed, 65 insertions(+), 24 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index b192c9a5..b751072e 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -322,6 +322,26 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc return nodeStates; } + public Map getNodeTimesClaimed() { + Map result = new HashMap<>(); + tableItemClaims.forEach((str, val) -> { + if (str.startsWith(SkillTreeNode.getPrefix())) + result.put(str, val); + }); + return result; + } + + public void resetNodeTimesClaimed() { + Map newTableItemClaims = new HashMap<>(); + tableItemClaims.forEach((str, val) -> { + if (!str.startsWith(SkillTreeNode.getPrefix())) + newTableItemClaims.put(str, val); + }); + tableItemClaims.clear(); + tableItemClaims.putAll(newTableItemClaims); + } + + public void addNodeLevel(SkillTreeNode node) { nodeLevels.put(node, nodeLevels.get(node) + 1); } @@ -447,16 +467,25 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc @Override public int getClaims(ExperienceObject object, ExperienceTable table, ExperienceItem item) { - String key = object.getKey() + "." + table.getId() + "." + item.getId(); + return getClaims(object.getKey() + "." + table.getId() + "." + item.getId()); + } + + public int getClaims(String key) { return tableItemClaims.getOrDefault(key, 0); + } @Override public void setClaims(ExperienceObject object, ExperienceTable table, ExperienceItem item, int times) { - String key = object.getKey() + "." + table.getId() + "." + item.getId(); - tableItemClaims.put(key, times); + setClaims(object.getKey() + "." + table.getId() + "." + item.getId(), times); } + public void setClaims(String key, int times) { + tableItemClaims.put(key, times); + + } + + public Map getItemClaims() { return tableItemClaims; } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java index 7e6d2f41..5a807ebf 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java @@ -26,6 +26,7 @@ public class SavedClassInformation { private final Map skills; private final Map skillTreePoints; private final Map nodeLevels; + private final Map nodeTimesClaimed; public SavedClassInformation(ConfigurationSection config) { level = config.getInt("level"); @@ -47,6 +48,9 @@ public class SavedClassInformation { nodeLevels = new HashMap<>(); if (config.contains("node-levels")) config.getConfigurationSection("node-levels").getKeys(false).forEach(key -> nodeLevels.put(MMOCore.plugin.skillTreeManager.getNode(key), config.getInt("node-levels." + key))); + nodeTimesClaimed = new HashMap<>(); + if (config.contains("node-times-claimed")) + config.getConfigurationSection("node-times-claimed").getKeys(false).forEach(key -> nodeTimesClaimed.put(key, config.getInt("node-times-claimed." + key))); } @@ -74,12 +78,18 @@ public class SavedClassInformation { if (json.has("node-levels")) for (Entry entry : json.getAsJsonObject("node-levels").entrySet()) nodeLevels.put(MMOCore.plugin.skillTreeManager.getNode(entry.getKey()), entry.getValue().getAsInt()); + nodeTimesClaimed=new HashMap<>(); + if (json.has("node-times-claimed")) + for (Entry entry : json.getAsJsonObject("node-times-claimed").entrySet()) + nodeTimesClaimed.put(entry.getKey(), entry.getValue().getAsInt()); + + } public SavedClassInformation(PlayerData player) { this(player.getLevel(), player.getExperience(), player.getSkillPoints(), player.getAttributePoints(), player.getAttributeReallocationPoints() , player.getSkillTreeReallocationPoints(), player.getSkillReallocationPoints(), - player.getAttributes().mapPoints(), player.mapSkillLevels(), player.getSkillTreePoints(), player.getNodeLevels()); + player.getAttributes().mapPoints(), player.mapSkillLevels(), player.getSkillTreePoints(), player.getNodeLevels(),player.getNodeTimesClaimed()); } public SavedClassInformation(PlayerDataManager.DefaultPlayerData data) { @@ -87,11 +97,11 @@ public class SavedClassInformation { } public SavedClassInformation(int level, double experience, int skillPoints, int attributePoints, int attributeReallocationPoints, int skillTreeReallocationPoints, int skillReallocationPoints) { - this(level, experience, skillPoints, attributePoints, attributeReallocationPoints, skillTreeReallocationPoints, skillReallocationPoints, new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>()); + this(level, experience, skillPoints, attributePoints, attributeReallocationPoints, skillTreeReallocationPoints, skillReallocationPoints, new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(),new HashMap<>()); } public SavedClassInformation(int level, double experience, int skillPoints, int attributePoints, int attributeReallocationPoints, int skillTreeReallocationPoints, int skillReallocationPoints, - Map attributes, Map skills, Map skillTreePoints, Map nodeLevels) { + Map attributes, Map skills, Map skillTreePoints, Map nodeLevels,Map nodeTimesClaimed) { this.level = level; this.skillPoints = skillPoints; this.attributePoints = attributePoints; @@ -103,6 +113,7 @@ public class SavedClassInformation { this.skills = skills; this.skillTreePoints = skillTreePoints; this.nodeLevels = nodeLevels; + this.nodeTimesClaimed=nodeTimesClaimed; } public int getLevel() { @@ -201,9 +212,10 @@ public class SavedClassInformation { for (SkillTree skillTree : player.getProfess().getSkillTrees()) for (SkillTreeNode node : skillTree.getNodes()) - node.getExperienceTable().removeStatTriggers(player, node); + node.getExperienceTable().reset(player, node); player.getNodeLevels().clear(); player.getNodeStates().clear(); + player.mapSkillLevels().forEach((skill, level) -> player.resetSkillLevel(skill)); player.getAttributes().getInstances().forEach(ins -> ins.setBase(0)); @@ -227,7 +239,8 @@ public class SavedClassInformation { attributes.forEach((id, pts) -> player.getAttributes().setBaseAttribute(id, pts)); skillTreePoints.forEach((skillTree, point) -> player.setSkillTreePoints(skillTree, point)); nodeLevels.forEach((node, level) -> player.setNodeLevel(node, level)); - + //Add the values to the times claimed table and claims the corresponding stat triggers. + nodeTimesClaimed.forEach((str,val)->player.setClaims(str,val)); nodeLevels.keySet().forEach(node -> node.getExperienceTable().claimStatTriggers(player, node)); //We claim back the stats triggers for(SkillTree skillTree:profess.getSkillTrees()) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/droptable/ExperienceTable.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/droptable/ExperienceTable.java index 0de8f925..4a565c00 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/droptable/ExperienceTable.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/experience/droptable/ExperienceTable.java @@ -67,15 +67,6 @@ public class ExperienceTable { } - public void removeStatTriggers(PlayerData playerData,ExperienceObject object) { - for (ExperienceItem item : items) { - int timesClaimed = playerData.getClaims(object, this, item); - for (int i = 0; i < timesClaimed; i++) - item.removeStatTriggers(playerData); - } - } - - /** * Called when a player joins and all the statTriggers are all triggered back * diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/SkillTreeNode.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/SkillTreeNode.java index 56224924..9e34d7ec 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/SkillTreeNode.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/SkillTreeNode.java @@ -53,11 +53,11 @@ public class SkillTreeNode implements Unlockable, ExperienceObject { name = Objects.requireNonNull(config.getString("name"), "Could not find node name"); size = Objects.requireNonNull(config.getInt("size")); isRoot = config.getBoolean("is-root", false); - if(config.contains("lores")) { - for(String key: config.getConfigurationSection("lores").getKeys(false)) { + if (config.contains("lores")) { + for (String key : config.getConfigurationSection("lores").getKeys(false)) { try { - lores.put(Integer.parseInt(key),config.getStringList("lores."+key)); - }catch (NumberFormatException e) { + lores.put(Integer.parseInt(key), config.getStringList("lores." + key)); + } catch (NumberFormatException e) { throw new RuntimeException("You must only specifiy integers in lores."); } } @@ -76,6 +76,14 @@ public class SkillTreeNode implements Unlockable, ExperienceObject { } } + /** + * Prefix used in the key + * @return + */ + public static String getPrefix() { + return "node"; + } + public SkillTree getTree() { return tree; @@ -158,7 +166,7 @@ public class SkillTreeNode implements Unlockable, ExperienceObject { @Override public String getKey() { - return "node_" + getFullId().replace("-", "_"); + return getPrefix()+":" + getFullId().replace("-", "_"); } @Nullable @@ -210,9 +218,9 @@ public class SkillTreeNode implements Unlockable, ExperienceObject { public List getLore(PlayerData playerData) { Placeholders holders = getPlaceholders(playerData); List parsedLore = new ArrayList<>(); - if(!lores.containsKey(playerData.getNodeLevel(this))) + if (!lores.containsKey(playerData.getNodeLevel(this))) return parsedLore; - List lore= lores.get(playerData.getNodeLevel(this)); + List lore = lores.get(playerData.getNodeLevel(this)); lore.forEach(string -> parsedLore.add( MythicLib.plugin.parseColors(holders.apply(playerData.getPlayer(), string)))); return parsedLore;