Search in sources :

Example 6 with Damageable

use of org.bukkit.entity.Damageable in project MagicPlugin by elBukkit.

the class RideEntityAction method perform.

@Override
public SpellResult perform(CastContext context) {
    if (mount == null) {
        return mount(context);
    }
    Entity mounted = context.getEntity();
    if (mounted == null) {
        return SpellResult.ENTITY_REQUIRED;
    }
    Entity currentMount = isPassenger ? mounted.getPassenger() : mounted.getVehicle();
    if (currentMount == null) {
        return SpellResult.CAST;
    }
    if (!mount.isValid()) {
        remount(context);
        if (mount == null) {
            return SpellResult.CAST;
        }
        if (isPassenger) {
            mounted.setPassenger(mount);
        } else {
            mount.setPassenger(mounted);
        }
    }
    // Play sound effects
    if (sound != null && nextSoundPlay < System.currentTimeMillis()) {
        nextSoundPlay = System.currentTimeMillis() + soundInterval;
        double speedRatio = 1;
        if (speed > 0) {
            double minForwardSpeed = Math.max(0, minSpeed);
            speedRatio = minSpeed >= maxSpeed ? 1 : (speed - minForwardSpeed) / (maxSpeed - minForwardSpeed);
        } else if (minSpeed < 0) {
            double maxBackwardSpeed = Math.max(Math.abs(minSpeed), maxSpeed);
            double backwardSpeed = Math.abs(speed);
            speedRatio = backwardSpeed / maxBackwardSpeed;
        }
        sound.setPitch((float) ((soundMaxPitch - soundMinPitch) * speedRatio));
        sound.setVolume((float) ((soundMaxVolume - soundMinVolume) * speedRatio));
        sound.play(context.getPlugin(), mounted);
    }
    // Check for crashing
    if (crashDistance > 0 && Math.abs(speed) >= crashSpeed) {
        Vector threshold = direction.clone().multiply(speed * crashDistance);
        if (checkForCrash(context, mounted.getLocation(), threshold)) {
            if (crash(context)) {
                return SpellResult.CAST;
            }
        }
    }
    if (!context.isPassthrough(mounted.getLocation().getBlock())) {
        if (crash(context)) {
            return SpellResult.CAST;
        }
    }
    if (crashEntityType != null && speed > 0 && crashEntityDistance > 0 && maxSpeed > 0) {
        List<Entity> nearby = mounted.getNearbyEntities(crashEntityDistance, crashEntityDistance, crashEntityDistance);
        Vector crashDirection = direction.clone();
        if (crashVelocityYOffset > 0) {
            crashDirection.setY(crashDirection.getY() + crashVelocityYOffset).normalize();
        }
        Vector velocity = crashDirection.multiply(crashVelocity * speed / maxSpeed);
        for (Entity entity : nearby) {
            if (entity == mounted || entity == mount || !entity.isValid() || !context.canTarget(entity, crashEntityType))
                continue;
            Vector targetDirection = entity.getLocation().subtract(mounted.getLocation()).toVector();
            double angle = targetDirection.angle(direction);
            if (angle > crashEntityFOV)
                continue;
            if (crashEntityDamage > 0 && entity instanceof Damageable) {
                Damageable damageable = (Damageable) entity;
                double crashDamage = maxSpeed > 0 ? crashEntityDamage * speed / maxSpeed : crashEntityDamage;
                CompatibilityUtils.damage(damageable, crashDamage, mounted);
            }
            SafetyUtils.setVelocity(entity, velocity);
            speed = Math.max(0, speed - crashBraking);
            if (mount instanceof Damageable && crashEntityVehicleDamage > 0) {
                double crashDamage = maxSpeed > 0 ? crashEntityVehicleDamage * speed / maxSpeed : crashEntityVehicleDamage;
                CompatibilityUtils.damage((Damageable) mount, crashDamage, mounted);
            }
            context.playEffects("crash_entity", 1.0f, null, mounted, null, entity);
        }
    }
    if (exemptionDuration > 0 && mounted instanceof Player) {
        context.getController().addFlightExemption((Player) mounted, exemptionDuration);
    }
    adjustHeading(context);
    if (System.currentTimeMillis() > liftoffTime + liftoffDuration) {
        applyThrust(context);
    }
    if (fallProtection > 0) {
        context.getMage().enableFallProtection(fallProtection, Integer.MAX_VALUE, context.getSpell());
    }
    return SpellResult.PENDING;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Damageable(org.bukkit.entity.Damageable) Vector(org.bukkit.util.Vector)

Example 7 with Damageable

use of org.bukkit.entity.Damageable in project Glowstone by GlowstoneMC.

the class GlowLightningStrike method pulse.

@Override
public void pulse() {
    super.pulse();
    if (getTicksLived() >= ticksToLive) {
        remove();
    }
    if (getTicksLived() == 1) {
        GlowWorld world = (GlowWorld) location.getWorld();
        // Play Sound
        if (!isSilent) {
            world.playSound(location, Sound.ENTITY_LIGHTNING_BOLT_THUNDER, 10000, 0.8F + ThreadLocalRandom.current().nextFloat() * 0.2F);
            world.playSound(location, Sound.ENTITY_GENERIC_EXPLODE, 2, 0.5F + ThreadLocalRandom.current().nextFloat() * 0.2F);
        }
        if (!effect) {
            // set target block on fire if required
            if (world.getGameRuleMap().getBoolean(GameRules.DO_FIRE_TICK)) {
                GlowBlock block = world.getBlockAt(location);
                setBlockOnFire(block);
                for (int i = 0; i < 4; i++) {
                    int x = location.getBlockX() - 1 + ThreadLocalRandom.current().nextInt(3);
                    int z = location.getBlockZ() - 1 + ThreadLocalRandom.current().nextInt(3);
                    int y = location.getBlockY() - 1 + ThreadLocalRandom.current().nextInt(3);
                    block = world.getBlockAt(x, y, z);
                    setBlockOnFire(block);
                }
            }
            // deal damage to nearby entities
            for (Entity entity : getNearbyEntities(3, 6, 3)) {
                if (entity.isDead()) {
                    continue;
                }
                if (entity instanceof Damageable) {
                    ((Damageable) entity).damage(5, this, EntityDamageEvent.DamageCause.LIGHTNING);
                }
                entity.setFireTicks(entity.getMaxFireTicks());
            }
        // TODO: Spawn Skeletontrap
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) GlowBlock(net.glowstone.block.GlowBlock) Damageable(org.bukkit.entity.Damageable) GlowWorld(net.glowstone.GlowWorld)

Example 8 with Damageable

use of org.bukkit.entity.Damageable in project QualityArmory by ZombieStriker.

the class PushbackCharger method shoot.

@SuppressWarnings("deprecation")
@Override
public boolean shoot(Gun g, Player p, ItemStack i) {
    Location start = p.getEyeLocation().clone();
    Vector go = p.getLocation().getDirection().normalize();
    // go.add(new Vector((Math.random() * 2 * sway) - sway, (Math.random() * 2 * sway) - sway,
    // (Math.random() * 2 * sway) - sway));
    GunUtil.playShoot(g, p);
    boolean lookup = (go.getY() > go.getX() && go.getY() > go.getZ());
    boolean lookdown = (-go.getY() > go.getX() && -go.getY() > go.getZ());
    double degreeVector = Math.atan2(go.getX(), go.getZ());
    if (degreeVector > Math.PI)
        degreeVector = 2 * Math.PI - degreeVector;
    for (Entity e : p.getNearbyEntities(g.getMaxDistance(), g.getMaxDistance(), g.getMaxDistance())) {
        double dis = e.getLocation().distance(start);
        if (e instanceof Damageable)
            if (e != p && e != p.getVehicle() && e != p.getPassenger()) {
                double degreeEntity = Math.atan2(e.getLocation().getX() - start.getX(), e.getLocation().getZ() - start.getZ());
                if (degreeEntity > Math.PI)
                    degreeEntity = 2 * Math.PI - degreeEntity;
                if ((lookup && e.getLocation().getY() > start.getY()) || (lookdown && e.getLocation().getY() < start.getY()) || (!lookdown && !lookup && Math.max(degreeEntity, degreeVector) - Math.min(degreeEntity, degreeVector) < (dis > 10 ? Math.PI / 4 : Math.PI / 2))) {
                    Vector pushback = new Vector(e.getLocation().getX() - start.getX(), e.getLocation().getY() - start.getY(), e.getLocation().getZ() - start.getZ());
                    pushback.normalize().multiply(g.getMaxDistance() / (dis));
                    e.setVelocity(pushback);
                }
            }
    }
    return false;
}
Also used : Entity(org.bukkit.entity.Entity) Damageable(org.bukkit.entity.Damageable) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 9 with Damageable

use of org.bukkit.entity.Damageable in project QualityArmory by ZombieStriker.

the class ExplosionHandler method handleAOEExplosion.

public static void handleAOEExplosion(Entity shooter, Location loc, double damage, double radius) {
    for (Entity e : loc.getWorld().getNearbyEntities(loc, radius, radius, radius)) {
        if (e instanceof Damageable) {
            Damageable d = (Damageable) e;
            d.damage(damage / e.getLocation().distance(loc), shooter);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Damageable(org.bukkit.entity.Damageable)

Example 10 with Damageable

use of org.bukkit.entity.Damageable in project EliteMobs by MagmaGuy.

the class HealthHandler method aggressiveHealthHandler.

public static void aggressiveHealthHandler(Entity entity, Entity deletedEntity) {
    if (entity.hasMetadata(MetadataHandler.CUSTOM_HEALTH)) {
        return;
    }
    Damageable damageableEntity = ((Damageable) entity);
    Damageable damageableDeleted = ((Damageable) deletedEntity);
    double defaultMaxHealth = DefaultMaxHealthGuesser.defaultMaxHealthGuesser(entity);
    int newEliteMobLevel = entity.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt();
    if (entity.hasMetadata(MetadataHandler.DOUBLE_DAMAGE_MD)) {
        newEliteMobLevel = (int) Math.floor(newEliteMobLevel / 2);
        if (newEliteMobLevel < 1) {
            newEliteMobLevel = 1;
        }
    }
    if (entity.hasMetadata(MetadataHandler.DOUBLE_HEALTH_MD)) {
        newEliteMobLevel = (int) Math.floor(newEliteMobLevel * 2);
    }
    damageableEntity.setMaxHealth(ScalingFormula.PowerFormula(defaultMaxHealth, newEliteMobLevel) * ConfigValues.defaultConfig.getDouble("Aggressive EliteMob life multiplier"));
    if (damageableEntity.getHealth() + damageableDeleted.getHealth() > damageableEntity.getMaxHealth()) {
        damageableEntity.setHealth(damageableEntity.getMaxHealth());
    } else {
        damageableEntity.setHealth(damageableEntity.getHealth() + damageableDeleted.getHealth());
    }
}
Also used : Damageable(org.bukkit.entity.Damageable)

Aggregations

Damageable (org.bukkit.entity.Damageable)15 Entity (org.bukkit.entity.Entity)12 LivingEntity (org.bukkit.entity.LivingEntity)8 Vector (org.bukkit.util.Vector)7 Player (org.bukkit.entity.Player)5 Block (org.bukkit.block.Block)3 Location (org.bukkit.Location)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)1 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1 ArrayList (java.util.ArrayList)1 AbstractBoundingBox (me.zombie_striker.qg.boundingbox.AbstractBoundingBox)1 GlowWorld (net.glowstone.GlowWorld)1 GlowBlock (net.glowstone.block.GlowBlock)1 World (org.bukkit.World)1 AttributeInstance (org.bukkit.attribute.AttributeInstance)1 IronGolem (org.bukkit.entity.IronGolem)1 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)1