Search in sources :

Example 1 with PlayerFilter

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

the class ChainLightning method partOfChainLightning.

private int partOfChainLightning(WarlordsPlayer wp, Set<WarlordsPlayer> playersHit, Entity checkFrom, boolean hasHitTotem) {
    int playersSize = playersHit.size();
    if (playersSize >= (hasHitTotem ? LIGHTING_MAX_PLAYERS_WITH_TOTEM : LIGHTING_MAX_PLAYERS_NO_TOTEM)) {
        return playersSize + (hasHitTotem ? 1 : 0);
    }
    /**
     * The first check has double the radius for checking, and only targets a totem when the player is looking at it.
     */
    boolean firstCheck = checkFrom == wp.getEntity();
    if (!hasHitTotem) {
        if (firstCheck) {
            if (checkFrom instanceof LivingEntity && lookingAtTotem((LivingEntity) checkFrom)) {
                ArmorStand totem = getTotem(wp);
                assert totem != null;
                chain(checkFrom.getLocation(), totem.getLocation());
                partOfChainLightningPulseDamage(wp, totem);
                return partOfChainLightning(wp, playersHit, totem, true);
            }
        // no else
        } else {
            ArmorStand totem = Utils.getTotemDownAndClose(wp, checkFrom);
            if (totem != null) {
                chain(checkFrom.getLocation(), totem.getLocation());
                partOfChainLightningPulseDamage(wp, totem);
                return partOfChainLightning(wp, playersHit, totem, true);
            }
        // no else
        }
    }
    // no else
    PlayerFilter filter = firstCheck ? PlayerFilter.entitiesAround(checkFrom, radius, 18, radius).filter(e -> Utils.isLookingAtChain(wp.getEntity(), e.getEntity()) && Utils.hasLineOfSight(wp.getEntity(), e.getEntity())) : PlayerFilter.entitiesAround(checkFrom, bounceRange, bounceRange, bounceRange).lookingAtFirst(wp);
    Optional<WarlordsPlayer> foundPlayer = filter.closestFirst(wp).aliveEnemiesOf(wp).excluding(playersHit).findFirst();
    if (foundPlayer.isPresent()) {
        WarlordsPlayer hit = foundPlayer.get();
        chain(checkFrom.getLocation(), hit.getLocation());
        float damageMultiplier;
        switch(playersSize) {
            case 0:
                // We hit the first player
                damageMultiplier = 1f;
                break;
            case 1:
                // We hit the second player
                damageMultiplier = .85f;
                break;
            default:
                damageMultiplier = .7f;
                break;
        }
        playersHit.add(hit);
        hit.addDamageInstance(wp, name, minDamageHeal * damageMultiplier, maxDamageHeal * damageMultiplier, critChance, critMultiplier, false);
        return partOfChainLightning(wp, playersHit, hit.getEntity(), hasHitTotem);
    } else {
        return playersSize + (hasHitTotem ? 1 : 0);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Utils(com.ebicep.warlords.util.warlords.Utils) Entity(org.bukkit.entity.Entity) Set(java.util.Set) CooldownTypes(com.ebicep.warlords.player.cooldowns.CooldownTypes) Player(org.bukkit.entity.Player) LivingEntity(org.bukkit.entity.LivingEntity) AbstractChainBase(com.ebicep.warlords.abilties.internal.AbstractChainBase) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) HashSet(java.util.HashSet) Stream(java.util.stream.Stream) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) Location(org.bukkit.Location) LocationBuilder(com.ebicep.warlords.util.bukkit.LocationBuilder) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) ArmorStand(org.bukkit.entity.ArmorStand) Optional(java.util.Optional) WarlordsDamageHealingEvent(com.ebicep.warlords.events.WarlordsDamageHealingEvent) Nonnull(javax.annotation.Nonnull) Material(org.bukkit.Material) Nullable(javax.annotation.Nullable) FallingBlockWaveEffect(com.ebicep.warlords.effects.FallingBlockWaveEffect) ArmorStand(org.bukkit.entity.ArmorStand) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter)

Aggregations

AbstractChainBase (com.ebicep.warlords.abilties.internal.AbstractChainBase)1 FallingBlockWaveEffect (com.ebicep.warlords.effects.FallingBlockWaveEffect)1 WarlordsDamageHealingEvent (com.ebicep.warlords.events.WarlordsDamageHealingEvent)1 WarlordsPlayer (com.ebicep.warlords.player.WarlordsPlayer)1 CooldownTypes (com.ebicep.warlords.player.cooldowns.CooldownTypes)1 RegularCooldown (com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown)1 LocationBuilder (com.ebicep.warlords.util.bukkit.LocationBuilder)1 PlayerFilter (com.ebicep.warlords.util.warlords.PlayerFilter)1 Utils (com.ebicep.warlords.util.warlords.Utils)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Stream (java.util.stream.Stream)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 Location (org.bukkit.Location)1 Material (org.bukkit.Material)1 ArmorStand (org.bukkit.entity.ArmorStand)1 Entity (org.bukkit.entity.Entity)1 LivingEntity (org.bukkit.entity.LivingEntity)1