Search in sources :

Example 1 with IndirectEntityDamageSource

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

the class FrimusBossManager method handleDamaged.

private void handleDamaged() {
    List<Instruction<DamagedCondition, Boss<Living, ZoneBossDetail<FreakyFourInstance>>>> damagedProcessor = getDamagedProcessor();
    damagedProcessor.add((condition, boss) -> {
        DamageEntityEvent event = condition.getEvent();
        new PlayerCombatParser() {

            @Override
            public void processPlayerAttack(Player attacker, Living defender) {
                if (condition.getDamageSource().get() instanceof IndirectEntityDamageSource) {
                    attacker.sendMessage(Text.of(TextColors.RED, "Projectiles can't harm me... Mwahahaha!"));
                    event.setCancelled(true);
                }
            }
        }.parse(event);
        return Optional.empty();
    });
}
Also used : DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Player(org.spongepowered.api.entity.living.player.Player) Living(org.spongepowered.api.entity.living.Living) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) NamedBindInstruction(com.skelril.skree.content.zone.group.catacombs.instruction.bossmove.NamedBindInstruction) Instruction(com.skelril.openboss.Instruction) HealthBindInstruction(com.skelril.skree.content.zone.group.freakyfour.boss.bossmove.HealthBindInstruction) ZoneBossDetail(com.skelril.skree.content.zone.ZoneBossDetail) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser)

Example 2 with IndirectEntityDamageSource

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

the class PatientXManager method setupBossManager.

private void setupBossManager() {
    Sponge.getEventManager().registerListeners(SkreePlugin.inst(), new BossListener<>(bossManager, Zombie.class));
    List<Instruction<BindCondition, Boss<Zombie, ZoneBossDetail<PatientXInstance>>>> bindProcessor = bossManager.getBindProcessor();
    bindProcessor.add((condition, boss) -> {
        Optional<Zombie> optBossEnt = boss.getTargetEntity();
        if (optBossEnt.isPresent()) {
            Zombie bossEnt = optBossEnt.get();
            bossEnt.offer(Keys.DISPLAY_NAME, Text.of("Patient X"));
            setMaxHealth(bossEnt, config.bossHealth, true);
        }
        return Optional.empty();
    });
    bindProcessor.add((condition, boss) -> {
        Optional<Zombie> optBoss = boss.getTargetEntity();
        if (optBoss.isPresent()) {
            optBoss.get().offer(Keys.PERSISTS, true);
        }
        return Optional.empty();
    });
    bindProcessor.add((condition, boss) -> {
        boss.getDetail().getZone().getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.GOLD, "Ice to meet you again!"));
        return Optional.empty();
    });
    List<Instruction<UnbindCondition, Boss<Zombie, ZoneBossDetail<PatientXInstance>>>> unbindProcessor = bossManager.getUnbindProcessor();
    unbindProcessor.add((condition, boss) -> {
        PatientXInstance inst = boss.getDetail().getZone();
        Location<World> target = inst.getCenter();
        for (Player player : inst.getPlayers(PlayerClassifier.PARTICIPANT)) {
            player.setLocation(target);
            boolean useX = Probability.getChance(2);
            int accel = Probability.getChance(2) ? 1 : -1;
            Vector3d v = new Vector3d(useX ? accel : 0, 0, !useX ? accel : 0);
            player.setVelocity(v);
        }
        inst.freezeBlocks(100, false);
        // Reset respawn mechanics
        inst.bossDied();
        return Optional.empty();
    });
    List<Instruction<DamageCondition, Boss<Zombie, ZoneBossDetail<PatientXInstance>>>> damageProcessor = bossManager.getDamageProcessor();
    damageProcessor.add((condition, boss) -> {
        PatientXInstance inst = boss.getDetail().getZone();
        DamageEntityEvent event = condition.getEvent();
        // Nullify all modifiers
        for (DamageFunction modifier : event.getModifiers()) {
            event.setDamage(modifier.getModifier(), (a) -> a);
        }
        event.setBaseDamage(inst.getDifficulty() * config.baseBossHit);
        return Optional.empty();
    });
    List<Instruction<DamagedCondition, Boss<Zombie, ZoneBossDetail<PatientXInstance>>>> damagedProcessor = bossManager.getDamagedProcessor();
    damagedProcessor.add((condition, boss) -> {
        DamageEntityEvent event = condition.getEvent();
        Optional<DamageSource> optDamageSource = condition.getDamageSource();
        if (optDamageSource.isPresent() && blockedDamage.contains(optDamageSource.get().getType())) {
            event.setCancelled(true);
            return Optional.empty();
        }
        return Optional.of((damagedCondition, zombieZoneBossDetailBoss) -> {
            PatientXInstance inst = boss.getDetail().getZone();
            if (optDamageSource.isPresent() && optDamageSource.get() instanceof EntityDamageSource) {
                if (optDamageSource.get() instanceof IndirectEntityDamageSource) {
                    Task.builder().execute(() -> {
                        VelocityEntitySpawner.sendRadial(EntityTypes.SNOWBALL, inst.getBoss().get(), Cause.source(SpawnCause.builder().type(SpawnTypes.PROJECTILE).build()).build());
                    }).delayTicks(1).submit(SkreePlugin.inst());
                } else {
                    Entity srcEntity = ((EntityDamageSource) optDamageSource.get()).getSource();
                    if (srcEntity instanceof Player) {
                        Optional<ItemStack> optHeld = ((Player) srcEntity).getItemInHand(HandTypes.MAIN_HAND);
                        if (optHeld.isPresent() && optHeld.get().getItem() == ItemTypes.BLAZE_ROD) {
                            inst.modifyDifficulty(2);
                        }
                    }
                }
            }
            inst.modifyDifficulty(.5);
            inst.teleportRandom(true);
            return Optional.empty();
        });
    });
}
Also used : Entity(org.spongepowered.api.entity.Entity) Instruction(com.skelril.openboss.Instruction) World(org.spongepowered.api.world.World) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) DamageFunction(org.spongepowered.api.event.cause.entity.damage.DamageFunction) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) 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) Zombie(org.spongepowered.api.entity.living.monster.Zombie) Vector3d(com.flowpowered.math.vector.Vector3d) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 3 with IndirectEntityDamageSource

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

