forked from Upstream/mmocore
Fixed issue #892 regarding path issues for skill trees.
This commit is contained in:
parent
83dcba2c0a
commit
4a22e0a357
@ -45,16 +45,16 @@ public class SkillTreeViewer extends EditableInventory {
|
|||||||
* A null skillTree means the global skill tree view is opened.
|
* A null skillTree means the global skill tree view is opened.
|
||||||
* Else this GUI represents a specific skill tree.
|
* Else this GUI represents a specific skill tree.
|
||||||
*/
|
*/
|
||||||
private final SkillTree skillTree;
|
private final SkillTree defaultSkillTree;
|
||||||
|
|
||||||
public SkillTreeViewer() {
|
public SkillTreeViewer() {
|
||||||
super("skill-tree");
|
super("skill-tree");
|
||||||
this.skillTree = null;
|
this.defaultSkillTree = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SkillTreeViewer(SkillTree skillTree, boolean isDefault) {
|
public SkillTreeViewer(SkillTree defaultSkillTree, boolean isDefault) {
|
||||||
super("specific-skill-tree-" + (isDefault ? "default" : UtilityMethods.ymlName(skillTree.getId())));
|
super("specific-skill-tree-" + (isDefault ? "default" : UtilityMethods.ymlName(defaultSkillTree.getId())));
|
||||||
this.skillTree = skillTree;
|
this.defaultSkillTree = defaultSkillTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -128,7 +128,7 @@ public class SkillTreeViewer extends EditableInventory {
|
|||||||
|
|
||||||
|
|
||||||
public SkillTreeInventory newInventory(PlayerData playerData) {
|
public SkillTreeInventory newInventory(PlayerData playerData) {
|
||||||
return new SkillTreeInventory(playerData, this, skillTree);
|
return new SkillTreeInventory(playerData, this, defaultSkillTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -242,7 +242,7 @@ public class SkillTreeViewer extends EditableInventory {
|
|||||||
@Override
|
@Override
|
||||||
public ItemStack display(SkillTreeInventory inv, int n) {
|
public ItemStack display(SkillTreeInventory inv, int n) {
|
||||||
IntegerCoordinates coordinates = inv.getCoordinates(n);
|
IntegerCoordinates coordinates = inv.getCoordinates(n);
|
||||||
if (inv.getSkillTree().isNode(coordinates) || inv.getSkillTree().isPath(coordinates)) {
|
if (inv.getSkillTree().isPathOrNode(coordinates)) {
|
||||||
Icon icon = inv.getIcon(coordinates);
|
Icon icon = inv.getIcon(coordinates);
|
||||||
ItemStack item = super.display(inv, n, icon.getMaterial(), icon.getCustomModelData());
|
ItemStack item = super.display(inv, n, icon.getMaterial(), icon.getCustomModelData());
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
@ -299,7 +299,8 @@ public class SkillTreeViewer extends EditableInventory {
|
|||||||
public Placeholders getPlaceholders(SkillTreeInventory inv, int n) {
|
public Placeholders getPlaceholders(SkillTreeInventory inv, int n) {
|
||||||
Placeholders holders = new Placeholders();
|
Placeholders holders = new Placeholders();
|
||||||
holders.register("skill-tree", inv.getSkillTree().getName());
|
holders.register("skill-tree", inv.getSkillTree().getName());
|
||||||
if (inv.getSkillTree().isNode(inv.getCoordinates(n))) {
|
boolean isNode = inv.getSkillTree().isNode(inv.getCoordinates(n));
|
||||||
|
if (isNode) {
|
||||||
SkillTreeNode node = inv.getNode(n);
|
SkillTreeNode node = inv.getNode(n);
|
||||||
holders.register("current-level", inv.getPlayerData().getNodeLevel(node));
|
holders.register("current-level", inv.getPlayerData().getNodeLevel(node));
|
||||||
SkillTreeStatus status = inv.getPlayerData().getNodeStatus(node);
|
SkillTreeStatus status = inv.getPlayerData().getNodeStatus(node);
|
||||||
@ -308,13 +309,15 @@ public class SkillTreeViewer extends EditableInventory {
|
|||||||
holders.register("max-children", node.getMaxChildren());
|
holders.register("max-children", node.getMaxChildren());
|
||||||
holders.register("size", node.getSize());
|
holders.register("size", node.getSize());
|
||||||
holders.register("point-consumed", node.getSkillTreePointsConsumed());
|
holders.register("point-consumed", node.getSkillTreePointsConsumed());
|
||||||
|
holders.register("display-type", node.getNodeType());
|
||||||
|
} else {
|
||||||
|
holders.register("display-type", inv.skillTree.getPath(inv.getCoordinates(n)).getPathType());
|
||||||
}
|
}
|
||||||
int maxPointSpent = inv.getSkillTree().getMaxPointSpent();
|
int maxPointSpent = inv.getSkillTree().getMaxPointSpent();
|
||||||
holders.register("max-point-spent", maxPointSpent == Integer.MAX_VALUE ? "∞" : maxPointSpent);
|
holders.register("max-point-spent", maxPointSpent == Integer.MAX_VALUE ? "∞" : maxPointSpent);
|
||||||
holders.register("point-spent", inv.getPlayerData().getPointSpent(inv.getSkillTree()));
|
holders.register("point-spent", inv.getPlayerData().getPointSpent(inv.getSkillTree()));
|
||||||
holders.register("skill-tree-points", inv.getPlayerData().getSkillTreePoint(inv.getSkillTree().getId()));
|
holders.register("skill-tree-points", inv.getPlayerData().getSkillTreePoint(inv.getSkillTree().getId()));
|
||||||
holders.register("global-points", inv.getPlayerData().getSkillTreePoint("global"));
|
holders.register("global-points", inv.getPlayerData().getSkillTreePoint("global"));
|
||||||
holders.register("display-type", inv.getDisplayType(inv.getCoordinates(n)));
|
|
||||||
|
|
||||||
return holders;
|
return holders;
|
||||||
}
|
}
|
||||||
@ -375,22 +378,10 @@ public class SkillTreeViewer extends EditableInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public DisplayType getDisplayType(IntegerCoordinates coordinates) {
|
|
||||||
Validate.isTrue(skillTree.isNode(coordinates), "The coordinates must be a node");
|
|
||||||
boolean hasUpPathOrNode = skillTree.isPathOrNode(new IntegerCoordinates(coordinates.getX(), coordinates.getY() - 1));
|
|
||||||
boolean hasDownPathOrNode = skillTree.isPathOrNode(new IntegerCoordinates(coordinates.getX(), coordinates.getY() + 1));
|
|
||||||
boolean hasRightPathOrNode = skillTree.isPathOrNode(new IntegerCoordinates(coordinates.getX() + 1, coordinates.getY()));
|
|
||||||
boolean hasLeftPathOrNode = skillTree.isPathOrNode(new IntegerCoordinates(coordinates.getX() - 1, coordinates.getY()));
|
|
||||||
if (skillTree.isNode(coordinates))
|
|
||||||
return NodeType.getNodeType(hasUpPathOrNode, hasRightPathOrNode, hasDownPathOrNode, hasLeftPathOrNode);
|
|
||||||
return PathType.getPathType(hasUpPathOrNode, hasRightPathOrNode, hasDownPathOrNode, hasLeftPathOrNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Icon getIcon(IntegerCoordinates coordinates) {
|
public Icon getIcon(IntegerCoordinates coordinates) {
|
||||||
DisplayType displayType = getDisplayType(coordinates);
|
|
||||||
if (skillTree.isNode(coordinates)) {
|
if (skillTree.isNode(coordinates)) {
|
||||||
NodeType nodeType = (NodeType) displayType;
|
|
||||||
SkillTreeNode node = skillTree.getNode(coordinates);
|
SkillTreeNode node = skillTree.getNode(coordinates);
|
||||||
|
NodeType nodeType = node.getNodeType();
|
||||||
SkillTreeStatus skillTreeStatus = playerData.getNodeStatus(node);
|
SkillTreeStatus skillTreeStatus = playerData.getNodeStatus(node);
|
||||||
//If the node has its own display, it will be shown.
|
//If the node has its own display, it will be shown.
|
||||||
if (node.hasIcon(skillTreeStatus))
|
if (node.hasIcon(skillTreeStatus))
|
||||||
@ -404,14 +395,15 @@ public class SkillTreeViewer extends EditableInventory {
|
|||||||
Validate.notNull(icon, "The node " + node.getFullId() + " has no icon for the type " + nodeType + " and the status " + skillTreeStatus);
|
Validate.notNull(icon, "The node " + node.getFullId() + " has no icon for the type " + nodeType + " and the status " + skillTreeStatus);
|
||||||
return icon;
|
return icon;
|
||||||
} else {
|
} else {
|
||||||
PathType pathType = (PathType) displayType;
|
|
||||||
SkillTreePath path = skillTree.getPath(coordinates);
|
SkillTreePath path = skillTree.getPath(coordinates);
|
||||||
DisplayInfo displayInfo = new PathDisplayInfo(pathType, path.getStatus(playerData));
|
PathType pathType = path.getPathType();
|
||||||
|
PathStatus pathStatus = path.getStatus(playerData);
|
||||||
|
DisplayInfo displayInfo = new PathDisplayInfo(pathType, pathStatus);
|
||||||
//Takes the display defined in the skill tree config if it exists.
|
//Takes the display defined in the skill tree config if it exists.
|
||||||
if (skillTree.hasIcon(displayInfo))
|
if (skillTree.hasIcon(displayInfo))
|
||||||
return skillTree.getIcon(displayInfo);
|
return skillTree.getIcon(displayInfo);
|
||||||
Icon icon = icons.get(displayInfo);
|
Icon icon = icons.get(displayInfo);
|
||||||
Validate.notNull(icon, "There is no icon for the path type " + pathType + " and the status " + path.getStatus(playerData));
|
Validate.notNull(icon, "There is no icon for the path type " + pathType + " and the status " + pathStatus);
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,24 +17,5 @@ public enum PathType implements DisplayType {
|
|||||||
|
|
||||||
DEFAULT;
|
DEFAULT;
|
||||||
|
|
||||||
public static PathType getPathType(boolean hasUp,boolean hasRight,boolean hasDown,boolean hasLeft) {
|
|
||||||
if ((hasUp || hasDown) && !hasLeft && !hasRight) {
|
|
||||||
return UP;
|
|
||||||
} else if ((hasRight || hasLeft)&& !hasUp && !hasDown) {
|
|
||||||
return RIGHT;
|
|
||||||
} else if (hasUp && hasRight) {
|
|
||||||
return UP_RIGHT;
|
|
||||||
}
|
|
||||||
else if (hasUp && hasLeft) {
|
|
||||||
return UP_LEFT;
|
|
||||||
}
|
|
||||||
else if (hasDown && hasRight) {
|
|
||||||
return DOWN_RIGHT;
|
|
||||||
}
|
|
||||||
else if (hasDown && hasLeft) {
|
|
||||||
return DOWN_LEFT;
|
|
||||||
}
|
|
||||||
return DEFAULT;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import net.Indyuce.mmocore.experience.ExperienceObject;
|
|||||||
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
|
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
|
||||||
import net.Indyuce.mmocore.gui.api.item.Placeholders;
|
import net.Indyuce.mmocore.gui.api.item.Placeholders;
|
||||||
import net.Indyuce.mmocore.gui.skilltree.display.Icon;
|
import net.Indyuce.mmocore.gui.skilltree.display.Icon;
|
||||||
|
import net.Indyuce.mmocore.gui.skilltree.display.NodeType;
|
||||||
import net.Indyuce.mmocore.skilltree.tree.ParentInformation;
|
import net.Indyuce.mmocore.skilltree.tree.ParentInformation;
|
||||||
import net.Indyuce.mmocore.skilltree.tree.SkillTree;
|
import net.Indyuce.mmocore.skilltree.tree.SkillTree;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
@ -228,6 +229,15 @@ public class SkillTreeNode implements ExperienceObject {
|
|||||||
return experienceTable != null;
|
return experienceTable != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NodeType getNodeType() {
|
||||||
|
boolean hasUpPathOrNode = tree.isPathOrNode(new IntegerCoordinates(coordinates.getX(), coordinates.getY() - 1));
|
||||||
|
boolean hasDownPathOrNode = tree.isPathOrNode(new IntegerCoordinates(coordinates.getX(), coordinates.getY() + 1));
|
||||||
|
boolean hasRightPathOrNode = tree.isPathOrNode(new IntegerCoordinates(coordinates.getX() + 1, coordinates.getY()));
|
||||||
|
boolean hasLeftPathOrNode = tree.isPathOrNode(new IntegerCoordinates(coordinates.getX() - 1, coordinates.getY()));
|
||||||
|
return NodeType.getNodeType(hasUpPathOrNode, hasRightPathOrNode, hasDownPathOrNode, hasLeftPathOrNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
@ -2,6 +2,7 @@ package net.Indyuce.mmocore.skilltree;
|
|||||||
|
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.gui.skilltree.display.PathStatus;
|
import net.Indyuce.mmocore.gui.skilltree.display.PathStatus;
|
||||||
|
import net.Indyuce.mmocore.gui.skilltree.display.PathType;
|
||||||
import net.Indyuce.mmocore.skilltree.tree.SkillTree;
|
import net.Indyuce.mmocore.skilltree.tree.SkillTree;
|
||||||
|
|
||||||
public record SkillTreePath(SkillTree tree, IntegerCoordinates coordinates, SkillTreeNode from, SkillTreeNode to) {
|
public record SkillTreePath(SkillTree tree, IntegerCoordinates coordinates, SkillTreeNode from, SkillTreeNode to) {
|
||||||
@ -18,5 +19,31 @@ public record SkillTreePath(SkillTree tree, IntegerCoordinates coordinates, Skil
|
|||||||
return PathStatus.LOCKED;
|
return PathStatus.LOCKED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PathType getPathType() {
|
||||||
|
IntegerCoordinates upCoor = new IntegerCoordinates(coordinates.getX(), coordinates.getY() - 1);
|
||||||
|
IntegerCoordinates downCoor = new IntegerCoordinates(coordinates.getX(), coordinates.getY() + 1);
|
||||||
|
IntegerCoordinates rightCoor = new IntegerCoordinates(coordinates.getX() + 1, coordinates.getY());
|
||||||
|
IntegerCoordinates leftCoor = new IntegerCoordinates(coordinates.getX() - 1, coordinates.getY());
|
||||||
|
boolean hasUp = tree.isPath(upCoor) || upCoor.equals(from.getCoordinates()) || upCoor.equals(to.getCoordinates());
|
||||||
|
boolean hasDown = tree.isPath(downCoor) || downCoor.equals(from.getCoordinates()) || downCoor.equals(to.getCoordinates());
|
||||||
|
boolean hasRight = tree.isPath(rightCoor) || rightCoor.equals(from.getCoordinates()) || rightCoor.equals(to.getCoordinates());
|
||||||
|
boolean hasLeft = tree.isPath(leftCoor) || leftCoor.equals(from.getCoordinates()) || leftCoor.equals(to.getCoordinates());
|
||||||
|
|
||||||
|
if ((hasUp || hasDown) && !hasLeft && !hasRight) {
|
||||||
|
return PathType.UP;
|
||||||
|
} else if ((hasRight || hasLeft) && !hasUp && !hasDown) {
|
||||||
|
return PathType.RIGHT;
|
||||||
|
} else if (hasUp && hasRight) {
|
||||||
|
return PathType.UP_RIGHT;
|
||||||
|
} else if (hasUp && hasLeft) {
|
||||||
|
return PathType.UP_LEFT;
|
||||||
|
} else if (hasDown && hasRight) {
|
||||||
|
return PathType.DOWN_RIGHT;
|
||||||
|
} else if (hasDown && hasLeft) {
|
||||||
|
return PathType.DOWN_LEFT;
|
||||||
|
}
|
||||||
|
return PathType.DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user