use of com.ebicep.warlords.classes.rogue.specs.Apothecary 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);
}
Aggregations