the class ShnugglesPrimeManager method setupBossManager.

private void setupBossManager() {
    Sponge.getEventManager().registerListeners(SkreePlugin.inst(), new BossListener<>(bossManager, Giant.class));
    List<Instruction<BindCondition, Boss<Giant, ZoneBossDetail<ShnugglesPrimeInstance>>>> bindProcessor = bossManager.getBindProcessor();
    bindProcessor.add((condition, boss) -> {
        Optional<Giant> optBossEnt = boss.getTargetEntity();
        if (optBossEnt.isPresent()) {
            Giant bossEnt = optBossEnt.get();
            bossEnt.offer(Keys.DISPLAY_NAME, Text.of("Shnuggles Prime"));
            setMaxHealth(bossEnt, 750, true);
        }
        return Optional.empty();
    });
    bindProcessor.add((condition, boss) -> {
        Optional<Giant> optBoss = boss.getTargetEntity();
        if (optBoss.isPresent()) {
            optBoss.get().offer(Keys.PERSISTS, true);
        }
        return Optional.empty();
    });
    bindProcessor.add((condition, boss) -> {
        boss.getDetail().getZone().getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.GOLD, "I live again!"));
        return Optional.empty();
    });
    List<Instruction<UnbindCondition, Boss<Giant, ZoneBossDetail<ShnugglesPrimeInstance>>>> unbindProcessor = bossManager.getUnbindProcessor();
    unbindProcessor.add((condition, boss) -> {
        ShnugglesPrimeInstance inst = boss.getDetail().getZone();
        // Reset respawn mechanics
        inst.bossDied();
        // Buff babies
        inst.buffBabies();
        return Optional.empty();
    });
    unbindProcessor.add((condition, boss) -> {
        ShnugglesPrimeInstance inst = boss.getDetail().getZone();
        int playerCount = inst.getPlayers(PlayerClassifier.PARTICIPANT).size();
        Collection<ItemStack> drops = DROP_TABLE.getDrops(Math.min(7000, playerCount * 1500));
        Optional<Giant> optEnt = boss.getTargetEntity();
        if (optEnt.isPresent()) {
            Task.builder().execute(() -> {
                new ItemDropper(optEnt.get().getLocation()).dropStacks(drops, SpawnTypes.DROPPED_ITEM);
            }).delayTicks(1).submit(SkreePlugin.inst());
        }
        return Optional.empty();
    });
    List<Instruction<DamagedCondition, Boss<Giant, ZoneBossDetail<ShnugglesPrimeInstance>>>> damagedProcessor = bossManager.getDamagedProcessor();
    damagedProcessor.add((condition, boss) -> {
        ShnugglesPrimeInstance inst = boss.getDetail().getZone();
        DamageEntityEvent event = condition.getEvent();
        // Schedule a task to change the display name to show HP
        Task.builder().execute(inst::printBossHealth).delayTicks(1).submit(SkreePlugin.inst());
        if (inst.damageHeals()) {
            if (inst.isActiveAttack(ShnugglesPrimeAttack.BASK_IN_MY_GLORY)) {
                if (boss.getTargetEntity().isPresent()) {
                    toFullHealth(boss.getTargetEntity().get());
                }
            } else {
                double healedDamage = event.getFinalDamage() * 2;
                if (boss.getTargetEntity().isPresent()) {
                    heal(boss.getTargetEntity().get(), healedDamage);
                }
            }
            event.setBaseDamage(0);
            if (Probability.getChance(3) && event.getCause().first(Player.class).isPresent()) {
                int affected = 0;
                if (boss.getTargetEntity().isPresent()) {
                    for (Entity e : boss.getTargetEntity().get().getNearbyEntities(8)) {
                        if (e.isLoaded() && !e.isRemoved() && e instanceof Player && inst.contains(e)) {
                            e.setVelocity(new Vector3d(Math.random() * 3 - 1.5, Math.random() * 4, Math.random() * 3 - 1.5));
                            e.offer(Keys.FIRE_TICKS, Probability.getRandom(20 * 60));
                            ++affected;
                        }
                    }
                }
                if (affected > 0) {
                    inst.sendAttackBroadcast("Feel my power!", AttackSeverity.INFO);
                }
            }
        }
        Optional<DamageSource> optDmgSource = condition.getDamageSource();
        if (optDmgSource.isPresent()) {
            DamageSource dmgSource = optDmgSource.get();
            Entity attacker = null;
            if (dmgSource instanceof IndirectEntityDamageSource) {
                attacker = ((IndirectEntityDamageSource) dmgSource).getIndirectSource();
            } else if (dmgSource instanceof EntityDamageSource) {
                attacker = ((EntityDamageSource) dmgSource).getSource();
                if (attacker instanceof Player) {
                /* TODO Convert to Sponge
                    if (ItemUtil.hasForgeBook((Player) attacker)) {
                        boss.setHealth(0);
                        final Player finalAttacker = (Player) attacker;
                        if (!finalAttacker.getGameMode().equals(GameMode.CREATIVE)) {
                            server().getScheduler().runTaskLater(inst(), () -> (finalAttacker).setItemInHand(null), 1);
                        }
                    }*/
                }
            }
            if (Probability.getChance(3) && attacker instanceof Player) {
                inst.spawnMinions((Player) attacker);
            }
        }
        event.setBaseDamage(Math.min(35, event.getBaseDamage()));
        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) ItemDropper(com.skelril.nitro.item.ItemDropper) 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) Instruction(com.skelril.openboss.Instruction) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) Vector3d(com.flowpowered.math.vector.Vector3d) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) Giant(org.spongepowered.api.entity.living.monster.Giant) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

