Modifications for class based skill tree

This commit is contained in:
Ka0rX 2022-10-17 07:11:14 +02:00
parent 3d4cd7ad00
commit 6dd27017ed
4 changed files with 65 additions and 24 deletions

View File

@ -322,6 +322,26 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
return nodeStates; return nodeStates;
} }
public Map<String, Integer> getNodeTimesClaimed() {
Map<String, Integer> result = new HashMap<>();
tableItemClaims.forEach((str, val) -> {
if (str.startsWith(SkillTreeNode.getPrefix()))
result.put(str, val);
});
return result;
}
public void resetNodeTimesClaimed() {
Map<String, Integer> 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) { public void addNodeLevel(SkillTreeNode node) {
nodeLevels.put(node, nodeLevels.get(node) + 1); nodeLevels.put(node, nodeLevels.get(node) + 1);
} }
@ -447,16 +467,25 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
@Override @Override
public int getClaims(ExperienceObject object, ExperienceTable table, ExperienceItem item) { 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); return tableItemClaims.getOrDefault(key, 0);
} }
@Override @Override
public void setClaims(ExperienceObject object, ExperienceTable table, ExperienceItem item, int times) { public void setClaims(ExperienceObject object, ExperienceTable table, ExperienceItem item, int times) {
String key = object.getKey() + "." + table.getId() + "." + item.getId(); setClaims(object.getKey() + "." + table.getId() + "." + item.getId(), times);
tableItemClaims.put(key, times);
} }
public void setClaims(String key, int times) {
tableItemClaims.put(key, times);
}
public Map<String, Integer> getItemClaims() { public Map<String, Integer> getItemClaims() {
return tableItemClaims; return tableItemClaims;
} }

View File

