mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-26 18:39:20 +00:00
feat(core): 添加对 MythicMobs 技能的支持
This commit is contained in:
@@ -34,4 +34,6 @@ public interface CompatibilityManager {
|
||||
String parse(Player player1, Player player2, String text);
|
||||
|
||||
int getPlayerProtocolVersion(UUID uuid);
|
||||
|
||||
void skillExecute(String skill, float power, Player player);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ public class EventFunctions {
|
||||
register(CommonFunctions.LEVELER_EXP, new LevelerExpFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
register(CommonFunctions.SET_COOLDOWN, new SetCooldownFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
register(CommonFunctions.REMOVE_COOLDOWN, new RemoveCooldownFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
register(CommonFunctions.MYTHIC_MOBS_SKILL, new MythicMobsSkillFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
}
|
||||
|
||||
public static void register(Key key, FunctionFactory<PlayerOptionalContext> factory) {
|
||||
|
||||
@@ -27,4 +27,5 @@ public final class CommonFunctions {
|
||||
public static final Key DROP_LOOT = Key.of("craftengine:drop_loot");
|
||||
public static final Key SWING_HAND = Key.of("craftengine:swing_hand");
|
||||
public static final Key LEVELER_EXP = Key.of("craftengine:leveler_exp");
|
||||
public static final Key MYTHIC_MOBS_SKILL = Key.of("craftengine:mythic_mobs_skill");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package net.momirealms.craftengine.core.plugin.context.function;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MythicMobsSkillFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
|
||||
private final String skill;
|
||||
private final float power;
|
||||
|
||||
public MythicMobsSkillFunction(String skill, float power, List<Condition<CTX>> predicates) {
|
||||
super(predicates);
|
||||
this.skill = skill;
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runInternal(CTX ctx) {
|
||||
ctx.getOptionalParameter(DirectContextParameters.PLAYER).ifPresent(it -> {
|
||||
CraftEngine.instance().compatibilityManager().skillExecute(this.skill, this.power, it);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return CommonFunctions.MYTHIC_MOBS_SKILL;
|
||||
}
|
||||
|
||||
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
|
||||
|
||||
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
|
||||
super(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function<CTX> create(Map<String, Object> args) {
|
||||
String skill = ResourceConfigUtils.requireNonEmptyStringOrThrow(args.get("skill"), "warning.config.function.mythic_mobs_skill.missing_skill");
|
||||
float power = ResourceConfigUtils.getAsFloat(args.getOrDefault("power", 1.0), "power");
|
||||
return new MythicMobsSkillFunction<>(skill, power, getPredicates(args));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user