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);
}
}
Aggregations