New triggers for skill management

This commit is contained in:
Jules 2023-04-14 17:32:02 +02:00
parent 39f95634a0
commit 039baed3d3
3 changed files with 74 additions and 0 deletions

View File

@ -29,6 +29,12 @@ public class DefaultMMOLoader extends MMOLoader {
if (config.getKey().equals("unlock_skill"))
return new UnlockSkillTrigger(config);
if (config.getKey().equals("bind_skill"))
return new BindSkillTrigger(config);
if (config.getKey().equals("levelup_skill"))
return new LevelUpSkillTrigger(config);
if (config.getKey().equals("skill_buff"))
return new SkillModifierTrigger(config);

View File

@ -0,0 +1,36 @@
package net.Indyuce.mmocore.api.quest.trigger;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.quest.trigger.api.Removable;
import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import javax.annotation.Nullable;
import java.util.Objects;
public class BindSkillTrigger extends Trigger implements Removable {
private final RegisteredSkill skill;
private final int slot;
public BindSkillTrigger(MMOLineConfig config) {
super(config);
config.validateKeys("skill", "slot");
slot = config.getInt("slot");
skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(config.getString("skill")));
}
@Override
public void apply(PlayerData playerData) {
final @Nullable ClassSkill found = playerData.getProfess().getSkill(skill);
if (found != null)
playerData.bindSkill(slot, found);
}
@Override
public void remove(PlayerData playerData) {
playerData.unbindSkill(slot);
}
}

View File

@ -0,0 +1,32 @@
package net.Indyuce.mmocore.api.quest.trigger;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.quest.trigger.api.Removable;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import java.util.Objects;
public class LevelUpSkillTrigger extends Trigger implements Removable {
private final RegisteredSkill skill;
private final int amount;
public LevelUpSkillTrigger(MMOLineConfig config) {
super(config);
config.validateKeys("skill", "amount");
amount = config.getInt("amount");
skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(config.getString("skill")));
}
@Override
public void apply(PlayerData playerData) {
playerData.setSkillLevel(skill, playerData.getSkillLevel(skill) + amount);
}
@Override
public void remove(PlayerData playerData) {
playerData.setSkillLevel(skill, Math.max(0, playerData.getSkillLevel(skill) - amount));
}
}