Example 4 with IndirectEntityDamageSource

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

the class PlayerCombatParser method parse.

default void parse(DamageEntityEvent event) {
    Entity entity = event.getTargetEntity();
    if (!(entity instanceof Living)) {
        return;
    }
    Optional<DamageSource> optDamageSource = event.getCause().first(DamageSource.class);
    if (optDamageSource.isPresent()) {
        Entity srcEntity = null;
        Entity indirectSrcEntity = null;
        if (optDamageSource.get() instanceof IndirectEntityDamageSource) {
            srcEntity = ((IndirectEntityDamageSource) optDamageSource.get()).getIndirectSource();
            indirectSrcEntity = ((IndirectEntityDamageSource) optDamageSource.get()).getSource();
        } else if (optDamageSource.get() instanceof EntityDamageSource) {
            srcEntity = ((EntityDamageSource) optDamageSource.get()).getSource();
        }
        if (!(srcEntity instanceof Living)) {
            if (entity instanceof Player) {
                processNonLivingAttack(optDamageSource.get(), (Player) entity);
            }
            return;
        }
        Living living = (Living) srcEntity;
        if (verify(living)) {
            if (entity instanceof Player && living instanceof Player) {
                processPvP((Player) living, (Player) entity);
                processPvP((Player) living, (Player) entity, indirectSrcEntity);
            } else if (entity instanceof Player) {
                processMonsterAttack(living, (Player) entity);
            } else if (living instanceof Player) {
                processPlayerAttack((Player) living, (Living) entity);
            }
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) 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)

Example 5 with IndirectEntityDamageSource

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

the class WildernessWorldWrapper method onEntityDeath.

@Listener
public void onEntityDeath(DestructEntityEvent.Death event) {
    Entity entity = event.getTargetEntity();
    Location<World> loc = entity.getLocation();
    Optional<Integer> optLevel = getLevel(loc);
    if (!optLevel.isPresent()) {
        return;
    }
    int level = optLevel.get();
    if (entity instanceof Monster) {
        DropTable dropTable;
        if (entity.getLocation().getExtent().getDimension() == DimensionTypes.NETHER || entity instanceof Wither) {
            dropTable = netherMobDropTable;
        } else {
            dropTable = commonDropTable;
        }
        Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
        if (optDamageSource.isPresent()) {
            Entity srcEntity;
            if (optDamageSource.get() instanceof IndirectEntityDamageSource) {
                srcEntity = ((IndirectEntityDamageSource) optDamageSource.get()).getIndirectSource();
            } else {
                srcEntity = optDamageSource.get().getSource();
            }
            int dropTier = level;
            if (srcEntity instanceof Player) {
                Optional<ItemStack> optHeldItem = ((Player) srcEntity).getItemInHand(HandTypes.MAIN_HAND);
                if (optHeldItem.isPresent()) {
                    Optional<ItemEnchantment> optLooting = EnchantmentUtil.getHighestEnchantment(optHeldItem.get(), Enchantments.LOOTING);
                    if (optLooting.isPresent()) {
                        dropTier += optLooting.get().getLevel();
                    }
                }
                dropTier = getDropTier(dropTier);
                Collection<ItemStack> drops = dropTable.getDrops((entity instanceof Boss ? 5 : 1) * dropTier, getDropMod(dropTier, ((Monster) entity).getHealthData().maxHealth().get(), entity.getType()));
                int times = 1;
                Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
                if (optService.isPresent()) {
                    ModifierService service = optService.get();
                    if (service.isActive(Modifiers.DOUBLE_WILD_DROPS)) {
                        times *= 2;
                    }
                }
                ItemDropper dropper = new ItemDropper(loc);
                for (int i = 0; i < times; ++i) {
                    dropper.dropStacks(drops, SpawnTypes.DROPPED_ITEM);
                }
                Optional<HighScoreService> optHighScores = Sponge.getServiceManager().provide(HighScoreService.class);
                optHighScores.ifPresent(highScoreService -> highScoreService.update((Player) srcEntity, ScoreTypes.WILDERNESS_MOB_KILLS, 1));
            }
        }
        if (entity.getType() == EntityTypes.ENDERMITE && Probability.getChance(20)) {
            entity.getWorld().triggerExplosion(Explosion.builder().location(entity.getLocation()).shouldBreakBlocks(true).radius(4F).build(), Cause.source(SkreePlugin.container()).build());
        }
    }
    if (entity instanceof Player) {
        Player player = (Player) entity;
        GRAVE_STONE.createGraveFromDeath(player);
        Optional<HighScoreService> optHighScores = Sponge.getServiceManager().provide(HighScoreService.class);
        optHighScores.ifPresent(highScoreService -> highScoreService.update(player, ScoreTypes.WILDERNESS_DEATHS, 1));
    }
}
Also used : Wither(org.spongepowered.api.entity.living.monster.Wither) Player(org.spongepowered.api.entity.living.player.Player) ItemDropper(com.skelril.nitro.item.ItemDropper) ModifierService(com.skelril.skree.service.ModifierService) World(org.spongepowered.api.world.World) DropTable(com.skelril.nitro.droptable.DropTable) MasterDropTable(com.skelril.nitro.droptable.MasterDropTable) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) HighScoreService(com.skelril.skree.service.HighScoreService) WanderingBoss(com.skelril.skree.content.world.wilderness.wanderer.WanderingBoss) Boss(org.spongepowered.api.entity.living.monster.Boss) ItemEnchantment(org.spongepowered.api.data.meta.ItemEnchantment) Monster(org.spongepowered.api.entity.living.monster.Monster) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener)

Aggregations

IndirectEntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)12 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