Search in sources :

Example 1 with PrimedTNT

use of org.spongepowered.api.entity.explosive.PrimedTNT in project Skree by Skelril.

the class WildernessWorldWrapper method onEntitySpawn.

@Listener
public void onEntitySpawn(SpawnEntityEvent event) {
    List<Entity> entities = event.getEntities();
    Optional<BlockSpawnCause> optBlockCause = event.getCause().first(BlockSpawnCause.class);
    for (Entity entity : entities) {
        Location<World> loc = entity.getLocation();
        Optional<Integer> optLevel = getLevel(loc);
        if (!optLevel.isPresent())
            continue;
        int level = optLevel.get();
        if (entity instanceof Egg && optBlockCause.isPresent()) {
            PrimedTNT explosive = (PrimedTNT) entity.getLocation().getExtent().createEntity(EntityTypes.PRIMED_TNT, entity.getLocation().getPosition());
            explosive.setVelocity(entity.getVelocity());
            explosive.offer(Keys.FUSE_DURATION, 20 * 4);
            // TODO used to have a 1/4 chance of creating fire
            entity.getLocation().getExtent().spawnEntity(explosive, Cause.source(SpawnCause.builder().type(SpawnTypes.DISPENSE).build()).build());
            event.setCancelled(true);
            return;
        }
        if (level > 1) {
            // TODO move damage modification
            if (entity instanceof Monster) {
                HealthData healthData = ((Monster) entity).getHealthData();
                double curMax = healthData.maxHealth().get();
                if (curMax <= 80) {
                    // TODO do this a better way, but for now it prevents super mobs
                    double newMax = curMax * getHealthMod(level);
                    healthData.set(Keys.MAX_HEALTH, newMax);
                    healthData.set(Keys.HEALTH, newMax);
                    entity.offer(healthData);
                }
                // Wandering Bosses
                Collection<String> wanderers = wanderingMobManager.getSupportedWanderersOfType(entity.getType());
                for (String wanderer : wanderers) {
                    if (wanderingMobManager.chanceBind(wanderer, level, entity)) {
                        break;
                    }
                }
            }
        }
        Optional<Value<Integer>> optExplosiveRadius = Optional.empty();
        if (optExplosiveRadius.isPresent()) {
            Value<Integer> explosiveRadius = optExplosiveRadius.get();
            int min = explosiveRadius.get();
            entity.offer(Keys.EXPLOSION_RADIUS, Optional.of(MathExt.bound((min + level) / 2, min, entity instanceof Fireball ? 4 : 9)));
        }
    }
}
Also used : PrimedTNT(org.spongepowered.api.entity.explosive.PrimedTNT) HealthData(org.spongepowered.api.data.manipulator.mutable.entity.HealthData) Egg(org.spongepowered.api.entity.projectile.Egg) World(org.spongepowered.api.world.World) Fireball(org.spongepowered.api.entity.projectile.explosive.fireball.Fireball) Monster(org.spongepowered.api.entity.living.monster.Monster) Value(org.spongepowered.api.data.value.mutable.Value) BlockSpawnCause(org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause) Listener(org.spongepowered.api.event.Listener)

Example 2 with PrimedTNT

use of org.spongepowered.api.entity.explosive.PrimedTNT in project Skree by Skelril.

the class PatientXInstance method runAttack.

