forked from Upstream/mmocore
SavedClassInformation changes to make skillTree class based
This commit is contained in:
parent
a7bea899a7
commit
b5c473c431
@ -223,6 +223,10 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
|||||||
return nodeLevelsString.entrySet();
|
return nodeLevelsString.entrySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<SkillTreeNode, Integer> getNodeLevels() {
|
||||||
|
return nodeLevels;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean canIncrementNodeLevel(SkillTreeNode node) {
|
public boolean canIncrementNodeLevel(SkillTreeNode node) {
|
||||||
NodeState nodeState = nodeStates.get(node);
|
NodeState nodeState = nodeStates.get(node);
|
||||||
//Check the State of the node
|
//Check the State of the node
|
||||||
@ -306,6 +310,14 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
|||||||
nodeLevels.put(node, nodeLevel);
|
nodeLevels.put(node, nodeLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetSkillTree(SkillTree skillTree) {
|
||||||
|
for (SkillTreeNode node : skillTree.getNodes()) {
|
||||||
|
node.getExperienceTable().reset(this,node);
|
||||||
|
setNodeLevel(node, 0);
|
||||||
|
}
|
||||||
|
skillTree.setupNodeState(this);
|
||||||
|
}
|
||||||
|
|
||||||
public void addNodeLevel(SkillTreeNode node) {
|
public void addNodeLevel(SkillTreeNode node) {
|
||||||
nodeLevels.put(node, nodeLevels.get(node) + 1);
|
nodeLevels.put(node, nodeLevels.get(node) + 1);
|
||||||
}
|
}
|
||||||
|
@ -5,21 +5,25 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.erethon.dungeonsxl.player.DPlayerData;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
||||||
import net.Indyuce.mmocore.manager.data.PlayerDataManager;
|
import net.Indyuce.mmocore.manager.data.PlayerDataManager;
|
||||||
import net.Indyuce.mmocore.skill.RegisteredSkill;
|
import net.Indyuce.mmocore.skill.RegisteredSkill;
|
||||||
|
import net.Indyuce.mmocore.tree.SkillTreeNode;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
public class SavedClassInformation {
|
public class SavedClassInformation {
|
||||||
private final int level, skillPoints, attributePoints, attributeReallocationPoints;
|
private final int level, skillPoints, attributePoints, attributeReallocationPoints, skillTreeReallocationPoints, skillReallocationPoints;
|
||||||
private final double experience;
|
private final double experience;
|
||||||
private final Map<String, Integer> attributes;
|
private final Map<String, Integer> attributes;
|
||||||
private final Map<String, Integer> skills;
|
private final Map<String, Integer> skills;
|
||||||
|
private final Map<String, Integer> skillTreePoints;
|
||||||
|
private final Map<SkillTreeNode, Integer> nodeLevels;
|
||||||
|
|
||||||
public SavedClassInformation(ConfigurationSection config) {
|
public SavedClassInformation(ConfigurationSection config) {
|
||||||
level = config.getInt("level");
|
level = config.getInt("level");
|
||||||
@ -27,13 +31,21 @@ public class SavedClassInformation {
|
|||||||
skillPoints = config.getInt("skill-points");
|
skillPoints = config.getInt("skill-points");
|
||||||
attributePoints = config.getInt("attribute-points");
|
attributePoints = config.getInt("attribute-points");
|
||||||
attributeReallocationPoints = config.getInt("attribute-realloc-points");
|
attributeReallocationPoints = config.getInt("attribute-realloc-points");
|
||||||
|
skillReallocationPoints = config.getInt("skill-reallocation-points");
|
||||||
|
skillTreeReallocationPoints = config.getInt("skill-tree-reallocation-points");
|
||||||
attributes = new HashMap<>();
|
attributes = new HashMap<>();
|
||||||
if (config.contains("attribute"))
|
if (config.contains("attribute"))
|
||||||
config.getConfigurationSection("attribute").getKeys(false).forEach(key -> attributes.put(key, config.getInt("attribute." + key)));
|
config.getConfigurationSection("attribute").getKeys(false).forEach(key -> attributes.put(key, config.getInt("attribute." + key)));
|
||||||
skills = new HashMap<>();
|
skills = new HashMap<>();
|
||||||
if (config.contains("skill"))
|
if (config.contains("skill"))
|
||||||
config.getConfigurationSection("skill").getKeys(false).forEach(key -> skills.put(key, config.getInt("skill." + key)));
|
config.getConfigurationSection("skill").getKeys(false).forEach(key -> skills.put(key, config.getInt("skill." + key)));
|
||||||
|
skillTreePoints = new HashMap<>();
|
||||||
|
if (config.contains("skill-tree-points"))
|
||||||
|
config.getConfigurationSection("skill-tree-points").getKeys(false).forEach(key -> skillTreePoints.put(key, config.getInt("skill-tree-points." + key)));
|
||||||
|
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)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SavedClassInformation(JsonObject json) {
|
public SavedClassInformation(JsonObject json) {
|
||||||
@ -42,7 +54,8 @@ public class SavedClassInformation {
|
|||||||
skillPoints = json.get("skill-points").getAsInt();
|
skillPoints = json.get("skill-points").getAsInt();
|
||||||
attributePoints = json.get("attribute-points").getAsInt();
|
attributePoints = json.get("attribute-points").getAsInt();
|
||||||
attributeReallocationPoints = json.get("attribute-realloc-points").getAsInt();
|
attributeReallocationPoints = json.get("attribute-realloc-points").getAsInt();
|
||||||
|
skillReallocationPoints = json.get("skill-reallocation-points").getAsInt();
|
||||||
|
skillTreeReallocationPoints = json.get("skill-tree-reallocation-points").getAsInt();
|
||||||
attributes = new HashMap<>();
|
attributes = new HashMap<>();
|
||||||
if (json.has("attribute"))
|
if (json.has("attribute"))
|
||||||
for (Entry<String, JsonElement> entry : json.getAsJsonObject("attribute").entrySet())
|
for (Entry<String, JsonElement> entry : json.getAsJsonObject("attribute").entrySet())
|
||||||
@ -51,31 +64,43 @@ public class SavedClassInformation {
|
|||||||
if (json.has("skill"))
|
if (json.has("skill"))
|
||||||
for (Entry<String, JsonElement> entry : json.getAsJsonObject("skill").entrySet())
|
for (Entry<String, JsonElement> entry : json.getAsJsonObject("skill").entrySet())
|
||||||
skills.put(entry.getKey(), entry.getValue().getAsInt());
|
skills.put(entry.getKey(), entry.getValue().getAsInt());
|
||||||
|
skillTreePoints = new HashMap<>();
|
||||||
|
if (json.has("skill-tree-points"))
|
||||||
|
for (Entry<String, JsonElement> entry : json.getAsJsonObject("skill-tree-points").entrySet())
|
||||||
|
skillTreePoints.put(entry.getKey(), entry.getValue().getAsInt());
|
||||||
|
nodeLevels = new HashMap<>();
|
||||||
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
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.getAttributes().mapPoints(), player.mapSkillLevels());
|
,player.getSkillTreeReallocationPoints(),player.getSkillReallocationPoints(),
|
||||||
|
player.getAttributes().mapPoints(), player.mapSkillLevels(), player.getSkillTreePoints(), player.getNodeLevels());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SavedClassInformation(PlayerDataManager.DefaultPlayerData data) {
|
public SavedClassInformation(PlayerDataManager.DefaultPlayerData data) {
|
||||||
this(data.getLevel(), 0, data.getSkillPoints(), data.getAttributePoints(), data.getAttrReallocPoints());
|
this(data.getLevel(), 0, data.getSkillPoints(), data.getAttributePoints(), data.getAttrReallocPoints(),data.getSkillTreeReallocPoints(),data.getSkillReallocPoints());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SavedClassInformation(int level, double experience, int skillPoints, int attributePoints, int attributeReallocationPoints) {
|
public SavedClassInformation(int level, double experience, int skillPoints, int attributePoints, int attributeReallocationPoints,int skillTreeReallocationPoints,int skillReallocationPoints) {
|
||||||
this(level, experience, skillPoints, attributePoints, attributeReallocationPoints, new HashMap<>(), new HashMap<>());
|
this(level, experience, skillPoints, attributePoints, attributeReallocationPoints,skillTreeReallocationPoints,skillReallocationPoints, new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private SavedClassInformation(int level, double experience, int skillPoints, int attributePoints, int attributeReallocationPoints,
|
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> attributes, Map<String, Integer> skills, Map<String, Integer> skillTreePoints, Map<SkillTreeNode, Integer> nodeLevels) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.experience = experience;
|
|
||||||
this.skillPoints = skillPoints;
|
this.skillPoints = skillPoints;
|
||||||
this.attributePoints = attributePoints;
|
this.attributePoints = attributePoints;
|
||||||
this.attributeReallocationPoints = attributeReallocationPoints;
|
this.attributeReallocationPoints = attributeReallocationPoints;
|
||||||
|
this.skillTreeReallocationPoints = skillTreeReallocationPoints;
|
||||||
|
this.skillReallocationPoints = skillReallocationPoints;
|
||||||
|
this.experience = experience;
|
||||||
this.attributes = attributes;
|
this.attributes = attributes;
|
||||||
this.skills = skills;
|
this.skills = skills;
|
||||||
|
this.skillTreePoints = skillTreePoints;
|
||||||
|
this.nodeLevels = nodeLevels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLevel() {
|
public int getLevel() {
|
||||||
@ -152,6 +177,7 @@ public class SavedClassInformation {
|
|||||||
*/
|
*/
|
||||||
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));
|
||||||
|
MMOCore.plugin.skillTreeManager.getAll().forEach(skillTree -> player.resetSkillTree(skillTree));
|
||||||
while (player.hasSkillBound(0))
|
while (player.hasSkillBound(0))
|
||||||
player.unbindSkill(0);
|
player.unbindSkill(0);
|
||||||
|
|
||||||
@ -165,10 +191,13 @@ public class SavedClassInformation {
|
|||||||
player.setSkillPoints(skillPoints);
|
player.setSkillPoints(skillPoints);
|
||||||
player.setAttributePoints(attributePoints);
|
player.setAttributePoints(attributePoints);
|
||||||
player.setAttributeReallocationPoints(attributeReallocationPoints);
|
player.setAttributeReallocationPoints(attributeReallocationPoints);
|
||||||
|
player.setSkillTreeReallocationPoints(skillTreeReallocationPoints);
|
||||||
|
player.setSkillReallocationPoints(skillReallocationPoints);
|
||||||
|
|
||||||
skills.forEach(player::setSkillLevel);
|
(skills).forEach(player::setSkillLevel);
|
||||||
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));
|
||||||
|
nodeLevels.forEach((node, level) -> player.setNodeLevel(node, level));
|
||||||
/*
|
/*
|
||||||
* unload current class information and set the new profess once
|
* unload current class information and set the new profess once
|
||||||
* everything is changed
|
* everything is changed
|
||||||
|
@ -382,12 +382,7 @@ public class SkillTreeViewer extends EditableInventory {
|
|||||||
//We remove all the nodeStates progress
|
//We remove all the nodeStates progress
|
||||||
playerData.giveSkillTreePoints(skillTree.getId(), reallocated);
|
playerData.giveSkillTreePoints(skillTree.getId(), reallocated);
|
||||||
playerData.giveSkillTreeReallocationPoints(-1);
|
playerData.giveSkillTreeReallocationPoints(-1);
|
||||||
for (SkillTreeNode node : skillTree.getNodes()) {
|
playerData.resetSkillTree(skillTree);
|
||||||
node.getExperienceTable().reset(playerData,node);
|
|
||||||
playerData.setNodeLevel(node, 0);
|
|
||||||
playerData.setNodeState(node, NodeState.LOCKED);
|
|
||||||
|
|
||||||
}
|
|
||||||
skillTree.setupNodeState(playerData);
|
skillTree.setupNodeState(playerData);
|
||||||
MMOCore.plugin.configManager.getSimpleMessage("reallocated-points", "points", "" + playerData.getSkillTreePoint(skillTree.getId()), "skill-tree", skillTree.getName()).send(player);
|
MMOCore.plugin.configManager.getSimpleMessage("reallocated-points", "points", "" + playerData.getSkillTreePoint(skillTree.getId()), "skill-tree", skillTree.getName()).send(player);
|
||||||
MMOCore.plugin.soundManager.getSound(SoundEvent.RESET_SKILL_TREE).playTo(player);
|
MMOCore.plugin.soundManager.getSound(SoundEvent.RESET_SKILL_TREE).playTo(player);
|
||||||
|
Loading…
Reference in New Issue
Block a user