Search in sources :

Example 26 with Target

use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.

the class OrientSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    Entity entity = target.getEntity();
    if (entity == null) {
        return SpellResult.NO_TARGET;
    }
    if (entity != mage.getEntity() && controller.isMage(entity)) {
        Mage mage = controller.getMage(entity);
        if (mage.isSuperProtected()) {
            return SpellResult.NO_TARGET;
        }
    }
    Location location = entity.getLocation();
    location.setPitch((float) parameters.getDouble("pitch", 0));
    location.setYaw((float) parameters.getDouble("yaw", 0));
    entity.teleport(location);
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) Target(com.elmakers.mine.bukkit.utility.Target) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Location(org.bukkit.Location)

Example 27 with Target

use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.

the class PushSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    boolean push = false;
    boolean pull = false;
    Entity sourceEntity = mage.getEntity();
    String typeString = parameters.getString("type", "");
    push = typeString.equals("push");
    pull = typeString.equals("pull");
    double multiplier = parameters.getDouble("size", 1);
    if (push) {
        multiplier *= mage.getDamageMultiplier();
    }
    int count = parameters.getInt("count", 0);
    boolean allowAll = mage.isSuperPowered() || parameters.getBoolean("allow_area", true);
    boolean forceArea = parameters.getBoolean("area", false);
    int itemMagnitude = parameters.getInt("item_force", DEFAULT_ITEM_MAGNITUDE);
    int entityMagnitude = parameters.getInt("entity_force", DEFAULT_ENTITY_MAGNITUDE);
    int maxAllDistance = parameters.getInt("area_range", DEFAULT_MAX_ALL_DISTANCE);
    int fallProtection = parameters.getInt("fall_protection", 0);
    double damage = parameters.getDouble("damage", 0) * mage.getDamageMultiplier();
    if (mage.isSuperPowered()) {
        allowAll = true;
    }
    if (allowAll && (forceArea || isLookingDown() || isLookingUp())) {
        forceAll(sourceEntity, multiplier, pull, entityMagnitude, itemMagnitude, maxAllDistance, damage, fallProtection);
        return SpellResult.ALTERNATE;
    }
    Target directTarget = getTarget();
    List<Target> targets = getAllTargetEntities();
    if (directTarget.hasEntity() && targets.size() == 0) {
        targets.add(directTarget);
    }
    if (targets.size() == 0) {
        return SpellResult.NO_TARGET;
    }
    int pushed = 0;
    for (Target target : targets) {
        Entity targetEntity = target.getEntity();
        Mage mage = targetEntity != null && controller.isMage(targetEntity) ? controller.getMage(targetEntity) : null;
        if (mage != null && mage.isSuperProtected()) {
            continue;
        }
        if (mage != null && fallProtection > 0) {
            mage.enableFallProtection(fallProtection);
        }
        int magnitude = (target instanceof LivingEntity) ? entityMagnitude : itemMagnitude;
        getCurrentTarget().setEntity(targetEntity);
        forceEntity(targetEntity, multiplier, getLocation(), target.getLocation(), magnitude, damage, pull);
        pushed++;
        if (count > 0 && pushed >= count)
            break;
    }
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Target(com.elmakers.mine.bukkit.utility.Target) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 28 with Target

use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.

