Search in sources :

Example 1 with Monster

use of org.spongepowered.api.entity.living.monster.Monster 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 Monster

use of org.spongepowered.api.entity.living.monster.Monster in project Skree by Skelril.

the class WildernessWorldWrapper method onEntityDeath.

@Listener
public void onEntityDeath(DestructEntityEvent.Death event) {
    Entity entity = event.getTargetEntity();
    Location<World> loc = entity.getLocation();
    Optional<Integer> optLevel = getLevel(loc);
    if (!optLevel.isPresent()) {
        return;
    }
    int level = optLevel.get();
    if (entity instanceof Monster) {
        DropTable dropTable;
        if (entity.getLocation().getExtent().getDimension() == DimensionTypes.NETHER || entity instanceof Wither) {
            dropTable = netherMobDropTable;
        } else {
            dropTable = commonDropTable;
        }
        Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
        if (optDamageSource.isPresent()) {
            Entity srcEntity;
            if (optDamageSource.get() instanceof IndirectEntityDamageSource) {
                srcEntity = ((IndirectEntityDamageSource) optDamageSource.get()).getIndirectSource();
            } else {
                srcEntity = optDamageSource.get().getSource();
            }
            int dropTier = level;
            if (srcEntity instanceof Player) {
                Optional<ItemStack> optHeldItem = ((Player) srcEntity).getItemInHand(HandTypes.MAIN_HAND);
                if (optHeldItem.isPresent()) {
                    Optional<ItemEnchantment> optLooting = EnchantmentUtil.getHighestEnchantment(optHeldItem.get(), Enchantments.LOOTING);
                    if (optLooting.isPresent()) {
                        dropTier += optLooting.get().getLevel();
                    }
                }
                dropTier = getDropTier(dropTier);
                Collection<ItemStack> drops = dropTable.getDrops((entity instanceof Boss ? 5 : 1) * dropTier, getDropMod(dropTier, ((Monster) entity).getHealthData().maxHealth().get(), entity.getType()));
                int times = 1;
                Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
                if (optService.isPresent()) {
                    ModifierService service = optService.get();
                    if (service.isActive(Modifiers.DOUBLE_WILD_DROPS)) {
                        times *= 2;
                    }
                }
                ItemDropper dropper = new ItemDropper(loc);
                for (int i = 0; i < times; ++i) {
                    dropper.dropStacks(drops, SpawnTypes.DROPPED_ITEM);
                }
            }
        }
        if (entity.getType() == EntityTypes.ENDERMITE && Probability.getChance(20)) {
            entity.getWorld().triggerExplosion(Explosion.builder().location(entity.getLocation()).shouldBreakBlocks(true).radius(4F).build(), Cause.source(SkreePlugin.container()).build());
        }
    }
    GRAVE_STONE.createGraveFromDeath(event);
}
Also used : Wither(org.spongepowered.api.entity.living.monster.Wither) Player(org.spongepowered.api.entity.living.player.Player) ItemDropper(com.skelril.nitro.item.ItemDropper) ModifierService(com.skelril.skree.service.ModifierService) World(org.spongepowered.api.world.World) DropTable(com.skelril.nitro.droptable.DropTable) MasterDropTable(com.skelril.nitro.droptable.MasterDropTable) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) WanderingBoss(com.skelril.skree.content.world.wilderness.wanderer.WanderingBoss) Boss(org.spongepowered.api.entity.living.monster.Boss) ItemEnchantment(org.spongepowered.api.data.meta.ItemEnchantment) Monster(org.spongepowered.api.entity.living.monster.Monster) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener)

Example 3 with Monster

use of org.spongepowered.api.entity.living.monster.Monster in project ClearMob by axle2005.

the class EntityLimiter method handle.

