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,178 +5,207 @@ 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");
|
||||||
experience = config.getDouble("experience");
|
experience = config.getDouble("experience");
|
||||||
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<>();
|
||||||
|
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) {
|
public SavedClassInformation(JsonObject json) {
|
||||||
level = json.get("level").getAsInt();
|
level = json.get("level").getAsInt();
|
||||||
experience = json.get("experience").getAsDouble();
|
experience = json.get("experience").getAsDouble();
|
||||||
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<>();
|
||||||
|
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<>();
|
public SavedClassInformation(PlayerData player) {
|
||||||
if (json.has("attribute"))
|
this(player.getLevel(), player.getExperience(), player.getSkillPoints(), player.getAttributePoints(), player.getAttributeReallocationPoints()
|
||||||
for (Entry<String, JsonElement> entry : json.getAsJsonObject("attribute").entrySet())
|
,player.getSkillTreeReallocationPoints(),player.getSkillReallocationPoints(),
|
||||||
attributes.put(entry.getKey(), entry.getValue().getAsInt());
|
player.getAttributes().mapPoints(), player.mapSkillLevels(), player.getSkillTreePoints(), player.getNodeLevels());
|
||||||
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(PlayerDataManager.DefaultPlayerData data) {
|
||||||
|
this(data.getLevel(), 0, data.getSkillPoints(), data.getAttributePoints(), data.getAttrReallocPoints(),data.getSkillTreeReallocPoints(),data.getSkillReallocPoints());
|
||||||
|
}
|
||||||
|
|
||||||
public SavedClassInformation(PlayerData player) {
|
public SavedClassInformation(int level, double experience, int skillPoints, int attributePoints, int attributeReallocationPoints,int skillTreeReallocationPoints,int skillReallocationPoints) {
|
||||||
this(player.getLevel(), player.getExperience(), player.getSkillPoints(), player.getAttributePoints(), player.getAttributeReallocationPoints(),
|
this(level, experience, skillPoints, attributePoints, attributeReallocationPoints,skillTreeReallocationPoints,skillReallocationPoints, new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>());
|
||||||
player.getAttributes().mapPoints(), player.mapSkillLevels());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public SavedClassInformation(PlayerDataManager.DefaultPlayerData data) {
|
public SavedClassInformation(int level, double experience, int skillPoints, int attributePoints, int attributeReallocationPoints, int skillTreeReallocationPoints, int skillReallocationPoints,
|
||||||
this(data.getLevel(), 0, data.getSkillPoints(), data.getAttributePoints(), data.getAttrReallocPoints());
|
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) {
|
public int getLevel() {
|
||||||
this(level, experience, skillPoints, attributePoints, attributeReallocationPoints, new HashMap<>(), new HashMap<>());
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SavedClassInformation(int level, double experience, int skillPoints, int attributePoints, int attributeReallocationPoints,
|
public double getExperience() {
|
||||||
Map<String, Integer> attributes, Map<String, Integer> skills) {
|
return experience;
|
||||||
this.level = level;
|
}
|
||||||
this.experience = experience;
|
|
||||||
this.skillPoints = skillPoints;
|
|
||||||
this.attributePoints = attributePoints;
|
|
||||||
this.attributeReallocationPoints = attributeReallocationPoints;
|
|
||||||
this.attributes = attributes;
|
|
||||||
this.skills = skills;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLevel() {
|
public int getSkillPoints() {
|
||||||
return level;
|
return skillPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getExperience() {
|
public int getAttributePoints() {
|
||||||
return experience;
|
return attributePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSkillPoints() {
|
public int getAttributeReallocationPoints() {
|
||||||
return skillPoints;
|
return attributeReallocationPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAttributePoints() {
|
public Set<String> getSkillKeys() {
|
||||||
return attributePoints;
|
return skills.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAttributeReallocationPoints() {
|
public int getSkillLevel(RegisteredSkill skill) {
|
||||||
return attributeReallocationPoints;
|
return getSkillLevel(skill.getHandler().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getSkillKeys() {
|
public int getSkillLevel(String id) {
|
||||||
return skills.keySet();
|
return skills.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSkillLevel(RegisteredSkill skill) {
|
public void registerSkillLevel(RegisteredSkill skill, int level) {
|
||||||
return getSkillLevel(skill.getHandler().getId());
|
registerSkillLevel(skill.getHandler().getId(), level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSkillLevel(String id) {
|
public void registerSkillLevel(String attribute, int level) {
|
||||||
return skills.get(id);
|
skills.put(attribute, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerSkillLevel(RegisteredSkill skill, int level) {
|
public Set<String> getAttributeKeys() {
|
||||||
registerSkillLevel(skill.getHandler().getId(), level);
|
return attributes.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerSkillLevel(String attribute, int level) {
|
public int getAttributeLevel(PlayerAttribute attribute) {
|
||||||
skills.put(attribute, level);
|
return getAttributeLevel(attribute.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getAttributeKeys() {
|
public int getAttributeLevel(String id) {
|
||||||
return attributes.keySet();
|
return attributes.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAttributeLevel(PlayerAttribute attribute) {
|
public void registerAttributeLevel(PlayerAttribute attribute, int level) {
|
||||||
return getAttributeLevel(attribute.getId());
|
registerAttributeLevel(attribute.getId(), level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAttributeLevel(String id) {
|
public void registerAttributeLevel(String attribute, int level) {
|
||||||
return attributes.get(id);
|
attributes.put(attribute, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerAttributeLevel(PlayerAttribute attribute, int level) {
|
public void load(PlayerClass profess, PlayerData player) {
|
||||||
registerAttributeLevel(attribute.getId(), level);
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
* reads this class info, applies it to the player. set class after
|
||||||
* class is a real class and not the default one.
|
* changing level so the player stats can be calculated based on new
|
||||||
*/
|
* level.
|
||||||
if (!player.getProfess().hasOption(ClassOption.DEFAULT) || MMOCore.plugin.configManager.saveDefaultClassInfo)
|
*/
|
||||||
player.applyClassInfo(player.getProfess(), new SavedClassInformation(player));
|
player.setLevel(level);
|
||||||
|
player.setExperience(experience);
|
||||||
|
player.setSkillPoints(skillPoints);
|
||||||
|
player.setAttributePoints(attributePoints);
|
||||||
|
player.setAttributeReallocationPoints(attributeReallocationPoints);
|
||||||
|
player.setSkillTreeReallocationPoints(skillTreeReallocationPoints);
|
||||||
|
player.setSkillReallocationPoints(skillReallocationPoints);
|
||||||
|
|
||||||
/*
|
(skills).forEach(player::setSkillLevel);
|
||||||
* resets information which much be reset after everything is saved.
|
attributes.forEach((id, pts) -> player.getAttributes().setBaseAttribute(id, pts));
|
||||||
*/
|
skillTreePoints.forEach((skillTree, point) -> player.setSkillTreePoints(skillTree, point));
|
||||||
player.mapSkillLevels().forEach((skill, level) -> player.resetSkillLevel(skill));
|
nodeLevels.forEach((node, level) -> player.setNodeLevel(node, level));
|
||||||
player.getAttributes().getInstances().forEach(ins -> ins.setBase(0));
|
/*
|
||||||
while (player.hasSkillBound(0))
|
* unload current class information and set the new profess once
|
||||||
player.unbindSkill(0);
|
* everything is changed
|
||||||
|
*/
|
||||||
|
player.setClass(profess);
|
||||||
|
player.unloadClassInfo(profess);
|
||||||
|
|
||||||
/*
|
// Updates level on exp bar
|
||||||
* reads this class info, applies it to the player. set class after
|
player.refreshVanillaExp();
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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