@ -26,6 +26,7 @@ public class SavedClassInformation {
private final Map<String, Integer> skills; private final Map<String, Integer> skills;
private final Map<String, Integer> skillTreePoints; private final Map<String, Integer> skillTreePoints;
private final Map<SkillTreeNode, Integer> nodeLevels; private final Map<SkillTreeNode, Integer> nodeLevels;
private final Map<String,Integer> nodeTimesClaimed;
public SavedClassInformation(ConfigurationSection config) { public SavedClassInformation(ConfigurationSection config) {
level = config.getInt("level"); level = config.getInt("level");
@ -47,6 +48,9 @@ public class SavedClassInformation {
nodeLevels = new HashMap<>(); nodeLevels = new HashMap<>();
if (config.contains("node-levels")) 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))); 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")) if (json.has("node-levels"))
for (Entry<String, JsonElement> entry : json.getAsJsonObject("node-levels").entrySet()) for (Entry<String, JsonElement> entry : json.getAsJsonObject("node-levels").entrySet())
nodeLevels.put(MMOCore.plugin.skillTreeManager.getNode(entry.getKey()), entry.getValue().getAsInt()); nodeLevels.put(MMOCore.plugin.skillTreeManager.getNode(entry.getKey()), entry.getValue().getAsInt());
nodeTimesClaimed=new HashMap<>();
if (json.has("node-times-claimed"))
for (Entry<String, JsonElement> entry : json.getAsJsonObject("node-times-claimed").entrySet())
nodeTimesClaimed.put(entry.getKey(), entry.getValue().getAsInt());
} }
public SavedClassInformation(PlayerData player) { public SavedClassInformation(PlayerData player) {
this(player.getLevel(), player.getExperience(), player.getSkillPoints(), player.getAttributePoints(), player.getAttributeReallocationPoints() this(player.getLevel(), player.getExperience(), player.getSkillPoints(), player.getAttributePoints(), player.getAttributeReallocationPoints()
, player.getSkillTreeReallocationPoints(), player.getSkillReallocationPoints(), , 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) { 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) { 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, public SavedClassInformation(int level, double experience, int skillPoints, int attributePoints, int attributeReallocationPoints, int skillTreeReallocationPoints, int skillReallocationPoints,
Map<String, Integer> attributes, Map<String, Integer> skills, Map<String, Integer> skillTreePoints, Map<SkillTreeNode, Integer> nodeLevels) { Map<String, Integer> attributes, Map<String, Integer> skills, Map<String, Integer> skillTreePoints, Map<SkillTreeNode, Integer> nodeLevels,Map<String, Integer> nodeTimesClaimed) {
this.level = level; this.level = level;
this.skillPoints = skillPoints; this.skillPoints = skillPoints;
this.attributePoints = attributePoints; this.attributePoints = attributePoints;
@ -103,6 +113,7 @@ public class SavedClassInformation {
this.skills = skills; this.skills = skills;
this.skillTreePoints = skillTreePoints; this.skillTreePoints = skillTreePoints;
this.nodeLevels = nodeLevels; this.nodeLevels = nodeLevels;
this.nodeTimesClaimed=nodeTimesClaimed;
} }
public int getLevel() { public int getLevel() {
@ -201,9 +212,10 @@ public class SavedClassInformation {
for (SkillTree skillTree : player.getProfess().getSkillTrees()) for (SkillTree skillTree : player.getProfess().getSkillTrees())
for (SkillTreeNode node : skillTree.getNodes()) for (SkillTreeNode node : skillTree.getNodes())
node.getExperienceTable().removeStatTriggers(player, node); node.getExperienceTable().reset(player, node);
player.getNodeLevels().clear(); player.getNodeLevels().clear();
player.getNodeStates().clear(); player.getNodeStates().clear();
player.mapSkillLevels().forEach((skill, level) -> player.resetSkillLevel(skill)); player.mapSkillLevels().forEach((skill, level) -> player.resetSkillLevel(skill));
player.getAttributes().getInstances().forEach(ins -> ins.setBase(0)); player.getAttributes().getInstances().forEach(ins -> ins.setBase(0));
@ -227,7 +239,8 @@ public class SavedClassInformation {
attributes.forEach((id, pts) -> player.getAttributes().setBaseAttribute(id, pts)); attributes.forEach((id, pts) -> player.getAttributes().setBaseAttribute(id, pts));
skillTreePoints.forEach((skillTree, point) -> player.setSkillTreePoints(skillTree, point)); skillTreePoints.forEach((skillTree, point) -> player.setSkillTreePoints(skillTree, point));
nodeLevels.forEach((node, level) -> player.setNodeLevel(node, level)); 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)); nodeLevels.keySet().forEach(node -> node.getExperienceTable().claimStatTriggers(player, node));
//We claim back the stats triggers //We claim back the stats triggers
for(SkillTree skillTree:profess.getSkillTrees()) for(SkillTree skillTree:profess.getSkillTrees())

View File

@ -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 * Called when a player joins and all the statTriggers are all triggered back
* *

View File

@ -53,11 +53,11 @@ public class SkillTreeNode implements Unlockable, ExperienceObject {
name = Objects.requireNonNull(config.getString("name"), "Could not find node name"); name = Objects.requireNonNull(config.getString("name"), "Could not find node name");
size = Objects.requireNonNull(config.getInt("size")); size = Objects.requireNonNull(config.getInt("size"));
isRoot = config.getBoolean("is-root", false); isRoot = config.getBoolean("is-root", false);
if(config.contains("lores")) { if (config.contains("lores")) {
for(String key: config.getConfigurationSection("lores").getKeys(false)) { for (String key : config.getConfigurationSection("lores").getKeys(false)) {
try { try {
lores.put(Integer.parseInt(key),config.getStringList("lores."+key)); lores.put(Integer.parseInt(key), config.getStringList("lores." + key));
}catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new RuntimeException("You must only specifiy integers in lores."); 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() { public SkillTree getTree() {
return tree; return tree;
@ -158,7 +166,7 @@ public class SkillTreeNode implements Unlockable, ExperienceObject {
@Override @Override
public String getKey() { public String getKey() {
return "node_" + getFullId().replace("-", "_"); return getPrefix()+":" + getFullId().replace("-", "_");
} }
@Nullable @Nullable
@ -210,9 +218,9 @@ public class SkillTreeNode implements Unlockable, ExperienceObject {
public List<String> getLore(PlayerData playerData) { public List<String> getLore(PlayerData playerData) {
Placeholders holders = getPlaceholders(playerData); Placeholders holders = getPlaceholders(playerData);
List<String> parsedLore = new ArrayList<>(); List<String> parsedLore = new ArrayList<>();
if(!lores.containsKey(playerData.getNodeLevel(this))) if (!lores.containsKey(playerData.getNodeLevel(this)))
return parsedLore; return parsedLore;
List<String> lore= lores.get(playerData.getNodeLevel(this)); List<String> lore = lores.get(playerData.getNodeLevel(this));
lore.forEach(string -> parsedLore.add( lore.forEach(string -> parsedLore.add(
MythicLib.plugin.parseColors(holders.apply(playerData.getPlayer(), string)))); MythicLib.plugin.parseColors(holders.apply(playerData.getPlayer(), string))));
return parsedLore; return parsedLore;