Search in sources :

Example 1 with DamageSource

use of org.spongepowered.api.event.cause.entity.damage.source.DamageSource 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"));
            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();
            if (damageSource.getType() == DamageTypes.EXPLOSIVE) {
                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 2 with DamageSource

use of org.spongepowered.api.event.cause.entity.damage.source.DamageSource 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 (Tuple<DamageModifier, Function<? super Double, Double>> modifier : event.getModifiers()) {
            event.setDamage(modifier.getFirst(), (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) Function(java.util.function.Function) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) 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 DamageSource

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

the class ShnugglesPrimeInstance method runAttack.

public void runAttack(ShnugglesPrimeAttack attackCase) {
    Optional<Giant> optBoss = getBoss();
    if (!optBoss.isPresent()) {
        return;
    }
    Giant boss = optBoss.get();
    double bossHealth = getHealth(boss);
    double maxBossHealth = getMaxHealth(boss);
    double delay = 15000;
    if (lastAttackTime != 0 && System.currentTimeMillis() - lastAttackTime <= delay) {
        return;
    }
    Collection<Player> contained = getPlayers(PARTICIPANT);
    if (contained.isEmpty()) {
        return;
    }
    // AI-ish system
    if ((attackCase == ShnugglesPrimeAttack.EVERLASTING || attackCase == ShnugglesPrimeAttack.MINION_LEECH) && bossHealth > maxBossHealth * .9) {
        attackCase = Probability.getChance(2) ? ShnugglesPrimeAttack.DARK_POTIONS : ShnugglesPrimeAttack.CORRUPTION;
    }
    for (Player player : contained) {
        if (player.get(Keys.HEALTH).get() < 4) {
            attackCase = ShnugglesPrimeAttack.CORRUPTION;
            break;
        }
    }
    Collection<Zombie> zombies = getContained(Zombie.class);
    if (zombies.size() > 200) {
        attackCase = ShnugglesPrimeAttack.BASK_IN_MY_GLORY;
    }
    if (bossHealth < maxBossHealth * .4 && Probability.getChance(5)) {
        if (zombies.size() < 100 && bossHealth > 200) {
            attackCase = ShnugglesPrimeAttack.EVERLASTING;
        } else {
            attackCase = ShnugglesPrimeAttack.MINION_LEECH;
        }
    }
    if ((attackCase == ShnugglesPrimeAttack.BLINDNESS || attackCase == ShnugglesPrimeAttack.FIRE) && bossHealth < maxBossHealth * .15) {
        runRandomAttack();
        return;
    }
    switch(attackCase) {
        case WRATH:
            sendAttackBroadcast("Taste my wrath!", AttackSeverity.NORMAL);
            for (Player player : contained) {
                player.offer(Keys.VELOCITY, new Vector3d(random.nextDouble() * 3 - 1.5, random.nextDouble() * 1 + .5, random.nextDouble() * 3 - 1.5));
                player.offer(Keys.FIRE_TICKS, 20 * 3);
            }
            break;
        case CORRUPTION:
            sendAttackBroadcast("Embrace my corruption!", AttackSeverity.NORMAL);
            PotionEffect witherEffect = PotionEffect.of(PotionEffectTypes.WITHER, 1, 20 * 3);
            for (Player player : contained) {
                List<PotionEffect> potionEffects = player.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>(1));
                potionEffects.add(witherEffect);
                player.offer(Keys.POTION_EFFECTS, potionEffects);
            }
            break;
        case BLINDNESS:
            sendAttackBroadcast("Are you BLIND? Mwhahahaha!", AttackSeverity.NORMAL);
            PotionEffect blindnessEffect = PotionEffect.of(PotionEffectTypes.BLINDNESS, 0, 20 * 4);
            for (Player player : contained) {
                List<PotionEffect> potionEffects = player.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>(1));
                potionEffects.add(blindnessEffect);
                player.offer(Keys.POTION_EFFECTS, potionEffects);
            }
            break;
        case TANGO_TIME:
            sendAttackBroadcast("Tango time!", AttackSeverity.ULTIMATE);
            activeAttacks.add(ShnugglesPrimeAttack.TANGO_TIME);
            Task.builder().delay(7, TimeUnit.SECONDS).execute(() -> {
                if (!isBossSpawned())
                    return;
                for (Player player : getPlayers(PARTICIPANT)) {
                    // TODO Convert to Sponge
                    if (((EntityGiantZombie) boss).canEntityBeSeen(tf(player))) {
                        player.sendMessage(Text.of(TextColors.YELLOW, "Come closer..."));
                        player.setLocation(boss.getLocation());
                        EntityDamageSource source = EntityDamageSource.builder().entity(boss).type(DamageTypes.ATTACK).build();
                        player.damage(100, source, Cause.source(boss).build());
                        player.offer(Keys.VELOCITY, new Vector3d(random.nextDouble() * 1.7 - 1.5, random.nextDouble() * 2, random.nextDouble() * 1.7 - 1.5));
                    } else {
                        player.sendMessage(Text.of(TextColors.YELLOW, "Fine... No tango this time..."));
                    }
                }
                sendAttackBroadcast("Now wasn't that fun?", AttackSeverity.INFO);
                activeAttacks.remove(ShnugglesPrimeAttack.TANGO_TIME);
            }).submit(SkreePlugin.inst());
            break;
        case EVERLASTING:
            if (!damageHeals) {
                activeAttacks.add(ShnugglesPrimeAttack.EVERLASTING);
                sendAttackBroadcast("I am everlasting!", AttackSeverity.NORMAL);
                damageHeals = true;
                Task.builder().delay(12, TimeUnit.SECONDS).execute(() -> {
                    if (damageHeals) {
                        damageHeals = false;
                        if (!isBossSpawned())
                            return;
                        sendAttackBroadcast("Thank you for your assistance.", AttackSeverity.INFO);
                    }
                    activeAttacks.remove(ShnugglesPrimeAttack.EVERLASTING);
                }).submit(SkreePlugin.inst());
                break;
            }
            runRandomAttack();
            return;
        case FIRE:
            sendAttackBroadcast("Fire is your friend...", AttackSeverity.NORMAL);
            for (Player player : contained) {
                player.offer(Keys.FIRE_TICKS, 20 * 5);
            }
            break;
        case BASK_IN_MY_GLORY:
            if (!damageHeals) {
                sendAttackBroadcast("Bask in my glory!", AttackSeverity.ULTIMATE);
                activeAttacks.add(ShnugglesPrimeAttack.BASK_IN_MY_GLORY);
                Task.builder().delay(7, TimeUnit.SECONDS).execute(() -> {
                    if (!isBossSpawned())
                        return;
                    boolean baskInGlory = false;
                    for (Player player : getContained(Player.class)) {
                        // TODO Convert to Sponge
                        if (((EntityGiantZombie) boss).canEntityBeSeen(tf(player))) {
                            player.sendMessage(Text.of(TextColors.DARK_RED, "You!"));
                            baskInGlory = true;
                        }
                    }
                    //Attack
                    if (baskInGlory) {
                        damageHeals = true;
                        spawnPts.stream().filter(pt -> Probability.getChance(12)).forEach(pt -> {
                            Explosion explosion = Explosion.builder().shouldDamageEntities(true).location(pt).radius(10).build();
                            getRegion().getExtent().triggerExplosion(explosion, Cause.source(SkreePlugin.container()).owner(boss).build());
                        });
                        //Schedule Reset
                        Task.builder().delay(500, TimeUnit.MILLISECONDS).execute(() -> {
                            damageHeals = false;
                        }).submit(SkreePlugin.inst());
                        return;
                    }
                    // Notify if avoided
                    sendAttackBroadcast("Gah... Afraid are you friends?", AttackSeverity.INFO);
                    activeAttacks.remove(ShnugglesPrimeAttack.BASK_IN_MY_GLORY);
                }).submit(SkreePlugin.inst());
                break;
            }
            runRandomAttack();
            break;
        case DARK_POTIONS:
            sendAttackBroadcast("Unleash the inner darkness!", AttackSeverity.NORMAL);
            PotionEffect instantDamageEffect = PotionEffect.of(PotionEffectTypes.INSTANT_DAMAGE, 0, 1);
            for (Living entity : getContained(Zombie.class)) {
                if (!Probability.getChance(5)) {
                    continue;
                }
                entity.offer(Keys.HEALTH, 0D);
                Location targetLoc = entity.getLocation();
                Entity potion = getRegion().getExtent().createEntity(EntityTypes.SPLASH_POTION, targetLoc.getPosition());
                potion.offer(Keys.POTION_EFFECTS, Lists.newArrayList(instantDamageEffect));
                getRegion().getExtent().spawnEntity(potion, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
            }
            return;
        case MINION_LEECH:
            sendAttackBroadcast("My minions our time is now!", AttackSeverity.ULTIMATE);
            activeAttacks.add(ShnugglesPrimeAttack.MINION_LEECH);
            IntegratedRunnable minionEater = new IntegratedRunnable() {

                @Override
                public boolean run(int times) {
                    if (!isBossSpawned())
                        return true;
                    for (Living entity : getContained(Living.class)) {
                        // TODO convert to Sponge
                        if (entity instanceof Giant || !Probability.getChance(5) || !((EntityGiantZombie) boss).canEntityBeSeen((EntityLivingBase) entity)) {
                            continue;
                        }
                        double realDamage = entity.get(Keys.HEALTH).get();
                        // TODO convert to Sponge
                        if (entity instanceof Zombie && ((EntityZombie) entity).isChild()) {
                            entity.offer(Keys.HEALTH, 0D);
                        } else {
                            DamageSource source = DamageSource.builder().type(DamageTypes.ATTACK).build();
                            entity.damage(realDamage, source, Cause.source(boss).build());
                        }
                        toHeal += Math.min(1, realDamage / 3);
                    }
                    if (new TimeFilter(-1, 2).matchesFilter(times + 1)) {
                        getPlayerMessageChannel(SPECTATOR).send(Text.of(TextColors.DARK_AQUA, "The boss has drawn in: " + (int) toHeal + " health."));
                    }
                    return true;
                }

                @Override
                public void end() {
                    if (!isBossSpawned())
                        return;
                    heal(boss, toHeal);
                    toHeal = 0;
                    sendAttackBroadcast("Thank you my minions!", AttackSeverity.INFO);
                    printBossHealth();
                    activeAttacks.remove(ShnugglesPrimeAttack.MINION_LEECH);
                }
            };
            TimedRunnable<IntegratedRunnable> minonEatingTask = new TimedRunnable<>(minionEater, 20);
            Task minionEatingTaskExecutor = Task.builder().interval(500, TimeUnit.MILLISECONDS).execute(minonEatingTask).submit(SkreePlugin.inst());
            minonEatingTask.setTask(minionEatingTaskExecutor);
            break;
    }
    lastAttackTime = System.currentTimeMillis();
    lastAttack = attackCase;
}
Also used : Boss(com.skelril.openboss.Boss) BossManager(com.skelril.openboss.BossManager) SpawnCause(org.spongepowered.api.event.cause.entity.spawn.SpawnCause) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) TimedRunnable(com.skelril.nitro.time.TimedRunnable) PotionEffectTypes(org.spongepowered.api.effect.potion.PotionEffectTypes) SkreePlugin(com.skelril.skree.SkreePlugin) TextColor(org.spongepowered.api.text.format.TextColor) TimeFilter(com.skelril.nitro.time.TimeFilter) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) ZoneBossDetail(com.skelril.skree.content.zone.ZoneBossDetail) Living(org.spongepowered.api.entity.living.Living) ForgeTransformer.tf(com.skelril.nitro.transformer.ForgeTransformer.tf) Location(org.spongepowered.api.world.Location) BlockTypes(org.spongepowered.api.block.BlockTypes) DamageTypes(org.spongepowered.api.event.cause.entity.damage.DamageTypes) CustomItemTypes(com.skelril.skree.content.registry.item.CustomItemTypes) Cause(org.spongepowered.api.event.cause.Cause) Explosion(org.spongepowered.api.world.explosion.Explosion) World(org.spongepowered.api.world.World) BlockType(org.spongepowered.api.block.BlockType) Player(org.spongepowered.api.entity.living.player.Player) Giant(org.spongepowered.api.entity.living.monster.Giant) EntityHealthPrinter(com.skelril.nitro.entity.EntityHealthPrinter) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) EntityHealthUtil(com.skelril.nitro.entity.EntityHealthUtil) LegacyZoneBase(com.skelril.skree.content.zone.LegacyZoneBase) java.util(java.util) Keys(org.spongepowered.api.data.key.Keys) EntityZombie(net.minecraft.entity.monster.EntityZombie) PARTICIPANT(com.skelril.skree.service.internal.zone.PlayerClassifier.PARTICIPANT) Vector3d(com.flowpowered.math.vector.Vector3d) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) Lists(com.google.common.collect.Lists) EntityTypes(org.spongepowered.api.entity.EntityTypes) Text(org.spongepowered.api.text.Text) ZoneRegion(com.skelril.skree.service.internal.zone.ZoneRegion) Task(org.spongepowered.api.scheduler.Task) ZoneStatus(com.skelril.skree.service.internal.zone.ZoneStatus) Probability(com.skelril.nitro.probability.Probability) Zombie(org.spongepowered.api.entity.living.monster.Zombie) TextColors(org.spongepowered.api.text.format.TextColors) Nullable(javax.annotation.Nullable) PlaceHolderText(com.skelril.nitro.text.PlaceHolderText) Zone(com.skelril.skree.service.internal.zone.Zone) Entity(org.spongepowered.api.entity.Entity) SPECTATOR(com.skelril.skree.service.internal.zone.PlayerClassifier.SPECTATOR) TimeUnit(java.util.concurrent.TimeUnit) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Vector3i(com.flowpowered.math.vector.Vector3i) CombinedText(com.skelril.nitro.text.CombinedText) EntityGiantZombie(net.minecraft.entity.monster.EntityGiantZombie) Clause(com.skelril.nitro.Clause) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Task(org.spongepowered.api.scheduler.Task) Explosion(org.spongepowered.api.world.explosion.Explosion) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) EntityZombie(net.minecraft.entity.monster.EntityZombie) Zombie(org.spongepowered.api.entity.living.monster.Zombie) EntityGiantZombie(net.minecraft.entity.monster.EntityGiantZombie) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) Living(org.spongepowered.api.entity.living.Living) TimeFilter(com.skelril.nitro.time.TimeFilter) EntityGiantZombie(net.minecraft.entity.monster.EntityGiantZombie) TimedRunnable(com.skelril.nitro.time.TimedRunnable) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) Vector3d(com.flowpowered.math.vector.Vector3d) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) Giant(org.spongepowered.api.entity.living.monster.Giant) Location(org.spongepowered.api.world.Location)

