Added max-point-spent for Skill Trees + Debug

This commit is contained in:
Ka0rX 2022-09-03 18:37:18 +02:00
parent 647865bdd3
commit f11caa17d4
5 changed files with 74 additions and 10 deletions

View File

@ -93,7 +93,10 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
private final PlayerAttributes attributes = new PlayerAttributes(this);
private final Map<String, SavedClassInformation> classSlots = new HashMap<>();
private final Map<PlayerActivity, Long> lastActivity = new HashMap<>();
/**
* Maps each skill tree to the number of points spent in it. Just in cache memory.
*/
private final HashMap<SkillTree,Integer> pointSpent= new HashMap<>();
private final Map<SkillTreeNode, Integer> nodeLevels = new HashMap<>();
private final Map<SkillTreeNode, NodeState> nodeStates = new HashMap<>();
private final Map<String, Integer> skillTreePoints = new HashMap<>();
@ -176,9 +179,14 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
public void setupNodeState() {
for (SkillTree skillTree : MMOCore.plugin.skillTreeManager.getAll())
skillTree.setupNodeState(this);
}
public int getPointSpent(SkillTree skillTree) {
return pointSpent.get(skillTree);
}
public void setSkillTreePoints(String treeId, int points) {
skillTreePoints.put(treeId, points);
}
@ -288,6 +296,8 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
}
public void setNodeLevel(SkillTreeNode node, int nodeLevel) {
int delta=nodeLevel-nodeLevels.getOrDefault(node,0);
pointSpent.put(node.getTree(),pointSpent.getOrDefault(node.getTree(),0)+delta);
nodeLevels.put(node, nodeLevel);
}

View File

