can-manually-bind option for SkillSlots and possibility to bind/unbind a skill to a slot through /mmocore admin slot bind <slot> <skill>.

This commit is contained in:
Ka0rX 2023-04-04 14:58:14 +01:00
parent 015f4544ce
commit 943553632b
7 changed files with 104 additions and 8 deletions

View File

@ -111,7 +111,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
if (config.contains("skill-slots." + i))
skillSlots.put(i, new SkillSlot(config.getConfigurationSection("skill-slots." + i)));
else
skillSlots.put(i, new SkillSlot(i, 0, "true", "&eSkill Slot " + MMOCoreUtils.intToRoman(i), new ArrayList<>(), false, new ArrayList<>()));
skillSlots.put(i, new SkillSlot(i, 0, "true", "&eSkill Slot " + MMOCoreUtils.intToRoman(i), new ArrayList<>(), false, true, new ArrayList<>()));
}
for (String string : config.getStringList("display.lore"))
description.add(ChatColor.GRAY + MythicLib.plugin.parseColors(string));

View File

@ -20,16 +20,19 @@ public class SkillSlot implements Unlockable {
private final boolean isUnlockedByDefault;
private final boolean canManuallyBind;
private final List<SkillBuffTrigger> skillBuffTriggers;
private Material item;
public SkillSlot(int slot, int modelData, String formula, String name, List<String> lore, boolean isUnlockedByDefault, List<SkillBuffTrigger> skillBuffTriggers) {
public SkillSlot(int slot, int modelData, String formula, String name, List<String> lore, boolean isUnlockedByDefault, boolean canManuallyBind, List<SkillBuffTrigger> skillBuffTriggers) {
this.slot = slot;
this.modelData = modelData;
this.formula = formula;
this.name = name;
this.lore = lore;
this.canManuallyBind = canManuallyBind;
this.isUnlockedByDefault = isUnlockedByDefault;
this.skillBuffTriggers = skillBuffTriggers;
}
@ -43,6 +46,7 @@ public class SkillSlot implements Unlockable {
this.item = Material.valueOf(section.getString("item"));
this.modelData = section.getInt("model-data", 0);
isUnlockedByDefault = section.getBoolean("unlocked-by-default", true);
canManuallyBind =section.getBoolean("can-manually-bind",true);
skillBuffTriggers = new ArrayList<>();
if (section.contains("skill-buffs"))
for (String skillBuff : section.getStringList("skill-buffs"))
@ -83,6 +87,10 @@ public class SkillSlot implements Unlockable {
return skillBuffTriggers;
}
public boolean canManuallyBind() {
return canManuallyBind;
}
public boolean canPlaceSkill(ClassSkill classSkill) {
return classSkill.getSkill().matchesFormula(formula);
}

View File

@ -22,14 +22,14 @@ public class AdminCommandTreeNode extends CommandTreeNode {
addChild(new AttributeCommandTreeNode(this));
addChild(new SkillCommandTreeNode(this));
addChild(new SaveDataTreeNode(this));
addChild(new SlotCommandTreeNode(this));
addChild(new PointsCommandTreeNode("skill", this, PlayerData::setSkillPoints, PlayerData::giveSkillPoints, PlayerData::getSkillPoints));
addChild(new PointsCommandTreeNode("class", this, PlayerData::setClassPoints, PlayerData::giveClassPoints, PlayerData::getClassPoints));
addChild(new PointsCommandTreeNode("attribute", this, PlayerData::setAttributePoints, PlayerData::giveAttributePoints, PlayerData::getAttributePoints));
addChild(new PointsCommandTreeNode("attr-realloc", this, PlayerData::setAttributeReallocationPoints, PlayerData::giveAttributeReallocationPoints, PlayerData::getAttributeReallocationPoints));
addChild(new PointsCommandTreeNode("skill-realloc", this, PlayerData::setSkillReallocationPoints, PlayerData::giveSkillReallocationPoints, PlayerData::getSkillReallocationPoints));
addChild(new PointsCommandTreeNode("skill-tree-realloc", this, PlayerData::setSkillTreeReallocationPoints, PlayerData::giveSkillTreeReallocationPoints, PlayerData::getSkillTreeReallocationPoints));
addChild(new SkillTreePointsCommandTreeNode(this,(playerData, integer, s) -> playerData.setSkillTreePoints(s,integer),(playerData, integer, s) -> playerData.giveSkillTreePoints(s,integer),((playerData, s) -> playerData.getSkillTreePoint(s))));
addChild(new SkillTreePointsCommandTreeNode(this, (playerData, integer, s) -> playerData.setSkillTreePoints(s, integer), (playerData, integer, s) -> playerData.giveSkillTreePoints(s, integer), ((playerData, s) -> playerData.getSkillTreePoint(s))));
for (PlayerResource res : PlayerResource.values())
addChild(new ResourceCommandTreeNode(res.name().toLowerCase(), this, res));
}

View File

@ -15,9 +15,11 @@ import org.bukkit.entity.Player;
public class SlotCommandTreeNode extends CommandTreeNode {
public SlotCommandTreeNode(CommandTreeNode parent) {
super(parent, "skill");
super(parent, "slot");
addChild(new LockSlotCommandTreeNode(this, "lock", true));
addChild(new LockSlotCommandTreeNode(this, "unlock", false));
addChild(new UnbindSlotCommandTreeNode(this, "unbind"));
addChild(new BindSlotCommandTreeNode(this, "bind"));
}
public class LockSlotCommandTreeNode extends CommandTreeNode {
@ -51,7 +53,7 @@ public class SlotCommandTreeNode extends CommandTreeNode {
sender.sendMessage(ChatColor.RED + "The slot can't be negative.");
return CommandResult.FAILURE;
}
SkillSlot skillSlot=playerData.getProfess().getSkillSlot(slot);
SkillSlot skillSlot = playerData.getProfess().getSkillSlot(slot);
if (lock) {
if (!playerData.hasUnlocked(skillSlot)) {
CommandVerbose.verbose(sender, CommandVerbose.CommandType.SKILL, ChatColor.RED + "The skill slot " + skillSlot.getName() + " is already locked" + " for " + player.getName());
@ -72,6 +74,80 @@ public class SlotCommandTreeNode extends CommandTreeNode {
}
public class BindSlotCommandTreeNode extends CommandTreeNode {
public BindSlotCommandTreeNode(CommandTreeNode parent, String id) {
super(parent, id);
addParameter(Parameter.PLAYER);
addParameter(Parameter.AMOUNT);
addParameter(new Parameter("<skill>",
(explorer, list) -> MMOCore.plugin.skillManager.getAll().forEach(skill -> list.add(skill.getHandler().getId().toUpperCase()))));
}
@Override
public CommandResult execute(CommandSender sender, String[] args) {
if (args.length < 6)
return CommandResult.THROW_USAGE;
Player player = Bukkit.getPlayer(args[3]);
if (player == null) {
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + ".");
return CommandResult.FAILURE;
}
PlayerData playerData = PlayerData.get(player);
int slot;
try {
slot = Integer.parseInt(args[4]);
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + args[4] + " is not a valid number.");
return CommandResult.FAILURE;
}
ClassSkill skill = playerData.getProfess().getSkill(args[5]);
if (skill == null) {
sender.sendMessage(ChatColor.RED + "The player's class doesn't have a skill called " + args[5] + ".");
return CommandResult.FAILURE;
}
playerData.bindSkill(slot, skill);
CommandVerbose.verbose(sender, CommandVerbose.CommandType.SKILL, ChatColor.GOLD + "The skill " + skill.getSkill().getHandler().getId() + " is now bound to the slot " + slot);
return CommandResult.SUCCESS;
}
}
public class UnbindSlotCommandTreeNode extends CommandTreeNode {
public UnbindSlotCommandTreeNode(CommandTreeNode parent, String id) {
super(parent, id);
addParameter(Parameter.PLAYER);
addParameter(Parameter.AMOUNT);
}
@Override
public CommandResult execute(CommandSender sender, String[] args) {
if (args.length < 5)
return CommandResult.THROW_USAGE;
Player player = Bukkit.getPlayer(args[3]);
if (player == null) {
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + ".");
return CommandResult.FAILURE;
}
PlayerData playerData = PlayerData.get(player);
int slot;
try {
slot = Integer.parseInt(args[4]);
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + args[4] + " is not a valid number.");
return CommandResult.FAILURE;
}
String skill = playerData.hasSkillBound(slot) ? playerData.getBoundSkill(slot).getSkill().getHandler().getId() : "none";
if (playerData.hasSkillBound(slot))
playerData.unbindSkill(slot);
CommandVerbose.verbose(sender, CommandVerbose.CommandType.SKILL, ChatColor.GOLD + "The skill " + skill + " has been unbounded from the slot " + slot);
return CommandResult.SUCCESS;
}
}
@Override
public CommandResult execute(CommandSender sender, String[] args) {
return CommandResult.THROW_USAGE;

View File

@ -160,7 +160,7 @@ public class SkillList extends EditableInventory {
@Override
public ItemStack display(SkillViewerInventory inv, int n) {
if (!inv.getPlayerData().hasUnlocked("slot:" + n)) {
if (!inv.getPlayerData().hasUnlocked("slot:" + (n+1))) {
return new ItemStack(Material.AIR);
}
SkillSlot skillSlot = inv.getPlayerData().getProfess().getSkillSlot(n + 1);
@ -403,6 +403,11 @@ public class SkillList extends EditableInventory {
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2);
return;
}
if(!playerData.getProfess().getSkillSlot(index).canManuallyBind()){
MMOCore.plugin.configManager.getSimpleMessage("cant-manually-bind").send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2);
return;
}
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
playerData.unbindSkill(index);
open();
@ -415,6 +420,12 @@ public class SkillList extends EditableInventory {
return;
}
if(!skillSlot.canManuallyBind()){
MMOCore.plugin.configManager.getSimpleMessage("cant-manually-bind").send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2);
return;
}
if (!skillSlot.canPlaceSkill(selected)) {
MMOCore.plugin.configManager.getSimpleMessage("not-compatible-skill").send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2);

View File

@ -198,7 +198,7 @@ death-exp-loss:
percent: 30
#Maximum number of slot. This means that you can't unlock a slot greater than max-slots. (The slot count starts at 1 & end at max-slots).
max-slots: 10
max-slots: 8
#If you want players to bound their passive skills.
#If false, all the passive skills unlocked will be active

View File

@ -203,6 +203,7 @@ upgrade-skill: '&eYour &6{skill} &eis now Level &6{level}&e!'
not-unlocked-skill: '&cYou have not unlocked that skill yet.'
no-skill-bound: '&cYou don''t have any skill bound to this slot.'
not-compatible-skill: '&cThe selected skill is not compatible with this slot.'
cant-manually-bind: "&cYou can't manually bind/unbind a skill to this slot."
skill-max-level-hit: '&cYou already hit the max level for that skill.'
no-skill-placeholder: 'No Skill Bound'
not-skill-reallocation-point: '&cYou do not have 1 skill reallocation point.'