Search in sources :

Example 6 with IndirectEntityDamageSource

use of org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource in project Skree by Skelril.

the class GraveDigger method setupGraveDigger.

private void setupGraveDigger() {
    Sponge.getEventManager().registerListeners(SkreePlugin.inst(), new BossListener<>(bossManager, Skeleton.class));
    List<Instruction<BindCondition, Boss<Skeleton, WildernessBossDetail>>> bindProcessor = bossManager.getBindProcessor();
    bindProcessor.add((condition, boss) -> {
        Optional<Skeleton> optBossEnt = boss.getTargetEntity();
        if (optBossEnt.isPresent()) {
            Skeleton bossEnt = optBossEnt.get();
            bossEnt.offer(Keys.DISPLAY_NAME, Text.of("Grave Digger"));
            bossEnt.offer(Keys.CUSTOM_NAME_VISIBLE, true);
            double bossHealth = 20 * 43 * boss.getDetail().getLevel();
            setMaxHealth(bossEnt, bossHealth, true);
        }
        return Optional.empty();
    });
    List<Instruction<DamageCondition, Boss<Skeleton, WildernessBossDetail>>> damageProcessor = bossManager.getDamageProcessor();
    damageProcessor.add((condition, boss) -> {
        Entity eToHit = condition.getAttacked();
        if (!(eToHit instanceof Living)) {
            return Optional.empty();
        }
        Living toHit = (Living) eToHit;
        Location<World> targetLocation = toHit.getLocation();
        makeExplosiveTomb(targetLocation, boss);
        return Optional.empty();
    });
    List<Instruction<DamagedCondition, Boss<Skeleton, WildernessBossDetail>>> damagedProcessor = bossManager.getDamagedProcessor();
    damagedProcessor.add((condition, boss) -> {
        Optional<DamageSource> optDamageSource = condition.getDamageSource();
        if (optDamageSource.isPresent()) {
            DamageSource damageSource = optDamageSource.get();
            // Explosions are show up as custom instead of Explosion
            if (damageSource.getType() == DamageTypes.CUSTOM) {
                condition.getEvent().setCancelled(true);
            }
            if (!(damageSource instanceof IndirectEntityDamageSource)) {
                return Optional.empty();
            }
            Entity source = ((IndirectEntityDamageSource) damageSource).getIndirectSource();
            Location<World> targetLocation = source.getLocation();
            makeExplosiveTomb(targetLocation, boss);
        }
        return Optional.empty();
    });
}
Also used : Entity(org.spongepowered.api.entity.Entity) WildernessBossDetail(com.skelril.skree.content.world.wilderness.WildernessBossDetail) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) Living(org.spongepowered.api.entity.living.Living) Instruction(com.skelril.openboss.Instruction) World(org.spongepowered.api.world.World) Skeleton(org.spongepowered.api.entity.living.monster.Skeleton) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)

Example 7 with IndirectEntityDamageSource

use of org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource in project modules-extra by CubeEngine.

the class Observe method cause.

public static Map<String, Object> cause(Object cause, boolean doRecursion) {
    if (cause instanceof EntityDamageSource) {
        Entity source = ((EntityDamageSource) cause).getSource();
        Map<String, Object> sourceCause = Observe.cause(source);
        Map<String, Object> indirectCause = null;
        if (cause instanceof IndirectEntityDamageSource) {
            indirectCause = Observe.cause(((IndirectEntityDamageSource) cause).getIndirectSource());
            if (sourceCause == null) {
                return indirectCause;
            }
        }
        // TODO indirectCause
        return sourceCause;
    } else if (cause instanceof BlockDamageSource) {
        return Observe.cause(((BlockDamageSource) cause).getBlockSnapshot());
    } else if (cause instanceof DamageSource) {
        return Observe.damageCause(((DamageSource) cause));
    }
    if (cause instanceof Player) {
        return playerCause(((Player) cause));
    } else if (cause instanceof BlockSnapshot) {
        return blockCause(((BlockSnapshot) cause));
    } else if (cause instanceof PrimedTNT) {
        return tntCause(((PrimedTNT) cause));
    } else if (cause instanceof Entity) {
        return entityCause(((Entity) cause), doRecursion);
    }
    // TODO other causes that interest us
    return null;
}
Also used : PrimedTNT(org.spongepowered.api.entity.explosive.PrimedTNT) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) BlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.BlockDamageSource) BlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.BlockDamageSource) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)

Example 8 with IndirectEntityDamageSource