the class UndoSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    int timeout = parameters.getInt("target_timeout", 0);
    boolean targetSelf = parameters.getBoolean("target_up_self", false);
    boolean targetDown = parameters.getBoolean("target_down_block", false);
    Entity targetEntity = target.getEntity();
    SpellResult result = SpellResult.CAST;
    if (targetSelf && isLookingUp()) {
        targetEntity = mage.getEntity();
        getCurrentCast().setTargetName(mage.getName());
        result = SpellResult.ALTERNATE_UP;
    }
    if (targetEntity != null && controller.isMage(targetEntity)) {
        Mage targetMage = controller.getMage(targetEntity);
        Batch batch = targetMage.cancelPending();
        if (batch != null) {
            undoListName = (batch instanceof SpellBatch) ? ((SpellBatch) batch).getSpell().getName() : null;
            return SpellResult.ALTERNATE;
        }
        UndoQueue queue = targetMage.getUndoQueue();
        UndoList undoList = queue.undoRecent(timeout);
        if (undoList != null) {
            undoListName = undoList.getName();
        }
        return undoList != null ? result : SpellResult.NO_TARGET;
    }
    if (!parameters.getBoolean("target_blocks", true)) {
        return SpellResult.NO_TARGET;
    }
    Block targetBlock = target.getBlock();
    if (targetDown && isLookingDown()) {
        targetBlock = getLocation().getBlock();
    }
    if (targetBlock != null) {
        boolean targetAll = mage.isSuperPowered();
        if (targetAll) {
            UndoList undid = controller.undoRecent(targetBlock, timeout);
            if (undid != null) {
                Mage targetMage = undid.getOwner();
                undoListName = undid.getName();
                getCurrentCast().setTargetName(targetMage.getName());
                return result;
            }
        } else {
            getCurrentCast().setTargetName(mage.getName());
            UndoList undoList = mage.undo(targetBlock);
            if (undoList != null) {
                undoListName = undoList.getName();
                return result;
            }
        }
    }
    return SpellResult.NO_TARGET;
}
Also used : Entity(org.bukkit.entity.Entity) SpellBatch(com.elmakers.mine.bukkit.api.batch.SpellBatch) Target(com.elmakers.mine.bukkit.utility.Target) UndoQueue(com.elmakers.mine.bukkit.api.block.UndoQueue) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Batch(com.elmakers.mine.bukkit.api.batch.Batch) SpellBatch(com.elmakers.mine.bukkit.api.batch.SpellBatch) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Block(org.bukkit.block.Block) SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult)

Example 29 with Target

use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.

the class WolfSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    ArrayList<Wolf> newWolves = new ArrayList<>();
    for (Wolf wolf : wolves) {
        if (!wolf.isDead()) {
            newWolves.add(wolf);
        }
    }
    wolves = newWolves;
    int maxWolves = parameters.getInt("max_wolves", DEFAULT_MAX_WOLVES);
    int scaledMaxWolves = (int) (mage.getRadiusMultiplier() * maxWolves);
    if (wolves.size() >= scaledMaxWolves) {
        Wolf killWolf = wolves.remove(0);
        killWolf.setHealth(0);
    }
    Wolf wolf = newWolf(target);
    if (wolf == null) {
        return SpellResult.NO_TARGET;
    }
    wolves.add(wolf);
    Entity e = target.getEntity();
    if (e != null && e instanceof LivingEntity) {
        LivingEntity targetEntity = (LivingEntity) e;
        for (Wolf w : wolves) {
            w.setTarget(targetEntity);
            w.setAngry(true);
        }
    }
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Target(com.elmakers.mine.bukkit.utility.Target) ArrayList(java.util.ArrayList) Wolf(org.bukkit.entity.Wolf)

Example 30 with Target

use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.

the class SimulateBatch method checkForPotentialHeart.

protected void checkForPotentialHeart(Block block, int distanceSquared) {
    liveBlocks.add(com.elmakers.mine.bukkit.block.BlockData.getBlockId(block));
    if (isAutomata) {
        if (distanceSquared <= commandMoveRangeSquared) {
            // commandMoveRangeSquared is kind of too big, but it doesn't matter all that much
            // we still look at targets that end up with a score of 0, it just affects the sort ordering.
            Target potential = new Target(center, block, 1, commandMoveRangeSquared, huntFov, fovWeight, reverseTargetDistanceScore);
            potentialHeartBlocks.add(potential);
        }
    }
}
Also used : Target(com.elmakers.mine.bukkit.utility.Target)

Aggregations

Target (com.elmakers.mine.bukkit.utility.Target)44 Entity (org.bukkit.entity.Entity)24 Location (org.bukkit.Location)20 Block (org.bukkit.block.Block)20 LivingEntity (org.bukkit.entity.LivingEntity)17 Player (org.bukkit.entity.Player)14 Mage (com.elmakers.mine.bukkit.api.magic.Mage)13 ArrayList (java.util.ArrayList)9 Vector (org.bukkit.util.Vector)7 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)5 ActionHandler (com.elmakers.mine.bukkit.action.ActionHandler)4 CoverAction (com.elmakers.mine.bukkit.action.builtin.CoverAction)4 ItemStack (org.bukkit.inventory.ItemStack)4 MaterialBrush (com.elmakers.mine.bukkit.api.block.MaterialBrush)3 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)3 Material (org.bukkit.Material)3 Ageable (org.bukkit.entity.Ageable)3 SpellResult (com.elmakers.mine.bukkit.api.spell.SpellResult)2 ConstructionType (com.elmakers.mine.bukkit.block.ConstructionType)2 World (org.bukkit.World)2