Example 4 with DamageSource

use of org.spongepowered.api.event.cause.entity.damage.source.DamageSource 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 = dropTable.getDrops(Math.min(7000, playerCount * 1500), 1);
        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);
            }
        }
        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 5 with DamageSource

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

the class PlayerCombatParser method parse.

default 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)

Aggregations

DamageSource (org.spongepowered.api.event.cause.entity.damage.source.DamageSource)9 Entity (org.spongepowered.api.entity.Entity)8 Player (org.spongepowered.api.entity.living.player.Player)7 IndirectEntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)5 Vector3d (com.flowpowered.math.vector.Vector3d)4 EntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)4 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)4 Instruction (com.skelril.openboss.Instruction)3 Living (org.spongepowered.api.entity.living.Living)3 ItemStack (org.spongepowered.api.item.inventory.ItemStack)3 World (org.spongepowered.api.world.World)3 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)2 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)2 Nullable (javax.annotation.Nullable)2 Giant (org.spongepowered.api.entity.living.monster.Giant)2 Zombie (org.spongepowered.api.entity.living.monster.Zombie)2 Vector3i (com.flowpowered.math.vector.Vector3i)1 Lists (com.google.common.collect.Lists)1 Clause (com.skelril.nitro.Clause)1 EntityHealthPrinter (com.skelril.nitro.entity.EntityHealthPrinter)1