Search in sources :

Example 11 with RegularCooldown

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

the class WarlordsPlayer method addDamageInstance.

private void addDamageInstance(WarlordsDamageHealingEvent event) {
    WarlordsPlayer attacker = event.getAttacker();
    String ability = event.getAbility();
    float min = event.getMin();
    float max = event.getMax();
    int critChance = event.getCritChance();
    int critMultiplier = event.getCritMultiplier();
    boolean ignoreReduction = event.isIgnoreReduction();
    boolean isLastStandFromShield = event.isIsLastStandFromShield();
    boolean isMeleeHit = ability.isEmpty();
    boolean isFallDamage = ability.equals("Fall");
    // Spawn Protection / Undying Army / Game State
    if ((dead && !cooldownManager.checkUndyingArmy(false)) || getGameState() != getGame().getState()) {
        return;
    }
    int initialHealth = health;
    for (AbstractCooldown<?> abstractCooldown : getCooldownManager().getCooldownsDistinct()) {
        abstractCooldown.doBeforeReductionFromSelf(event);
    }
    for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
        abstractCooldown.doBeforeReductionFromAttacker(event);
    }
    for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
        critChance = abstractCooldown.addCritChanceFromAttacker(event, critChance);
        critMultiplier = abstractCooldown.addCritMultiplierFromAttacker(event, critMultiplier);
    }
    // crit
    float damageValue = (int) ((Math.random() * (max - min)) + min);
    int crit = (int) ((Math.random() * (100)));
    boolean isCrit = false;
    if (crit <= critChance && attacker.canCrit) {
        isCrit = true;
        damageValue *= critMultiplier / 100f;
    }
    final float damageHealValueBeforeReduction = damageValue;
    addAbsorbed(Math.abs(damageValue - (damageValue *= 1 - spec.getDamageResistance() / 100f)));
    if (attacker == this && (isFallDamage || isMeleeHit)) {
        if (isMeleeHit) {
            // True damage
            sendMessage(GIVE_ARROW + ChatColor.GRAY + " You took " + ChatColor.RED + Math.round(min) + ChatColor.GRAY + " melee damage.");
            regenTimer = 10;
            if (health - min <= 0 && !cooldownManager.checkUndyingArmy(false)) {
                if (entity instanceof Player) {
                    PacketUtils.sendTitle((Player) entity, ChatColor.RED + "YOU DIED!", ChatColor.GRAY + "You took " + ChatColor.RED + Math.round(min) + ChatColor.GRAY + " melee damage and died.", 0, 40, 0);
                }
                health = 0;
                die(attacker);
            } else {
                health -= min;
                playHurtAnimation(this.entity, attacker);
            }
        } else {
            // Fall Damage
            sendMessage(GIVE_ARROW + ChatColor.GRAY + " You took " + ChatColor.RED + Math.round(damageValue) + ChatColor.GRAY + " fall damage.");
            regenTimer = 10;
            if (health - damageValue < 0 && !cooldownManager.checkUndyingArmy(false)) {
                // Title card "YOU DIED!"
                if (entity instanceof Player) {
                    PacketUtils.sendTitle((Player) entity, ChatColor.RED + "YOU DIED!", ChatColor.GRAY + "You took " + ChatColor.RED + Math.round(damageValue) + ChatColor.GRAY + " fall damage and died.", 0, 40, 0);
                }
                health = 0;
                die(attacker);
            } else {
                health -= damageValue;
                playHurtAnimation(entity, attacker);
            }
            addAbsorbed(Math.abs(damageValue * spec.getDamageResistance() / 100));
        }
        cancelHealingPowerUp();
        return;
    }
    // Reduction before Intervene.
    if (!ignoreReduction) {
        // Flag carrier multiplier.
        damageValue *= getFlagDamageMultiplier();
        // Checks whether the player is standing in a Hammer of Light.
        if (!HammerOfLight.standingInHammer(attacker, entity)) {
            for (AbstractCooldown<?> abstractCooldown : getCooldownManager().getCooldownsDistinct()) {
                damageValue = abstractCooldown.modifyDamageBeforeInterveneFromSelf(event, damageValue);
            }
            for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
                damageValue = abstractCooldown.modifyDamageBeforeInterveneFromAttacker(event, damageValue);
            }
        }
    }
    // Intervene
    Optional<RegularCooldown> optionalInterveneCooldown = new CooldownFilter<>(this, RegularCooldown.class).filterCooldownClass(Intervene.class).filter(regularCooldown -> regularCooldown.getFrom() != this).findFirst();
    if (optionalInterveneCooldown.isPresent() && !HammerOfLight.standingInHammer(attacker, entity) && isEnemy(attacker)) {
        Intervene intervene = (Intervene) optionalInterveneCooldown.get().getCooldownObject();
        WarlordsPlayer intervenedBy = optionalInterveneCooldown.get().getFrom();
        damageValue *= .5;
        intervenedBy.addAbsorbed(damageValue);
        intervenedBy.setRegenTimer(10);
        intervene.addDamagePrevented(damageValue);
        intervenedBy.addDamageInstance(attacker, "Intervene", damageValue, damageValue, isCrit ? 100 : -1, 100, false);
        Location loc = getLocation();
        // EFFECTS + SOUNDS
        Utils.playGlobalSound(loc, "warrior.intervene.block", 2, 1);
        playHitSound(attacker);
        entity.playEffect(EntityEffect.HURT);
        intervenedBy.getEntity().playEffect(EntityEffect.HURT);
        // Red line particle if the player gets hit
        EffectUtils.playParticleLinkAnimation(getLocation(), intervenedBy.getLocation(), 255, 0, 0, 2);
        // Remove horses.
        removeHorse();
        intervenedBy.removeHorse();
        for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
            abstractCooldown.onInterveneFromAttacker(event, damageValue);
        }
    } else {
        // Damage reduction after Intervene
        if (!ignoreReduction) {
            if (!HammerOfLight.standingInHammer(attacker, entity)) {
                // Example: .8 = 20% reduction.
                for (AbstractCooldown<?> abstractCooldown : getCooldownManager().getCooldownsDistinct()) {
                    damageValue = abstractCooldown.modifyDamageAfterInterveneFromSelf(event, damageValue);
                }
                for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
                    damageValue = abstractCooldown.modifyDamageAfterInterveneFromAttacker(event, damageValue);
                }
            }
        }
        // Arcane Shield
        List<ArcaneShield> arcaneShields = new CooldownFilter<>(this, RegularCooldown.class).filterCooldownClassAndMapToObjectsOfClass(ArcaneShield.class).collect(Collectors.toList());
        if (!arcaneShields.isEmpty() && isEnemy(attacker) && !HammerOfLight.standingInHammer(attacker, entity)) {
            ArcaneShield arcaneShield = arcaneShields.get(0);
            // adding dmg to shield
            arcaneShield.addShieldHealth(-damageValue);
            // check if broken
            if (arcaneShield.getShieldHealth() < 0) {
                if (entity instanceof Player) {
                    ((EntityLiving) ((CraftPlayer) entity).getHandle()).setAbsorptionHearts(0);
                }
                cooldownManager.removeCooldown(arcaneShield);
                addDamageInstance(new WarlordsDamageHealingEvent(this, attacker, ability, -arcaneShield.getShieldHealth(), -arcaneShield.getShieldHealth(), isCrit ? 100 : -1, 100, false, true, true));
                addAbsorbed(-(arcaneShield.getShieldHealth()));
                return;
            } else {
                if (entity instanceof Player) {
                    ((EntityLiving) ((CraftPlayer) entity).getHandle()).setAbsorptionHearts((float) (arcaneShield.getShieldHealth() / (maxHealth * .5) * 20));
                }
                if (isMeleeHit) {
                    sendMessage(GIVE_ARROW + ChatColor.GRAY + " You absorbed " + attacker.getName() + "'s melee " + ChatColor.GRAY + "hit.");
                    attacker.sendMessage(RECEIVE_ARROW + ChatColor.GRAY + " Your melee hit was absorbed by " + name);
                } else {
                    sendMessage(GIVE_ARROW + ChatColor.GRAY + " You absorbed " + attacker.getName() + "'s " + ability + " " + ChatColor.GRAY + "hit.");
                    attacker.sendMessage(RECEIVE_ARROW + ChatColor.GRAY + " Your " + ability + " was absorbed by " + name + ChatColor.GRAY + ".");
                }
                addAbsorbed(Math.abs(damageHealValueBeforeReduction));
            }
            for (AbstractCooldown<?> abstractCooldown : getCooldownManager().getCooldownsDistinct()) {
                abstractCooldown.onShieldFromSelf(event, damageValue, isCrit);
            }
            for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
                abstractCooldown.onShieldFromAttacker(event, damageValue, isCrit);
            }
            playHurtAnimation(this.entity, attacker);
            if (!isMeleeHit) {
                playHitSound(attacker);
            }
            removeHorse();
        } else {
            boolean debt = getCooldownManager().hasCooldownFromName("Spirits Respite");
            if (isEnemy(attacker)) {
                hitBy.put(attacker, 10);
                cancelHealingPowerUp();
                removeHorse();
                regenTimer = 10;
                sendDamageMessage(attacker, this, ability, damageValue, isCrit, isMeleeHit);
                if (spec instanceof Vindicator) {
                    ((SoulShackle) spec.getRed()).addToShacklePool(damageValue);
                }
                // Repentance
                if (spec instanceof Spiritguard) {
                    ((Repentance) spec.getBlue()).addToPool(damageValue);
                }
                for (AbstractCooldown<?> abstractCooldown : getCooldownManager().getCooldownsDistinct()) {
                    abstractCooldown.onDamageFromSelf(event, damageValue, isCrit);
                }
                for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
                    abstractCooldown.onDamageFromAttacker(event, damageValue, isCrit);
                }
            }
            updateJimmyHealth();
            // debt and healing
            if (!debt && takeDamage) {
                this.health -= Math.round(damageValue);
            }
            attacker.addDamage(damageValue);
            playHurtAnimation(this.entity, attacker);
            recordDamage.add(damageValue);
            // The player died.
            if (this.health <= 0 && !cooldownManager.checkUndyingArmy(false)) {
                if (attacker.entity instanceof Player) {
                    ((Player) attacker.entity).playSound(attacker.getLocation(), Sound.ORB_PICKUP, 500f, 1);
                    ((Player) attacker.entity).playSound(attacker.getLocation(), Sound.ORB_PICKUP, 500f, 0.5f);
                }
                attacker.addKill();
                sendMessage(ChatColor.GRAY + "You were killed by " + attacker.getColoredName());
                attacker.sendMessage(ChatColor.GRAY + "You killed " + getColoredName());
                gameState.getGame().forEachOnlinePlayer((p, t) -> {
                    if (p != this.entity && p != attacker.entity) {
                        p.sendMessage(getColoredName() + ChatColor.GRAY + " was killed by " + attacker.getColoredName());
                    }
                });
                for (WarlordsPlayer enemy : PlayerFilter.playingGame(game).enemiesOf(this).stream().collect(Collectors.toList())) {
                    for (AbstractCooldown<?> abstractCooldown : enemy.getCooldownManager().getCooldownsDistinct()) {
                        abstractCooldown.onDeathFromEnemies(event, damageValue, isCrit, enemy == attacker);
                    }
                }
                // Title card "YOU DIED!"
                if (this.entity instanceof Player) {
                    PacketUtils.sendTitle((Player) entity, ChatColor.RED + "YOU DIED!", ChatColor.GRAY + attacker.getName() + " killed you.", 0, 40, 0);
                }
                die(attacker);
            } else {
                if (!isMeleeHit && this != attacker && damageValue != 0) {
                    playHitSound(attacker);
                }
            }
        }
    }
    for (AbstractCooldown<?> abstractCooldown : getCooldownManager().getCooldownsDistinct()) {
        abstractCooldown.onEndFromSelf(event, damageValue, isCrit);
    }
    for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
        abstractCooldown.onEndFromAttacker(event, damageValue, isCrit);
    }
    getCooldownManager().getCooldowns().removeAll(new CooldownFilter<>(attacker, DamageHealCompleteCooldown.class).stream().collect(Collectors.toList()));
    attacker.getCooldownManager().getCooldowns().removeAll(new CooldownFilter<>(attacker, DamageHealCompleteCooldown.class).stream().collect(Collectors.toList()));
