Search in sources :

Example 1 with GameRunnable

use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.

the class Warlords method startMainLoop.

private void startMainLoop() {
    new BukkitRunnable() {

        int counter = 0;

        @Override
        public void run() {
            // Every 1 tick - 0.05 seconds.
            {
                for (WarlordsPlayer wp : players.values()) {
                    Player player = wp.getEntity() instanceof Player ? (Player) wp.getEntity() : null;
                    if (player != null) {
                        // ACTION BAR
                        if (player.getInventory().getHeldItemSlot() != 8) {
                            wp.displayActionBar();
                        } else {
                            wp.displayFlagActionBar(player);
                        }
                    }
                    // Checks whether the game is paused.
                    if (wp.getGame().isFrozen()) {
                        continue;
                    }
                    // Updating all player speed.
                    wp.getSpeed().updateSpeed();
                    // will add more efficient system later
                    if (wp.getSpec() instanceof Apothecary) {
                        wp.getSpeed().addSpeedModifier("Base Speed", 23, 1, "BASE");
                    }
                    CooldownManager cooldownManager = wp.getCooldownManager();
                    // Setting the flag tracking compass.
                    if (player != null && wp.getCompassTarget() != null) {
                        player.setCompassTarget(wp.getCompassTarget().getLocation());
                    }
                    // Checks whether the player has cooldowns disabled.
                    if (wp.isDisableCooldowns()) {
                        wp.getSpec().getRed().setCurrentCooldown(0);
                        wp.getSpec().getPurple().setCurrentCooldown(0);
                        wp.getSpec().getBlue().setCurrentCooldown(0);
                        wp.getSpec().getOrange().setCurrentCooldown(0);
                        wp.setHorseCooldown(0);
                        wp.updateRedItem();
                        wp.updatePurpleItem();
                        wp.updateBlueItem();
                        wp.updateOrangeItem();
                        wp.updateHorseItem();
                    }
                    // Decrementing red skill's cooldown.
                    if (wp.getSpec().getRed().getCurrentCooldown() > 0) {
                        wp.getSpec().getRed().subtractCooldown(.05f);
                        if (player != null) {
                            wp.updateRedItem(player);
                        }
                    }
                    // Decrementing purple skill's cooldown.
                    if (wp.getSpec().getPurple().getCurrentCooldown() > 0) {
                        wp.getSpec().getPurple().subtractCooldown(.05f);
                        if (player != null) {
                            wp.updatePurpleItem(player);
                        }
                    }
                    // Decrementing blue skill's cooldown.
                    if (wp.getSpec().getBlue().getCurrentCooldown() > 0) {
                        wp.getSpec().getBlue().subtractCooldown(.05f);
                        if (player != null) {
                            wp.updateBlueItem(player);
                        }
                    }
                    // Decrementing orange skill's cooldown.
                    if (wp.getSpec().getOrange().getCurrentCooldown() > 0) {
                        wp.getSpec().getOrange().subtractCooldown(.05f);
                        if (player != null) {
                            wp.updateOrangeItem(player);
                        }
                    }
                    // Decrementing mount cooldown.
                    if (wp.getHorseCooldown() > 0 && !wp.getEntity().isInsideVehicle()) {
                        wp.setHorseCooldown(wp.getHorseCooldown() - .05f);
                        if (player != null) {
                            wp.updateHorseItem(player);
                        }
                    }
                    wp.getCooldownManager().reduceCooldowns();
                    // Checks whether the player has overheal active and is full health or not.
                    boolean hasOverhealCooldown = wp.getCooldownManager().hasCooldown(Overheal.OVERHEAL_MARKER);
                    boolean hasTooMuchHealth = wp.getHealth() > wp.getMaxHealth();
                    if (hasOverhealCooldown && !hasTooMuchHealth) {
                        wp.getCooldownManager().removeCooldown(Overheal.OVERHEAL_MARKER);
                    }
                    if (!hasOverhealCooldown && hasTooMuchHealth) {
                        wp.setHealth(wp.getMaxHealth());
                    }
                    // Checks whether the player has Vindicate active.
                    if (wp.getCooldownManager().hasCooldownFromName("Vindicate Debuff Immunity")) {
                        wp.getSpeed().removeSlownessModifiers();
                        wp.getCooldownManager().removeDebuffCooldowns();
                        wp.getEntity().removePotionEffect(PotionEffectType.BLINDNESS);
                    }
                    // Checks whether the displayed health can be above or under 40 health total. (20 hearts.)
                    float newHealth = (float) wp.getHealth() / wp.getMaxHealth() * 40;
                    if (newHealth < 0) {
                        newHealth = 0;
                    } else if (newHealth > 40) {
                        newHealth = 40;
                    }
                    // Checks whether the player has any remaining active Undying Army instances active.
                    if (wp.getCooldownManager().checkUndyingArmy(false) && newHealth <= 0) {
                        for (RegularCooldown undyingArmyCooldown : new CooldownFilter<>(wp, RegularCooldown.class).filterCooldownClass(UndyingArmy.class).stream().collect(Collectors.toList())) {
                            UndyingArmy undyingArmy = (UndyingArmy) undyingArmyCooldown.getCooldownObject();
                            if (!undyingArmy.isArmyDead(wp)) {
                                undyingArmy.pop(wp);
                                // Drops the flag when popped.
                                FlagHolder.dropFlagForPlayer(wp);
                                // Sending the message + check if getFrom is self
                                if (undyingArmyCooldown.getFrom() == wp) {
                                    wp.sendMessage("§a\u00BB§7 " + ChatColor.LIGHT_PURPLE + "Your Undying Army revived you with temporary health. Fight until your death! Your health will decay by " + ChatColor.RED + (wp.getMaxHealth() / 10) + ChatColor.LIGHT_PURPLE + " every second.");
                                } else {
                                    wp.sendMessage("§a\u00BB§7 " + ChatColor.LIGHT_PURPLE + undyingArmyCooldown.getFrom().getName() + "'s Undying Army revived you with temporary health. Fight until your death! Your health will decay by " + ChatColor.RED + (wp.getMaxHealth() / 10) + ChatColor.LIGHT_PURPLE + " every second.");
                                }
                                FireWorkEffectPlayer.playFirework(wp.getLocation(), FireworkEffect.builder().withColor(Color.LIME).with(FireworkEffect.Type.BALL).build());
                                wp.heal();
                                if (player != null) {
                                    player.getWorld().spigot().strikeLightningEffect(wp.getLocation(), false);
                                    player.getInventory().setItem(5, UndyingArmy.BONE);
                                }
                                newHealth = 40;
                                // gives 50% of max energy if player is less than half
                                if (wp.getEnergy() < wp.getMaxEnergy() / 2) {
                                    wp.setEnergy(wp.getMaxEnergy() / 2);
                                }
                                new GameRunnable(wp.getGame()) {

                                    @Override
                                    public void run() {
                                        if (wp.getRespawnTimer() >= 0 || wp.isDead()) {
                                            this.cancel();
                                        } else {
                                            // UNDYING ARMY - dmg 10% of max health each popped army
                                            wp.addDamageInstance(wp, "", wp.getMaxHealth() / 10f, wp.getMaxHealth() / 10f, -1, 100, false);
                                        }
                                    }
                                }.runTaskTimer(0, 20);
                                break;
                            }
                        }
                    }
                    if (player != null) {
                        // precaution
                        if (newHealth > 0 && newHealth <= 40) {
                            player.setHealth(newHealth);
                        }
                    }
                    // Respawn fix for when a player is stuck or leaves the game.
                    if (player != null) {
                        if (wp.getHealth() <= 0 && player.getGameMode() == GameMode.SPECTATOR) {
                            wp.heal();
                        }
                    }
                    if (wp.getEnergy() < wp.getMaxEnergy()) {
                        // Standard energy value per second.
                        float energyGainPerTick = wp.getSpec().getEnergyPerSec() / 20f;
                        // Checks whether the player has Avenger's Wrath active.
                        for (RegularCooldown regularCooldown : new CooldownFilter<>(cooldownManager, RegularCooldown.class).filterCooldownClass(AvengersWrath.class).stream().collect(Collectors.toList())) {
                            energyGainPerTick += 1;
                        }
                        // Checks whether the player has Inspiring Presence active.
                        for (RegularCooldown regularCooldown : new CooldownFilter<>(cooldownManager, RegularCooldown.class).filterCooldownClass(InspiringPresence.class).stream().collect(Collectors.toList())) {
                            energyGainPerTick += .5;
                        }
                        // Checks whether the player has been marked by an Avenger.
                        for (RegularCooldown regularCooldown : new CooldownFilter<>(cooldownManager, RegularCooldown.class).filterCooldownClass(HolyRadianceAvenger.class).stream().collect(Collectors.toList())) {
                            energyGainPerTick -= .4;
                        }
                        // Checks whether the player has been marked by a Crusader.
                        for (RegularCooldown regularCooldown : new CooldownFilter<>(cooldownManager, RegularCooldown.class).filterCooldownClass(HolyRadianceCrusader.class).stream().collect(Collectors.toList())) {
                            energyGainPerTick += .3;
                        }
                        // Checks whether the player has Acupressure active.
                        for (RegularCooldown regularCooldown : new CooldownFilter<>(cooldownManager, RegularCooldown.class).filterCooldownClass(VitalityLiquor.class).stream().collect(Collectors.toList())) {
                            energyGainPerTick += .75;
                        }
                        // Checks whether the player has the Energy Powerup active.
                        if (cooldownManager.hasCooldown(EnergyPowerup.class)) {
                            energyGainPerTick *= 1.4;
                        }
                        // Setting energy gain to the value after all ability instance multipliers have been applied.
                        float newEnergy = wp.getEnergy() + energyGainPerTick;
                        if (newEnergy > wp.getMaxEnergy()) {
                            newEnergy = wp.getMaxEnergy();
                        }
                        wp.setEnergy(newEnergy);
                    }
                    // Checks whether the player has under 0 energy to avoid infinite energy bugs.
                    if (player != null) {
                        if (wp.getEnergy() < 0) {
                            wp.setEnergy(1);
                        }
                        player.setLevel((int) wp.getEnergy());
                        player.setExp(wp.getEnergy() / wp.getMaxEnergy());
                    }
                    // Melee Cooldown
                    if (wp.getHitCooldown() > 0) {
                        wp.setHitCooldown(wp.getHitCooldown() - 1);
                    }
                    // Orbs of Life
                    Location playerPosition = wp.getLocation();
                    List<OrbsOfLife.Orb> orbs = new ArrayList<>();
                    PlayerFilter.playingGame(wp.getGame()).teammatesOf(wp).forEach(p -> {
                        new CooldownFilter<>(p, PersistentCooldown.class).filterCooldownClassAndMapToObjectsOfClass(OrbsOfLife.class).forEachOrdered(orbsOfLife -> orbs.addAll(orbsOfLife.getSpawnedOrbs()));
                    });
                    Iterator<OrbsOfLife.Orb> itr = orbs.iterator();
                    while (itr.hasNext()) {
                        OrbsOfLife.Orb orb = itr.next();
                        Location orbPosition = orb.getArmorStand().getLocation();
                        if ((orb.getPlayerToMoveTowards() == null || (orb.getPlayerToMoveTowards() != null && orb.getPlayerToMoveTowards() == wp)) && orbPosition.distanceSquared(playerPosition) < 1.35 * 1.35 && !wp.isDeath()) {
                            orb.remove();
                            itr.remove();
                            float orbHeal = OrbsOfLife.ORB_HEALING;
                            if (Warlords.getPlayerSettings(orb.getOwner().getUuid()).getSkillBoostForClass() == ClassesSkillBoosts.ORBS_OF_LIFE) {
                                orbHeal *= 1.2;
                            }
                            // 225 *= 1.4 = 315
                            if (orb.getPlayerToMoveTowards() == null) {
                                orbHeal *= 1 + orb.getTicksLived() / 325f;
                            }
                            wp.addHealingInstance(orb.getOwner(), "Orbs of Life", orbHeal, orbHeal, -1, 100, false, false);
                            if (player != null) {
                                Utils.playGlobalSound(player.getLocation(), Sound.ORB_PICKUP, 0.2f, 1);
                            }
                            for (WarlordsPlayer nearPlayer : PlayerFilter.entitiesAround(wp, 6, 6, 6).aliveTeammatesOfExcludingSelf(wp).limit(2)) {
                                nearPlayer.addHealingInstance(orb.getOwner(), "Orbs of Life", orbHeal, orbHeal, -1, 100, false, false);
                                if (player != null) {
                                    Utils.playGlobalSound(player.getLocation(), Sound.ORB_PICKUP, 0.2f, 1);
                                }
                            }
                        }
                        // Checks whether the Orb of Life has lived for 8 seconds.
                        if (orb.getBukkitEntity().getTicksLived() > 160 || (orb.getPlayerToMoveTowards() != null && orb.getPlayerToMoveTowards().isDeath())) {
                            orb.remove();
                            itr.remove();
                        }
                    }
                    // Saves the amount of blocks travelled per player.
                    if (player != null) {
                        wp.setBlocksTravelledCM(Utils.getPlayerMovementStatistics(player));
                    }
                }
                // Loops every 10 ticks - .5 second.
                if (counter % 10 == 0) {
                    for (WarlordsPlayer wps : players.values()) {
                        // Soulbinding Weapon - decrementing time left on the ability.
                        new CooldownFilter<>(wps, PersistentCooldown.class).filterCooldownClassAndMapToObjectsOfClass(Soulbinding.class).forEachOrdered(soulbinding -> soulbinding.getSoulBindedPlayers().forEach(Soulbinding.SoulBoundPlayer::decrementTimeLeft));
                        // Soulbinding Weapon - Removing bound players.
                        new CooldownFilter<>(wps, PersistentCooldown.class).filterCooldownClassAndMapToObjectsOfClass(Soulbinding.class).forEachOrdered(soulbinding -> soulbinding.getSoulBindedPlayers().removeIf(boundPlayer -> boundPlayer.getTimeLeft() == 0 || (boundPlayer.isHitWithSoul() && boundPlayer.isHitWithLink())));
                    }
                }
                // Loops every 20 ticks - 1 second.
                if (counter % 20 == 0) {
                    // Removes leftover horses if there are any.
                    RemoveEntities.removeHorsesInGame();
                    for (WarlordsPlayer wps : players.values()) {
                        // Checks whether the game is paused.
                        if (wps.getGame().isFrozen()) {
                            continue;
                        }
                        wps.runEverySecond();
                        Player player = wps.getEntity() instanceof Player ? (Player) wps.getEntity() : null;
                        // Natural Regen
                        if (wps.getRegenTimer() != 0) {
                            wps.setRegenTimer(wps.getRegenTimer() - 1);
                            if (wps.getRegenTimer() == 0) {
                                wps.getHitBy().clear();
                            }
                        } else {
                            int healthToAdd = (int) (wps.getMaxHealth() / 55.3);
                            wps.setHealth(Math.max(wps.getHealth(), Math.min(wps.getHealth() + healthToAdd, wps.getMaxHealth())));
                        }
                        // Checks whether the player has a flag cooldown.
                        if (wps.getFlagCooldown() > 0) {
                            wps.setFlagCooldown(wps.getFlagCooldown() - 1);
                        }
                        // Checks whether the player has the healing powerup active.
                        if (wps.getCooldownManager().hasCooldown(HealingPowerup.class)) {
                            int heal = (int) (wps.getMaxHealth() * .08);
                            if (wps.getHealth() + heal > wps.getMaxHealth()) {
                                heal = wps.getMaxHealth() - wps.getHealth();
                            }
                            if (heal != 0) {
                                wps.setHealth(wps.getHealth() + heal);
                                wps.sendMessage(WarlordsPlayer.RECEIVE_ARROW + " §7Healed §a" + heal + " §7health.");
                            }
                        }
                        // Combat Timer - Logs combat time after 4 seconds.
                        if (wps.getRegenTimer() > 6) {
                            wps.getMinuteStats().addTimeInCombat();
                        }
                        // Assists - 10 seconds timer.
                        wps.getHitBy().replaceAll((wp, integer) -> integer - 1);
                        wps.getHealedBy().replaceAll((wp, integer) -> integer - 1);
                        wps.getHitBy().entrySet().removeIf(p -> p.getValue() <= 0);
                        wps.getHealedBy().entrySet().removeIf(p -> p.getValue() <= 0);
                    }
                    WarlordsEvents.entityList.removeIf(e -> !e.isValid());
                }
                // Loops every 50 ticks - 2.5 seconds.
                if (counter % 50 == 0) {
                    for (WarlordsPlayer warlordsPlayer : players.values()) {
                        if (warlordsPlayer.getGame().isFrozen()) {
                            continue;
                        }
                        LivingEntity player = warlordsPlayer.getEntity();
                        List<Location> locations = warlordsPlayer.getLocations();
                        if (warlordsPlayer.isDeath() && !locations.isEmpty()) {
                            locations.add(locations.get(locations.size() - 1));
                        } else {
                            locations.add(player.getLocation());
                        }
                    }
                }
                // Loops every 100 ticks - 5 seconds.
                if (counter % 100 == 0) {
                    BotManager.sendStatusMessage(false);
                }
            }
            counter++;
        }
    }.runTaskTimer(this, 0, 0);
}
Also used : LoginException(javax.security.auth.login.LoginException) com.ebicep.warlords.game(com.ebicep.warlords.game) PersistentCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.PersistentCooldown) BukkitTaskChainFactory(co.aikar.taskchain.BukkitTaskChainFactory) LoggerFactory(org.slf4j.LoggerFactory) com.ebicep.warlords.commands.debugcommands(com.ebicep.warlords.commands.debugcommands) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) Player(org.bukkit.entity.Player) SkullMeta(org.bukkit.inventory.meta.SkullMeta) org.bukkit(org.bukkit) StreamCommand(com.ebicep.warlords.party.StreamCommand) HolographicDisplaysAPI(me.filoghost.holographicdisplays.api.beta.HolographicDisplaysAPI) TaskChainFactory(co.aikar.taskchain.TaskChainFactory) RemoveEntities(com.ebicep.warlords.util.bukkit.RemoveEntities) LocationFactory(com.ebicep.warlords.util.bukkit.LocationFactory) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) QueueCommand(com.ebicep.warlords.queuesystem.QueueCommand) BotManager(com.ebicep.jda.BotManager) HealingPowerup(com.ebicep.warlords.abilties.internal.HealingPowerup) Overheal(com.ebicep.warlords.abilties.internal.Overheal) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) Entity(org.bukkit.entity.Entity) TaskChain(co.aikar.taskchain.TaskChain) com.ebicep.warlords.commands.miscellaneouscommands(com.ebicep.warlords.commands.miscellaneouscommands) Hologram(me.filoghost.holographicdisplays.api.beta.hologram.Hologram) ListenerPriority(com.comphenix.protocol.events.ListenerPriority) FlagHolder(com.ebicep.warlords.game.option.marker.FlagHolder) PacketType(com.comphenix.protocol.PacketType) FireWorkEffectPlayer(com.ebicep.warlords.effects.FireWorkEffectPlayer) LivingEntity(org.bukkit.entity.LivingEntity) PartyListener(com.ebicep.warlords.party.PartyListener) Collectors(java.util.stream.Collectors) CraftServer(org.bukkit.craftbukkit.v1_8_R3.CraftServer) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) ItemStack(org.bukkit.inventory.ItemStack) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) MetadataValue(org.bukkit.metadata.MetadataValue) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) NPCManager(com.ebicep.customentities.npc.NPCManager) LocationBuilder(com.ebicep.warlords.util.bukkit.LocationBuilder) LeaderboardCommand(com.ebicep.warlords.database.leaderboards.LeaderboardCommand) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) ProtocolManager(com.comphenix.protocol.ProtocolManager) PotionEffectType(org.bukkit.potion.PotionEffectType) BotCommands(com.ebicep.jda.BotCommands) ConfigurationSerialization(org.bukkit.configuration.serialization.ConfigurationSerialization) Utils(com.ebicep.warlords.util.warlords.Utils) java.util(java.util) ApplicationConfiguration(com.ebicep.warlords.database.configuration.ApplicationConfiguration) ProtocolLibrary(com.comphenix.protocol.ProtocolLibrary) PacketUtils(com.ebicep.warlords.util.bukkit.PacketUtils) CooldownManager(com.ebicep.warlords.player.cooldowns.CooldownManager) FutureMessageManager(com.ebicep.warlords.database.FutureMessageManager) PacketPlayInSteerVehicle(net.minecraft.server.v1_8_R3.PacketPlayInSteerVehicle) GameMode(org.bukkit.GameMode) PollCommand(com.ebicep.warlords.poll.PollCommand) PacketAdapter(com.comphenix.protocol.events.PacketAdapter) Apothecary(com.ebicep.warlords.classes.rogue.specs.Apothecary) BotListener(com.ebicep.jda.BotListener) MenuEventListener(com.ebicep.warlords.menu.MenuEventListener) Utils.iterable(com.ebicep.warlords.util.warlords.Utils.iterable) Nonnull(javax.annotation.Nonnull) com.ebicep.warlords.abilties(com.ebicep.warlords.abilties) Nullable(javax.annotation.Nullable) PacketEvent(com.comphenix.protocol.events.PacketEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Field(java.lang.reflect.Field) File(java.io.File) PartyCommand(com.ebicep.warlords.party.PartyCommand) com.ebicep.warlords.player(com.ebicep.warlords.player) PartyManager(com.ebicep.warlords.party.PartyManager) ChatChannels(com.ebicep.warlords.util.chat.ChatChannels) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) EnergyPowerup(com.ebicep.warlords.abilties.internal.EnergyPowerup) WarlordsEvents(com.ebicep.warlords.events.WarlordsEvents) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) LivingEntity(org.bukkit.entity.LivingEntity) Apothecary(com.ebicep.warlords.classes.rogue.specs.Apothecary) Player(org.bukkit.entity.Player) FireWorkEffectPlayer(com.ebicep.warlords.effects.FireWorkEffectPlayer) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) CooldownManager(com.ebicep.warlords.player.cooldowns.CooldownManager)