@Listener(beforeModifications = true)
public void handle(SpawnEntityEvent event) throws Exception {
    List<Entity> entity = event.getEntities();
    Integer count = 0;
    Integer xpcount = 0;
    for (World w : plugin.getWorlds()) {
        for (Entity e : w.getEntities()) {
            if (e instanceof Monster && !(e instanceof Boss)) {
                count++;
            }
            if (e instanceof ExperienceOrb) {
                xpcount++;
            }
        }
    }
    for (int i = 0; i < entity.size(); i++) {
        if (entity.get(i) instanceof Monster && (count > plugin.getMobLimit()) && !(entity.get(i) instanceof Boss)) {
            event.setCancelled(true);
        }
        if ((entity.get(i) instanceof ExperienceOrb && entity.get(i).getNearbyEntities(10).size() > 20)) {
            event.setCancelled(true);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Boss(org.spongepowered.api.entity.living.monster.Boss) Monster(org.spongepowered.api.entity.living.monster.Monster) ExperienceOrb(org.spongepowered.api.entity.ExperienceOrb) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Example 4 with Monster

use of org.spongepowered.api.entity.living.monster.Monster in project Skree by Skelril.

the class WildernessWorldWrapper method createFor.

private PlayerCombatParser createFor(Cancellable event, int level) {
    return new PlayerCombatParser() {

        @Override
        public void processPvP(Player attacker, Player defender) {
            if (allowsPvP(level)) {
                return;
            }
            Optional<PvPService> optService = Sponge.getServiceManager().provide(PvPService.class);
            if (optService.isPresent()) {
                PvPService service = optService.get();
                if (service.getPvPState(attacker).allowByDefault() && service.getPvPState(defender).allowByDefault()) {
                    return;
                }
            }
            attacker.sendMessage(Text.of(TextColors.RED, "PvP is opt-in only in this part of the Wilderness!"));
            attacker.sendMessage(Text.of(TextColors.RED, "Mandatory PvP is from level ", getFirstPvPLevel(), " and on."));
            event.setCancelled(true);
        }

        @Override
        public void processMonsterAttack(Living attacker, Player defender) {
            if (!(event instanceof DamageEntityEvent)) {
                return;
            }
            DamageEntityEvent dEvent = (DamageEntityEvent) event;
            // If they're endermites they hit through armor, otherwise they get a damage boost
            if (attacker.getType() == EntityTypes.ENDERMITE) {
                for (Tuple<DamageModifier, Function<? super Double, Double>> modifier : dEvent.getModifiers()) {
                    dEvent.setDamage(modifier.getFirst(), (a) -> 0D);
                }
                dEvent.setBaseDamage(1);
            } else {
                dEvent.setBaseDamage(dEvent.getBaseDamage() + getDamageMod(level));
            }
            // Only apply scoring while in survival mode
            if (defender.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL) != GameModes.SURVIVAL) {
                return;
            }
            WildernessPlayerMeta meta = playerMetaMap.get(defender.getUniqueId());
            if (meta != null) {
                meta.hit();
            }
        }

        @Override
        public void processPlayerAttack(Player attacker, Living defender) {
            Task.builder().delayTicks(1).execute(() -> healthPrinter.print(MessageChannel.fixed(attacker), defender)).submit(SkreePlugin.inst());
            if (!(defender instanceof Monster) || defender instanceof Creeper) {
                return;
            }
            // Only apply scoring while in survival mode
            if (attacker.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL) != GameModes.SURVIVAL) {
                return;
            }
            WildernessPlayerMeta meta = playerMetaMap.get(attacker.getUniqueId());
            if (meta != null) {
                meta.attack();
                if (meta.getRatio() > 30 && meta.getFactors() > 35) {
                    Deque<Entity> spawned = new ArrayDeque<>();
                    for (int i = Probability.getRandom(5); i > 0; --i) {
                        Entity entity = attacker.getWorld().createEntity(EntityTypes.ENDERMITE, defender.getLocation().getPosition());
                        entity.getWorld().spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
                        spawned.add(entity);
                    }
                    IntegratedRunnable runnable = new IntegratedRunnable() {

                        @Override
                        public boolean run(int times) {
                            Entity mob = spawned.poll();
                            if (mob.isLoaded() && mob.getWorld().equals(attacker.getWorld())) {
                                mob.setLocation(attacker.getLocation());
                            }
                            return true;
                        }

                        @Override
                        public void end() {
                        }
                    };
                    TimedRunnable timedRunnable = new TimedRunnable<>(runnable, spawned.size());
                    timedRunnable.setTask(Task.builder().execute(timedRunnable).delayTicks(40).intervalTicks(20).submit(SkreePlugin.inst()));
                }
                if (System.currentTimeMillis() - meta.getLastReset() >= TimeUnit.MINUTES.toMillis(5)) {
                    meta.reset();
                }
            }
        }
    };
}
Also used : DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Player(org.spongepowered.api.entity.living.player.Player) Living(org.spongepowered.api.entity.living.Living) Creeper(org.spongepowered.api.entity.living.monster.Creeper) TimedRunnable(com.skelril.nitro.time.TimedRunnable) Function(java.util.function.Function) PvPService(com.skelril.skree.service.PvPService) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) Monster(org.spongepowered.api.entity.living.monster.Monster) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser)

Example 5 with Monster

use of org.spongepowered.api.entity.living.monster.Monster in project Skree by Skelril.

the class BuildWorldWrapper 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) {
        if (!isApplicable(entity))
            continue;
        if (entity instanceof Lightning) {
            ((Lightning) entity).setEffect(true);
            continue;
        }
        if (entity instanceof Egg && optBlockCause.isPresent()) {
            new ItemDropper(entity.getLocation()).dropStacks(Lists.newArrayList(newItemStack(ItemTypes.EGG)), SpawnTypes.DISPENSE);
            event.setCancelled(true);
            return;
        }
        if (entity instanceof Monster || (entity instanceof Horse && entity.get(Keys.HORSE_VARIANT).get().equals(HorseVariants.SKELETON_HORSE))) {
            event.setCancelled(true);
            return;
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Egg(org.spongepowered.api.entity.projectile.Egg) ItemDropper(com.skelril.nitro.item.ItemDropper) Lightning(org.spongepowered.api.entity.weather.Lightning) Monster(org.spongepowered.api.entity.living.monster.Monster) Horse(org.spongepowered.api.entity.living.animal.Horse) BlockSpawnCause(org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause) Listener(org.spongepowered.api.event.Listener)

Aggregations

Monster (org.spongepowered.api.entity.living.monster.Monster)7 Entity (org.spongepowered.api.entity.Entity)4 Listener (org.spongepowered.api.event.Listener)4 World (org.spongepowered.api.world.World)4 Player (org.spongepowered.api.entity.living.player.Player)3 ItemDropper (com.skelril.nitro.item.ItemDropper)2 Living (org.spongepowered.api.entity.living.Living)2 Boss (org.spongepowered.api.entity.living.monster.Boss)2 Egg (org.spongepowered.api.entity.projectile.Egg)2 BlockSpawnCause (org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause)2 Vector3i (com.flowpowered.math.vector.Vector3i)1 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)1 DropTable (com.skelril.nitro.droptable.DropTable)1 MasterDropTable (com.skelril.nitro.droptable.MasterDropTable)1 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)1 IntegratedRunnable (com.skelril.nitro.time.IntegratedRunnable)1 TimedRunnable (com.skelril.nitro.time.TimedRunnable)1 WanderingBoss (com.skelril.skree.content.world.wilderness.wanderer.WanderingBoss)1 ModifierService (com.skelril.skree.service.ModifierService)1 PvPService (com.skelril.skree.service.PvPService)1