forked from Upstream/mmocore
Added option to have more than 1 skill tree point required for a certain some skill tree.
This commit is contained in:
parent
a54bfc03a0
commit
08b8239291
@ -207,7 +207,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int countSkillTreePoints(SkillTree skillTree) {
|
public int countSkillTreePoints(SkillTree skillTree) {
|
||||||
return nodeLevels.keySet().stream().filter(node -> node.getTree().equals(skillTree)).mapToInt(nodeLevels::get).sum();
|
return nodeLevels.keySet().stream().filter(node -> node.getTree().equals(skillTree)).mapToInt(node -> nodeLevels.get(node) * node.getSkillTreePointsConsumed()).sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -262,7 +262,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
|||||||
//Check the State of the node
|
//Check the State of the node
|
||||||
if (nodeStatus != NodeStatus.UNLOCKED && nodeStatus != NodeStatus.UNLOCKABLE)
|
if (nodeStatus != NodeStatus.UNLOCKED && nodeStatus != NodeStatus.UNLOCKABLE)
|
||||||
return false;
|
return false;
|
||||||
return getNodeLevel(node) < node.getMaxLevel() && (skillTreePoints.getOrDefault(node.getTree().getId(), 0) > 0 || skillTreePoints.getOrDefault("global", 0) > 0);
|
return getNodeLevel(node) < node.getMaxLevel() && (skillTreePoints.getOrDefault(node.getTree().getId(), 0) + skillTreePoints.getOrDefault("global", 0) >= node.getSkillTreePointsConsumed());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -277,10 +277,14 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
|||||||
|
|
||||||
if (nodeStates.get(node) == NodeStatus.UNLOCKABLE)
|
if (nodeStates.get(node) == NodeStatus.UNLOCKABLE)
|
||||||
setNodeState(node, NodeStatus.UNLOCKED);
|
setNodeState(node, NodeStatus.UNLOCKED);
|
||||||
if (skillTreePoints.get(node.getTree().getId()) > 0)
|
int pointToWithdraw = node.getSkillTreePointsConsumed();
|
||||||
withdrawSkillTreePoints(node.getTree().getId(), 1);
|
if (skillTreePoints.get(node.getTree().getId()) > 0) {
|
||||||
else
|
int pointWithdrawn = Math.min(pointToWithdraw, skillTreePoints.get(node.getTree().getId()));
|
||||||
withdrawSkillTreePoints("global", 1);
|
withdrawSkillTreePoints(node.getTree().getId(), pointWithdrawn);
|
||||||
|
pointToWithdraw -= pointWithdrawn;
|
||||||
|
}
|
||||||
|
if (pointToWithdraw > 0)
|
||||||
|
withdrawSkillTreePoints("global", pointToWithdraw);
|
||||||
//We unload the nodeStates map (for the skill tree) and reload it completely
|
//We unload the nodeStates map (for the skill tree) and reload it completely
|
||||||
for (SkillTreeNode node1 : node.getTree().getNodes())
|
for (SkillTreeNode node1 : node.getTree().getNodes())
|
||||||
nodeStates.remove(node1);
|
nodeStates.remove(node1);
|
||||||
@ -950,7 +954,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getHealth() {
|
public double getHealth() {
|
||||||
return isOnline() ? getPlayer().getHealth():health ;
|
return isOnline() ? getPlayer().getHealth() : health;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,6 +22,10 @@ public class SkillTreeNode implements ExperienceObject {
|
|||||||
private final SkillTree tree;
|
private final SkillTree tree;
|
||||||
private final String name, id;
|
private final String name, id;
|
||||||
private IntegerCoordinates coordinates;
|
private IntegerCoordinates coordinates;
|
||||||
|
/**
|
||||||
|
* The number of skill tree points this node requires.
|
||||||
|
*/
|
||||||
|
private final int skillTreePointsConsumed;
|
||||||
private boolean isRoot;
|
private boolean isRoot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,7 +60,8 @@ public class SkillTreeNode implements 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);
|
||||||
|
skillTreePointsConsumed=config.getInt("skill-tree-points",1);
|
||||||
|
Validate.isTrue(skillTreePointsConsumed>0,"The skill tree points consumed by a node must be greater than 0.");
|
||||||
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 {
|
||||||
@ -100,6 +105,10 @@ public class SkillTreeNode implements ExperienceObject {
|
|||||||
children.add(child);
|
children.add(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getSkillTreePointsConsumed() {
|
||||||
|
return skillTreePointsConsumed;
|
||||||
|
}
|
||||||
|
|
||||||
public void setCoordinates(IntegerCoordinates coordinates) {
|
public void setCoordinates(IntegerCoordinates coordinates) {
|
||||||
this.coordinates = coordinates;
|
this.coordinates = coordinates;
|
||||||
}
|
}
|
||||||
@ -112,6 +121,7 @@ public class SkillTreeNode implements ExperienceObject {
|
|||||||
return softParents.containsKey(parent) || strongParents.containsKey(parent);
|
return softParents.containsKey(parent) || strongParents.containsKey(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getMaxLevel() {
|
public int getMaxLevel() {
|
||||||
return maxLevel;
|
return maxLevel;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user