Search in sources :

Example 6 with PotionEffect

use of org.spongepowered.api.effect.potion.PotionEffect in project SpongeCommon by SpongePowered.

the class AreaEffectCloudDataProcessor method getValues.

@Override
protected Map<Key<?>, ?> getValues(EntityAreaEffectCloud dataHolder) {
    final HashMap<Key<?>, Object> map = new HashMap<>();
    map.put(Keys.AREA_EFFECT_CLOUD_AGE, dataHolder.ticksExisted);
    map.put(Keys.AREA_EFFECT_CLOUD_COLOR, Color.ofRgb(dataHolder.getColor()));
    map.put(Keys.AREA_EFFECT_CLOUD_RADIUS, dataHolder.getRadius());
    final IMixinAreaEffectCloud mixinAreaEffect = (IMixinAreaEffectCloud) dataHolder;
    final List<net.minecraft.potion.PotionEffect> potionEffects = mixinAreaEffect.getPotionEffects();
    final List<PotionEffect> effects = new ArrayList<>(potionEffects.size());
    for (net.minecraft.potion.PotionEffect potionEffect : potionEffects) {
        effects.add((PotionEffect) potionEffect);
    }
    map.put(Keys.POTION_EFFECTS, effects);
    map.put(Keys.AREA_EFFECT_CLOUD_RADIUS_ON_USE, mixinAreaEffect.getRadiusOnUse());
    map.put(Keys.AREA_EFFECT_CLOUD_RADIUS_PER_TICK, mixinAreaEffect.getRadiusPerTick());
    map.put(Keys.AREA_EFFECT_CLOUD_DURATION, dataHolder.getDuration());
    map.put(Keys.AREA_EFFECT_CLOUD_DURATION_ON_USE, mixinAreaEffect.getDurationOnUse());
    map.put(Keys.AREA_EFFECT_CLOUD_REAPPLICATION_DELAY, mixinAreaEffect.getReapplicationDelay());
    map.put(Keys.AREA_EFFECT_CLOUD_WAIT_TIME, mixinAreaEffect.getWaitTime());
    map.put(Keys.AREA_EFFECT_CLOUD_PARTICLE_TYPE, ParticleTypes.MOB_SPELL);
    return map;
}
Also used : HashMap(java.util.HashMap) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) ArrayList(java.util.ArrayList) IMixinAreaEffectCloud(org.spongepowered.common.mixin.core.entity.IMixinAreaEffectCloud) Key(org.spongepowered.api.data.key.Key)

Example 7 with PotionEffect

use of org.spongepowered.api.effect.potion.PotionEffect in project SpongeCommon by SpongePowered.

the class AreaEffectCloudDataProcessor method set.

