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;
}
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));
}
}
}
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;
}
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);
}
}
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);
}
}
}
Aggregations