Search in sources :

Example 6 with TimedRunnable

use of com.skelril.nitro.time.TimedRunnable in project Skree by Skelril.

the class WildernessWorldWrapper method addPool.

private void addPool(Location<World> block, Supplier<Collection<ItemStackSnapshot>> itemStackSupplier) {
    Optional<Integer> optLevel = getLevel(block);
    Validate.isTrue(optLevel.isPresent());
    int level = optLevel.get();
    int times = Probability.getRandom(getOreMod(getDropTier(level)));
    WildernessDropPool dropPool = new WildernessDropPool(block, itemStackSupplier, times);
    TimedRunnable<IntegratedRunnable> runnable = new TimedRunnable<>(dropPool, times);
    Task task = Task.builder().execute(runnable).delay(1, SECONDS).interval(1, SECONDS).submit(SkreePlugin.inst());
    runnable.setTask(task);
}
Also used : Task(org.spongepowered.api.scheduler.Task) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) TimedRunnable(com.skelril.nitro.time.TimedRunnable)

Example 7 with TimedRunnable

use of com.skelril.nitro.time.TimedRunnable 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 8 with TimedRunnable

use of com.skelril.nitro.time.TimedRunnable in project Skree by Skelril.

the class WildernessDropPool method run.

@Override
public boolean run(int timesL) {
    dropper.dropStackSnapshots(itemStackProvider.get(), SpawnTypes.DROPPED_ITEM);
    float volumeLevel = Math.min(1, (((float) timesL / times) * .6F) + ((float) 1 / times));
    IntegratedRunnable music = new IntegratedRunnable() {

        @Override
        public boolean run(int musicPitchT) {
            getExtent().playSound(SoundTypes.BLOCK_NOTE_HARP, getPos(), volumeLevel, (musicPitchT / 3) + 1);
            return true;
        }

        @Override
        public void end() {
        }
    };
    TimedRunnable<IntegratedRunnable> runnable = new TimedRunnable<>(music, 3);
    Task task = Task.builder().execute(runnable).intervalTicks(3).submit(SkreePlugin.inst());
    runnable.setTask(task);
    return true;
}
Also used : Task(org.spongepowered.api.scheduler.Task) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) TimedRunnable(com.skelril.nitro.time.TimedRunnable)

Example 9 with TimedRunnable

use of com.skelril.nitro.time.TimedRunnable in project Skree by Skelril.

the class AntiPeskListener method punish.

private void punish(Player player) {
    player.sendMessage(Text.of(TextColors.RED, "Command forbidden..."));
    player.sendMessage(Text.of(TextColors.RED, "... prepare to hate your life ..."));
    IntegratedRunnable integratedRunnable = new IntegratedRunnable() {

        @Override
        public boolean run(int times) {
            player.setVelocity(new Vector3d(Probability.getRangedRandom(-3.0, 3.0), Probability.getRangedRandom(-3.0, 3.0), Probability.getRangedRandom(-3.0, 3.0)));
            return true;
        }

        @Override
        public void end() {
            player.kick(Text.of("How about you don't do that again, K?"));
        }
    };
    TimedRunnable<IntegratedRunnable> runnable = new TimedRunnable<>(integratedRunnable, 12);
    Task task = Task.builder().execute(runnable).interval(1, TimeUnit.SECONDS).delay(5, TimeUnit.SECONDS).submit(SkreePlugin.inst());
    runnable.setTask(task);
}
Also used : Task(org.spongepowered.api.scheduler.Task) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) Vector3d(com.flowpowered.math.vector.Vector3d) TimedRunnable(com.skelril.nitro.time.TimedRunnable)

Aggregations

IntegratedRunnable (com.skelril.nitro.time.IntegratedRunnable)9 TimedRunnable (com.skelril.nitro.time.TimedRunnable)9 Task (org.spongepowered.api.scheduler.Task)6 Vector3d (com.flowpowered.math.vector.Vector3d)3 Vector3i (com.flowpowered.math.vector.Vector3i)3 BlockType (org.spongepowered.api.block.BlockType)2 Player (org.spongepowered.api.entity.living.player.Player)2 Lists (com.google.common.collect.Lists)1 EditSession (com.sk89q.worldedit.EditSession)1 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 Vector (com.sk89q.worldedit.Vector)1 Clause (com.skelril.nitro.Clause)1 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)1 EntityHealthPrinter (com.skelril.nitro.entity.EntityHealthPrinter)1 EntityHealthUtil (com.skelril.nitro.entity.EntityHealthUtil)1 ItemDropper (com.skelril.nitro.item.ItemDropper)1 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)1 PositionRandomizer (com.skelril.nitro.position.PositionRandomizer)1 Probability (com.skelril.nitro.probability.Probability)1 CombinedText (com.skelril.nitro.text.CombinedText)1