Search in sources :

Example 1 with ThrownPotion

use of org.spongepowered.api.entity.projectile.ThrownPotion in project Skree by Skelril.

the class JungleRaidEffectListener method onProjectileHit.

@Listener
public void onProjectileHit(CollideEvent.Impact event, @First Entity entity) {
    Optional<JungleRaidInstance> optInst = manager.getApplicableZone(entity);
    if (!optInst.isPresent())
        return;
    JungleRaidInstance inst = optInst.get();
    if (inst.getState() != JungleRaidState.IN_PROGRESS) {
        return;
    }
    int explosionSize = 2;
    if (entity.getType() == EntityTypes.TIPPED_ARROW) {
        if (inst.isFlagEnabled(JungleRaidFlag.TORMENT_ARROWS)) {
            ProjectileSource shooter = ((Arrow) entity).getShooter();
            CuboidContainmentPredicate predicate = new CuboidContainmentPredicate(entity.getLocation().getPosition(), 16, 16, 16);
            for (Entity e : entity.getNearbyEntities(en -> predicate.test(en.getLocation().getPosition()))) {
                if (e.equals(shooter))
                    continue;
                if (e instanceof Living && shooter instanceof Living) {
                    e.damage(1, IndirectEntityDamageSource.builder().type(DamageTypes.PROJECTILE).entity(entity).proxySource((Living) shooter).build());
                    if (Probability.getChance(5)) {
                        EntityHealthUtil.heal((Living) shooter, 1);
                    }
                }
            }
        }
        if (inst.isFlagEnabled(JungleRaidFlag.EXPLOSIVE_ARROWS)) {
            if (inst.isFlagEnabled(JungleRaidFlag.SUPER))
                explosionSize = 4;
        } else
            return;
    }
    if (entity instanceof Snowball) {
        if (inst.isFlagEnabled(JungleRaidFlag.GRENADES)) {
            if (inst.isFlagEnabled(JungleRaidFlag.SUPER))
                explosionSize = 10;
            else
                explosionSize = 6;
        } else
            return;
    }
    if (entity instanceof ThrownPotion) {
        return;
    }
    entity.getLocation().getExtent().triggerExplosion(Explosion.builder().radius(explosionSize).location(entity.getLocation()).shouldDamageEntities(true).shouldBreakBlocks(true).build(), Cause.source(SkreePlugin.container()).build());
}
Also used : Arrow(org.spongepowered.api.entity.projectile.arrow.Arrow) CuboidContainmentPredicate(com.skelril.nitro.position.CuboidContainmentPredicate) Entity(org.spongepowered.api.entity.Entity) Snowball(org.spongepowered.api.entity.projectile.Snowball) Living(org.spongepowered.api.entity.living.Living) ThrownPotion(org.spongepowered.api.entity.projectile.ThrownPotion) ProjectileSource(org.spongepowered.api.entity.projectile.source.ProjectileSource) Listener(org.spongepowered.api.event.Listener)

Example 2 with ThrownPotion

use of org.spongepowered.api.entity.projectile.ThrownPotion 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

ThrownPotion (org.spongepowered.api.entity.projectile.ThrownPotion)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 Vector3i (com.flowpowered.math.vector.Vector3i)1 ItemDropper (com.skelril.nitro.item.ItemDropper)1 CuboidContainmentPredicate (com.skelril.nitro.position.CuboidContainmentPredicate)1 PotionEffectType (org.spongepowered.api.effect.potion.PotionEffectType)1 Entity (org.spongepowered.api.entity.Entity)1 PrimedTNT (org.spongepowered.api.entity.explosive.PrimedTNT)1 Living (org.spongepowered.api.entity.living.Living)1 Snowball (org.spongepowered.api.entity.projectile.Snowball)1 Arrow (org.spongepowered.api.entity.projectile.arrow.Arrow)1 ProjectileSource (org.spongepowered.api.entity.projectile.source.ProjectileSource)1 Listener (org.spongepowered.api.event.Listener)1 Location (org.spongepowered.api.world.Location)1 World (org.spongepowered.api.world.World)1