Example 2 with GameRunnable

use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.

the class Berserk method onActivate.

@Override
public boolean onActivate(WarlordsPlayer wp, Player player) {
    Berserk tempBerserk = new Berserk();
    wp.subtractEnergy(energyCost);
    Runnable cancelSpeed = wp.getSpeed().addSpeedModifier(name, speedBuff, duration * 20, "BASE");
    wp.getCooldownManager().addCooldown(new RegularCooldown<Berserk>(name, "BERS", Berserk.class, tempBerserk, wp, CooldownTypes.ABILITY, cooldownManager -> {
    }, duration * 20) {

        @Override
        public float modifyDamageBeforeInterveneFromSelf(WarlordsDamageHealingEvent event, float currentDamageValue) {
            return currentDamageValue * (1 + damageTakenIncrease / 100);
        }

        @Override
        public float modifyDamageBeforeInterveneFromAttacker(WarlordsDamageHealingEvent event, float currentDamageValue) {
            return currentDamageValue * (1 + damageIncrease / 100);
        }
    });
    Utils.playGlobalSound(player.getLocation(), "warrior.berserk.activation", 2, 1);
    new GameRunnable(wp.getGame()) {

        @Override
        public void run() {
            if (wp.getCooldownManager().hasCooldown(tempBerserk)) {
                Location location = wp.getLocation();
                location.add(0, 2.1, 0);
                ParticleEffect.VILLAGER_ANGRY.display(0, 0, 0, 0.1F, 1, location, 500);
            } else {
                cancelSpeed.run();
                this.cancel();
            }
        }
    }.runTaskTimer(0, 3);
    return true;
}
Also used : Utils(com.ebicep.warlords.util.warlords.Utils) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) Location(org.bukkit.Location) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) CooldownTypes(com.ebicep.warlords.player.cooldowns.CooldownTypes) Player(org.bukkit.entity.Player) AbstractAbility(com.ebicep.warlords.classes.AbstractAbility) WarlordsDamageHealingEvent(com.ebicep.warlords.events.WarlordsDamageHealingEvent) ParticleEffect(com.ebicep.warlords.effects.ParticleEffect) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) WarlordsDamageHealingEvent(com.ebicep.warlords.events.WarlordsDamageHealingEvent) Location(org.bukkit.Location)

