Search in sources :

Example 1 with RegularCooldown

use of com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown 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 RegularCooldown

use of com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown 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 RegularCooldown

use of com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown in project Warlords by ebicep.

the class HammerOfLight method onActivate.

@Override
public boolean onActivate(WarlordsPlayer wp, Player player) {
    if (player.getTargetBlock((Set<Material>) null, 25).getType() == Material.AIR)
        return false;
    Location location = player.getTargetBlock((Set<Material>) null, 25).getLocation().add(1, 0, 1).clone();
    ArmorStand hammer = spawnHammer(location, wp);
    wp.subtractEnergy(energyCost);
    wp.getSpec().getOrange().setCurrentCooldown((float) (cooldown * wp.getCooldownModifier()));
    HammerOfLight tempHammerOfLight = new HammerOfLight();
    wp.getCooldownManager().addRegularCooldown(name, "HAMMER", HammerOfLight.class, tempHammerOfLight, wp, CooldownTypes.ABILITY, cooldownManager -> {
    }, duration * 20);
    Utils.playGlobalSound(player.getLocation(), "paladin.hammeroflight.impact", 2, 0.85f);
    CircleEffect circleEffect = new CircleEffect(wp.getGame(), wp.getTeam(), location, radius, new CircumferenceEffect(ParticleEffect.VILLAGER_HAPPY, ParticleEffect.REDSTONE), new LineEffect(location.clone().add(0, 2.3, 0), ParticleEffect.SPELL));
    BukkitTask task = wp.getGame().registerGameTask(circleEffect::playEffects, 0, 1);
    location.add(0, 1, 0);
    final int[] timeLeftHammer = { duration };
    new GameRunnable(wp.getGame()) {

        int counter = 0;

        @Override
        public void run() {
            if (counter % 20 == 0) {
                timeLeftHammer[0]--;
                for (WarlordsPlayer warlordsPlayer : PlayerFilter.entitiesAround(location, radius, radius, radius).isAlive()) {
                    if (wp.isTeammateAlive(warlordsPlayer)) {
                        warlordsPlayer.addHealingInstance(wp, name, minDamageHeal, maxDamageHeal, critChance, critMultiplier, false, false);
                    } else {
                        warlordsPlayer.addDamageInstance(wp, name, 178, 244, critChance, critMultiplier, false);
                    }
                }
            }
            if (timeLeftHammer[0] <= 0) {
                hammer.remove();
                this.cancel();
                task.cancel();
            }
            counter++;
        }
    }.runTaskTimer(0, 0);
    new GameRunnable(wp.getGame()) {

        boolean wasSneaking = false;

        @Override
        public void run() {
            if (wp.isAlive() && wp.isSneaking() && !wasSneaking) {
                tempHammerOfLight.setCrownOfLight(true);
                new CooldownFilter<>(wp, RegularCooldown.class).filterCooldownObject(tempHammerOfLight).findAny().ifPresent(regularCooldown -> {
                    regularCooldown.setNameAbbreviation("CROWN");
                });
                Utils.playGlobalSound(wp.getLocation(), "warrior.revenant.orbsoflife", 2, 0.15f);
                Utils.playGlobalSound(wp.getLocation(), "mage.firebreath.activation", 2, 0.25f);
                BukkitTask particles = new GameRunnable(wp.getGame()) {

                    @Override
                    public void run() {
                        double angle = 0;
                        for (int i = 0; i < 9; i++) {
                            double x = .4 * Math.cos(angle);
                            double z = .4 * Math.sin(angle);
                            angle += 40;
                            Vector v = new Vector(x, 2, z);
                            Location loc = wp.getLocation().clone().add(v);
                            ParticleEffect.SPELL.display(0, 0, 0, 0f, 1, loc, 500);
                        }
                        CircleEffect circle = new CircleEffect(wp.getGame(), wp.getTeam(), wp.getLocation().add(0, 0.75f, 0), radius / 2f);
                        circle.addEffect(new CircumferenceEffect(ParticleEffect.SPELL).particlesPerCircumference(0.5f));
                        circle.playEffects();
                    }
                }.runTaskTimer(0, 6);
                new GameRunnable(wp.getGame()) {

                    int timeLeft = timeLeftHammer[0];

                    @Override
                    public void run() {
                        PlayerFilter.entitiesAround(wp.getLocation(), radius, radius, radius).aliveTeammatesOf(wp).forEach(teammate -> teammate.addHealingInstance(wp, "Crown of Light", minDamageHeal * 1.5f, maxDamageHeal * 1.5f, critChance, critMultiplier, false, false));
                        timeLeft--;
                        if (timeLeft <= 0 || wp.isDead()) {
                            this.cancel();
                            particles.cancel();
                        }
                    }
                }.runTaskTimer(2, 20);
                this.cancel();
                timeLeftHammer[0] = 0;
            }
            wasSneaking = wp.isSneaking();
            if (wp.isDead() || timeLeftHammer[0] <= 0) {
                this.cancel();
            }
        }
    }.runTaskTimer(0, 0);
    return true;
}
Also used : Utils(com.ebicep.warlords.util.warlords.Utils) Player(org.bukkit.entity.Player) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) ArrayList(java.util.ArrayList) Location(org.bukkit.Location) CircleEffect(com.ebicep.warlords.effects.circle.CircleEffect) AbstractAbility(com.ebicep.warlords.classes.AbstractAbility) ParticleEffect(com.ebicep.warlords.effects.ParticleEffect) Material(org.bukkit.Material) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) Entity(org.bukkit.entity.Entity) CircumferenceEffect(com.ebicep.warlords.effects.circle.CircumferenceEffect) Set(java.util.Set) Warlords(com.ebicep.warlords.Warlords) CooldownTypes(com.ebicep.warlords.player.cooldowns.CooldownTypes) LineEffect(com.ebicep.warlords.effects.circle.LineEffect) EntityType(org.bukkit.entity.EntityType) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) List(java.util.List) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) EulerAngle(org.bukkit.util.EulerAngle) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) ArmorStand(org.bukkit.entity.ArmorStand) BukkitTask(org.bukkit.scheduler.BukkitTask) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) Protector(com.ebicep.warlords.classes.paladin.specs.Protector) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) Set(java.util.Set) LineEffect(com.ebicep.warlords.effects.circle.LineEffect) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) BukkitTask(org.bukkit.scheduler.BukkitTask) Material(org.bukkit.Material) CircumferenceEffect(com.ebicep.warlords.effects.circle.CircumferenceEffect) ArmorStand(org.bukkit.entity.ArmorStand) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) CircleEffect(com.ebicep.warlords.effects.circle.CircleEffect) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 4 with RegularCooldown