use of org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource in project AtherysCore by Atherys-Horizons.

the class DamageConfig method getDamageType.

public AtherysDamageType getDamageType(EntityDamageSource originalSource) {
    Entity source;
    if (originalSource instanceof IndirectEntityDamageSource) {
        source = ((IndirectEntityDamageSource) originalSource).getIndirectSource();
    } else {
        source = originalSource.getSource();
    }
    Optional<ItemStack> stack = InventoryUtils.getMainHand(source);
    if (stack.isPresent()) {
        return getItemDamageType(stack.get().getType());
    } else {
        return AtherysDamageTypes.UNARMED;
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 9 with IndirectEntityDamageSource

use of org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource in project Skree by Skelril.

the class BackTeleportInstruction method apply.

@Override
public Optional<Instruction<DamagedCondition, Boss<Living, ZoneBossDetail<FreakyFourInstance>>>> apply(DamagedCondition damagedCondition, Boss<Living, ZoneBossDetail<FreakyFourInstance>> livingZoneBossDetailBoss) {
    DamageEntityEvent event = damagedCondition.getEvent();
    new PlayerCombatParser() {

        @Override
        public void processPlayerAttack(Player attacker, Living defender) {
            boolean backTeleport = Probability.getChance(config.backTeleport);
            if (backTeleport || damagedCondition.getDamageSource().get() instanceof IndirectEntityDamageSource) {
                double distSQ = 2;
                double maxDist = 1;
                if (defender instanceof Skeleton) {
                    distSQ = defender.getLocation().getPosition().distanceSquared(attacker.getLocation().getPosition());
                    maxDist = config.snipeeTeleportDist;
                }
                if (backTeleport || distSQ > Math.pow(maxDist, 2)) {
                    final Entity finalDamager = attacker;
                    Task.builder().execute(() -> {
                        defender.setLocation(finalDamager.getLocation());
                        throwBack(defender);
                    }).delayTicks(1).submit(SkreePlugin.inst());
                }
            }
        }
    }.parse(event);
    return Optional.empty();
}
Also used : DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Living(org.spongepowered.api.entity.living.Living) Skeleton(org.spongepowered.api.entity.living.monster.Skeleton) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser)

Example 10 with IndirectEntityDamageSource

use of org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource in project Skree by Skelril.

the class RangedSpecialAttackClusterListener method getSource.

public Optional<Clause<Living, ItemStackSnapshot>> getSource(Cause cause) {
    Optional<EntityDamageSource> optEntityDamageSource = cause.first(EntityDamageSource.class);
    if (!optEntityDamageSource.isPresent()) {
        return Optional.empty();
    }
    EntityDamageSource damageSource = optEntityDamageSource.get();
    if (!(damageSource instanceof IndirectEntityDamageSource)) {
        return Optional.empty();
    }
    Entity projectile = damageSource.getSource();
    Entity source = ((IndirectEntityDamageSource) damageSource).getIndirectSource();
    if (!(source instanceof Living)) {
        return Optional.empty();
    }
    return Optional.of(new Clause<>((Living) source, projectile.get(SHOOTING_ITEM_DATA_KEY).map(Optional::get).orElse(null)));
}
Also used : Entity(org.spongepowered.api.entity.Entity) Living(org.spongepowered.api.entity.living.Living) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)

Aggregations

IndirectEntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)11 Entity (org.spongepowered.api.entity.Entity)9 Player (org.spongepowered.api.entity.living.player.Player)7 EntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)7 Living (org.spongepowered.api.entity.living.Living)6 DamageSource (org.spongepowered.api.event.cause.entity.damage.source.DamageSource)5 Instruction (com.skelril.openboss.Instruction)4 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)4 ItemStack (org.spongepowered.api.item.inventory.ItemStack)4 World (org.spongepowered.api.world.World)3 Vector3d (com.flowpowered.math.vector.Vector3d)2 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)2 ItemDropper (com.skelril.nitro.item.ItemDropper)2 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)2 Skeleton (org.spongepowered.api.entity.living.monster.Skeleton)2 DropTable (com.skelril.nitro.droptable.DropTable)1 MasterDropTable (com.skelril.nitro.droptable.MasterDropTable)1 WildernessBossDetail (com.skelril.skree.content.world.wilderness.WildernessBossDetail)1 WanderingBoss (com.skelril.skree.content.world.wilderness.wanderer.WanderingBoss)1 ZoneBossDetail (com.skelril.skree.content.zone.ZoneBossDetail)1