Search in sources :

Example 11 with Entity

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

the class Fangz method setupFangz.

private void setupFangz() {
    Sponge.getEventManager().registerListeners(SkreePlugin.inst(), new BossListener<>(bossManager, Spider.class));
    List<Instruction<BindCondition, Boss<Spider, WildernessBossDetail>>> bindProcessor = bossManager.getBindProcessor();
    bindProcessor.add((condition, boss) -> {
        Optional<Spider> optBossEnt = boss.getTargetEntity();
        if (optBossEnt.isPresent()) {
            Spider bossEnt = optBossEnt.get();
            bossEnt.offer(Keys.DISPLAY_NAME, Text.of("Fangz"));
            double bossHealth = 20 * 50 * boss.getDetail().getLevel();
            setMaxHealth(bossEnt, bossHealth, true);
        }
        return Optional.empty();
    });
    List<Instruction<UnbindCondition, Boss<Spider, WildernessBossDetail>>> unbindProcessor = bossManager.getUnbindProcessor();
    unbindProcessor.add((condition, boss) -> {
        Optional<Spider> optBossEnt = boss.getTargetEntity();
        if (optBossEnt.isPresent()) {
            Spider bossEnt = optBossEnt.get();
            CuboidContainmentPredicate predicate = new CuboidContainmentPredicate(bossEnt.getLocation().getPosition(), 3, 2, 3);
            for (Entity aEntity : bossEnt.getNearbyEntities((entity) -> predicate.test(entity.getLocation().getPosition()))) {
                Optional<PotionEffectData> optPotionEffects = aEntity.getOrCreate(PotionEffectData.class);
                if (!optPotionEffects.isPresent()) {
                    continue;
                }
                PotionEffectData potionEffects = optPotionEffects.get();
                potionEffects.addElement(PotionEffect.of(PotionEffectTypes.SLOWNESS, 2, 20 * 30));
                potionEffects.addElement(PotionEffect.of(PotionEffectTypes.POISON, 2, 20 * 30));
                aEntity.offer(potionEffects);
            }
        }
        return Optional.empty();
    });
    List<Instruction<DamageCondition, Boss<Spider, WildernessBossDetail>>> damageProcessor = bossManager.getDamageProcessor();
    damageProcessor.add((condition, boss) -> {
        Optional<Spider> optBossEnt = boss.getTargetEntity();
        if (optBossEnt.isPresent()) {
            Spider bossEnt = optBossEnt.get();
            Entity eToHit = condition.getAttacked();
            if (!(eToHit instanceof Living))
                return Optional.empty();
            Living toHit = (Living) eToHit;
            DamageEntityEvent event = condition.getEvent();
            event.setBaseDamage(event.getBaseDamage() * 2);
            EntityHealthUtil.heal(bossEnt, event.getBaseDamage());
            Optional<PotionEffectData> optPotionEffects = toHit.getOrCreate(PotionEffectData.class);
            if (!optPotionEffects.isPresent()) {
                return Optional.empty();
            }
            PotionEffectData potionEffects = optPotionEffects.get();
            potionEffects.addElement(PotionEffect.of(PotionEffectTypes.SLOWNESS, 1, 20 * 15));
            potionEffects.addElement(PotionEffect.of(PotionEffectTypes.POISON, 1, 20 * 15));
            toHit.offer(potionEffects);
        }
        return Optional.empty();
    });
}
Also used : CuboidContainmentPredicate(com.skelril.nitro.position.CuboidContainmentPredicate) DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Entity(org.spongepowered.api.entity.Entity) WildernessBossDetail(com.skelril.skree.content.world.wilderness.WildernessBossDetail) Living(org.spongepowered.api.entity.living.Living) Instruction(com.skelril.openboss.Instruction) Spider(org.spongepowered.api.entity.living.monster.Spider) PotionEffectData(org.spongepowered.api.data.manipulator.mutable.PotionEffectData)

Example 12 with Entity

use of org.spongepowered.api.entity.Entity 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 13 with Entity

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

the class GraveDigger method makeExplosiveTomb.

