Search in sources :

Example 6 with ActionHandler

use of com.elmakers.mine.bukkit.action.ActionHandler in project MagicPlugin by elBukkit.

the class AsynchronousAction method perform.

@Override
public SpellResult perform(CastContext context) {
    if (queued) {
        return SpellResult.NO_ACTION;
    }
    ActionHandler handler = getHandler("actions");
    if (handler == null) {
        return SpellResult.NO_ACTION;
    }
    actionContext = new com.elmakers.mine.bukkit.action.CastContext(context);
    handler = (ActionHandler) handler.clone();
    handler.reset(actionContext);
    actionContext.addHandler(handler);
    queued = true;
    return SpellResult.PENDING;
}
Also used : ActionHandler(com.elmakers.mine.bukkit.action.ActionHandler)

Example 7 with ActionHandler

use of com.elmakers.mine.bukkit.action.ActionHandler in project MagicPlugin by elBukkit.

the class RandomAction method mapActions.

protected void mapActions() {
    actionProbability = new ArrayDeque<>();
    ActionHandler actions = getHandler("actions");
    if (actions != null) {
        List<ActionContext> options = actions.getActions();
        float totalWeight = 0;
        for (ActionContext option : options) {
            float weight = 1;
            ConfigurationSection actionParameters = option.getActionParameters();
            if (actionParameters != null) {
                weight = (float) actionParameters.getDouble("weight", weight);
            }
            totalWeight += weight;
            actionProbability.add(new WeightedPair<>(totalWeight, weight, option));
        }
    }
}
Also used : ActionContext(com.elmakers.mine.bukkit.action.ActionContext) ActionHandler(com.elmakers.mine.bukkit.action.ActionHandler) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 8 with ActionHandler

use of com.elmakers.mine.bukkit.action.ActionHandler in project MagicPlugin by elBukkit.

the class MultiplyAction method perform.

@Override
public SpellResult perform(CastContext context) {
    SpellResult result = SpellResult.NO_ACTION;
    if (remaining.size() == 0)
        return result;
    int startingWork = context.getWorkAllowed();
    List<ActionHandler> subActions = new ArrayList<>(remaining);
    remaining.clear();
    context.setWorkAllowed(0);
    int splitWork = Math.max(1, startingWork / subActions.size());
    for (ActionHandler action : subActions) {
        context.setWorkAllowed(context.getWorkAllowed() + splitWork);
        SpellResult actionResult = action.perform(context);
        context.addResult(actionResult);
        if (actionResult.isStop()) {
            remaining.add(action);
        }
        result = result.min(actionResult);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult) ActionHandler(com.elmakers.mine.bukkit.action.ActionHandler)

Example 9 with ActionHandler

use of com.elmakers.mine.bukkit.action.ActionHandler in project MagicPlugin by elBukkit.

the class MultiplyAction method reset.

@Override
public void reset(CastContext context) {
    super.reset(context);
    remaining = new ArrayList<>(multiplied);
    for (ActionHandler handler : remaining) {
        handler.reset(context);
    }
}
Also used : ActionHandler(com.elmakers.mine.bukkit.action.ActionHandler)

Example 10 with ActionHandler

use of com.elmakers.mine.bukkit.action.ActionHandler in project MagicPlugin by elBukkit.

the class MultiplyAction method prepare.

@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
    super.prepare(context, parameters);
    multiply = parameters.getInt("multiply", parameters.getInt("repeat", 2));
    multiplied = new ArrayList<>();
    ActionHandler base = getHandler("actions");
    if (base != null) {
        ConfigurationSection initialParameters = ConfigurationUtils.getConfigurationSection(parameters, "first");
        if (initialParameters != null) {
            ConfigurationSection combined = ConfigurationUtils.addConfigurations(new MemoryConfiguration(), parameters);
            initialParameters = ConfigurationUtils.addConfigurations(combined, initialParameters);
        }
        for (int i = 0; i < multiply; i++) {
            ActionHandler handler = (ActionHandler) base.clone();
            if (i == 0 && initialParameters != null) {
                handler.prepare(context, initialParameters);
            } else {
                handler.prepare(context, parameters);
            }
            multiplied.add(handler);
        }
    }
}
Also used : MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) ActionHandler(com.elmakers.mine.bukkit.action.ActionHandler) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

ActionHandler (com.elmakers.mine.bukkit.action.ActionHandler)15 CoverAction (com.elmakers.mine.bukkit.action.builtin.CoverAction)4 Target (com.elmakers.mine.bukkit.utility.Target)4 Block (org.bukkit.block.Block)4 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)3 ActionContext (com.elmakers.mine.bukkit.action.ActionContext)2 SpellResult (com.elmakers.mine.bukkit.api.spell.SpellResult)2 AbsorbAction (com.elmakers.mine.bukkit.action.builtin.AbsorbAction)1 BurnAction (com.elmakers.mine.bukkit.action.builtin.BurnAction)1 DamageAction (com.elmakers.mine.bukkit.action.builtin.DamageAction)1 FlowerAction (com.elmakers.mine.bukkit.action.builtin.FlowerAction)1 FreezeAction (com.elmakers.mine.bukkit.action.builtin.FreezeAction)1 LightningAction (com.elmakers.mine.bukkit.action.builtin.LightningAction)1 PotionEffectAction (com.elmakers.mine.bukkit.action.builtin.PotionEffectAction)1 TargetType (com.elmakers.mine.bukkit.api.spell.TargetType)1 SourceLocation (com.elmakers.mine.bukkit.magic.SourceLocation)1 ArrayList (java.util.ArrayList)1 MemoryConfiguration (org.bukkit.configuration.MemoryConfiguration)1