From 9abe1fd92969bdfd53d934f4b4775a4a0b09de2c Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Mon, 3 Oct 2022 20:00:52 +0200 Subject: [PATCH] Passive Skill Bounding System (data saving, GUI modification, Passive Skill Map modification when binding/unbinding) --- .../mmocore/api/player/PlayerData.java | 26 ++++++++++--------- .../api/player/profess/PlayerClass.java | 12 ++++----- .../mmocore/api/player/stats/PlayerStats.java | 5 +--- .../net/Indyuce/mmocore/gui/SkillList.java | 8 +++--- .../mmocore/manager/ConfigManager.java | 6 +++-- .../data/mysql/MySQLPlayerDataManager.java | 4 +-- .../data/yaml/YAMLPlayerDataManager.java | 4 +-- .../net/Indyuce/mmocore/skill/ClassSkill.java | 5 ++++ MMOCore-Dist/src/main/resources/config.yml | 5 ++++ 9 files changed, 44 insertions(+), 31 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 d2b232e5..62f9341e 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 @@ -3,6 +3,7 @@ package net.Indyuce.mmocore.api.player; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.player.MMOPlayerData; import io.lumine.mythic.lib.player.cooldown.CooldownMap; +import io.lumine.mythic.lib.player.skill.PassiveSkill; import net.Indyuce.mmocore.party.provided.Party; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigMessage; @@ -79,14 +80,13 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc private Guild guild; private SkillCastingHandler skillCasting; private SkillTree cachedSkillTree; - private final PlayerQuests questData; private final PlayerStats playerStats; private final List friends = new ArrayList<>(); private final Set waypoints = new HashSet<>(); private final Map skills = new HashMap<>(); private final List boundSkills = new ArrayList<>(); - private final List boundPassiveSkills = new ArrayList<>(); + private final List boundPassiveSkills = new ArrayList<>(); private final PlayerProfessions collectSkills = new PlayerProfessions(this); private final PlayerAttributes attributes = new PlayerAttributes(this); private final Map classSlots = new HashMap<>(); @@ -1050,35 +1050,36 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc return slot >= boundSkills.size() ? null : boundSkills.get(slot); } - public void setBoundPassiveSkill(int slot, ClassSkill skill) { + public void setBoundPassiveSkill(int slot, PassiveSkill skill) { Validate.notNull(skill, "Skill cannot be null"); - if (boundPassiveSkills.size() < getProfess().getMaxBoundSkills()) + if (boundPassiveSkills.size() < getProfess().getMaxBoundActiveSkills()) boundPassiveSkills.add(skill); else boundPassiveSkills.set(slot, skill); - boundPassiveSkills.get(slot).toPassive(this).register(getMMOPlayerData()); - + boundPassiveSkills.get(slot).register(getMMOPlayerData()); } public boolean hasPassiveSkillBound(int slot) { return slot < boundPassiveSkills.size(); } - public ClassSkill getBoundPassiveSkill(int slot) { + public PassiveSkill getBoundPassiveSkill(int slot) { return slot >= boundPassiveSkills.size() ? null : boundPassiveSkills.get(slot); } - public void addPassiveBoundSkill(ClassSkill skill) { + public void addPassiveBoundSkill(PassiveSkill skill) { boundPassiveSkills.add(skill); - skill.toPassive(this).register(getMMOPlayerData()); + skill.register(getMMOPlayerData()); } public void setBoundSkill(int slot, ClassSkill skill) { + Validate.notNull(skill, "Skill cannot be null"); - if (boundSkills.size() < getProfess().getMaxBoundSkills()) + if (boundSkills.size() < getProfess().getMaxBoundActiveSkills()) boundSkills.add(skill); else boundSkills.set(slot, skill); + } public void unbindSkill(int slot) { @@ -1086,7 +1087,8 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc } public void unbindPassiveSkill(int slot) { - boundPassiveSkills.get(slot).toPassive(this).unregister(getMMOPlayerData()); + PassiveSkill skill = boundPassiveSkills.get(slot); + skill.unregister(getMMOPlayerData()); boundPassiveSkills.remove(slot); } @@ -1095,7 +1097,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc return boundSkills; } - public List getBoundPassiveSkills() { + public List getBoundPassiveSkills() { return boundPassiveSkills; } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java index 81b2ece9..f8089309 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java @@ -68,7 +68,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { @NotNull private final CastingParticle castParticle; - private final int maxBoundSkills, maxBoundPassiveSkills; + private final int maxBoundActiveSkills, maxBoundPassiveSkills; private final List classScripts = new LinkedList(); private final Map stats = new HashMap<>(); private final Map skills = new LinkedHashMap<>(); @@ -123,8 +123,8 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { ? MMOCore.plugin.experience.getCurveOrThrow( config.get("exp-curve").toString().toLowerCase().replace("_", "-").replace(" ", "-")) : ExpCurve.DEFAULT; - maxBoundSkills = config.getInt("max-bound-skills", 6); - maxBoundPassiveSkills = config.getInt("max-bound-passive-skills", 3); + maxBoundActiveSkills = config.getInt("max-bound-active-skills", MMOCore.plugin.configManager.maxBoundActiveSkills); + maxBoundPassiveSkills = config.getInt("max-bound-passive-skills", MMOCore.plugin.configManager.maxBoundPassiveSkills); ExperienceTable expTable = null; if (config.contains("exp-table")) try { @@ -259,7 +259,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { this.icon = new ItemStack(material); setOption(ClassOption.DISPLAY, false); setOption(ClassOption.DEFAULT, false); - maxBoundSkills = 6; + maxBoundActiveSkills = 6; maxBoundPassiveSkills=3; for (PlayerResource resource : PlayerResource.values()) resourceHandlers.put(resource, new ResourceRegeneration(resource)); @@ -316,8 +316,8 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { return expCurve; } - public int getMaxBoundSkills() { - return maxBoundSkills; + public int getMaxBoundActiveSkills() { + return maxBoundActiveSkills; } public int getMaxBoundPassiveSkills() { return maxBoundPassiveSkills; diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/stats/PlayerStats.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/stats/PlayerStats.java index 479db212..5e5c2941 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/stats/PlayerStats.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/stats/PlayerStats.java @@ -96,11 +96,8 @@ public class PlayerStats { * * This updates the player's PASSIVE skills */ + final PassiveSkillMap skillMap = data.getMMOPlayerData().getPassiveSkillMap(); - skillMap.removeModifiers("MMOCorePassiveSkill"); - for (ClassSkill skill : data.getProfess().getSkills()) - if (skill.getSkill().getTrigger().isPassive()) - skillMap.addModifier(skill.toPassive(data)); // This updates the player's class SCRIPTS skillMap.removeModifiers("MMOCoreClassScript"); 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 a822d596..6766ef8a 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 @@ -64,7 +64,7 @@ public class SkillList extends EditableInventory { return new SlotItem(config) { @Override public ItemStack display(SkillViewerInventory inv, int n) { - if (n >= inv.getPlayerData().getProfess().getMaxBoundSkills()) { + if (n >= inv.getPlayerData().getProfess().getMaxBoundActiveSkills()) { return new ItemStack(Material.AIR); } ItemStack item = super.display(inv, n); @@ -115,7 +115,9 @@ public class SkillList extends EditableInventory { public Placeholders getPlaceholders(SkillViewerInventory inv, int n) { Placeholders holders= super.getPlaceholders(inv, n); String none = MythicLib.plugin.parseColors(config.getString("no-skill")); - RegisteredSkill skill = inv.getPlayerData().hasPassiveSkillBound(n) ? inv.getPlayerData().getBoundPassiveSkill(n).getSkill() : null; + RegisteredSkill skill = inv.getPlayerData().hasPassiveSkillBound(n) ? + MMOCore.plugin.skillManager.getSkill(inv.getPlayerData().getBoundPassiveSkill(n).getTriggeredSkill().getHandler().getId()) + : null; holders.register("skill", skill == null ? none : skill.getName()); return holders; } @@ -453,7 +455,7 @@ public class SkillList extends EditableInventory { } player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2); - playerData.setBoundPassiveSkill(index, selected); + playerData.setBoundPassiveSkill(index, selected.toPassive(playerData)); open(); return; } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index 95920fbb..42ed06f8 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -27,10 +27,11 @@ public class ConfigManager { public ChatColor staminaFull, staminaHalf, staminaEmpty; public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown, globalSkillCooldown; public double lootChestsChanceWeight, fishingDropsChanceWeight; - public int maxPartyLevelDifference,maxBoundSkills,waypointWarpTime; + public int maxPartyLevelDifference,maxBoundActiveSkills,maxBoundPassiveSkills,waypointWarpTime; private final FileConfiguration messages; + /* * the instance must be created after the other managers since all it does * is to update them based on the config except for the classes which are @@ -118,7 +119,8 @@ public class ConfigManager { canCreativeCast = MMOCore.plugin.getConfig().getBoolean("can-creative-cast"); cobbleGeneratorXP = MMOCore.plugin.getConfig().getBoolean("should-cobblestone-generators-give-exp"); saveDefaultClassInfo = MMOCore.plugin.getConfig().getBoolean("save-default-class-info"); - maxBoundSkills = MMOCore.plugin.getConfig().getInt("max-bound-skills", 6); + maxBoundActiveSkills = MMOCore.plugin.getConfig().getInt("max-bound-active-skills", 6); + maxBoundPassiveSkills = MMOCore.plugin.getConfig().getInt("max-bound-passive-skills", 3); overrideVanillaExp = MMOCore.plugin.getConfig().getBoolean("override-vanilla-exp"); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java index 0bef606a..2e42af1b 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java @@ -119,7 +119,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager { if (data.getProfess().hasSkill(id)) { ClassSkill skill = data.getProfess().getSkill(id); if (skill.getSkill().getTrigger().isPassive()) - data.addPassiveBoundSkill(skill); + data.addPassiveBoundSkill(skill.toPassive(data)); else data.getBoundSkills().add(skill); } @@ -200,7 +200,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager { sql.updateJSONArray("friends", data.getFriends().stream().map(UUID::toString).collect(Collectors.toList())); List boundSkills = new ArrayList<>(); data.getBoundSkills().forEach(skill -> boundSkills.add(skill.getSkill().getHandler().getId())); - data.getBoundPassiveSkills().forEach(skill -> boundSkills.add(skill.getSkill().getHandler().getId())); + data.getBoundPassiveSkills().forEach(skill -> boundSkills.add(skill.getTriggeredSkill().getHandler().getId())); sql.updateJSONArray("bound_skills", boundSkills); sql.updateJSONObject("skills", data.mapSkillLevels().entrySet()); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java index 163e85b6..86bb8c6c 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java @@ -71,7 +71,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager { if (data.getProfess().hasSkill(id)) { ClassSkill skill = data.getProfess().getSkill(id); if (skill.getSkill().getTrigger().isPassive()) - data.addPassiveBoundSkill(skill); + data.addPassiveBoundSkill(skill.toPassive(data)); else data.getBoundSkills().add(skill); @@ -152,7 +152,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager { List boundSkills = new ArrayList<>(); data.getBoundSkills().forEach(skill -> boundSkills.add(skill.getSkill().getHandler().getId())); - data.getBoundPassiveSkills().forEach(skill -> boundSkills.add(skill.getSkill().getHandler().getId())); + data.getBoundPassiveSkills().forEach(skill -> boundSkills.add(skill.getTriggeredSkill().getHandler().getId())); config.set("bound-skills", boundSkills); config.set("attribute", null); 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 0f9ddd0f..52a9d381 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 @@ -125,6 +125,11 @@ public class ClassSkill implements CooldownObject { return new CastableSkill(this, caster.getSkillLevel(getSkill())); } + /** + * Be careful, this method creates a new UUID each time it is called. Need to be remembered when trying to unregister passive skill + * from PassiveSkillMap. + * @return + */ public PassiveSkill toPassive(PlayerData caster) { Validate.isTrue(skill.getTrigger().isPassive(), "Skill is active"); return new PassiveSkill("MMOCorePassiveSkill", toCastable(caster), EquipmentSlot.OTHER, ModifierSource.OTHER); diff --git a/MMOCore-Dist/src/main/resources/config.yml b/MMOCore-Dist/src/main/resources/config.yml index d7ea9767..8787d144 100644 --- a/MMOCore-Dist/src/main/resources/config.yml +++ b/MMOCore-Dist/src/main/resources/config.yml @@ -185,6 +185,11 @@ death-exp-loss: # Percentage of current EXP you lose when dying. percent: 30 +#Default max bound active and passive skills. +#These value can be modified for each class in the class yml. +max-bound-active-skills: 6 +max-bound-passive-skills: 3 + # Fun extra RPG feature that switches the player's hotbar with # the 9 lower row items of his inventory. This allows the player # to have two different item sets or quickly have access to pots