private void makeExplosiveTomb(Location<World> targetLocation, Boss<Skeleton, WildernessBossDetail> boss) {
    makeSphere(targetLocation, 3, 3, 3);
    for (int i = 0; i < boss.getDetail().getLevel(); ++i) {
        Entity explosive = targetLocation.getExtent().createEntity(EntityTypes.PRIMED_TNT, targetLocation.getPosition());
        explosive.offer(Keys.FUSE_DURATION, 20 * 4);
        targetLocation.getExtent().spawnEntity(explosive, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity)

Example 14 with Entity

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

the class WanderingMobManager method summon.

public boolean summon(String wandererType, int level, Location<World> location) {
    WanderingBoss<? extends Entity> wanderer = wanderers.get(wandererType);
    if (wanderer == null) {
        return false;
    }
    Entity entity = wanderer.createEntity(location);
    boolean spawned = location.getExtent().spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
    if (!spawned) {
        return false;
    }
    return wanderer.apply(entity, new WildernessBossDetail(level));
}
Also used : Entity(org.spongepowered.api.entity.Entity)

Example 15 with Entity

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

the class CursedMineListener method onItemDrop.

@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause, @Named(NamedCause.NOTIFIER) Player player) {
    if (!Probability.getChance(4)) {
        return;
    }
    BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();
    Optional<Location<World>> optLocation = blockSnapshot.getLocation();
    if (!optLocation.isPresent()) {
        return;
    }
    Location<World> loc = optLocation.get();
    Optional<CursedMineInstance> optInst = manager.getApplicableZone(loc);
    if (!optInst.isPresent()) {
        return;
    }
    CursedMineInstance inst = optInst.get();
    if (!inst.hasrecordForPlayerAt(player, loc)) {
        return;
    }
    List<ItemStackSnapshot> itemStacks = new ArrayList<>();
    Iterator<Entity> entityIterator = event.getEntities().iterator();
    while (entityIterator.hasNext()) {
        Entity entity = entityIterator.next();
        if (entity instanceof Item) {
            ItemStackSnapshot snapshot = ((Item) entity).item().get();
            itemStacks.add(snapshot);
            entityIterator.remove();
        }
    }
    int times = 1;
    Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
    if (optService.isPresent()) {
        ModifierService service = optService.get();
        if (service.isActive(Modifiers.DOUBLE_CURSED_ORES)) {
            times *= 2;
        }
    }
    for (ItemStackSnapshot stackSnapshot : itemStacks) {
        int quantity = Math.min(stackSnapshot.getCount() * Probability.getRangedRandom(4, 8), stackSnapshot.getType().getMaxStackQuantity());
        for (int i = 0; i < times; ++i) {
            ItemStack stack = stackSnapshot.createStack();
            stack.setQuantity(quantity);
            player.getInventory().offer(stack);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ModifierService(com.skelril.skree.service.ModifierService) World(org.spongepowered.api.world.World) Item(org.spongepowered.api.entity.Item) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Aggregations

Entity (org.spongepowered.api.entity.Entity)59 Player (org.spongepowered.api.entity.living.player.Player)23 World (org.spongepowered.api.world.World)19 Living (org.spongepowered.api.entity.living.Living)17 Listener (org.spongepowered.api.event.Listener)13 Vector3d (com.flowpowered.math.vector.Vector3d)10 ArrayList (java.util.ArrayList)8 DamageSource (org.spongepowered.api.event.cause.entity.damage.source.DamageSource)8 Instruction (com.skelril.openboss.Instruction)7 ItemStack (org.spongepowered.api.item.inventory.ItemStack)7 Location (org.spongepowered.api.world.Location)7 Zombie (org.spongepowered.api.entity.living.monster.Zombie)6 IndirectEntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)6 ZoneBossDetail (com.skelril.skree.content.zone.ZoneBossDetail)5 PotionEffect (org.spongepowered.api.effect.potion.PotionEffect)5 EntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)5 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)5 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)4 Vector3i (com.flowpowered.math.vector.Vector3i)3 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)3