use of com.elmakers.mine.bukkit.api.spell.SpellResult in project MagicPlugin by elBukkit.
the class ActionSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
currentCast.setWorkAllowed(workThreshold);
SpellResult result = SpellResult.CAST;
currentHandler = actions.get("cast");
ActionHandler downHandler = actions.get("alternate_down");
ActionHandler upHandler = actions.get("alternate_up");
ActionHandler sneakHandler = actions.get("alternate_sneak");
ActionHandler jumpHandler = actions.get("alternate_jumping");
workThreshold = parameters.getInt("work_threshold", 500);
if (downHandler != null && isLookingDown()) {
result = SpellResult.ALTERNATE_DOWN;
currentHandler = downHandler;
} else if (upHandler != null && isLookingUp()) {
result = SpellResult.ALTERNATE_UP;
currentHandler = upHandler;
} else if (sneakHandler != null && mage.isSneaking()) {
result = SpellResult.ALTERNATE_SNEAK;
currentHandler = sneakHandler;
} else if (jumpHandler != null && mage.isJumping()) {
result = SpellResult.ALTERNATE_JUMPING;
currentHandler = jumpHandler;
}
if (isUndoable()) {
getMage().prepareForUndo(getUndoList());
}
target();
playEffects("precast");
if (currentHandler != null) {
currentHandler = (ActionHandler) currentHandler.clone();
try {
result = result.max(currentHandler.start(currentCast, parameters));
currentCast.setInitialResult(result);
} catch (Exception ex) {
controller.getLogger().log(Level.WARNING, "Spell cast failed for " + getKey(), ex);
result = SpellResult.FAIL;
try {
currentHandler.finish(currentCast);
} catch (Exception finishException) {
controller.getLogger().log(Level.WARNING, "Failed to clean up failed spell " + getKey(), finishException);
}
}
}
return result;
}
use of com.elmakers.mine.bukkit.api.spell.SpellResult in project MagicPlugin by elBukkit.
the class ParallelAction method perform.
@Override
public SpellResult perform(CastContext context) {
SpellResult result = SpellResult.NO_ACTION;
int startingWork = context.getWorkAllowed();
List<ActionContext> subActions = new ArrayList<>(remaining);
remaining.clear();
context.setWorkAllowed(0);
int splitWork = Math.max(1, startingWork / subActions.size());
for (ActionContext 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.api.spell.SpellResult in project MagicPlugin by elBukkit.
the class CreateFieldAction method perform.
@Override
public SpellResult perform(CastContext context) {
SpellResult result = super.perform(context);
if (!result.isSuccess() || fieldType != context.getTargetBlock().getType()) {
return result;
}
MageController apiController = context.getController();
if (!(apiController instanceof MagicController)) {
return SpellResult.FAIL;
}
MagicController controller = (MagicController) apiController;
PreciousStonesManager preciousStones = controller.getPreciousStones();
context.getMage().sendDebugMessage(ChatColor.GRAY + "Placing field", 7);
if (!preciousStones.createField(context.getTargetLocation(), context.getMage().getPlayer())) {
context.getMage().sendDebugMessage(ChatColor.RED + "Could not place field", 2);
return SpellResult.NO_TARGET;
}
if (!rent.isEmpty() && !rentPeriod.isEmpty()) {
if (!preciousStones.rentField(context.getTargetLocation().getBlock().getRelative(BlockFace.UP).getLocation(), context.getMage().getPlayer(), rent, rentPeriod, rentSignDirection)) {
context.getMage().sendDebugMessage(ChatColor.RED + "Could not rent field", 2);
}
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.spell.SpellResult in project MagicPlugin by elBukkit.
the class VolumeAction method step.
@Override
public SpellResult step(CastContext context) {
SpellResult result = SpellResult.NO_ACTION;
boolean singleBlock = radius < 1;
boolean validBlock = singleBlock ? true : containsPoint(dx, dy, dz);
float probability = centerProbability;
if (!singleBlock && centerProbability != outerProbability) {
float weight = Math.abs((float) dx + dz) / ((float) spiralRadius * 2);
probability = RandomUtils.lerp(centerProbability, outerProbability, weight);
}
validBlock = validBlock && (probability >= 1 || context.getRandom().nextDouble() <= probability);
if (validBlock) {
Block block = context.getTargetBlock();
Vector offset = new Vector();
if (autoOrient) {
if (reorient) {
updateOrient(actionContext);
}
offset.setX(dx + xOffset);
offset.setY(dy);
offset.setZ(dz + zOffset);
Block originalBlock = block.getRelative(offset.getBlockX(), offset.getBlockY(), offset.getBlockZ());
actionContext.setTargetSourceLocation(originalBlock.getRelative(-xOffset, 0, -zOffset).getLocation());
offset = rotate(yaw, pitch, offset.getX(), offset.getY(), offset.getZ());
} else {
offset.setX(dx);
offset.setY(dy);
offset.setZ(dz);
}
Block targetBlock = block.getRelative(offset.getBlockX(), offset.getBlockY(), offset.getBlockZ());
if (replaceMaterial == null || targetBlock.getType() == replaceMaterial) {
actionContext.setTargetLocation(targetBlock.getLocation());
result = startActions();
}
} else {
skippedActions(context);
}
return result;
}
use of com.elmakers.mine.bukkit.api.spell.SpellResult in project MagicPlugin by elBukkit.
the class ActionContext method perform.
public SpellResult perform(CastContext context) {
boolean hasTarget = context.getTargetLocation() != null;
boolean hasEntityTarget = context.getTargetEntity() != null;
if (action.requiresTarget() && !hasTarget)
return SpellResult.NO_TARGET;
if (action.requiresTargetEntity() && !hasEntityTarget)
return SpellResult.NO_TARGET;
SpellResult result = action.perform(context);
return action.ignoreResult() && !result.isStop() ? SpellResult.NO_ACTION : result;
}
Aggregations