2014-06-27 18:51:42 +00:00
|
|
|
package com.projectkorra.ProjectKorra.firebending;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
2014-08-30 22:34:27 +00:00
|
|
|
import com.projectkorra.ProjectKorra.BendingPlayer;
|
2014-06-27 18:51:42 +00:00
|
|
|
import com.projectkorra.ProjectKorra.Methods;
|
|
|
|
import com.projectkorra.ProjectKorra.ProjectKorra;
|
|
|
|
import com.projectkorra.ProjectKorra.Ability.AvatarState;
|
2015-01-04 18:48:39 +00:00
|
|
|
import com.projectkorra.ProjectKorra.Utilities.ParticleEffect;
|
2014-06-27 18:51:42 +00:00
|
|
|
|
|
|
|
public class WallOfFire {
|
|
|
|
|
|
|
|
private Player player;
|
|
|
|
|
|
|
|
private static double maxangle = 50;
|
|
|
|
|
|
|
|
public static FileConfiguration config = ProjectKorra.plugin.getConfig();
|
2015-01-02 08:31:15 +00:00
|
|
|
private static int RANGE = config.getInt("Abilities.Fire.WallOfFire.Range");
|
|
|
|
private int HEIGHT = config.getInt("Abilities.Fire.WallOfFire.Height");
|
|
|
|
private int WIDTH = config.getInt("Abilities.Fire.WallOfFire.Width");
|
|
|
|
private long DURATION = config.getLong("Abilities.Fire.WallOfFire.Duration");
|
|
|
|
private int DAMAGE = config.getInt("Abilities.Fire.WallOfFire.Damage");
|
2014-06-27 18:51:42 +00:00
|
|
|
private static long interval = 250;
|
2015-01-02 08:31:15 +00:00
|
|
|
private static long COOLDOWN = config.getLong("Abilities.Fire.WallOfFire.Cooldown");
|
2014-06-27 18:51:42 +00:00
|
|
|
public static ConcurrentHashMap<Player, WallOfFire> instances = new ConcurrentHashMap<Player, WallOfFire>();
|
2015-01-02 08:31:15 +00:00
|
|
|
private static long DAMAGE_INTERVAL = config.getLong("Abilities.Fire.WallOfFire.Interval");
|
2014-06-27 18:51:42 +00:00
|
|
|
|
|
|
|
private Location origin;
|
|
|
|
private long time, starttime;
|
|
|
|
private boolean active = true;
|
|
|
|
private int damagetick = 0, intervaltick = 0;
|
2015-01-02 08:31:15 +00:00
|
|
|
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;
|
2014-06-27 18:51:42 +00:00
|
|
|
private List<Block> blocks = new ArrayList<Block>();
|
|
|
|
|
|
|
|
public WallOfFire(Player player) {
|
|
|
|
if (instances.containsKey(player) && !AvatarState.isAvatarState(player)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-30 22:34:27 +00:00
|
|
|
|
|
|
|
BendingPlayer bPlayer = Methods.getBendingPlayer(player.getName());
|
|
|
|
|
|
|
|
if (bPlayer.isOnCooldown("WallOfFire")) return;
|
2014-06-27 18:51:42 +00:00
|
|
|
|
|
|
|
this.player = player;
|
|
|
|
|
|
|
|
origin = Methods.getTargetedLocation(player, range);
|
|
|
|
|
|
|
|
World world = player.getWorld();
|
|
|
|
|
|
|
|
if (Methods.isDay(player.getWorld())) {
|
2014-07-29 11:34:46 +00:00
|
|
|
width = (int) Methods.getFirebendingDayAugment((double) width, world);
|
|
|
|
height = (int) Methods.getFirebendingDayAugment((double) height, world);
|
|
|
|
duration = (long) Methods.getFirebendingDayAugment((double) duration,
|
2014-06-27 18:51:42 +00:00
|
|
|
world);
|
2014-07-29 11:34:46 +00:00
|
|
|
damage = (int) Methods.getFirebendingDayAugment((double) damage, world);
|
2014-06-27 18:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
time = System.currentTimeMillis();
|
|
|
|
starttime = time;
|
|
|
|
|
|
|
|
Block block = origin.getBlock();
|
|
|
|
|
|
|
|
if (block.isLiquid() || Methods.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();
|
|
|
|
|
|
|
|
instances.put(player, this);
|
2014-08-30 22:34:27 +00:00
|
|
|
bPlayer.addCooldown("WallOfFire", cooldown);
|
2014-06-27 18:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void progress() {
|
|
|
|
time = System.currentTimeMillis();
|
|
|
|
|
|
|
|
if (time - starttime > cooldown) {
|
|
|
|
instances.remove(player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (time - starttime > duration) {
|
|
|
|
active = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time - starttime > intervaltick * interval) {
|
|
|
|
intervaltick++;
|
|
|
|
display();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time - starttime > damagetick * damageinterval) {
|
|
|
|
damagetick++;
|
|
|
|
damage();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeBlocks() {
|
|
|
|
Vector direction = player.getEyeLocation().getDirection();
|
|
|
|
direction = direction.normalize();
|
|
|
|
|
|
|
|
Vector ortholr = Methods.getOrthogonalVector(direction, 0, 1);
|
|
|
|
ortholr = ortholr.normalize();
|
|
|
|
|
|
|
|
Vector orthoud = Methods.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));
|
2014-06-28 21:06:05 +00:00
|
|
|
if (Methods.isRegionProtectedFromBuild(player,
|
|
|
|
"WallOfFire", location))
|
|
|
|
continue;
|
2014-06-27 18:51:42 +00:00
|
|
|
Block block = location.getBlock();
|
|
|
|
if (!blocks.contains(block))
|
|
|
|
blocks.add(block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void display() {
|
|
|
|
for (Block block : blocks) {
|
2015-01-04 18:48:39 +00:00
|
|
|
ParticleEffect.FLAME.display(block.getLocation(), 0.6F, 0.6F, 0.6F, 0, 6);
|
|
|
|
ParticleEffect.SMOKE.display(block.getLocation(), 0.6F, 0.6F, 0.6F, 0, 6);
|
2014-09-28 06:26:18 +00:00
|
|
|
|
2014-09-28 14:44:06 +00:00
|
|
|
if (Methods.rand.nextInt(7) == 0) {
|
2014-09-28 06:26:18 +00:00
|
|
|
Methods.playFirebendingSound(block.getLocation());
|
|
|
|
}
|
2014-06-27 18:51:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void damage() {
|
|
|
|
double radius = height;
|
|
|
|
if (radius < width)
|
|
|
|
radius = width;
|
|
|
|
radius = radius + 1;
|
|
|
|
List<Entity> entities = Methods.getEntitiesAroundPoint(origin, radius);
|
|
|
|
if (entities.contains(player))
|
|
|
|
entities.remove(player);
|
|
|
|
for (Entity entity : entities) {
|
2014-06-28 21:06:05 +00:00
|
|
|
if (Methods.isRegionProtectedFromBuild(player, "WallOfFire",
|
|
|
|
entity.getLocation()))
|
|
|
|
continue;
|
2014-06-27 18:51:42 +00:00
|
|
|
for (Block block : blocks) {
|
|
|
|
if (entity.getLocation().distance(block.getLocation()) <= 1.5) {
|
|
|
|
affect(entity);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void affect(Entity entity) {
|
|
|
|
entity.setFireTicks(50);
|
2014-09-23 10:33:53 +00:00
|
|
|
Methods.setVelocity(entity, new Vector(0, 0, 0));
|
2014-06-27 18:51:42 +00:00
|
|
|
if (entity instanceof LivingEntity) {
|
2014-07-13 20:41:07 +00:00
|
|
|
Methods.damageEntity(player, entity, damage);
|
2014-06-27 18:51:42 +00:00
|
|
|
new Enflamed(entity, player);
|
2014-08-24 11:13:09 +00:00
|
|
|
Methods.breakBreathbendingHold(entity);
|
2014-06-27 18:51:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void manage() {
|
|
|
|
for (Player player : instances.keySet()) {
|
|
|
|
instances.get(player).progress();
|
|
|
|
}
|
|
|
|
}
|
2015-01-02 08:31:15 +00:00
|
|
|
|
|
|
|
public Player getPlayer() {
|
|
|
|
return player;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getRange() {
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setRange(int range) {
|
|
|
|
this.range = range;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getHeight() {
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setHeight(int height) {
|
|
|
|
this.height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getWidth() {
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setWidth(int width) {
|
|
|
|
this.width = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getDuration() {
|
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDuration(long duration) {
|
|
|
|
this.duration = duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getDamage() {
|
|
|
|
return damage;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDamage(int damage) {
|
|
|
|
this.damage = damage;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getCooldown() {
|
|
|
|
return cooldown;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCooldown(long cooldown) {
|
|
|
|
this.cooldown = cooldown;
|
|
|
|
if(player != null)
|
|
|
|
Methods.getBendingPlayer(player.getName()).addCooldown("WallOfFire", cooldown);
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getDamageinterval() {
|
|
|
|
return damageinterval;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDamageinterval(long damageinterval) {
|
|
|
|
this.damageinterval = damageinterval;
|
|
|
|
}
|
2014-06-27 18:51:42 +00:00
|
|
|
}
|