Passive Skill Bounding System (data saving, GUI modification, Passive Skill Map modification when binding/unbinding)

This commit is contained in:
Ka0rX 2022-10-03 20:00:52 +02:00
parent ce292019d6
commit 9abe1fd929
9 changed files with 44 additions and 31 deletions

View File

@ -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<UUID> friends = new ArrayList<>();
private final Set<String> waypoints = new HashSet<>();
private final Map<String, Integer> skills = new HashMap<>();
private final List<ClassSkill> boundSkills = new ArrayList<>();
private final List<ClassSkill> boundPassiveSkills = new ArrayList<>();
private final List<PassiveSkill> boundPassiveSkills = new ArrayList<>();
private final PlayerProfessions collectSkills = new PlayerProfessions(this);
private final PlayerAttributes attributes = new PlayerAttributes(this);
private final Map<String, SavedClassInformation> 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<ClassSkill> getBoundPassiveSkills() {
public List<PassiveSkill> getBoundPassiveSkills() {
return boundPassiveSkills;
}

View File

@ -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<PassiveSkill> classScripts = new LinkedList();
private final Map<String, LinearValue> stats = new HashMap<>();
private final Map<String, ClassSkill> 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;

View File

@ -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");

View File

@ -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;
}

View File

@ -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");
}

View File

@ -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<String> 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());

View File

@ -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<String> 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);

View File

@ -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);

View File

@ -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