use of com.elmakers.mine.bukkit.action.ActionHandler 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.action.ActionHandler in project MagicPlugin by elBukkit.
the class CustomProjectileAction method prepare.
@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
super.prepare(context, parameters);
// Parameters that can be modified by a flight plan need
// to be reset here.
gravity = 0;
drag = 0;
reorient = false;
trackEntity = false;
trackCursorRange = 0;
trackSpeed = 0;
velocityTransform = null;
speed = 1;
tickSize = 0.5;
ignoreTargeting = false;
returnToCaster = false;
resetTimeOnPathChange = false;
updateLaunchLocation = false;
projectileFollowPlayer = false;
modifyParameters(parameters);
// These parameters can't be changed mid-flight
targeting.processParameters(parameters);
interval = parameters.getInt("interval", 30);
lifetime = parameters.getInt("lifetime", 8000);
attachDuration = parameters.getInt("attach_duration", 0);
reverseDirection = parameters.getBoolean("reverse", false);
startDistance = parameters.getInt("start", 0);
range = parameters.getInt("range", 0);
minEntityRange = parameters.getDouble("min_entity_range", 0);
minBlockRange = parameters.getDouble("min_block_range", 0);
minRange = parameters.getDouble("min_entity_range", Math.max(minEntityRange, minBlockRange));
if (minRange < Math.max(minEntityRange, minBlockRange)) {
minRange = Math.max(minEntityRange, minBlockRange);
}
projectileEffectKey = parameters.getString("projectile_effects", "projectile");
headshotEffectKey = parameters.getString("headshot_effects", "headshot");
hitEffectKey = parameters.getString("hit_effects", "hit");
missEffectKey = parameters.getString("miss_effects", "miss");
tickEffectKey = parameters.getString("tick_effects", "tick");
sourceLocation = new SourceLocation(parameters);
targetSelfTimeout = parameters.getInt("target_self_timeout", 0);
targetSelf = parameters.contains("target_self") ? parameters.getBoolean("target_self") : null;
breaksBlocks = parameters.getBoolean("break_blocks", true);
hitRequiresEntity = parameters.getBoolean("hit_requires_entity", false);
targetBreakables = parameters.getDouble("target_breakables", 1);
targetBreakableSize = parameters.getInt("breakable_size", 1);
bypassBackfire = parameters.getBoolean("bypass_backfire", false);
spread = parameters.getDouble("spread", 0);
maxMovementSpread = parameters.getDouble("spread_movement_max", 0);
movementSpread = parameters.getDouble("spread_movement", 0);
int hitLimit = parameters.getInt("hit_count", 1);
entityHitLimit = parameters.getInt("entity_hit_count", hitLimit);
blockHitLimit = parameters.getInt("block_hit_count", hitLimit);
reflectLimit = parameters.getInt("reflect_count", -1);
pitchMin = parameters.getInt("pitch_min", 90);
pitchMax = parameters.getInt("pitch_max", -90);
reflectReorient = parameters.getBoolean("reflect_reorient", false);
reflectResetDistanceTraveled = parameters.getBoolean("reflect_reset_distance_traveled", true);
reflectTargetCaster = parameters.getBoolean("reflect_target_caster", true);
reflectTrackEntity = parameters.getBoolean("reflect_track_target", false);
reflectTrackCursorRange = parameters.getDouble("reflect_track_range", 0D);
hitOnMiss = parameters.getBoolean("hit_on_miss", false);
returnOffset = ConfigurationUtils.getVector(parameters, "return_offset");
returnRelativeOffset = ConfigurationUtils.getVector(parameters, "return_relative_offset");
range = (int) (range * context.getMage().getRangeMultiplier());
// Some parameter tweaks to make sure things are sane
TargetType targetType = targeting.getTargetType();
if (targetType == TargetType.NONE) {
targeting.setTargetType(TargetType.OTHER);
}
// Flags to optimize FX calls
hasTickEffects = context.getEffects(tickEffectKey).size() > 0;
hasBlockMissEffects = context.getEffects("blockmiss").size() > 0;
hasStepEffects = context.getEffects("step").size() > 0;
hasPreHitEffects = context.getEffects("prehit").size() > 0;
ActionHandler handler = getHandler("tick");
hasTickActions = handler != null && handler.size() > 0;
planConfiguration = ConfigurationUtils.getNodeList(parameters, "plan");
}
use of com.elmakers.mine.bukkit.action.ActionHandler in project MagicPlugin by elBukkit.
the class ParallelAction method reset.
@Override
public void reset(CastContext context) {
super.reset(context);
ActionHandler actions = getHandler("actions");
if (actions != null) {
remaining = new ArrayList<>(actions.getActions());
for (ActionContext action : remaining) {
action.getAction().reset(context);
}
}
}
use of com.elmakers.mine.bukkit.action.ActionHandler in project MagicPlugin by elBukkit.
the class LightningSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target target = getTarget();
if (target == null || !target.isValid()) {
return SpellResult.NO_TARGET;
}
Block targetBlock = target.getBlock();
if (!hasBuildPermission(targetBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
CoverAction cover = new CoverAction();
cover.addAction(new LightningAction());
ActionHandler handler = new ActionHandler();
handler.loadAction(cover);
handler.initialize(this, parameters);
registerForUndo();
return handler.start(getCurrentCast(), parameters);
}
use of com.elmakers.mine.bukkit.action.ActionHandler in project MagicPlugin by elBukkit.
the class FrostSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target target = getTarget();
if (target == null || !target.isValid()) {
return SpellResult.NO_TARGET;
}
Block targetBlock = target.getBlock();
if (!hasBuildPermission(targetBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
CoverAction cover = new CoverAction();
cover.addAction(new FreezeAction());
cover.addAction(new DamageAction());
cover.addAction(new PotionEffectAction());
ActionHandler handler = new ActionHandler();
handler.loadAction(cover);
handler.initialize(this, parameters);
registerForUndo();
return handler.start(getCurrentCast(), parameters);
}
Aggregations