Example 3 with GameRunnable

use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.

the class CapacitorTotem method onActivation.

@Override
protected void onActivation(WarlordsPlayer wp, Player player, ArmorStand totemStand) {
    wp.getCooldownManager().addRegularCooldown(name, "TOTEM", CapacitorTotem.class, new CapacitorTotem(), wp, CooldownTypes.ABILITY, cooldownManager -> {
    }, duration * 20);
    new GameRunnable(wp.getGame()) {

        int timeLeft = duration;

        @Override
        public void run() {
            if (timeLeft == 0) {
                totemStand.remove();
                this.cancel();
            }
            timeLeft--;
        }
    }.runTaskTimer(0, 20);
}
Also used : GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable)

Example 4 with GameRunnable

use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.

the class DrainingMiasma method onActivate.

@Override
public boolean onActivate(@Nonnull WarlordsPlayer wp, @Nonnull Player player) {
    wp.subtractEnergy(energyCost);
    Utils.playGlobalSound(player.getLocation(), "rogue.drainingmiasma.activation", 2, 1.7f);
    Utils.playGlobalSound(player.getLocation(), "shaman.earthlivingweapon.activation", 2, 0.65f);
    EffectUtils.playSphereAnimation(player, 6, ParticleEffect.SLIME, 1);
    FireWorkEffectPlayer.playFirework(wp.getLocation(), FireworkEffect.builder().withColor(Color.LIME).with(FireworkEffect.Type.BALL_LARGE).build());
    DrainingMiasma tempDrainingMiasma = new DrainingMiasma();
    for (WarlordsPlayer miasmaTarget : PlayerFilter.entitiesAround(wp, getEnemyHitRadius(), getEnemyHitRadius(), getEnemyHitRadius()).aliveEnemiesOf(wp)) {
        miasmaTarget.getCooldownManager().addRegularCooldown("Draining Miasma", "MIASMA", DrainingMiasma.class, tempDrainingMiasma, wp, CooldownTypes.DEBUFF, cooldownManager -> {
        }, duration * 20);
        miasmaTarget.getSpeed().addSpeedModifier("Draining Miasma Slow", -25, 3 * 20, "BASE");
        new GameRunnable(wp.getGame()) {

            float totalDamage = 0;

            @Override
            public void run() {
                float healthDamage = miasmaTarget.getMaxHealth() * maxHealthDamage / 100f;
                if (miasmaTarget.getCooldownManager().hasCooldown(tempDrainingMiasma)) {
                    // 4% current health damage.
                    miasmaTarget.addDamageInstance(wp, name, 50 + healthDamage, 50 + healthDamage, -1, 100, false);
                    totalDamage += healthDamage;
                    Utils.playGlobalSound(miasmaTarget.getLocation(), Sound.DIG_SNOW, 2, 0.4f);
                    for (int i = 0; i < 3; i++) {
                        ParticleEffect.REDSTONE.display(new ParticleEffect.OrdinaryColor(30, 200, 30), miasmaTarget.getLocation().clone().add((Math.random() * 2) - 1, 1.2 + (Math.random() * 2) - 1, (Math.random() * 2) - 1), 500);
                    }
                    for (WarlordsPlayer ally : PlayerFilter.entitiesAround(wp, getAllyHitRadius(), getAllyHitRadius(), getAllyHitRadius()).aliveTeammatesOf(wp)) {
                        ally.addHealingInstance(wp, name, totalDamage * damageDealtHealing / 100f, totalDamage * damageDealtHealing / 100f, -1, 100, false, false);
                        totalDamage = 0;
                        ally.getSpeed().addSpeedModifier("Draining Miasma Speed", 30, 2 * 20, "BASE");
                    }
                } else {
                    this.cancel();
                }
            }
        }.runTaskTimer(0, 20);
    }
    return true;
}
Also used : WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable)