// WarlordsDamageHealingFinalEvent finalEvent = new WarlordsDamageHealingFinalEvent(
// this,
// attacker,
// ability,
// initialHealth,
// damageValue,
// critChance,
// critMultiplier,
// isCrit,
// true);
// secondStats.addDamageHealingEventAsSelf(finalEvent);
// attacker.getSecondStats().addDamageHealingEventAsAttacker(finalEvent);
// 
// checkForAchievementsDamage(attacker);
}
Also used : EffectUtils(com.ebicep.warlords.effects.EffectUtils) ItemFlag(org.bukkit.inventory.ItemFlag) PatternType(org.bukkit.block.banner.PatternType) Enchantment(org.bukkit.enchantments.Enchantment) Zombie(org.bukkit.entity.Zombie) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) ChallengeAchievements(com.ebicep.warlords.achievements.types.ChallengeAchievements) org.bukkit(org.bukkit) AbstractPlayerClass(com.ebicep.warlords.classes.AbstractPlayerClass) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) CustomHorse(com.ebicep.customentities.CustomHorse) FlagInfo(com.ebicep.warlords.game.flags.FlagInfo) Achievement(com.ebicep.warlords.achievements.Achievement) SpawnLocationMarker(com.ebicep.warlords.game.option.marker.SpawnLocationMarker) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) Spiritguard(com.ebicep.warlords.classes.shaman.specs.spiritguard.Spiritguard) TeleportUtils(com.ebicep.warlords.util.bukkit.TeleportUtils) AbstractAbility(com.ebicep.warlords.classes.AbstractAbility) PlayerFlagLocation(com.ebicep.warlords.game.flags.PlayerFlagLocation) CompassTargetMarker(com.ebicep.warlords.game.option.marker.CompassTargetMarker) HealingPowerup(com.ebicep.warlords.abilties.internal.HealingPowerup) Entity(org.bukkit.entity.Entity) Team(com.ebicep.warlords.game.Team) Warlords(com.ebicep.warlords.Warlords) FlagHolder(com.ebicep.warlords.game.option.marker.FlagHolder) LivingEntity(org.bukkit.entity.LivingEntity) NumberFormat(com.ebicep.warlords.util.java.NumberFormat) Collectors(java.util.stream.Collectors) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) ItemStack(org.bukkit.inventory.ItemStack) WarlordsRespawnEvent(com.ebicep.warlords.events.WarlordsRespawnEvent) Vindicator(com.ebicep.warlords.classes.rogue.specs.Vindicator) Game(com.ebicep.warlords.game.Game) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) AbstractCooldown(com.ebicep.warlords.player.cooldowns.AbstractCooldown) EntityLiving(net.minecraft.server.v1_8_R3.EntityLiving) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) GenericAttributes(net.minecraft.server.v1_8_R3.GenericAttributes) WarlordsDamageHealingEvent(com.ebicep.warlords.events.WarlordsDamageHealingEvent) PotionEffectType(org.bukkit.potion.PotionEffectType) Utils(com.ebicep.warlords.util.warlords.Utils) GameAddon(com.ebicep.warlords.game.GameAddon) java.util(java.util) ItemMeta(org.bukkit.inventory.meta.ItemMeta) PacketUtils(com.ebicep.warlords.util.bukkit.PacketUtils) Pattern(org.bukkit.block.banner.Pattern) PlayingState(com.ebicep.warlords.game.state.PlayingState) CooldownManager(com.ebicep.warlords.player.cooldowns.CooldownManager) CraftEntity(org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) BannerMeta(org.bukkit.inventory.meta.BannerMeta) Nonnull(javax.annotation.Nonnull) com.ebicep.warlords.abilties(com.ebicep.warlords.abilties) Nullable(javax.annotation.Nullable) WarlordsDeathEvent(com.ebicep.warlords.events.WarlordsDeathEvent) DamageHealCompleteCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.DamageHealCompleteCooldown) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) EntityEquipment(org.bukkit.inventory.EntityEquipment) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) Vindicator(com.ebicep.warlords.classes.rogue.specs.Vindicator) EntityLiving(net.minecraft.server.v1_8_R3.EntityLiving) Spiritguard(com.ebicep.warlords.classes.shaman.specs.spiritguard.Spiritguard) DamageHealCompleteCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.DamageHealCompleteCooldown) WarlordsDamageHealingEvent(com.ebicep.warlords.events.WarlordsDamageHealingEvent) PlayerFlagLocation(com.ebicep.warlords.game.flags.PlayerFlagLocation)