use of com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown in project Warlords by ebicep.

the class Inferno method onActivate.

@Override
public boolean onActivate(WarlordsPlayer wp, Player player) {
    Inferno tempInferno = new Inferno();
    wp.getCooldownManager().addCooldown(new RegularCooldown<Inferno>(name, "INFR", Inferno.class, tempInferno, wp, CooldownTypes.ABILITY, cooldownManager -> {
    }, duration * 20) {

        @Override
        public boolean distinct() {
            return true;
        }

        @Override
        public int addCritChanceFromAttacker(WarlordsDamageHealingEvent event, int currentCritChance) {
            if (event.getAbility().isEmpty() || event.getAbility().equals("Time Warp"))
                return currentCritChance;
            return currentCritChance + critChanceIncrease;
        }

        @Override
        public int addCritMultiplierFromAttacker(WarlordsDamageHealingEvent event, int currentCritMultiplier) {
            if (event.getAbility().isEmpty() || event.getAbility().equals("Time Warp"))
                return currentCritMultiplier;
            return currentCritMultiplier + critMultiplierIncrease;
        }
    });
    Utils.playGlobalSound(player.getLocation(), "mage.inferno.activation", 2, 1);
    new GameRunnable(wp.getGame()) {

        @Override
        public void run() {
            if (wp.getCooldownManager().hasCooldown(tempInferno)) {
                Location location = wp.getLocation();
                location.add(0, 1.2, 0);
                ParticleEffect.DRIP_LAVA.display(0.5F, 0.3F, 0.5F, 0.4F, 1, location, 500);
                ParticleEffect.FLAME.display(0.5F, 0.3F, 0.5F, 0.0001F, 1, location, 500);
                ParticleEffect.CRIT.display(0.5F, 0.3F, 0.5F, 0.0001F, 1, location, 500);
            } else {
                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) WarlordsDamageHealingEvent(com.ebicep.warlords.events.WarlordsDamageHealingEvent) Location(org.bukkit.Location)

Example 5 with RegularCooldown

use of com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown in project Warlords by ebicep.

the class OrderOfEviscerate method onActivate.

@Override
public boolean onActivate(@Nonnull WarlordsPlayer wp, @Nonnull Player player) {
    wp.subtractEnergy(energyCost);
    wp.getCooldownManager().removeCooldown(OrderOfEviscerate.class);
    wp.getCooldownManager().addCooldown(new RegularCooldown<OrderOfEviscerate>("Order of Eviscerate", "ORDER", OrderOfEviscerate.class, new OrderOfEviscerate(), wp, CooldownTypes.ABILITY, cooldownManager -> {
    }, duration * 20) {

        @Override
        public void doBeforeReductionFromSelf(WarlordsDamageHealingEvent event) {
            OrderOfEviscerate.removeCloak(wp, false);
        }

        @Override
        public void doBeforeReductionFromAttacker(WarlordsDamageHealingEvent event) {
            // mark message here so it displays before damage
            WarlordsPlayer victim = event.getPlayer();
            if (!Objects.equals(this.getCooldownObject().getMarkedPlayer(), victim)) {
                wp.sendMessage(WarlordsPlayer.RECEIVE_ARROW + ChatColor.GRAY + " You have marked §e" + victim.getName());
            }
            this.getCooldownObject().setMarkedPlayer(victim);
        }

        @Override
        public float modifyDamageBeforeInterveneFromAttacker(WarlordsDamageHealingEvent event, float currentDamageValue) {
            if (this.getCooldownObject().getMarkedPlayer().equals(event.getPlayer()) && !Utils.isLineOfSightAssassin(event.getPlayer().getEntity(), event.getAttacker().getEntity())) {
                return currentDamageValue * 1.25f;
            }
            return currentDamageValue;
        }

        @Override
        public void onDeathFromEnemies(WarlordsDamageHealingEvent event, float currentDamageValue, boolean isCrit, boolean isKiller) {
            wp.getCooldownManager().removeCooldown(OrderOfEviscerate.class);
            wp.getCooldownManager().removeCooldownByName("Cloaked");
            if (isKiller) {
                wp.sendMessage(WarlordsPlayer.RECEIVE_ARROW + ChatColor.GRAY + " You killed your mark," + ChatColor.YELLOW + " your cooldowns have been reset" + ChatColor.GRAY + "!");
                new GameRunnable(wp.getGame()) {

                    @Override
                    public void run() {
                        wp.getSpec().getPurple().setCurrentCooldown(0);
                        wp.getSpec().getOrange().setCurrentCooldown(0);
                        wp.updatePurpleItem();
                        wp.updateOrangeItem();
                        wp.subtractEnergy(-wp.getSpec().getOrange().getEnergyCost());
                    }
                }.runTaskLater(2);
            } else {
                new GameRunnable(wp.getGame()) {

                    @Override
                    public void run() {
                        wp.sendMessage(WarlordsPlayer.RECEIVE_ARROW + ChatColor.GRAY + " You assisted in killing your mark," + ChatColor.YELLOW + " your cooldowns have been reduced by half" + ChatColor.GRAY + "!");
                        wp.getSpec().getPurple().setCurrentCooldown(wp.getSpec().getPurple().getCurrentCooldown() / 2);
                        wp.getSpec().getOrange().setCurrentCooldown(wp.getSpec().getOrange().getCurrentCooldown() / 2);
                        wp.updatePurpleItem();
                        wp.updateOrangeItem();
                        wp.subtractEnergy(-wp.getSpec().getOrange().getEnergyCost() / 2);
                    }
                }.runTaskLater(2);
            }
            if (wp.getEntity() instanceof Player) {
                ((Player) wp.getEntity()).playSound(wp.getLocation(), Sound.AMBIENCE_THUNDER, 1, 2);
            }
        }
    });
    if (!FlagHolder.isPlayerHolderFlag(wp)) {
        wp.getCooldownManager().removeCooldownByName("Cloaked");
        wp.getCooldownManager().addRegularCooldown("Cloaked", "INVIS", OrderOfEviscerate.class, new OrderOfEviscerate(), wp, CooldownTypes.BUFF, cooldownManager -> {
        }, duration * 20);
        player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, duration * 20, 0, true, false), true);
        wp.updateArmor();
        PlayerFilter.playingGame(wp.getGame()).enemiesOf(wp).forEach(warlordsPlayer -> {
            LivingEntity livingEntity = warlordsPlayer.getEntity();
            if (livingEntity instanceof Player) {
                ((Player) livingEntity).hidePlayer(player);
            }
        });
    }
    Runnable cancelSpeed = wp.getSpeed().addSpeedModifier("Order of Eviscerate", 40, duration * 20, "BASE");
    Utils.playGlobalSound(player.getLocation(), Sound.GHAST_FIREBALL, 2, 0.7f);
    new GameRunnable(wp.getGame()) {

        @Override
        public void run() {
            if (!wp.getCooldownManager().hasCooldown(OrderOfEviscerate.class)) {
                this.cancel();
                // wp.setMarkedTarget(null);
                cancelSpeed.run();
                removeCloak(wp, true);
            } else {
                ParticleEffect.SMOKE_NORMAL.display(0.01f, 0.28f, 0.01f, 0.05f, 6, wp.getLocation(), 500);
                Utils.playGlobalSound(wp.getLocation(), Sound.AMBIENCE_CAVE, 0.08f, 2);
            }
        }
    }.runTaskTimer(0, 1);
    return true;
}
Also used : Utils(com.ebicep.warlords.util.warlords.Utils) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) CooldownTypes(com.ebicep.warlords.player.cooldowns.CooldownTypes) FlagHolder(com.ebicep.warlords.game.option.marker.FlagHolder) Sound(org.bukkit.Sound) Player(org.bukkit.entity.Player) LivingEntity(org.bukkit.entity.LivingEntity) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) PotionEffect(org.bukkit.potion.PotionEffect) Objects(java.util.Objects) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) ChatColor(org.bukkit.ChatColor) AbstractAbility(com.ebicep.warlords.classes.AbstractAbility) WarlordsDamageHealingEvent(com.ebicep.warlords.events.WarlordsDamageHealingEvent) Nonnull(javax.annotation.Nonnull) ParticleEffect(com.ebicep.warlords.effects.ParticleEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) Player(org.bukkit.entity.Player) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) PotionEffect(org.bukkit.potion.PotionEffect) LivingEntity(org.bukkit.entity.LivingEntity) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) WarlordsDamageHealingEvent(com.ebicep.warlords.events.WarlordsDamageHealingEvent)