@SuppressWarnings("unchecked")
@Override
protected boolean set(EntityAreaEffectCloud dataHolder, Map<Key<?>, Object> keyValues) {
    final int age = (int) keyValues.get(Keys.AREA_EFFECT_CLOUD_AGE);
    final Color color = (Color) keyValues.get(Keys.AREA_EFFECT_CLOUD_COLOR);
    final double radius = (double) keyValues.get(Keys.AREA_EFFECT_CLOUD_RADIUS);
    final double radiusOnUse = (double) keyValues.get(Keys.AREA_EFFECT_CLOUD_RADIUS_ON_USE);
    final int duration = (int) keyValues.get(Keys.AREA_EFFECT_CLOUD_DURATION);
    final int durationOnUse = (int) keyValues.get(Keys.AREA_EFFECT_CLOUD_DURATION_ON_USE);
    final int waitTime = (int) keyValues.get(Keys.AREA_EFFECT_CLOUD_WAIT_TIME);
    final int reapplicationDelay = (int) keyValues.get(Keys.AREA_EFFECT_CLOUD_REAPPLICATION_DELAY);
    final List<PotionEffect> potionEffects = (List<PotionEffect>) keyValues.get(Keys.POTION_EFFECTS);
    final ParticleType particleType = (ParticleType) keyValues.get(Keys.AREA_EFFECT_CLOUD_PARTICLE_TYPE);
    dataHolder.ticksExisted = age;
    dataHolder.setColor(color.getRgb());
    dataHolder.setRadius((float) radius);
    dataHolder.setRadiusOnUse((float) radiusOnUse);
    dataHolder.setDuration(duration);
    ((IMixinAreaEffectCloud) dataHolder).setDurationOnUse(durationOnUse);
    dataHolder.setWaitTime(waitTime);
    final EnumParticleTypes internalType = ((SpongeParticleType) particleType).getInternalType();
    dataHolder.setParticle(internalType == null ? EnumParticleTypes.SPELL_MOB : internalType);
    final List<net.minecraft.potion.PotionEffect> effects = new ArrayList<>();
    for (PotionEffect effect : potionEffects) {
        effects.add((net.minecraft.potion.PotionEffect) effect);
    }
    ((IMixinAreaEffectCloud) dataHolder).setPotionEffects(effects);
    ((IMixinAreaEffectCloud) dataHolder).setReapplicationDelay(reapplicationDelay);
    return true;
}
Also used : SpongeParticleType(org.spongepowered.common.effect.particle.SpongeParticleType) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) Color(org.spongepowered.api.util.Color) ArrayList(java.util.ArrayList) SpongeParticleType(org.spongepowered.common.effect.particle.SpongeParticleType) ParticleType(org.spongepowered.api.effect.particle.ParticleType) EnumParticleTypes(net.minecraft.util.EnumParticleTypes) ArrayList(java.util.ArrayList) List(java.util.List) IMixinAreaEffectCloud(org.spongepowered.common.mixin.core.entity.IMixinAreaEffectCloud)

Example 8 with PotionEffect

use of org.spongepowered.api.effect.potion.PotionEffect in project SpongeCommon by SpongePowered.

the class AreaEffectCloudPotionEffectsProcessor method set.

@Override
protected boolean set(EntityAreaEffectCloud container, List<PotionEffect> value) {
    final List<net.minecraft.potion.PotionEffect> effects = new ArrayList<>(value.size());
    for (PotionEffect effect : value) {
        effects.add((net.minecraft.potion.PotionEffect) effect);
    }
    ((IMixinAreaEffectCloud) container).setPotionEffects(effects);
    return true;
}
Also used : PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) ArrayList(java.util.ArrayList) IMixinAreaEffectCloud(org.spongepowered.common.mixin.core.entity.IMixinAreaEffectCloud)

Example 9 with PotionEffect

use of org.spongepowered.api.effect.potion.PotionEffect in project SpongeCommon by SpongePowered.

the class TippedArrowPotionDataProcessor method set.

@Override
protected boolean set(EntityTippedArrow dataHolder, List<PotionEffect> value) {
    dataHolder.customPotionEffects.clear();
    for (PotionEffect effect : value) {
        net.minecraft.potion.PotionEffect mcEffect = PotionUtil.copyToNative(effect);
        dataHolder.addEffect(mcEffect);
    }
    return false;
}
Also used : PotionEffect(org.spongepowered.api.effect.potion.PotionEffect)

Example 10 with PotionEffect

use of org.spongepowered.api.effect.potion.PotionEffect 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)

Aggregations

PotionEffect (org.spongepowered.api.effect.potion.PotionEffect)37 Entity (org.spongepowered.api.entity.Entity)11 Player (org.spongepowered.api.entity.living.player.Player)11 ArrayList (java.util.ArrayList)6 Vector3d (com.flowpowered.math.vector.Vector3d)5 List (java.util.List)5 PotionEffectType (org.spongepowered.api.effect.potion.PotionEffectType)5 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)4 MobEffectInstance (net.minecraft.world.effect.MobEffectInstance)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 IntegratedRunnable (com.skelril.nitro.time.IntegratedRunnable)3 TimedRunnable (com.skelril.nitro.time.TimedRunnable)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 BlockType (org.spongepowered.api.block.BlockType)3 Keys (org.spongepowered.api.data.Keys)3 Keys (org.spongepowered.api.data.key.Keys)3 Listener (org.spongepowered.api.event.Listener)3 Cause (org.spongepowered.api.event.cause.Cause)3