@ -60,7 +60,10 @@ public class SkillTreeViewer extends EditableInventory {
holders.register("skill-tree-points", inv.getPlayerData().getSkillTreePoint(inv.getSkillTree().getId()));
holders.register("global-points", inv.getPlayerData().getSkillTreePoint("global"));
holders.register("realloc-points", inv.getPlayerData().getSkillTreeReallocationPoints());
holders.register("total", inv.getPlayerData().countSkillTreePoints(inv.getSkillTree()));
int maxPointSpent=inv.getSkillTree().getMaxPointSpent();
holders.register("max-point-spent",maxPointSpent==Integer.MAX_VALUE?"":maxPointSpent);
holders.register("point-spent",inv.getPlayerData().getPointSpent(inv.getSkillTree()));
return holders;
}
};
@ -131,6 +134,9 @@ public class SkillTreeViewer extends EditableInventory {
Placeholders holders = new Placeholders();
holders.register("name", skillTree.getName());
holders.register("id", skillTree.getId());
int maxPointSpent=inv.getSkillTree().getMaxPointSpent();
holders.register("max-point-spent",maxPointSpent==Integer.MAX_VALUE?"":maxPointSpent);
holders.register("point-spent",inv.getPlayerData().getPointSpent(inv.getSkillTree()));
holders.register("skill-tree-points", inv.getPlayerData().getSkillTreePoint(inv.getSkillTree().getId()));
holders.register("global-points", inv.getPlayerData().getSkillTreePoint("global"));
return holders;
@ -244,6 +250,9 @@ public class SkillTreeViewer extends EditableInventory {
holders.register("max-children", node.getMaxChildren());
holders.register("size", node.getSize());
}
int maxPointSpent=inv.getSkillTree().getMaxPointSpent();
holders.register("max-point-spent",maxPointSpent==Integer.MAX_VALUE?"":maxPointSpent);
holders.register("point-spent",inv.getPlayerData().getPointSpent(inv.getSkillTree()));
holders.register("skill-tree-points", inv.getPlayerData().getSkillTreePoint(inv.getSkillTree().getId()));
holders.register("global-points", inv.getPlayerData().getSkillTreePoint("global"));
return holders;
@ -408,6 +417,14 @@ public class SkillTreeViewer extends EditableInventory {
return;
}
SkillTreeNode node = skillTree.getNode(new IntegerCoordinates(x, y));
if(playerData.getPointSpent(skillTree)>= skillTree.getMaxPointSpent()) {
MMOCore.plugin.configManager.getSimpleMessage("max-points-reached").send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
event.setCancelled(true);
return;
}
if (playerData.canIncrementNodeLevel(node)) {
playerData.incrementNodeLevel(node);
MMOCore.plugin.configManager.getSimpleMessage("upgrade-skill-node", "skill-node", node.getName(), "level", "" + playerData.getNodeLevel(node)).send(player);

View File

@ -12,7 +12,6 @@ import net.Indyuce.mmocore.tree.skilltree.display.Icon;
import net.Indyuce.mmocore.tree.IntegerCoordinates;
import net.Indyuce.mmocore.tree.SkillTreeNode;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
@ -48,6 +47,7 @@ public abstract class SkillTree extends PostLoadObject implements RegisteredObje
//Represents all the nodes
protected final Map<IntegerCoordinates, SkillTreeNode> coordinatesNodes = new HashMap<>();
protected final Map<String, SkillTreeNode> nodes = new HashMap<>();
protected final int maxPointSpent;
//Caches the height of the skill tree
protected int minX, minY, maxX, maxY;
protected final HashMap<DisplayInfo, Icon> icons = new HashMap<>();
@ -61,7 +61,7 @@ public abstract class SkillTree extends PostLoadObject implements RegisteredObje
Objects.requireNonNull(config.getStringList("lore"), "Could not find skill tree lore").forEach(str -> lore.add(MythicLib.plugin.parseColors(str)));
this.item = Material.valueOf(UtilityMethods.enumName(Objects.requireNonNull(config.getString("item"))));
Validate.isTrue(config.isConfigurationSection("nodes"), "Could not find any nodes in the tree");
this.maxPointSpent =config.getInt("max-point-spent",Integer.MAX_VALUE);
for (String key : config.getConfigurationSection("nodes").getKeys(false)) {
try {
@ -147,6 +147,10 @@ public abstract class SkillTree extends PostLoadObject implements RegisteredObje
return lore;
}
public int getMaxPointSpent() {
return maxPointSpent;
}
public static SkillTree loadSkillTree(ConfigurationSection config) {
SkillTree skillTree = null;
@ -222,7 +226,7 @@ public abstract class SkillTree extends PostLoadObject implements RegisteredObje
for (SkillTreeNode softParent : node.getSoftParents()) {
if (playerData.getNodeLevel(softParent) > node.getParentNeededLevel(softParent)) {
if (playerData.getNodeLevel(softParent) >= node.getParentNeededLevel(softParent)) {
isUnlockableFromSoftParent = true;
}
//We count the number of children the parent

View File

@ -6,6 +6,32 @@ name: '&eCurrent Skill Tree: &6{skill-tree-name}'
slots: 54
items:
up:
function: up
item: PLAYER_HEAD
name: "Up"
texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTk5YWFmMjQ1NmE2MTIyZGU4ZjZiNjI2ODNmMmJjMmVlZDlhYmI4MWZkNWJlYTFiNGMyM2E1ODE1NmI2NjkifX19
slots: [ 52 ]
down:
function: down
item: PLAYER_HEAD
name: "Down"
texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzkxMmQ0NWIxYzc4Y2MyMjQ1MjcyM2VlNjZiYTJkMTU3NzdjYzI4ODU2OGQ2YzFiNjJhNTQ1YjI5YzcxODcifX19
slots: [ 51 ]
right:
function: right
item: PLAYER_HEAD
name: "Right"
texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTNmYzUyMjY0ZDhhZDllNjU0ZjQxNWJlZjAxYTIzOTQ3ZWRiY2NjY2Y2NDkzNzMyODliZWE0ZDE0OTU0MWY3MCJ9fX0=
slots: [ 50 ]
left:
function: left
item: PLAYER_HEAD
name: "Left"
texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWYxMzNlOTE5MTlkYjBhY2VmZGMyNzJkNjdmZDg3YjRiZTg4ZGM0NGE5NTg5NTg4MjQ0NzRlMjFlMDZkNTNlNiJ9fX0=
slots: [ 49 ]
skill-tree:
name: '{skill-tree-node}'
function: skill-tree
@ -16,17 +42,21 @@ items:
- '{tree-lore}'
- ''
- '--------------------'
- '&e◆Max points&e: &6{max-point-spent}'
- '&e◆Points spent&e:&6 {point-spent}'
- '&e◆Current {name} &epoints: &6{skill-tree-points}'
- '&e◆Current Global points: &6{global-points}'
next-tree-list-page:
function: 'next-tree-list-page'
item: ARROW
name: "Next Page"
slots: [ 36 ]
previous-tree-list-page:
function: 'previous-tree-list-page'
item: 'ARROW'
name: "Previous Page"
slots: [ 0 ]
reallocation:
@ -36,7 +66,8 @@ items:
name: '&aReallocate Skill Tree Points'
lore:
- ''
- 'You have spent a total of &6{total}&7 skill tree points.'
- '&7You have spent a total of &6{point-spent}&7 skill tree points.'
- '&7The maximum points that can be spent is: &6{max-point-spent}'
- '&7Right click to reallocate them.'
- ''
- '&eCosts 1 attribute reallocation point.'
@ -63,6 +94,8 @@ items:
- '--------------------'
- '{node-lore}'
- '--------------------'
- '&eCurrent {skill-tree} &epoints: &6{skill-tree-points}'
- '&eCurrent global points: &6{global-points}'
- '&e◆Max points for {skill-tree}&e: &6{max-point-spent}'
- '&e◆Points spent for {skill-tree}&e:&6 {point-spent}'
- '&e◆Current {skill-tree} &epoints: &6{skill-tree-points}'
- '&e◆Current &6global&e points: &6{global-points}'

View File

@ -176,7 +176,7 @@ no-skill-placeholder: 'No Skill Bound'
not-skill-reallocation-point: '&cYou do not have 1 skill reallocation point.'
no-skill-points-spent: '&cYou have not spent any skill points.'
skill-points-reallocated: '&eYou successfully reset your attributes. You now have &6{points} &eskill points.'
max-points-reached: '&cYou reached the maximum points you can spend. You need to reallocate your points to rollback.'
# Skill Trees
no-skill-tree-points-spent: '&cYou have not spent any skill tree points.'
locked-node: '&cThis skill is locked!'