Example 12 with RegularCooldown

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

the class CooldownManager method getNumberOfBoundPlayersLink.

public int getNumberOfBoundPlayersLink(WarlordsPlayer warlordsPlayer) {
    int counter = 0;
    for (Soulbinding soulbinding : new CooldownFilter<>(this, RegularCooldown.class).filterCooldownClassAndMapToObjectsOfClass(Soulbinding.class).collect(Collectors.toList())) {
        if (soulbinding.hasBoundPlayerLink(warlordsPlayer)) {
            counter++;
        }
    }
    incrementCooldown(new RegularCooldown<Void>("KB Resistance", "KB", null, null, this.warlordsPlayer, CooldownTypes.BUFF, cooldownManager -> {
    }, counter * 20), (int) (counter * 1.2 * 20), (int) (3.6 * 20));
    return counter;
}
Also used : PersistentCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.PersistentCooldown) Soulbinding(com.ebicep.warlords.abilties.Soulbinding) OrbsOfLife(com.ebicep.warlords.abilties.OrbsOfLife) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) Intervene(com.ebicep.warlords.abilties.Intervene) UndyingArmy(com.ebicep.warlords.abilties.UndyingArmy) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) Optional(java.util.Optional) Pair(com.ebicep.warlords.util.java.Pair) Soulbinding(com.ebicep.warlords.abilties.Soulbinding)