public void runAttack(PatientXAttack attackCase) {
    Optional<Zombie> optBoss = getBoss();
    if (!optBoss.isPresent()) {
        return;
    }
    Zombie boss = optBoss.get();
    Collection<Player> contained = getPlayers(PARTICIPANT);
    if (contained.isEmpty()) {
        return;
    }
    switch(attackCase) {
        case MUSICAL_CHAIRS:
            sendAttackBroadcast("Let's play musical chairs!", AttackSeverity.NORMAL);
            for (Player player : contained) {
                do {
                    player.setLocation(getRandomDest());
                } while (player.getLocation().getPosition().distanceSquared(boss.getLocation().getPosition()) <= 5 * 5);
                // TODO convert to Sponge
                if (((EntityZombie) boss).canEntityBeSeen(tf(player))) {
                    player.offer(Keys.HEALTH, Probability.getRandom(player.get(Keys.MAX_HEALTH).get()));
                    sendAttackBroadcast("Don't worry, I have a medical degree...", AttackSeverity.NORMAL);
                    sendAttackBroadcast("...or was that a certificate of insanity?", AttackSeverity.NORMAL);
                }
            }
            attackDur = System.currentTimeMillis() + 2000;
            break;
        case SMASHING_HIT:
            for (Player player : contained) {
                final double old = player.get(Keys.HEALTH).get();
                player.offer(Keys.HEALTH, 3D);
                Task.builder().execute(() -> {
                    if (!player.isRemoved() || !contains(player))
                        return;
                    player.offer(Keys.HEALTH, old * .75);
                }).delay(2, TimeUnit.SECONDS).submit(SkreePlugin.inst());
            }
            attackDur = System.currentTimeMillis() + 3000;
            sendAttackBroadcast("This special attack will be a \"smashing hit\"!", AttackSeverity.NORMAL);
            break;
        case BOMB_PERFORMANCE:
            double tntQuantity = Math.max(2, difficulty / 2.4);
            for (Player player : contained) {
                for (double i = Probability.getRangedRandom(tntQuantity, Math.pow(2, Math.min(9, tntQuantity))); i > 0; i--) {
                    PrimedTNT explosive = (PrimedTNT) getRegion().getExtent().createEntity(EntityTypes.PRIMED_TNT, player.getLocation().getPosition());
                    explosive.setVelocity(new Vector3d(random.nextDouble() * 1 - .5, random.nextDouble() * .8 + .2, random.nextDouble() * 1 - .5));
                    explosive.offer(Keys.FUSE_DURATION, 20 * 4);
                    getRegion().getExtent().spawnEntity(explosive, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
                }
            }
            attackDur = System.currentTimeMillis() + 5000;
            sendAttackBroadcast("Your performance is really going to \"bomb\"!", AttackSeverity.NORMAL);
            break;
        case WITHER_AWAY:
            PotionEffect witherEffect = PotionEffect.of(PotionEffectTypes.WITHER, 1, 20 * 15);
            for (Player player : contained) {
                List<PotionEffect> potionEffects = player.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>(1));
                potionEffects.add(witherEffect);
                player.offer(Keys.POTION_EFFECTS, potionEffects);
            }
            attackDur = System.currentTimeMillis() + 15750;
            sendAttackBroadcast("Like a candle I hope you don't \"whither\" and die!", AttackSeverity.NORMAL);
            break;
        case SPLASH_TO_IT:
            for (Player player : contained) {
                for (int i = Probability.getRandom(6) + 2; i > 0; --i) {
                    throwSlashPotion(player.getLocation());
                }
            }
            attackDur = System.currentTimeMillis() + 2000;
            sendAttackBroadcast("Splash to it!", AttackSeverity.NORMAL);
            break;
        case COLD_FEET:
            PotionEffect slowEffect = PotionEffect.of(PotionEffectTypes.SLOWNESS, 2, 20 * 60);
            for (Player player : contained) {
                List<PotionEffect> potionEffects = player.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>(1));
                potionEffects.add(slowEffect);
                player.offer(Keys.POTION_EFFECTS, potionEffects);
            }
            attackDur = System.currentTimeMillis() + 20000;
            sendAttackBroadcast("What's the matter, got cold feet?", AttackSeverity.NORMAL);
            break;
        case IM_JUST_BATTY:
            for (Player player : contained) {
                Cause cause = Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build();
                player.simulateChat(Text.of("I love Patient X!"), cause);
                Entity bat = getRegion().getExtent().createEntity(EntityTypes.BAT, player.getLocation().getPosition());
                getRegion().getExtent().spawnEntity(bat, cause);
                bat.getPassengers().add(player);
            }
            attackDur = System.currentTimeMillis() + 20000;
            sendAttackBroadcast("Awe, I love you too!", AttackSeverity.NORMAL);
            sendAttackBroadcast("But only cause I'm a little batty...", AttackSeverity.NORMAL);
            break;
        case RADIATION:
            ParticleEffect radiationEffect = ParticleEffect.builder().type(ParticleTypes.FLAME).quantity(1).build();
            Task.builder().execute(() -> {
                for (int i = config.radiationTimes; i > 0; i--) {
                    Task.builder().execute(() -> {
                        if (isBossSpawned()) {
                            for (Player player : getPlayers(PlayerClassifier.PARTICIPANT)) {
                                for (int e = 0; e < 30; ++e) {
                                    getRegion().getExtent().spawnParticles(radiationEffect, player.getLocation().getPosition().add(5 - Probability.getRandom(10) + Probability.getRangedRandom(0, 1.0), 5 - Probability.getRandom(10) + Probability.getRangedRandom(0, 1.0), 5 - Probability.getRandom(10) + Probability.getRangedRandom(0, 1.0)));
                                }
                                if (LightLevelUtil.getMaxLightLevel(player.getLocation()).get() >= config.radiationLightLevel) {
                                    player.damage(difficulty * config.radiationMultiplier, EntityDamageSource.builder().entity(boss).type(DamageTypes.MAGIC).build());
                                }
                            }
                        }
                    }).delay(i * 500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst());
                }
            }).delay(3, TimeUnit.SECONDS).submit(SkreePlugin.inst());
            attackDur = System.currentTimeMillis() + (config.radiationTimes * 500);
            sendAttackBroadcast("Ahhh not the radiation treatment!", AttackSeverity.NORMAL);
            break;
        case SNOWBALL_FIGHT:
            final int burst = Probability.getRangedRandom(10, 20);
            Task.builder().execute(() -> {
                for (int i = burst; i > 0; i--) {
                    Task.builder().execute(() -> {
                        if (boss != null)
                            freezeBlocks(true);
                    }).delay(i * 500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst());
                }
            }).delay(7, TimeUnit.SECONDS).submit(SkreePlugin.inst());
            attackDur = System.currentTimeMillis() + 7000 + (500 * burst);
            sendAttackBroadcast("Let's have a snow ball fight!", AttackSeverity.NORMAL);
            break;
    }
    lastAttack = attackCase;
}
Also used : PrimedTNT(org.spongepowered.api.entity.explosive.PrimedTNT) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) EntityZombie(net.minecraft.entity.monster.EntityZombie) Zombie(org.spongepowered.api.entity.living.monster.Zombie) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) EntityZombie(net.minecraft.entity.monster.EntityZombie) Vector3d(com.flowpowered.math.vector.Vector3d) SpawnCause(org.spongepowered.api.event.cause.entity.spawn.SpawnCause) Cause(org.spongepowered.api.event.cause.Cause)

