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();
|
||||
}
|
||||
|
||||
public Map<SkillTreeNode, Integer> getNodeLevels() {
|
||||
return nodeLevels;
|
||||
}
|
||||
|
||||
public boolean canIncrementNodeLevel(SkillTreeNode node) {
|
||||
NodeState nodeState = nodeStates.get(node);
|
||||
//Check the State of the node
|
||||
@ -306,6 +310,14 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
||||
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) {
|
||||
nodeLevels.put(node, nodeLevels.get(node) + 1);
|
||||
}
|
||||
|
@ -5,178 +5,207 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import de.erethon.dungeonsxl.player.DPlayerData;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
||||
import net.Indyuce.mmocore.manager.data.PlayerDataManager;
|
||||
import net.Indyuce.mmocore.skill.RegisteredSkill;
|
||||
import net.Indyuce.mmocore.tree.SkillTreeNode;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class SavedClassInformation {
|
||||
private final int level, skillPoints, attributePoints, attributeReallocationPoints;
|
||||
private final double experience;
|
||||
private final Map<String, Integer> attributes;
|
||||
private final Map<String, Integer> skills;
|
||||
private final int level, skillPoints, attributePoints, attributeReallocationPoints, skillTreeReallocationPoints, skillReallocationPoints;
|
||||
private final double experience;
|
||||
private final Map<String, Integer> attributes;
|
||||
private final Map<String, Integer> skills;
|
||||
private final Map<String, Integer> skillTreePoints;
|
||||
private final Map<SkillTreeNode, Integer> nodeLevels;
|
||||
|
||||
public SavedClassInformation(ConfigurationSection config) {
|
||||
level = config.getInt("level");
|
||||
experience = config.getDouble("experience");
|
||||
skillPoints = config.getInt("skill-points");
|
||||
attributePoints = config.getInt("attribute-points");
|
||||
attributeReallocationPoints = config.getInt("attribute-realloc-points");
|
||||
public SavedClassInformation(ConfigurationSection config) {
|
||||
level = config.getInt("level");
|
||||
experience = config.getDouble("experience");
|
||||
skillPoints = config.getInt("skill-points");
|
||||
attributePoints = config.getInt("attribute-points");
|
||||
attributeReallocationPoints = config.getInt("attribute-realloc-points");
|
||||
skillReallocationPoints = config.getInt("skill-reallocation-points");
|
||||
skillTreeReallocationPoints = config.getInt("skill-tree-reallocation-points");
|
||||
attributes = new HashMap<>();
|
||||
if (config.contains("attribute"))
|
||||
config.getConfigurationSection("attribute").getKeys(false).forEach(key -> attributes.put(key, config.getInt("attribute." + key)));
|
||||
skills = new HashMap<>();
|
||||
if (config.contains("skill"))
|
||||
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)));
|
||||
|
||||
attributes = new HashMap<>();
|
||||
if (config.contains("attribute"))
|
||||
config.getConfigurationSection("attribute").getKeys(false).forEach(key -> attributes.put(key, config.getInt("attribute." + key)));
|
||||
skills = new HashMap<>();
|
||||
if (config.contains("skill"))
|
||||
config.getConfigurationSection("skill").getKeys(false).forEach(key -> skills.put(key, config.getInt("skill." + key)));
|
||||
}
|
||||
}
|
||||
|
||||
public SavedClassInformation(JsonObject json) {
|
||||
level = json.get("level").getAsInt();
|
||||
experience = json.get("experience").getAsDouble();
|
||||
skillPoints = json.get("skill-points").getAsInt();
|
||||
attributePoints = json.get("attribute-points").getAsInt();
|
||||
attributeReallocationPoints = json.get("attribute-realloc-points").getAsInt();
|
||||
public SavedClassInformation(JsonObject json) {
|
||||
level = json.get("level").getAsInt();
|
||||
experience = json.get("experience").getAsDouble();
|
||||
skillPoints = json.get("skill-points").getAsInt();
|
||||
attributePoints = json.get("attribute-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<>();
|
||||
if (json.has("attribute"))
|
||||
for (Entry<String, JsonElement> entry : json.getAsJsonObject("attribute").entrySet())
|
||||
attributes.put(entry.getKey(), entry.getValue().getAsInt());
|
||||
skills = new HashMap<>();
|
||||
if (json.has("skill"))
|
||||
for (Entry<String, JsonElement> entry : json.getAsJsonObject("skill").entrySet())
|
||||
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());
|
||||
}
|
||||
|
||||
attributes = new HashMap<>();
|
||||
if (json.has("attribute"))
|
||||
for (Entry<String, JsonElement> entry : json.getAsJsonObject("attribute").entrySet())
|
||||
attributes.put(entry.getKey(), entry.getValue().getAsInt());
|
||||
skills = new HashMap<>();
|
||||
if (json.has("skill"))
|
||||
for (Entry<String, JsonElement> entry : json.getAsJsonObject("skill").entrySet())
|
||||
skills.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());
|
||||
}
|
||||
|
||||
}
|
||||
public SavedClassInformation(PlayerDataManager.DefaultPlayerData data) {
|
||||
this(data.getLevel(), 0, data.getSkillPoints(), data.getAttributePoints(), data.getAttrReallocPoints(),data.getSkillTreeReallocPoints(),data.getSkillReallocPoints());
|
||||
}
|
||||
|
||||
public SavedClassInformation(PlayerData player) {
|
||||
this(player.getLevel(), player.getExperience(), player.getSkillPoints(), player.getAttributePoints(), player.getAttributeReallocationPoints(),
|
||||
player.getAttributes().mapPoints(), player.mapSkillLevels());
|
||||
}
|
||||
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<>());
|
||||
}
|
||||
|
||||
public SavedClassInformation(PlayerDataManager.DefaultPlayerData data) {
|
||||
this(data.getLevel(), 0, data.getSkillPoints(), data.getAttributePoints(), data.getAttrReallocPoints());
|
||||
}
|
||||
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) {
|
||||
this.level = level;
|
||||
this.skillPoints = skillPoints;
|
||||
this.attributePoints = attributePoints;
|
||||
this.attributeReallocationPoints = attributeReallocationPoints;
|
||||
this.skillTreeReallocationPoints = skillTreeReallocationPoints;
|
||||
this.skillReallocationPoints = skillReallocationPoints;
|
||||
this.experience = experience;
|
||||
this.attributes = attributes;
|
||||
this.skills = skills;
|
||||
this.skillTreePoints = skillTreePoints;
|
||||
this.nodeLevels = nodeLevels;
|
||||
}
|
||||
|
||||
public SavedClassInformation(int level, double experience, int skillPoints, int attributePoints, int attributeReallocationPoints) {
|
||||
this(level, experience, skillPoints, attributePoints, attributeReallocationPoints, new HashMap<>(), new HashMap<>());
|
||||
}
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
private SavedClassInformation(int level, double experience, int skillPoints, int attributePoints, int attributeReallocationPoints,
|
||||
Map<String, Integer> attributes, Map<String, Integer> skills) {
|
||||
this.level = level;
|
||||
this.experience = experience;
|
||||
this.skillPoints = skillPoints;
|
||||
this.attributePoints = attributePoints;
|
||||
this.attributeReallocationPoints = attributeReallocationPoints;
|
||||
this.attributes = attributes;
|
||||
this.skills = skills;
|
||||
}
|
||||
public double getExperience() {
|
||||
return experience;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
public int getSkillPoints() {
|
||||
return skillPoints;
|
||||
}
|
||||
|
||||
public double getExperience() {
|
||||
return experience;
|
||||
}
|
||||
public int getAttributePoints() {
|
||||
return attributePoints;
|
||||
}
|
||||
|
||||
public int getSkillPoints() {
|
||||
return skillPoints;
|
||||
}
|
||||
public int getAttributeReallocationPoints() {
|
||||
return attributeReallocationPoints;
|
||||
}
|
||||
|
||||
public int getAttributePoints() {
|
||||
return attributePoints;
|
||||
}
|
||||
public Set<String> getSkillKeys() {
|
||||
return skills.keySet();
|
||||
}
|
||||
|
||||
public int getAttributeReallocationPoints() {
|
||||
return attributeReallocationPoints;
|
||||
}
|
||||
public int getSkillLevel(RegisteredSkill skill) {
|
||||
return getSkillLevel(skill.getHandler().getId());
|
||||
}
|
||||
|
||||
public Set<String> getSkillKeys() {
|
||||
return skills.keySet();
|
||||
}
|
||||
public int getSkillLevel(String id) {
|
||||
return skills.get(id);
|
||||
}
|
||||
|
||||
public int getSkillLevel(RegisteredSkill skill) {
|
||||
return getSkillLevel(skill.getHandler().getId());
|
||||
}
|
||||
public void registerSkillLevel(RegisteredSkill skill, int level) {
|
||||
registerSkillLevel(skill.getHandler().getId(), level);
|
||||
}
|
||||
|
||||
public int getSkillLevel(String id) {
|
||||
return skills.get(id);
|
||||
}
|
||||
public void registerSkillLevel(String attribute, int level) {
|
||||
skills.put(attribute, level);
|
||||
}
|
||||
|
||||
public void registerSkillLevel(RegisteredSkill skill, int level) {
|
||||
registerSkillLevel(skill.getHandler().getId(), level);
|
||||
}
|
||||
public Set<String> getAttributeKeys() {
|
||||
return attributes.keySet();
|
||||
}
|
||||
|
||||
public void registerSkillLevel(String attribute, int level) {
|
||||
skills.put(attribute, level);
|
||||
}
|
||||
public int getAttributeLevel(PlayerAttribute attribute) {
|
||||
return getAttributeLevel(attribute.getId());
|
||||
}
|
||||
|
||||
public Set<String> getAttributeKeys() {
|
||||
return attributes.keySet();
|
||||
}
|
||||
public int getAttributeLevel(String id) {
|
||||
return attributes.get(id);
|
||||
}
|
||||
|
||||
public int getAttributeLevel(PlayerAttribute attribute) {
|
||||
return getAttributeLevel(attribute.getId());
|
||||
}
|
||||
public void registerAttributeLevel(PlayerAttribute attribute, int level) {
|
||||
registerAttributeLevel(attribute.getId(), level);
|
||||
}
|
||||
|
||||
public int getAttributeLevel(String id) {
|
||||
return attributes.get(id);
|
||||
}
|
||||
public void registerAttributeLevel(String attribute, int level) {
|
||||
attributes.put(attribute, level);
|
||||
}
|
||||
|
||||
public void registerAttributeLevel(PlayerAttribute attribute, int level) {
|
||||
registerAttributeLevel(attribute.getId(), level);
|
||||
}
|
||||
public void load(PlayerClass profess, PlayerData player) {
|
||||
|
||||
public void registerAttributeLevel(String attribute, int level) {
|
||||
attributes.put(attribute, level);
|
||||
}
|
||||
/*
|
||||
* saves current class info inside a SavedClassInformation, only if the
|
||||
* class is a real class and not the default one.
|
||||
*/
|
||||
if (!player.getProfess().hasOption(ClassOption.DEFAULT) || MMOCore.plugin.configManager.saveDefaultClassInfo)
|
||||
player.applyClassInfo(player.getProfess(), new SavedClassInformation(player));
|
||||
|
||||
public void load(PlayerClass profess, PlayerData player) {
|
||||
/*
|
||||
* resets information which much be reset after everything is saved.
|
||||
*/
|
||||
player.mapSkillLevels().forEach((skill, level) -> player.resetSkillLevel(skill));
|
||||
player.getAttributes().getInstances().forEach(ins -> ins.setBase(0));
|
||||
MMOCore.plugin.skillTreeManager.getAll().forEach(skillTree -> player.resetSkillTree(skillTree));
|
||||
while (player.hasSkillBound(0))
|
||||
player.unbindSkill(0);
|
||||
|
||||
/*
|
||||
* saves current class info inside a SavedClassInformation, only if the
|
||||
* class is a real class and not the default one.
|
||||
*/
|
||||
if (!player.getProfess().hasOption(ClassOption.DEFAULT) || MMOCore.plugin.configManager.saveDefaultClassInfo)
|
||||
player.applyClassInfo(player.getProfess(), new SavedClassInformation(player));
|
||||
/*
|
||||
* reads this class info, applies it to the player. set class after
|
||||
* changing level so the player stats can be calculated based on new
|
||||
* level.
|
||||
*/
|
||||
player.setLevel(level);
|
||||
player.setExperience(experience);
|
||||
player.setSkillPoints(skillPoints);
|
||||
player.setAttributePoints(attributePoints);
|
||||
player.setAttributeReallocationPoints(attributeReallocationPoints);
|
||||
player.setSkillTreeReallocationPoints(skillTreeReallocationPoints);
|
||||
player.setSkillReallocationPoints(skillReallocationPoints);
|
||||
|
||||
/*
|
||||
* resets information which much be reset after everything is saved.
|
||||
*/
|
||||
player.mapSkillLevels().forEach((skill, level) -> player.resetSkillLevel(skill));
|
||||
player.getAttributes().getInstances().forEach(ins -> ins.setBase(0));
|
||||
while (player.hasSkillBound(0))
|
||||
player.unbindSkill(0);
|
||||
(skills).forEach(player::setSkillLevel);
|
||||
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
|
||||
* everything is changed
|
||||
*/
|
||||
player.setClass(profess);
|
||||
player.unloadClassInfo(profess);
|
||||
|
||||
/*
|
||||
* reads this class info, applies it to the player. set class after
|
||||
* changing level so the player stats can be calculated based on new
|
||||
* level.
|
||||
*/
|
||||
player.setLevel(level);
|
||||
player.setExperience(experience);
|
||||
player.setSkillPoints(skillPoints);
|
||||
player.setAttributePoints(attributePoints);
|
||||
player.setAttributeReallocationPoints(attributeReallocationPoints);
|
||||
|
||||
skills.forEach(player::setSkillLevel);
|
||||
attributes.forEach((id, pts) -> player.getAttributes().setBaseAttribute(id, pts));
|
||||
|
||||
/*
|
||||
* unload current class information and set the new profess once
|
||||
* everything is changed
|
||||
*/
|
||||
player.setClass(profess);
|
||||
player.unloadClassInfo(profess);
|
||||
|
||||
// Updates level on exp bar
|
||||
player.refreshVanillaExp();
|
||||
}
|
||||
// Updates level on exp bar
|
||||
player.refreshVanillaExp();
|
||||
}
|
||||
}
|
||||
|
@ -382,12 +382,7 @@ public class SkillTreeViewer extends EditableInventory {
|
||||
//We remove all the nodeStates progress
|
||||
playerData.giveSkillTreePoints(skillTree.getId(), reallocated);
|
||||
playerData.giveSkillTreeReallocationPoints(-1);
|
||||
for (SkillTreeNode node : skillTree.getNodes()) {
|
||||
node.getExperienceTable().reset(playerData,node);
|
||||
playerData.setNodeLevel(node, 0);
|
||||
playerData.setNodeState(node, NodeState.LOCKED);
|
||||
|
||||
}
|
||||
playerData.resetSkillTree(skillTree);
|
||||
skillTree.setupNodeState(playerData);
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user