TF-ProjectKorra/src/com/projectkorra/projectkorra/firebending/WallOfFire.java
Christopher Martin 787b303c9f
1.9.1 (#1145)
## Additions
* Adds a built-in bending board sidebar to visualize bound abilities and cooldowns.
  * The board respects worlds where bending is disabled.
  * Players can use the command `/pk board` to toggle the visibility of their board.
  * Includes an API that community developers can use in BendingBoardManager.
  * Adds the `"Properties.BendingBoard"` config option to enable or disable the board server.
  * Adds language file configuration options to control BendingBoard visuals.
    * `"Board.Title"`
      * Controls the title at the top of the board.
      * Supports the standard Minecraft color codes.
    * `"Board.SelectionPrefix"`
      * Controls the prefix shown corresponding to your current hot bar slot.
      * Supports the standard Minecraft color codes.
    * `"Board.EmptySlot"`
      * Controls what is shown for empty slots.
      * Supports the standard Minecraft color codes.
      * `{slot_number}` can be used as a placeholder for the slot number.
    * `"Board.MiscSeparator"`
      * Controls the separation between hot bar binds and temporary cooldowns such as Combos.
      * Supports the standard Minecraft color codes.
* Adds support for KingdomsX version 1.10.19.1
* Adds ability permission check to passive abilities. They should now respect their `bending.ability.<ability name>` permissions.
* Adds `AbilityVelocityAffectEntityEvent`
  * A cancellable event that will fire whenever an ability would alter the velocity of an entity.
* Adds the `Abilities.Earth.EarthSmash.Shoot.CollisionRadius` configuration option
  * Sets the collision radius of shot EarthSmash.

## Fixes
* Fixes FireBlast going through liquids.
* Fixes duplication involving waterlogged containers.
* Fixes being able to not enter the name of a Preset when using the `/pk preset create <name>` command.
* Fixes getDayFactor() not being applied correctly and occasionally producing the wrong value.
* Fixes a rounding issue with some Fire ability damage configuration options.
* Fixes an error when attempting to start EarthGrab.
* Fixes PhaseChange error when melting snow.
* Fixes a memory/process leak in how cooldowns were removed.
  * A player's cooldowns could only be removed when they were online. If a player's cooldown expired while they weren't online, their cooldown would attempt to revert every tick until the player rejoined. This has been resolved so cooldowns can revert while a player is offline.
  * A side effect of this fix is that it is now possible for `PlayerCooldownChangeEvents` to fire while their corresponding Player is offline.
* Fixes an issue with `MultiAbilityManager#hasMultiAbilityBound` where it would return true if any MultiAbility is bound, not if the specified MultiAbility was bound.

## Misc Changes
* Updates Towny version to 0.96.2.0
* DensityShift sand blocks can now be used as a bendable source.
* Changes AvatarState so that its cooldown is applied when the ability ends instead of when it starts.
* Changes togglable abilities such as AvatarState, Illumination, and TremorSense to visually show when they are enabled in the BendingBoard and on BendingPreview in the same way as the ChiBlocking Stances.
* Updated the text of some ability descriptions and instructions.
* Adds new cache to PhaseChange to greatly improve the performance of water/ice updates.
2021-06-07 16:58:29 -07:00

387 lines
10 KiB
Java

package com.projectkorra.projectkorra.firebending;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import com.projectkorra.projectkorra.Element.SubElement;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.AirAbility;
import com.projectkorra.projectkorra.ability.BlueFireAbility;
import com.projectkorra.projectkorra.ability.FireAbility;
import com.projectkorra.projectkorra.attribute.Attribute;
import com.projectkorra.projectkorra.firebending.util.FireDamageTimer;
import com.projectkorra.projectkorra.util.DamageHandler;
import com.projectkorra.projectkorra.util.TempBlock;
public class WallOfFire extends FireAbility {
private boolean active;
private int damageTick;
private int intervalTick;
@Attribute(Attribute.RANGE)
private int range;
@Attribute(Attribute.HEIGHT)
private int height;
@Attribute(Attribute.WIDTH)
private int width;
@Attribute(Attribute.DAMAGE)
private double damage;
@Attribute(Attribute.COOLDOWN)
private long cooldown;
private long damageInterval;
@Attribute(Attribute.DURATION)
private long duration;
private long time;
private long interval;
@Attribute(Attribute.FIRE_TICK)
private double fireTicks;
private double maxAngle;
private Random random;
private Location origin;
private List<Block> blocks;
public WallOfFire(final Player player) {
super(player);
this.active = true;
this.maxAngle = getConfig().getDouble("Abilities.Fire.WallOfFire.MaxAngle");
this.interval = getConfig().getLong("Abilities.Fire.WallOfFire.Interval");
this.range = getConfig().getInt("Abilities.Fire.WallOfFire.Range");
this.height = getConfig().getInt("Abilities.Fire.WallOfFire.Height");
this.width = getConfig().getInt("Abilities.Fire.WallOfFire.Width");
this.damage = getConfig().getDouble("Abilities.Fire.WallOfFire.Damage");
this.cooldown = getConfig().getLong("Abilities.Fire.WallOfFire.Cooldown");
this.damageInterval = getConfig().getLong("Abilities.Fire.WallOfFire.DamageInterval");
this.duration = getConfig().getLong("Abilities.Fire.WallOfFire.Duration");
this.fireTicks = getConfig().getDouble("Abilities.Fire.WallOfFire.FireTicks");
this.random = new Random();
this.blocks = new ArrayList<>();
if (hasAbility(player, WallOfFire.class) && !this.bPlayer.isAvatarState()) {
return;
} else if (this.bPlayer.isOnCooldown(this)) {
return;
}
this.origin = GeneralMethods.getTargetedLocation(player, this.range);
double widthMod = 0;
double heightMod = 0;
long durationMod = 0;
double damageMod = 0;
if (isDay(player.getWorld())) {
widthMod = this.getDayFactor(this.width) - this.width;
heightMod = this.getDayFactor(this.height) - this.height;
durationMod = ((long) this.getDayFactor(this.duration) - this.duration);
damageMod = this.getDayFactor(this.damage) - this.damage;
}
widthMod = (int) (bPlayer.canUseSubElement(SubElement.BLUE_FIRE) ? (BlueFireAbility.getRangeFactor() * width - width) + widthMod : widthMod);
heightMod = (int) (bPlayer.canUseSubElement(SubElement.BLUE_FIRE) ? (BlueFireAbility.getRangeFactor() * height - height) + heightMod : heightMod);
durationMod = (int) (bPlayer.canUseSubElement(SubElement.BLUE_FIRE) ? (duration / BlueFireAbility.getCooldownFactor() - duration) + durationMod : durationMod);
damageMod = (int) (bPlayer.canUseSubElement(SubElement.BLUE_FIRE) ? (BlueFireAbility.getDamageFactor() * damage - damage) + damageMod : damageMod);
if (this.bPlayer.isAvatarState()) {
this.width = getConfig().getInt("Abilities.Avatar.AvatarState.Fire.WallOfFire.Width");
this.height = getConfig().getInt("Abilities.Avatar.AvatarState.Fire.WallOfFire.Height");
this.duration = getConfig().getLong("Abilities.Avatar.AvatarState.Fire.WallOfFire.Duration");
this.damage = getConfig().getInt("Abilities.Avatar.AvatarState.Fire.WallOfFire.Damage");
this.fireTicks = getConfig().getDouble("Abilities.Avatar.AvatarState.Fire.WallOfFire.FireTicks");
}
this.width += widthMod;
this.height += heightMod;
this.duration += durationMod;
this.damage += damageMod;
this.time = System.currentTimeMillis();
final Block block = this.origin.getBlock();
if (block.isLiquid() || GeneralMethods.isSolid(block)) {
return;
}
final Vector direction = player.getEyeLocation().getDirection();
final Vector compare = direction.clone();
compare.setY(0);
if (Math.abs(direction.angle(compare)) > Math.toRadians(this.maxAngle)) {
return;
}
this.initializeBlocks();
this.start();
}
private void affect(final Entity entity) {
GeneralMethods.setVelocity(this, entity, new Vector(0, 0, 0));
if (entity instanceof LivingEntity) {
final Block block = ((LivingEntity) entity).getEyeLocation().getBlock();
if (TempBlock.isTempBlock(block) && isIce(block)) {
return;
}
DamageHandler.damageEntity(entity, this.damage, this);
AirAbility.breakBreathbendingHold(entity);
}
entity.setFireTicks((int) (this.fireTicks * 20));
new FireDamageTimer(entity, this.player);
}
private void damage() {
double radius = this.height;
if (radius < this.width) {
radius = this.width;
}
radius = radius + 1;
final List<Entity> entities = GeneralMethods.getEntitiesAroundPoint(this.origin, radius);
if (entities.contains(this.player)) {
entities.remove(this.player);
}
for (final Entity entity : entities) {
if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation())) {
continue;
}
for (final Block block : this.blocks) {
if (entity.getLocation().distanceSquared(block.getLocation()) <= 1.5 * 1.5) {
this.affect(entity);
break;
}
}
}
}
private void display() {
for (final Block block : this.blocks) {
if (!this.isTransparent(block)) {
continue;
}
playFirebendingParticles(block.getLocation(), 3, 0.6, 0.6, 0.6);
if (this.random.nextInt(7) == 0) {
playFirebendingSound(block.getLocation());
}
}
}
private void initializeBlocks() {
Vector direction = this.player.getEyeLocation().getDirection();
direction = direction.normalize();
Vector ortholr = GeneralMethods.getOrthogonalVector(direction, 0, 1);
ortholr = ortholr.normalize();
Vector orthoud = GeneralMethods.getOrthogonalVector(direction, 90, 1);
orthoud = orthoud.normalize();
final double w = this.width;
final double h = this.height;
for (double i = -w; i <= w; i++) {
for (double j = -h; j <= h; j++) {
Location location = this.origin.clone().add(orthoud.clone().multiply(j));
location = location.add(ortholr.clone().multiply(i));
if (GeneralMethods.isRegionProtectedFromBuild(this, location)) {
continue;
}
final Block block = location.getBlock();
if (!this.blocks.contains(block)) {
this.blocks.add(block);
}
}
}
}
@Override
public void progress() {
this.time = System.currentTimeMillis();
if (this.time - this.getStartTime() > this.cooldown) {
this.remove();
return;
} else if (!this.active) {
return;
} else if (this.time - this.getStartTime() > this.duration) {
this.active = false;
return;
}
if (this.time - this.getStartTime() > this.intervalTick * this.interval) {
this.intervalTick++;
this.display();
}
if (this.time - this.getStartTime() > this.damageTick * this.damageInterval) {
this.damageTick++;
this.damage();
}
}
@Override
public void remove() {
super.remove();
this.bPlayer.addCooldown(this);
}
@Override
public String getName() {
return "WallOfFire";
}
@Override
public Location getLocation() {
return this.origin;
}
@Override
public long getCooldown() {
return this.cooldown;
}
@Override
public boolean isSneakAbility() {
return false;
}
@Override
public boolean isHarmlessAbility() {
return false;
}
@Override
public List<Location> getLocations() {
final ArrayList<Location> locations = new ArrayList<>();
for (final Block block : this.blocks) {
locations.add(block.getLocation());
}
return locations;
}
public boolean isActive() {
return this.active;
}
public void setActive(final boolean active) {
this.active = active;
}
public int getDamageTick() {
return this.damageTick;
}
public void setDamageTick(final int damageTick) {
this.damageTick = damageTick;
}
public int getIntervalTick() {
return this.intervalTick;
}
public void setIntervalTick(final int intervalTick) {
this.intervalTick = intervalTick;
}
public int getRange() {
return this.range;
}
public void setRange(final int range) {
this.range = range;
}
public int getHeight() {
return this.height;
}
public void setHeight(final int height) {
this.height = height;
}
public int getWidth() {
return this.width;
}
public void setWidth(final int width) {
this.width = width;
}
public double getDamage() {
return this.damage;
}
public void setDamage(final int damage) {
this.damage = damage;
}
public long getDamageInterval() {
return this.damageInterval;
}
public void setDamageInterval(final long damageInterval) {
this.damageInterval = damageInterval;
}
public long getDuration() {
return this.duration;
}
public void setDuration(final long duration) {
this.duration = duration;
}
public long getTime() {
return this.time;
}
public void setTime(final long time) {
this.time = time;
}
public long getInterval() {
return this.interval;
}
public void setInterval(final long interval) {
this.interval = interval;
}
public double getFireTicks() {
return this.fireTicks;
}
public void setFireTicks(final double fireTicks) {
this.fireTicks = fireTicks;
}
public double getMaxAngle() {
return this.maxAngle;
}
public void setMaxAngle(final double maxAngle) {
this.maxAngle = maxAngle;
}
public Location getOrigin() {
return this.origin;
}
public void setOrigin(final Location origin) {
this.origin = origin;
}
public List<Block> getBlocks() {
return this.blocks;
}
public void setCooldown(final long cooldown) {
this.cooldown = cooldown;
}
}