Example 13 with RegularCooldown

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

the class Windfury method onActivate.

@Override
public boolean onActivate(WarlordsPlayer wp, Player player) {
    wp.subtractEnergy(energyCost);
    Windfury tempWindfury = new Windfury();
    final boolean[] firstProc = { true };
    wp.getCooldownManager().addCooldown(new RegularCooldown<Windfury>(name, "FURY", Windfury.class, tempWindfury, wp, CooldownTypes.ABILITY, cooldownManager -> {
    }, duration * 20) {

        @Override
        public void onEndFromAttacker(WarlordsDamageHealingEvent event, float currentDamageValue, boolean isCrit) {
            if (event.getAbility().isEmpty()) {
                WarlordsPlayer victim = event.getPlayer();
                WarlordsPlayer attacker = event.getAttacker();
                float min = event.getMin();
                float max = event.getMax();
                int windfuryActivate = (int) (Math.random() * 100);
                if (firstProc[0]) {
                    firstProc[0] = false;
                    windfuryActivate = 0;
                }
                if (windfuryActivate < procChance) {
                    new BukkitRunnable() {

                        int counter = 0;

                        @Override
                        public void run() {
                            victim.getGameState().getGame().forEachOnlinePlayerWithoutSpectators((player1, t) -> {
                                player1.playSound(victim.getLocation(), "shaman.windfuryweapon.impact", 2, 1);
                            });
                            if (Warlords.getPlayerSettings(attacker.getUuid()).getSkillBoostForClass() == ClassesSkillBoosts.WINDFURY_WEAPON) {
                                victim.addDamageInstance(attacker, "Windfury Weapon", min * 1.35f * 1.2f, max * 1.35f * 1.2f, 25, 200, false);
                            } else {
                                victim.addDamageInstance(attacker, "Windfury Weapon", min * 1.35f, max * 1.35f, 25, 200, false);
                            }
                            counter++;
                            if (counter == 2) {
                                this.cancel();
                            }
                        }
                    }.runTaskTimer(Warlords.getInstance(), 3, 3);
                }
            }
        }
    });
    Utils.playGlobalSound(player.getLocation(), "shaman.windfuryweapon.activation", 2, 1);
    new GameRunnable(wp.getGame()) {

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

Example 14 with RegularCooldown

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

the class DeathsDebt method onActivation.

@Override
protected void onActivation(WarlordsPlayer wp, Player player, ArmorStand totemStand) {
    final int ticksLeft = (4 + (2 * (int) Math.round((double) wp.getHealth() / wp.getMaxHealth()))) * 20;
    DeathsDebt tempDeathsDebt = new DeathsDebt();
    CircleEffect circle = new CircleEffect(wp, totemStand.getLocation().clone().add(0, 1.25, 0), respiteRadius);
    circle.addEffect(new CircumferenceEffect(ParticleEffect.SPELL));
    circle.addEffect(new DoubleLineEffect(ParticleEffect.REDSTONE));
    BukkitTask particles = Bukkit.getScheduler().runTaskTimer(Warlords.getInstance(), circle::playEffects, 0, 1);
    AtomicReference<RegularCooldown<DeathsDebt>> deathsDebtCooldown = new AtomicReference<>();
    RegularCooldown<DeathsDebt> spiritRespiteCooldown = new RegularCooldown<DeathsDebt>("Spirits Respite", "RESP", DeathsDebt.class, tempDeathsDebt, wp, CooldownTypes.ABILITY, cooldownManagerRespite -> {
        tempDeathsDebt.setInDebt(true);
        // beginning debt
        deathsDebtCooldown.set(new RegularCooldown<>(name, "DEBT", DeathsDebt.class, tempDeathsDebt, wp, CooldownTypes.ABILITY, cooldownManagerDebt -> {
            // final damage tick
            wp.getWorld().spigot().strikeLightningEffect(totemStand.getLocation(), false);
            // Enemy damage
            PlayerFilter.entitiesAround(totemStand, debtRadius, debtRadius - 1, debtRadius).aliveEnemiesOf(wp).forEach((nearPlayer) -> {
                nearPlayer.addDamageInstance(wp, name, tempDeathsDebt.getDelayedDamage() * .15f, tempDeathsDebt.getDelayedDamage() * .15f, critChance, critMultiplier, false);
            });
            // 6 damage waves, stop the function
            totemStand.remove();
            particles.cancel();
        }, 6 * 20));
        wp.getCooldownManager().addCooldown(deathsDebtCooldown.get());
        if (!tempDeathsDebt.playerInRadius) {
            wp.sendMessage("§7You walked outside your §dDeath's Debt §7radius");
        } else {
            wp.sendMessage("§c\u00AB §2Spirit's Respite §7delayed §c" + Math.round(tempDeathsDebt.getDelayedDamage()) + " §7damage. §dYour debt must now be paid.");
        }
        circle.replaceEffects(e -> e instanceof DoubleLineEffect, new DoubleLineEffect(ParticleEffect.SPELL_WITCH));
        circle.setRadius(debtRadius);
        // blue to purple totem
        totemStand.setHelmet(new ItemStack(Material.DARK_OAK_FENCE_GATE));
    }, ticksLeft) {

        @Override
        public void onDamageFromSelf(WarlordsDamageHealingEvent event, float currentDamageValue, boolean isCrit) {
            tempDeathsDebt.addDelayedDamage(currentDamageValue);
        }
    };
    wp.getCooldownManager().addCooldown(spiritRespiteCooldown);
    new GameRunnable(wp.getGame()) {

        int counter = 0;

        @Override
        public void run() {
            if (wp.isDead()) {
                totemStand.remove();
                particles.cancel();
                this.cancel();
            } else {
                if (wp.getWorld() != totemStand.getWorld()) {
                    totemStand.remove();
                    particles.cancel();
                    this.cancel();
                    return;
                }
                boolean isPlayerInRadius = wp.getLocation().distanceSquared(totemStand.getLocation()) < respiteRadius * respiteRadius;
                if (!isPlayerInRadius && wp.getCooldownManager().hasCooldown(tempDeathsDebt) && !tempDeathsDebt.isInDebt()) {
                    tempDeathsDebt.setInDebt(true);
                    tempDeathsDebt.setPlayerInRadius(false);
                    spiritRespiteCooldown.setTicksLeft(0);
                }
                // every second
                if (counter % 20 == 0) {
                    if (!tempDeathsDebt.isInDebt()) {
                        // respite
                        Utils.playGlobalSound(totemStand.getLocation(), "shaman.earthlivingweapon.impact", 2, 1.5F);
                        wp.sendMessage(ChatColor.GREEN + "\u00BB §2Spirit's Respite §7delayed §c" + Math.round(tempDeathsDebt.getDelayedDamage()) + " §7damage. §6" + Math.round(spiritRespiteCooldown.getTicksLeft() / 20f) + " §7seconds left.");
                    } else {
                        // during debt
                        onDebtTick(wp, totemStand, tempDeathsDebt);
                    }
                }
                counter++;
                if (deathsDebtCooldown.get() == null) {
                    return;
                }
                if (!wp.getCooldownManager().hasCooldown(deathsDebtCooldown.get())) {
                    totemStand.remove();
                    particles.cancel();
                    this.cancel();
                }
            }
        }
    }.runTaskTimer(2, 0);
}
Also used : Utils(com.ebicep.warlords.util.warlords.Utils) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) AbstractTotemBase(com.ebicep.warlords.abilties.internal.AbstractTotemBase) CircumferenceEffect(com.ebicep.warlords.effects.circle.CircumferenceEffect) Warlords(com.ebicep.warlords.Warlords) CooldownTypes(com.ebicep.warlords.player.cooldowns.CooldownTypes) Player(org.bukkit.entity.Player) AtomicReference(java.util.concurrent.atomic.AtomicReference) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) ItemStack(org.bukkit.inventory.ItemStack) DoubleLineEffect(com.ebicep.warlords.effects.circle.DoubleLineEffect) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) Location(org.bukkit.Location) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) ArmorStand(org.bukkit.entity.ArmorStand) BukkitTask(org.bukkit.scheduler.BukkitTask) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) ChatColor(org.bukkit.ChatColor) CircleEffect(com.ebicep.warlords.effects.circle.CircleEffect) WarlordsDamageHealingEvent(com.ebicep.warlords.events.WarlordsDamageHealingEvent) ParticleEffect(com.ebicep.warlords.effects.ParticleEffect) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) DoubleLineEffect(com.ebicep.warlords.effects.circle.DoubleLineEffect) BukkitTask(org.bukkit.scheduler.BukkitTask) CircumferenceEffect(com.ebicep.warlords.effects.circle.CircumferenceEffect) AtomicReference(java.util.concurrent.atomic.AtomicReference) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) CircleEffect(com.ebicep.warlords.effects.circle.CircleEffect) WarlordsDamageHealingEvent(com.ebicep.warlords.events.WarlordsDamageHealingEvent) ItemStack(org.bukkit.inventory.ItemStack)

