Search in sources :

Example 6 with PlayerCombatParser

use of com.skelril.nitro.combat.PlayerCombatParser 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 7 with PlayerCombatParser

use of com.skelril.nitro.combat.PlayerCombatParser in project Skree by Skelril.

the class MainWorldWrapper method createFor.

private PlayerCombatParser createFor(Cancellable event) {
    return new PlayerCombatParser() {

        @Override
        public void processPvP(Player attacker, Player defender, @Nullable Entity indirectSource) {
            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;
                }
            }
            if (!(indirectSource instanceof Snowball) || !lobby.contains(attacker)) {
                attacker.sendMessage(Text.of(TextColors.RED, "PvP is opt-in only in the main world!"));
                event.setCancelled(true);
            }
        }

        @Override
        public void processNonLivingAttack(DamageSource attacker, Player defender) {
            if (attacker.getType() == DamageTypes.VOID) {
                defender.setLocation(defender.getWorld().getSpawnLocation());
                defender.offer(Keys.FALL_DISTANCE, 0F);
                event.setCancelled(true);
            }
        }
    };
}
Also used : Entity(org.spongepowered.api.entity.Entity) Snowball(org.spongepowered.api.entity.projectile.Snowball) Player(org.spongepowered.api.entity.living.player.Player) PvPService(com.skelril.skree.service.PvPService) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser) Nullable(javax.annotation.Nullable)

Example 8 with PlayerCombatParser

use of com.skelril.nitro.combat.PlayerCombatParser in project Skree by Skelril.

the class JungleRaidEffectListener method createFor.

private PlayerCombatParser createFor(Cancellable event, JungleRaidInstance inst) {
    return new PlayerCombatParser() {

        @Override
        public void processPvP(Player attacker, Player defender, @Nullable Entity indirectSource) {
            final boolean isDamageEntityEvent = event instanceof DamageEntityEvent;
            // Do Death Touch before anything else
            if (inst.isFlagEnabled(JungleRaidFlag.DEATH_TOUCH) && isDamageEntityEvent) {
                ((DamageEntityEvent) event).setBaseDamage(Math.pow(defender.get(Keys.MAX_HEALTH).orElse(20D), 3));
                return;
            }
            Optional<JungleRaidClass> optClass = inst.getClass(attacker);
            if (optClass.isPresent()) {
                JungleRaidClass jrClass = optClass.get();
                if (jrClass == JungleRaidClass.SNIPER) {
                    Optional<ItemStack> optHeld = attacker.getItemInHand(HandTypes.MAIN_HAND);
                    boolean hasWoodenSword = optHeld.isPresent() && optHeld.get().getItem() == ItemTypes.WOODEN_SWORD;
                    if (indirectSource != null || !hasWoodenSword) {
                        double distSq = attacker.getLocation().getPosition().distanceSquared(defender.getLocation().getPosition());
                        double targetDistSq = Math.pow(70, 2);
                        double ratio = Math.min(distSq, targetDistSq) / targetDistSq;
                        if (isDamageEntityEvent) {
                            // Handle damage modification
                            ((DamageEntityEvent) event).setBaseDamage(((DamageEntityEvent) event).getBaseDamage() * ratio);
                        } else {
                            // Disable the arrow fire in the Impact event
                            if (ratio < .7 && indirectSource != null) {
                                indirectSource.offer(Keys.FIRE_TICKS, 0);
                            }
                        }
                    }
                }
            }
            if (inst.isFlagEnabled(JungleRaidFlag.TITAN_MODE) && attacker.getUniqueId().equals(inst.getFlagData().titan) && isDamageEntityEvent) {
                ((DamageEntityEvent) event).setBaseDamage(((DamageEntityEvent) event).getBaseDamage() * 2);
            }
        }

        @Override
        public void processNonLivingAttack(DamageSource attacker, Player defender) {
            if (!(event instanceof DamageEntityEvent)) {
                return;
            }
            if (attacker.getType() == DamageTypes.FALL) {
                BlockType belowType = defender.getLocation().add(0, -1, 0).getBlockType();
                if (inst.isFlagEnabled(JungleRaidFlag.TRAMPOLINE)) {
                    Vector3d oldVel = defender.getVelocity();
                    Vector3d newVel = new Vector3d(oldVel.getX(), 0, oldVel.getZ());
                    defender.setVelocity(new Vector3d(0, .1, 0).mul(((DamageEntityEvent) event).getBaseDamage()).add(newVel));
                    event.setCancelled(true);
                } else if (belowType == BlockTypes.LEAVES || belowType == BlockTypes.LEAVES2) {
                    if (Probability.getChance(2)) {
                        Vector3d oldVel = defender.getVelocity();
                        Vector3d newVel = new Vector3d(oldVel.getX() > 0 ? -.5 : .5, 0, oldVel.getZ() > 0 ? -.5 : .5);
                        defender.setVelocity(new Vector3d(0, .1, 0).mul(((DamageEntityEvent) event).getBaseDamage()).add(newVel));
                    }
                    event.setCancelled(true);
                }
            } else if (attacker.getType() == DamageTypes.CUSTOM) {
                if (inst.isFlagEnabled(JungleRaidFlag.EXPLOSIVE_ARROWS) || inst.isFlagEnabled(JungleRaidFlag.GRENADES)) {
                    ((DamageEntityEvent) event).setBaseDamage(Math.min(((DamageEntityEvent) event).getBaseDamage(), 2));
                }
            }
        }
    };
}
Also used : DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) BlockType(org.spongepowered.api.block.BlockType) Vector3d(com.flowpowered.math.vector.Vector3d) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Nullable(javax.annotation.Nullable)