Aggregations

RegularCooldown (com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown)22 WarlordsPlayer (com.ebicep.warlords.player.WarlordsPlayer)20 Utils (com.ebicep.warlords.util.warlords.Utils)18 Player (org.bukkit.entity.Player)18 CooldownTypes (com.ebicep.warlords.player.cooldowns.CooldownTypes)17 WarlordsDamageHealingEvent (com.ebicep.warlords.events.WarlordsDamageHealingEvent)16 GameRunnable (com.ebicep.warlords.util.warlords.GameRunnable)16 AbstractAbility (com.ebicep.warlords.classes.AbstractAbility)15 ParticleEffect (com.ebicep.warlords.effects.ParticleEffect)14 PlayerFilter (com.ebicep.warlords.util.warlords.PlayerFilter)13 Location (org.bukkit.Location)11 Nonnull (javax.annotation.Nonnull)8 Warlords (com.ebicep.warlords.Warlords)7 ChatColor (org.bukkit.ChatColor)7 EffectUtils (com.ebicep.warlords.effects.EffectUtils)6 CircleEffect (com.ebicep.warlords.effects.circle.CircleEffect)5 CircumferenceEffect (com.ebicep.warlords.effects.circle.CircumferenceEffect)5 CooldownFilter (com.ebicep.warlords.player.cooldowns.CooldownFilter)5 Material (org.bukkit.Material)5 ItemStack (org.bukkit.inventory.ItemStack)5