Example 15 with RegularCooldown

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

the class Earthliving method onActivate.

@Override
public boolean onActivate(WarlordsPlayer wp, Player player) {
    wp.subtractEnergy(energyCost);
    Earthliving tempEarthliving = new Earthliving();
    final boolean[] firstProc = { true };
    wp.getCooldownManager().addCooldown(new RegularCooldown<Earthliving>(name, "EARTH", Earthliving.class, tempEarthliving, wp, CooldownTypes.ABILITY, cooldownManager -> {
    }, duration * 20) {

        @Override
        public void onEndFromAttacker(WarlordsDamageHealingEvent event, float currentDamageValue, boolean isCrit) {
            if (event.getAbility().isEmpty()) {
                WarlordsPlayer victim = event.getPlayer();
                WarlordsPlayer attacker = event.getAttacker();
                int earthlivingActivate = (int) (Math.random() * 100);
                if (firstProc[0]) {
                    firstProc[0] = false;
                    earthlivingActivate = 0;
                }
                if (earthlivingActivate < procChance) {
                    attacker.addHealingInstance(attacker, "Earthliving Weapon", 132 * 2.4f, 179 * 2.4f, 25, 200, false, false);
                    victim.getGameState().getGame().forEachOnlinePlayerWithoutSpectators((p, t) -> {
                        p.playSound(victim.getLocation(), "shaman.earthlivingweapon.impact", 2, 1);
                    });
                    for (WarlordsPlayer nearPlayer : PlayerFilter.entitiesAround(attacker, 6, 6, 6).aliveTeammatesOfExcludingSelf(attacker).limit(2)) {
                        nearPlayer.addHealingInstance(attacker, "Earthliving Weapon", 132 * 2.4f, 179 * 2.4f, 25, 200, false, false);
                    }
                }
            }
        }
    });
    Utils.playGlobalSound(player.getLocation(), "shaman.earthlivingweapon.activation", 2, 1);
    new GameRunnable(wp.getGame()) {

        @Override
        public void run() {
            if (wp.getCooldownManager().hasCooldown(tempEarthliving)) {
                Location location = wp.getLocation();
                location.add(0, 1.2, 0);
                ParticleEffect.VILLAGER_HAPPY.display(0.3F, 0.3F, 0.3F, 0.1F, 2, location, 500);
            } else {
                this.cancel();
            }
        }
    }.runTaskTimer(0, 4);
    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) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) WarlordsDamageHealingEvent(com.ebicep.warlords.events.WarlordsDamageHealingEvent) Location(org.bukkit.Location)

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