Example 9 with PlayerCombatParser

use of com.skelril.nitro.combat.PlayerCombatParser in project Skree by Skelril.

the class BackTeleportInstruction method apply.

@Override
public Optional<Instruction<DamagedCondition, Boss<Living, ZoneBossDetail<FreakyFourInstance>>>> apply(DamagedCondition damagedCondition, Boss<Living, ZoneBossDetail<FreakyFourInstance>> livingZoneBossDetailBoss) {
    DamageEntityEvent event = damagedCondition.getEvent();
    new PlayerCombatParser() {

        @Override
        public void processPlayerAttack(Player attacker, Living defender) {
            boolean backTeleport = Probability.getChance(config.backTeleport);
            if (backTeleport || damagedCondition.getDamageSource().get() instanceof IndirectEntityDamageSource) {
                double distSQ = 2;
                double maxDist = 1;
                if (defender instanceof Skeleton) {
                    distSQ = defender.getLocation().getPosition().distanceSquared(attacker.getLocation().getPosition());
                    maxDist = config.snipeeTeleportDist;
                }
                if (backTeleport || distSQ > Math.pow(maxDist, 2)) {
                    final Entity finalDamager = attacker;
                    Task.builder().execute(() -> {
                        defender.setLocation(finalDamager.getLocation());
                        throwBack(defender);
                    }).delayTicks(1).submit(SkreePlugin.inst());
                }
            }
        }
    }.parse(event);
    return Optional.empty();
}
Also used : DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Living(org.spongepowered.api.entity.living.Living) Skeleton(org.spongepowered.api.entity.living.monster.Skeleton) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser)

Aggregations

PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)9 Player (org.spongepowered.api.entity.living.player.Player)9 Living (org.spongepowered.api.entity.living.Living)5 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)5 PvPService (com.skelril.skree.service.PvPService)4 Entity (org.spongepowered.api.entity.Entity)3 IndirectEntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)3 Nullable (javax.annotation.Nullable)2 DamageSource (org.spongepowered.api.event.cause.entity.damage.source.DamageSource)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)1 IntegratedRunnable (com.skelril.nitro.time.IntegratedRunnable)1 TimedRunnable (com.skelril.nitro.time.TimedRunnable)1 Instruction (com.skelril.openboss.Instruction)1 ZoneBossDetail (com.skelril.skree.content.zone.ZoneBossDetail)1 CatacombsBossDetail (com.skelril.skree.content.zone.group.catacombs.CatacombsBossDetail)1 CatacombsInstance (com.skelril.skree.content.zone.group.catacombs.CatacombsInstance)1 NamedBindInstruction (com.skelril.skree.content.zone.group.catacombs.instruction.bossmove.NamedBindInstruction)1 HealthBindInstruction (com.skelril.skree.content.zone.group.freakyfour.boss.bossmove.HealthBindInstruction)1 Function (java.util.function.Function)1