Search in sources :

Example 1 with SpellResult

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;
}
Also used : SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult) ActionHandler(com.elmakers.mine.bukkit.action.ActionHandler)

Example 2 with SpellResult

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;
}
Also used : ArrayList(java.util.ArrayList) SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult) ActionContext(com.elmakers.mine.bukkit.action.ActionContext)

Example 3 with SpellResult

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;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) MagicController(com.elmakers.mine.bukkit.magic.MagicController) PreciousStonesManager(com.elmakers.mine.bukkit.protection.PreciousStonesManager) SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult)

Example 4 with SpellResult

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;
}
Also used : Block(org.bukkit.block.Block) SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult) Vector(org.bukkit.util.Vector)

Example 5 with SpellResult

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;
}
Also used : SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult)

Aggregations

SpellResult (com.elmakers.mine.bukkit.api.spell.SpellResult)21 Entity (org.bukkit.entity.Entity)6 Mage (com.elmakers.mine.bukkit.api.magic.Mage)5 Block (org.bukkit.block.Block)5 Batch (com.elmakers.mine.bukkit.api.batch.Batch)3 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)3 MageController (com.elmakers.mine.bukkit.api.magic.MageController)3 Location (org.bukkit.Location)3 Vector (org.bukkit.util.Vector)3 ActionHandler (com.elmakers.mine.bukkit.action.ActionHandler)2 UndoQueue (com.elmakers.mine.bukkit.api.block.UndoQueue)2 Wand (com.elmakers.mine.bukkit.api.wand.Wand)2 Target (com.elmakers.mine.bukkit.utility.Target)2 ArrayList (java.util.ArrayList)2 ArmorStand (org.bukkit.entity.ArmorStand)2 ActionContext (com.elmakers.mine.bukkit.action.ActionContext)1 SpellBatch (com.elmakers.mine.bukkit.api.batch.SpellBatch)1 CastEvent (com.elmakers.mine.bukkit.api.event.CastEvent)1 PreCastEvent (com.elmakers.mine.bukkit.api.event.PreCastEvent)1 Messages (com.elmakers.mine.bukkit.api.magic.Messages)1