2015-08-02 06:58:35 +00:00
|
|
|
package com.projectkorra.projectkorra.firebending;
|
|
|
|
|
2015-11-11 09:26:39 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2015-08-02 06:58:35 +00:00
|
|
|
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.World;
|
|
|
|
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;
|
|
|
|
|
2015-11-11 09:26:39 +00:00
|
|
|
import com.projectkorra.projectkorra.BendingPlayer;
|
|
|
|
import com.projectkorra.projectkorra.GeneralMethods;
|
|
|
|
import com.projectkorra.projectkorra.ability.AvatarState;
|
|
|
|
import com.projectkorra.projectkorra.airbending.AirMethods;
|
|
|
|
import com.projectkorra.projectkorra.configuration.ConfigLoadable;
|
|
|
|
import com.projectkorra.projectkorra.util.ParticleEffect;
|
2015-08-02 06:58:35 +00:00
|
|
|
|
2015-11-11 09:26:39 +00:00
|
|
|
public class WallOfFire implements ConfigLoadable {
|
|
|
|
public static final ConcurrentHashMap<Player, WallOfFire> instances = new ConcurrentHashMap<>();
|
|
|
|
|
2015-08-02 06:58:35 +00:00
|
|
|
private static double maxangle = 50;
|
|
|
|
|
|
|
|
private static int RANGE = config.get().getInt("Abilities.Fire.WallOfFire.Range");
|
|
|
|
|
|
|
|
private static int HEIGHT = config.get().getInt("Abilities.Fire.WallOfFire.Height");
|
|
|
|
private static int WIDTH = config.get().getInt("Abilities.Fire.WallOfFire.Width");
|
|
|
|
private static long DURATION = config.get().getLong("Abilities.Fire.WallOfFire.Duration");
|
|
|
|
private static int DAMAGE = config.get().getInt("Abilities.Fire.WallOfFire.Damage");
|
|
|
|
private static long interval = 250;
|
|
|
|
private static long COOLDOWN = config.get().getLong("Abilities.Fire.WallOfFire.Cooldown");
|
|
|
|
private static long DAMAGE_INTERVAL = config.get().getLong("Abilities.Fire.WallOfFire.Interval");
|
|
|
|
private static double FIRETICKS = config.get().getDouble("Abilities.Fire.WallOfFire.FireTicks");
|
|
|
|
private Player player;
|
|
|
|
|
|
|
|
private Location origin;
|
|
|
|
private long time, starttime;
|
|
|
|
private boolean active = true;
|
|
|
|
private int damagetick = 0, intervaltick = 0;
|
|
|
|
private int range = RANGE;
|
|
|
|
private int height = HEIGHT;
|
|
|
|
private int width = WIDTH;
|
|
|
|
private long duration = DURATION;
|
|
|
|
private int damage = DAMAGE;
|
|
|
|
private long cooldown = COOLDOWN;
|
|
|
|
private long damageinterval = DAMAGE_INTERVAL;
|
|
|
|
private List<Block> blocks = new ArrayList<Block>();
|
|
|
|
|
|
|
|
public WallOfFire(Player player) {
|
|
|
|
/* Initial Checks */
|
2015-11-11 09:26:39 +00:00
|
|
|
if (instances.containsKey(player) && !AvatarState.isAvatarState(player)) {
|
2015-08-02 06:58:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName());
|
|
|
|
if (bPlayer.isOnCooldown("WallOfFire"))
|
|
|
|
return;
|
|
|
|
/* End Initial Checks */
|
|
|
|
|
|
|
|
this.player = player;
|
|
|
|
|
|
|
|
origin = GeneralMethods.getTargetedLocation(player, range);
|
|
|
|
|
|
|
|
World world = player.getWorld();
|
|
|
|
|
|
|
|
if (FireMethods.isDay(player.getWorld())) {
|
|
|
|
width = (int) FireMethods.getFirebendingDayAugment((double) width, world);
|
|
|
|
height = (int) FireMethods.getFirebendingDayAugment((double) height, world);
|
|
|
|
duration = (long) FireMethods.getFirebendingDayAugment((double) duration, world);
|
|
|
|
damage = (int) FireMethods.getFirebendingDayAugment((double) damage, world);
|
|
|
|
}
|
|
|
|
|
|
|
|
time = System.currentTimeMillis();
|
|
|
|
starttime = time;
|
|
|
|
|
|
|
|
Block block = origin.getBlock();
|
|
|
|
|
|
|
|
if (block.isLiquid() || GeneralMethods.isSolid(block)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector direction = player.getEyeLocation().getDirection();
|
|
|
|
Vector compare = direction.clone();
|
|
|
|
compare.setY(0);
|
|
|
|
|
|
|
|
if (Math.abs(direction.angle(compare)) > Math.toRadians(maxangle)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
initializeBlocks();
|
|
|
|
|
2015-11-11 09:26:39 +00:00
|
|
|
instances.put(player, this);
|
2015-08-02 06:58:35 +00:00
|
|
|
bPlayer.addCooldown("WallOfFire", cooldown);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void affect(Entity entity) {
|
|
|
|
entity.setFireTicks((int) (FIRETICKS * 20));
|
|
|
|
GeneralMethods.setVelocity(entity, new Vector(0, 0, 0));
|
|
|
|
if (entity instanceof LivingEntity) {
|
2015-09-26 00:04:11 +00:00
|
|
|
GeneralMethods.damageEntity(player, entity, damage, "WallOfFire");
|
2015-08-02 06:58:35 +00:00
|
|
|
new Enflamed(entity, player);
|
|
|
|
AirMethods.breakBreathbendingHold(entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void damage() {
|
|
|
|
double radius = height;
|
|
|
|
if (radius < width)
|
|
|
|
radius = width;
|
|
|
|
radius = radius + 1;
|
|
|
|
List<Entity> entities = GeneralMethods.getEntitiesAroundPoint(origin, radius);
|
|
|
|
if (entities.contains(player))
|
|
|
|
entities.remove(player);
|
|
|
|
for (Entity entity : entities) {
|
|
|
|
if (GeneralMethods.isRegionProtectedFromBuild(player, "WallOfFire", entity.getLocation()))
|
|
|
|
continue;
|
|
|
|
for (Block block : blocks) {
|
|
|
|
if (entity.getLocation().distance(block.getLocation()) <= 1.5) {
|
|
|
|
affect(entity);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void display() {
|
|
|
|
for (Block block : blocks) {
|
2015-08-02 22:17:41 +00:00
|
|
|
ParticleEffect.FLAME.display(block.getLocation(), 0.6F, 0.6F, 0.6F, 0, 3);
|
|
|
|
ParticleEffect.SMOKE.display(block.getLocation(), 0.6F, 0.6F, 0.6F, 0, 1);
|
2015-08-02 06:58:35 +00:00
|
|
|
|
|
|
|
if (GeneralMethods.rand.nextInt(7) == 0) {
|
|
|
|
FireMethods.playFirebendingSound(block.getLocation());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getCooldown() {
|
|
|
|
return cooldown;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getDamage() {
|
|
|
|
return damage;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getDamageinterval() {
|
|
|
|
return damageinterval;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getDuration() {
|
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getHeight() {
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Player getPlayer() {
|
|
|
|
return player;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getRange() {
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getWidth() {
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeBlocks() {
|
|
|
|
Vector direction = 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();
|
|
|
|
|
|
|
|
double w = (double) width;
|
|
|
|
double h = (double) height;
|
|
|
|
|
|
|
|
for (double i = -w; i <= w; i++) {
|
|
|
|
for (double j = -h; j <= h; j++) {
|
|
|
|
Location location = origin.clone().add(orthoud.clone().multiply(j));
|
|
|
|
location = location.add(ortholr.clone().multiply(i));
|
|
|
|
if (GeneralMethods.isRegionProtectedFromBuild(player, "WallOfFire", location))
|
|
|
|
continue;
|
|
|
|
Block block = location.getBlock();
|
|
|
|
if (!blocks.contains(block))
|
|
|
|
blocks.add(block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean progress() {
|
|
|
|
time = System.currentTimeMillis();
|
|
|
|
|
|
|
|
if (time - starttime > cooldown) {
|
|
|
|
remove();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!active)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (time - starttime > duration) {
|
|
|
|
active = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time - starttime > intervaltick * interval) {
|
|
|
|
intervaltick++;
|
|
|
|
display();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time - starttime > damagetick * damageinterval) {
|
|
|
|
damagetick++;
|
|
|
|
damage();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-11-11 09:26:39 +00:00
|
|
|
|
2015-11-11 20:19:45 +00:00
|
|
|
public static void progressAll() {
|
|
|
|
for (WallOfFire ability : instances.values()) {
|
|
|
|
ability.progress();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-11 09:26:39 +00:00
|
|
|
public void remove() {
|
|
|
|
instances.remove(player);
|
|
|
|
}
|
2015-11-11 20:19:45 +00:00
|
|
|
|
|
|
|
public static void removeAll() {
|
|
|
|
for (WallOfFire ability : instances.values()) {
|
|
|
|
ability.remove();
|
|
|
|
}
|
|
|
|
}
|
2015-08-02 06:58:35 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void reloadVariables() {
|
|
|
|
RANGE = config.get().getInt("Abilities.Fire.WallOfFire.Range");
|
|
|
|
HEIGHT = config.get().getInt("Abilities.Fire.WallOfFire.Height");
|
|
|
|
WIDTH = config.get().getInt("Abilities.Fire.WallOfFire.Width");
|
|
|
|
DURATION = config.get().getLong("Abilities.Fire.WallOfFire.Duration");
|
|
|
|
DAMAGE = config.get().getInt("Abilities.Fire.WallOfFire.Damage");
|
|
|
|
COOLDOWN = config.get().getLong("Abilities.Fire.WallOfFire.Cooldown");
|
|
|
|
DAMAGE_INTERVAL = config.get().getLong("Abilities.Fire.WallOfFire.Interval");
|
|
|
|
FIRETICKS = config.get().getDouble("Abilities.Fire.WallOfFire.FireTicks");
|
|
|
|
range = RANGE;
|
|
|
|
height = HEIGHT;
|
|
|
|
width = WIDTH;
|
|
|
|
duration = DURATION;
|
|
|
|
damage = DAMAGE;
|
|
|
|
cooldown = COOLDOWN;
|
|
|
|
damageinterval = DAMAGE_INTERVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCooldown(long cooldown) {
|
|
|
|
this.cooldown = cooldown;
|
|
|
|
if (player != null)
|
|
|
|
GeneralMethods.getBendingPlayer(player.getName()).addCooldown("WallOfFire", cooldown);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDamage(int damage) {
|
|
|
|
this.damage = damage;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDamageinterval(long damageinterval) {
|
|
|
|
this.damageinterval = damageinterval;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDuration(long duration) {
|
|
|
|
this.duration = duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setHeight(int height) {
|
|
|
|
this.height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setRange(int range) {
|
|
|
|
this.range = range;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setWidth(int width) {
|
|
|
|
this.width = width;
|
|
|
|
}
|
|
|
|
}
|