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;
}
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) {
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<String, Integer> getItemClaims() {
return tableItemClaims;
}

View File

@ -26,6 +26,7 @@ public class SavedClassInformation {
private final Map<String, Integer> skills;
private final Map<String, Integer> skillTreePoints;
private final Map<SkillTreeNode, Integer> nodeLevels;
private final Map<String,Integer> 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<String, JsonElement> 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<String, JsonElement> 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<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.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())

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
*

View File

@ -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<String> getLore(PlayerData playerData) {
Placeholders holders = getPlaceholders(playerData);
List<String> parsedLore = new ArrayList<>();
if(!lores.containsKey(playerData.getNodeLevel(this)))
if (!lores.containsKey(playerData.getNodeLevel(this)))
return parsedLore;
List<String> lore= lores.get(playerData.getNodeLevel(this));
List<String> lore = lores.get(playerData.getNodeLevel(this));
lore.forEach(string -> parsedLore.add(
MythicLib.plugin.parseColors(holders.apply(playerData.getPlayer(), string))));
return parsedLore;