Made it possible to have SkillBuffs associated to a SkillSlot.

This commit is contained in:
Ka0rX 2023-04-02 19:18:13 +01:00
parent de5bfd5ed1
commit 9e98cd0640
3 changed files with 43 additions and 4 deletions

View File

@ -1202,6 +1202,11 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
if (boundSkills.containsKey(slot))
boundSkills.get(slot).unbind();
if (slot >= 0) {
//We apply the skill buffs associated with the slot to the skill.
profess.getSkillSlot(slot).getSkillBuffTriggers().forEach(skillBuffTrigger ->
skillBuffTrigger.apply(this,skill.getSkill().getHandler().getId()));
if (skill.getSkill().getTrigger().isPassive()) {
PassiveSkill passiveSkill = skill.toPassive(this);
passiveSkill.register(mmoData);
@ -1213,6 +1218,10 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
}
public void unbindSkill(int slot) {
//We remove the skill buffs associated with the slot from the skill that is .
profess.getSkillSlot(slot).getSkillBuffTriggers().forEach(skillBuffTrigger ->
skillBuffTrigger.remove(this,boundSkills.get(slot).getClassSkill().getSkill().getHandler().getId()));
BoundSkillInfo boundSkillInfo = boundSkills.remove(slot);
boundSkillInfo.unbind();
}

View File

@ -1,9 +1,12 @@
package net.Indyuce.mmocore.api.player.profess.skillbinding;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.quest.trigger.SkillBuffTrigger;
import net.Indyuce.mmocore.skill.ClassSkill;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import java.util.ArrayList;
import java.util.List;
public class SkillSlot {
@ -11,14 +14,18 @@ public class SkillSlot {
private final String formula;
private final String name;
private final List<String> lore;
private final List<SkillBuffTrigger> skillBuffTriggers;
private Material item;
public SkillSlot(int slot, int modelData, String formula, String name, List<String> lore, Material item) {
public SkillSlot(int slot, int modelData, String formula, String name, List<String> lore, List<SkillBuffTrigger> skillBuffTriggers, Material item) {
this.slot = slot;
this.modelData = modelData;
this.formula = formula;
this.name = name;
this.lore = lore;
this.skillBuffTriggers = skillBuffTriggers;
this.item = item;
}
@ -30,6 +37,12 @@ public class SkillSlot {
if (section.contains("item"))
this.item = Material.valueOf(section.getString("item"));
this.modelData = section.getInt("model-data", 0);
skillBuffTriggers= new ArrayList<>();
if(section.contains("skill-buffs"))
for(String skillBuff:section.getStringList("skill-buffs"))
if(skillBuff.startsWith("skill_buff")){
skillBuffTriggers.add((SkillBuffTrigger) MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(skillBuff)));
}
}
public int getSlot() {
@ -56,6 +69,10 @@ public class SkillSlot {
return modelData;
}
public List<SkillBuffTrigger> getSkillBuffTriggers() {
return skillBuffTriggers;
}
public boolean canPlaceSkill(ClassSkill classSkill) {
return classSkill.getSkill().matchesFormula(formula);
}

View File

@ -21,11 +21,10 @@ public class SkillBuffTrigger extends Trigger implements Removable {
super(config);
config.validateKeys("modifier");
config.validateKeys("amount");
config.validateKeys("formula");
config.validateKeys("type");
amount = config.getDouble("amount");
String skillModifier = config.getString("modifier");
String formula = config.getString("formula");
String formula = config.getString("formula", "true");
List<String> targetSkills = new ArrayList<>();
for (RegisteredSkill skill : MMOCore.plugin.skillManager.getAll()) {
if (skill.matchesFormula(formula))
@ -47,4 +46,18 @@ public class SkillBuffTrigger extends Trigger implements Removable {
public void remove(PlayerData playerData) {
skillBuff.unregister(playerData.getMMOPlayerData());
}
/**
* Used by skill slots to apply a skillBuff to a specific skill dynamically chosen .
*/
public void apply(PlayerData playerData, String skill) {
skillBuff.register(playerData.getMMOPlayerData(), skill);
}
/**
* Used by skill slots to remove a skillBuff from a specific skill dynamically chosen.
*/
public void remove(PlayerData playerData, String skill) {
skillBuff.unregister(playerData.getMMOPlayerData(), skill);
}
}