From aaa777267d6bb6c5478ec67ddb9c44dfc42ef164 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Tue, 21 Mar 2023 16:49:17 +0100 Subject: [PATCH] Skill Unlocking Mechanic. --- .../mmocore/api/player/PlayerData.java | 34 +++++++++---------- .../net/Indyuce/mmocore/gui/SkillList.java | 5 ++- .../net/Indyuce/mmocore/skill/ClassSkill.java | 13 +++++-- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index ae4879e8..3910d815 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -166,11 +166,11 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc MMOCore.log(Level.SEVERE, "[Userdata] Could not find class " + getProfess().getId() + " while refreshing player data."); } - Iterator ite=boundSkills.keySet().iterator(); + Iterator ite = boundSkills.keySet().iterator(); while (ite.hasNext()) try { - int slot=ite.next(); - BoundSkillInfo boundSkillInfo=new BoundSkillInfo(boundSkills.get(slot)); + int slot = ite.next(); + BoundSkillInfo boundSkillInfo = new BoundSkillInfo(boundSkills.get(slot)); boundSkills.put(slot, boundSkillInfo); } catch (Exception ignored) { } @@ -222,9 +222,9 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc @Override public Map mapBoundSkills() { - Map result= new HashMap<>(); - for(int slot:boundSkills.keySet()) - result.put(slot,boundSkills.get(slot).getClassSkill().getSkill().getHandler().getId()); + Map result = new HashMap<>(); + for (int slot : boundSkills.keySet()) + result.put(slot, boundSkills.get(slot).getClassSkill().getSkill().getHandler().getId()); return result; } @@ -534,20 +534,18 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc /** * @return If the item is unlocked by the player - * @deprecated Not used yet + * This is used for skills that can be locked & unlocked. */ - @Deprecated public boolean hasUnlocked(Unlockable unlockable) { return unlockedItems.contains(unlockable.getUnlockNamespacedKey()); } + /** - * Unlocks an item for the player + * Unlocks an item for the player. This is mainly used to unlock skills. * * @return If the item was already unlocked when calling this method - * @deprecated Not used yet */ - @Deprecated public boolean unlock(Unlockable unlockable) { return unlockedItems.add(unlockable.getUnlockNamespacedKey()); } @@ -769,9 +767,9 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc final double r = Math.sin((double) t / warpTime * Math.PI); for (double j = 0; j < Math.PI * 2; j += Math.PI / 4) getPlayer().getLocation().getWorld().spawnParticle(Particle.REDSTONE, getPlayer().getLocation().add( - Math.cos((double) 5 * t / warpTime + j) * r, - (double) 2 * t / warpTime, - Math.sin((double) 5 * t / warpTime + j) * r), + Math.cos((double) 5 * t / warpTime + j) * r, + (double) 2 * t / warpTime, + Math.sin((double) 5 * t / warpTime + j) * r), 1, new Particle.DustOptions(Color.PURPLE, 1.25f)); } }.runTaskTimer(MMOCore.plugin, 0, 1); @@ -1067,9 +1065,9 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc public void refreshBoundedSkill(String skill) { boundSkills.values() .stream() - .filter(skillInfo->skillInfo.getClassSkill().getSkill().getHandler().getId().equals(skill)) + .filter(skillInfo -> skillInfo.getClassSkill().getSkill().getHandler().getId().equals(skill)) .forEach(BoundSkillInfo::refresh); - } + } @Deprecated public boolean hasSkillUnlocked(RegisteredSkill skill) { @@ -1140,7 +1138,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc } public ClassSkill getBoundSkill(int slot) { - return boundSkills.containsKey(slot) ? boundSkills.get(slot).getClassSkill():null; + return boundSkills.containsKey(slot) ? boundSkills.get(slot).getClassSkill() : null; } @@ -1173,7 +1171,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc } public void unbindSkill(int slot) { - BoundSkillInfo boundSkillInfo=boundSkills.remove(slot); + BoundSkillInfo boundSkillInfo = boundSkills.remove(slot); boundSkillInfo.unbind(); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java index 99b6e1ba..1a1bc7ed 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java @@ -323,7 +323,10 @@ public class SkillList extends EditableInventory { public SkillViewerInventory(PlayerData playerData, EditableInventory editable) { super(playerData, editable); - skills = new ArrayList<>(playerData.getProfess().getSkills()); + skills = playerData.getProfess().getSkills() + .stream() + .filter((classSkill)->playerData.hasUnlocked(classSkill.getSkill())) + .collect(Collectors.toList()); skillSlots = getEditable().getByFunction("skill").getSlots(); Validate.notNull(getEditable().getByFunction("slot"), "Your skill GUI config file is out-of-date, please regenerate it."); slotSlots = getEditable().getByFunction("slot").getSlots(); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/ClassSkill.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/ClassSkill.java index f301c62a..4a2cf373 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/ClassSkill.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/ClassSkill.java @@ -17,6 +17,7 @@ import java.util.*; public class ClassSkill implements CooldownObject { private final RegisteredSkill skill; private final int unlockLevel, maxSkillLevel; + private final boolean unlockedByDefault; private final Map modifiers = new HashMap<>(); @Deprecated @@ -32,10 +33,14 @@ public class ClassSkill implements CooldownObject { * It is also used by the MMOCore API to force players to cast abilities. */ public ClassSkill(RegisteredSkill skill, int unlockLevel, int maxSkillLevel) { + this(skill, unlockLevel, maxSkillLevel, true); + } + + public ClassSkill(RegisteredSkill skill, int unlockLevel, int maxSkillLevel, boolean unlockedByDefault) { this.skill = skill; this.unlockLevel = unlockLevel; this.maxSkillLevel = maxSkillLevel; - + this.unlockedByDefault = unlockedByDefault; for (String mod : skill.getHandler().getModifiers()) this.modifiers.put(mod, skill.getModifierInfo(mod)); } @@ -44,7 +49,7 @@ public class ClassSkill implements CooldownObject { this.skill = skill; unlockLevel = config.getInt("level"); maxSkillLevel = config.getInt("max-level"); - + unlockedByDefault = config.getBoolean("unlocked-by-default", true); for (String mod : skill.getHandler().getModifiers()) { LinearValue defaultValue = skill.getModifierInfo(mod); this.modifiers.put(mod, config.isConfigurationSection(mod) ? readLinearValue(defaultValue, config.getConfigurationSection(mod)) : defaultValue); @@ -68,6 +73,10 @@ public class ClassSkill implements CooldownObject { return maxSkillLevel; } + public boolean isUnlockedByDefault() { + return unlockedByDefault; + } + /** * This method can only override default modifiers and * will throw an error when trying to define non existing modifiers