Example 5 with GameRunnable

use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.

the class GroundSlam method onActivate.

@Override
public boolean onActivate(WarlordsPlayer wp, Player player) {
    wp.subtractEnergy(energyCost);
    List<List<Location>> fallingBlockLocations = new ArrayList<>();
    List<CustomFallingBlock> customFallingBlocks = new ArrayList<>();
    List<WarlordsPlayer> playersHit = new ArrayList<>();
    Location location = player.getLocation();
    for (int i = 0; i < 6; i++) {
        fallingBlockLocations.add(getCircle(location, i, (i * ((int) (Math.PI * 2)))));
    }
    fallingBlockLocations.get(0).add(player.getLocation());
    Utils.playGlobalSound(player.getLocation(), "warrior.groundslam.activation", 2, 1);
    new GameRunnable(wp.getGame()) {

        @Override
        public void run() {
            for (List<Location> fallingBlockLocation : fallingBlockLocations) {
                for (Location location : fallingBlockLocation) {
                    if (location.getWorld().getBlockAt(location.clone().add(0, 1, 0)).getType() == Material.AIR) {
                        FallingBlock fallingBlock = addFallingBlock(location.clone());
                        customFallingBlocks.add(new CustomFallingBlock(fallingBlock, wp, GroundSlam.this));
                        WarlordsEvents.addEntityUUID(fallingBlock);
                    }
                    // ParticleEffect.VILLAGER_HAPPY.display(0 , 0 ,0, 0, 10, location.getBlock().getLocation(), 1000);
                    // ParticleEffect.FLAME.display(0 , 0 ,0, 0, 10, location, 1000);
                    // DAMAGE
                    PlayerFilter.entitiesAroundRectangle(location.clone().add(0, -.75, 0), 0.75, 4.5, 0.75).enemiesOf(wp).forEach(enemy -> {
                        if (!playersHit.contains(enemy)) {
                            playersHit.add(enemy);
                            final Location loc = enemy.getLocation();
                            final Vector v = wp.getLocation().toVector().subtract(loc.toVector()).normalize().multiply(-1.25).setY(0.25);
                            enemy.setVelocity(v, false);
                            enemy.addDamageInstance(wp, name, minDamageHeal, maxDamageHeal, critChance, critMultiplier, false);
                        }
                    });
                }
                fallingBlockLocations.remove(fallingBlockLocation);
                break;
            }
            if (fallingBlockLocations.isEmpty()) {
                this.cancel();
            }
        }
    }.runTaskTimer(0, 2);
    new GameRunnable(wp.getGame()) {

        @Override
        public void run() {
            for (int i = 0; i < customFallingBlocks.size(); i++) {
                CustomFallingBlock customFallingBlock = customFallingBlocks.get(i);
                customFallingBlock.setTicksLived(customFallingBlock.getTicksLived() + 1);
                if (Utils.getDistance(customFallingBlock.getFallingBlock().getLocation(), .05) <= .25 || customFallingBlock.getTicksLived() > 10) {
                    customFallingBlock.getFallingBlock().remove();
                    customFallingBlocks.remove(i);
                    i--;
                }
            }
            if (fallingBlockLocations.isEmpty() && customFallingBlocks.isEmpty()) {
                this.cancel();
            }
        }
    }.runTaskTimer(0, 0);
    return true;
}
Also used : Utils(com.ebicep.warlords.util.warlords.Utils) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) Player(org.bukkit.entity.Player) CustomFallingBlock(com.ebicep.customentities.CustomFallingBlock) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) ArrayList(java.util.ArrayList) Vector(org.bukkit.util.Vector) List(java.util.List) Location(org.bukkit.Location) World(org.bukkit.World) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) WarlordsEvents(com.ebicep.warlords.events.WarlordsEvents) FallingBlock(org.bukkit.entity.FallingBlock) AbstractAbility(com.ebicep.warlords.classes.AbstractAbility) Material(org.bukkit.Material) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) ArrayList(java.util.ArrayList) CustomFallingBlock(com.ebicep.customentities.CustomFallingBlock) FallingBlock(org.bukkit.entity.FallingBlock) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) CustomFallingBlock(com.ebicep.customentities.CustomFallingBlock) ArrayList(java.util.ArrayList) List(java.util.List) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Aggregations

GameRunnable (com.ebicep.warlords.util.warlords.GameRunnable)53 WarlordsPlayer (com.ebicep.warlords.player.WarlordsPlayer)39 Location (org.bukkit.Location)34 Player (org.bukkit.entity.Player)23 Utils (com.ebicep.warlords.util.warlords.Utils)21 CooldownTypes (com.ebicep.warlords.player.cooldowns.CooldownTypes)17 AbstractAbility (com.ebicep.warlords.classes.AbstractAbility)16 ParticleEffect (com.ebicep.warlords.effects.ParticleEffect)16 RegularCooldown (com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown)16 PlayerFilter (com.ebicep.warlords.util.warlords.PlayerFilter)16 WarlordsDamageHealingEvent (com.ebicep.warlords.events.WarlordsDamageHealingEvent)13 ItemStack (org.bukkit.inventory.ItemStack)13 ArmorStand (org.bukkit.entity.ArmorStand)12 Vector (org.bukkit.util.Vector)11 ChatColor (org.bukkit.ChatColor)10 Material (org.bukkit.Material)10 Warlords (com.ebicep.warlords.Warlords)9 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Nonnull (javax.annotation.Nonnull)9