Example 3 with PrimedTNT

use of org.spongepowered.api.entity.explosive.PrimedTNT in project Skree by Skelril.

the class JungleRaidEffectProcessor method distributor.

private static void distributor(JungleRaidInstance inst) {
    FlagEffectData data = inst.getFlagData();
    boolean isSuddenDeath = inst.isSuddenDeath();
    if (isSuddenDeath) {
        data.amt = 100;
    }
    if (inst.isFlagEnabled(JungleRaidFlag.END_OF_DAYS) || inst.isFlagEnabled(JungleRaidFlag.GRENADES) || inst.isFlagEnabled(JungleRaidFlag.POTION_PLUMMET) || isSuddenDeath) {
        Vector3i bvMax = inst.getRegion().getMaximumPoint();
        Vector3i bvMin = inst.getRegion().getMinimumPoint();
        for (int i = 0; i < Probability.getRangedRandom(data.amt / 3, data.amt); i++) {
            Location<World> testLoc = new Location<>(inst.getRegion().getExtent(), Probability.getRangedRandom(bvMin.getX(), bvMax.getX()), bvMax.getY(), Probability.getRangedRandom(bvMin.getZ(), bvMax.getZ()));
            if (testLoc.getBlockType() != BlockTypes.AIR)
                continue;
            if (inst.isFlagEnabled(JungleRaidFlag.END_OF_DAYS) || isSuddenDeath) {
                PrimedTNT explosive = (PrimedTNT) inst.getRegion().getExtent().createEntity(EntityTypes.PRIMED_TNT, testLoc.getPosition());
                explosive.setVelocity(new Vector3d(random.nextDouble() * 2.0 - 1, random.nextDouble() * 2 * -1, random.nextDouble() * 2.0 - 1));
                explosive.offer(Keys.FUSE_DURATION, 20 * 4);
                // TODO used to have a 1/4 chance of creating fire
                inst.getRegion().getExtent().spawnEntity(explosive, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
            }
            if (inst.isFlagEnabled(JungleRaidFlag.POTION_PLUMMET)) {
                PotionEffectType type = Probability.pickOneOf(Sponge.getRegistry().getAllOf(PotionEffectType.class));
                for (int ii = Probability.getRandom(5); ii > 0; --ii) {
                    ThrownPotion potion = (ThrownPotion) inst.getRegion().getExtent().createEntity(EntityTypes.SPLASH_POTION, testLoc.getPosition());
                    potion.setVelocity(new Vector3d(random.nextDouble() * 2.0 - 1, 0, random.nextDouble() * 2.0 - 1));
                    potion.offer(Keys.POTION_EFFECTS, Lists.newArrayList(PotionEffect.of(type, 1, type.isInstant() ? 1 : 20 * 10)));
                    inst.getRegion().getExtent().spawnEntity(potion, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
                }
            }
            if (inst.isFlagEnabled(JungleRaidFlag.GRENADES)) {
                new ItemDropper(testLoc).dropStacks(Lists.newArrayList(newItemStack(ItemTypes.SNOWBALL, Probability.getRandom(3))), SpawnTypes.PLUGIN);
            }
        }
        if (data.amt < 150 && Probability.getChance(inst.isFlagEnabled(JungleRaidFlag.SUPER) ? 9 : 25))
            ++data.amt;
    }
}
Also used : PrimedTNT(org.spongepowered.api.entity.explosive.PrimedTNT) ItemDropper(com.skelril.nitro.item.ItemDropper) Vector3d(com.flowpowered.math.vector.Vector3d) PotionEffectType(org.spongepowered.api.effect.potion.PotionEffectType) Vector3i(com.flowpowered.math.vector.Vector3i) ThrownPotion(org.spongepowered.api.entity.projectile.ThrownPotion) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location)

Aggregations

PrimedTNT (org.spongepowered.api.entity.explosive.PrimedTNT)3 Vector3d (com.flowpowered.math.vector.Vector3d)2 World (org.spongepowered.api.world.World)2 Vector3i (com.flowpowered.math.vector.Vector3i)1 ItemDropper (com.skelril.nitro.item.ItemDropper)1 EntityZombie (net.minecraft.entity.monster.EntityZombie)1 HealthData (org.spongepowered.api.data.manipulator.mutable.entity.HealthData)1 Value (org.spongepowered.api.data.value.mutable.Value)1 ParticleEffect (org.spongepowered.api.effect.particle.ParticleEffect)1 PotionEffect (org.spongepowered.api.effect.potion.PotionEffect)1 PotionEffectType (org.spongepowered.api.effect.potion.PotionEffectType)1 Entity (org.spongepowered.api.entity.Entity)1 Monster (org.spongepowered.api.entity.living.monster.Monster)1 Zombie (org.spongepowered.api.entity.living.monster.Zombie)1 Player (org.spongepowered.api.entity.living.player.Player)1 Egg (org.spongepowered.api.entity.projectile.Egg)1 ThrownPotion (org.spongepowered.api.entity.projectile.ThrownPotion)1 Fireball (org.spongepowered.api.entity.projectile.explosive.fireball.Fireball)1 Listener (org.spongepowered.api.event.Listener)1 Cause (org.spongepowered.api.event.cause.Cause)1