Decoreability Fire and Air

This commit is contained in:
nathank33 2015-11-11 01:26:39 -08:00
parent 10414ffd90
commit 6760985369
6 changed files with 178 additions and 173 deletions

View file

@ -1,14 +1,8 @@
package com.projectkorra.projectkorra.airbending; package com.projectkorra.projectkorra.airbending;
import com.projectkorra.projectkorra.BendingPlayer; import java.util.ArrayList;
import com.projectkorra.projectkorra.GeneralMethods; import java.util.Arrays;
import com.projectkorra.projectkorra.ProjectKorra; import java.util.concurrent.ConcurrentHashMap;
import com.projectkorra.projectkorra.ability.AvatarState;
import com.projectkorra.projectkorra.ability.StockAbility;
import com.projectkorra.projectkorra.ability.api.CoreAbility;
import com.projectkorra.projectkorra.command.Commands;
import com.projectkorra.projectkorra.object.HorizontalVelocityTracker;
import com.projectkorra.projectkorra.util.Flight;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.Location; import org.bukkit.Location;
@ -25,12 +19,17 @@ import org.bukkit.material.Lever;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.ArrayList; import com.projectkorra.projectkorra.BendingPlayer;
import java.util.Arrays; import com.projectkorra.projectkorra.GeneralMethods;
import java.util.concurrent.ConcurrentHashMap; import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.ability.AvatarState;
public class AirBlast extends CoreAbility { import com.projectkorra.projectkorra.command.Commands;
import com.projectkorra.projectkorra.configuration.ConfigLoadable;
import com.projectkorra.projectkorra.object.HorizontalVelocityTracker;
import com.projectkorra.projectkorra.util.Flight;
public class AirBlast implements ConfigLoadable {
public static ConcurrentHashMap<Integer, AirBlast> instances = new ConcurrentHashMap<>();
private static ConcurrentHashMap<Player, Location> origins = new ConcurrentHashMap<Player, Location>(); private static ConcurrentHashMap<Player, Location> origins = new ConcurrentHashMap<Player, Location>();
public static double speed = config.get().getDouble("Abilities.Air.AirBlast.Speed"); public static double speed = config.get().getDouble("Abilities.Air.AirBlast.Speed");
@ -38,13 +37,14 @@ public class AirBlast extends CoreAbility {
public static double affectingradius = config.get().getDouble("Abilities.Air.AirBlast.Radius"); public static double affectingradius = config.get().getDouble("Abilities.Air.AirBlast.Radius");
public static double defaultpushfactor = config.get().getDouble("Abilities.Air.AirBlast.Push.Entities"); public static double defaultpushfactor = config.get().getDouble("Abilities.Air.AirBlast.Push.Entities");
public static double otherpushfactor = config.get().getDouble("Abilities.Air.AirBlast.Push.Self"); public static double otherpushfactor = config.get().getDouble("Abilities.Air.AirBlast.Push.Self");
public static boolean flickLevers = config.get().getBoolean("Abilities.Air.AirBlast.CanFlickLevers"); public static boolean flickLevers = config.get().getBoolean("Abilities.Air.AirBlast.CanFlickLevers");
public static boolean openDoors = config.get().getBoolean("Abilities.Air.AirBlast.CanOpenDoors"); public static boolean openDoors = config.get().getBoolean("Abilities.Air.AirBlast.CanOpenDoors");
public static boolean pressButtons = config.get().getBoolean("Abilities.Air.AirBlast.CanPressButtons"); public static boolean pressButtons = config.get().getBoolean("Abilities.Air.AirBlast.CanPressButtons");
public static boolean coolLava = config.get().getBoolean("Abilities.Air.AirBlast.CanCoolLava"); public static boolean coolLava = config.get().getBoolean("Abilities.Air.AirBlast.CanCoolLava");
private static double originselectrange = 10; private static double originselectrange = 10;
private static int idCounter = 0;
private static final int maxticks = 10000; private static final int maxticks = 10000;
/* Package visible variables */ /* Package visible variables */
static double maxspeed = 1. / defaultpushfactor; static double maxspeed = 1. / defaultpushfactor;
@ -65,6 +65,7 @@ public class AirBlast extends CoreAbility {
private boolean otherorigin = false; private boolean otherorigin = false;
private boolean showParticles = true; private boolean showParticles = true;
private int ticks = 0; private int ticks = 0;
private int id = 0;
private ArrayList<Block> affectedlevers = new ArrayList<Block>(); private ArrayList<Block> affectedlevers = new ArrayList<Block>();
private ArrayList<Entity> affectedentities = new ArrayList<Entity>(); private ArrayList<Entity> affectedentities = new ArrayList<Entity>();
@ -76,8 +77,6 @@ public class AirBlast extends CoreAbility {
if (location.getBlock().isLiquid()) { if (location.getBlock().isLiquid()) {
return; return;
} }
//reloadVariables();
source = burst; source = burst;
this.player = player; this.player = player;
@ -85,8 +84,9 @@ public class AirBlast extends CoreAbility {
this.direction = direction.clone(); this.direction = direction.clone();
this.location = location.clone(); this.location = location.clone();
pushfactor *= factorpush; pushfactor *= factorpush;
//instances.put(uuid, this); instances.put(idCounter, this);
putInstance(player, this); this.id = idCounter;
idCounter = (idCounter + 1) % Integer.MAX_VALUE;
} }
public AirBlast(Player player) { public AirBlast(Player player) {
@ -98,7 +98,7 @@ public class AirBlast extends CoreAbility {
return; return;
} }
/* End Initial Checks */ /* End Initial Checks */
//reloadVariables(); // reloadVariables();
this.player = player; this.player = player;
if (origins.containsKey(player)) { if (origins.containsKey(player)) {
otherorigin = true; otherorigin = true;
@ -115,8 +115,9 @@ public class AirBlast extends CoreAbility {
direction = player.getEyeLocation().getDirection().normalize(); direction = player.getEyeLocation().getDirection().normalize();
} }
location = origin.clone(); location = origin.clone();
putInstance(player, this); instances.put(idCounter, this);
//instances.put(uuid, this); this.id = idCounter;
idCounter = (idCounter + 1) % Integer.MAX_VALUE;
bPlayer.addCooldown("AirBlast", GeneralMethods.getGlobalCooldown()); bPlayer.addCooldown("AirBlast", GeneralMethods.getGlobalCooldown());
// time = System.currentTimeMillis(); // time = System.currentTimeMillis();
@ -137,7 +138,8 @@ public class AirBlast extends CoreAbility {
return; return;
} }
if (!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBlast") || !GeneralMethods.canBend(player.getName(), "AirBlast")) { if (!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBlast")
|| !GeneralMethods.canBend(player.getName(), "AirBlast")) {
origins.remove(player); origins.remove(player);
return; return;
} }
@ -148,12 +150,14 @@ public class AirBlast extends CoreAbility {
} }
AirMethods.playAirbendingParticles(origin, 4); AirMethods.playAirbendingParticles(origin, 4);
// origin.getWorld().playEffect(origin, Effect.SMOKE, 4, // origin.getWorld().playEffect(origin, Effect.SMOKE, 4,
// (int) originselectrange); // (int) originselectrange);
} }
public static void progressAll() { public static void progressAll() {
CoreAbility.progressAll(StockAbility.AirBlast); for (AirBlast blast : instances.values()) {
blast.progress();
}
for (Player player : origins.keySet()) { for (Player player : origins.keySet()) {
playOriginEffect(player); playOriginEffect(player);
} }
@ -263,14 +267,9 @@ public class AirBlast extends CoreAbility {
return this.showParticles; return this.showParticles;
} }
@Override
public StockAbility getStockAbility() {
return StockAbility.AirBlast;
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public boolean progress() { public boolean progress() {
//ProjectKorra.log.info("FireBlast id: " + getID()); // ProjectKorra.log.info("FireBlast id: " + getID());
if (player.isDead() || !player.isOnline()) { if (player.isDead() || !player.isOnline()) {
remove(); remove();
return false; return false;
@ -296,9 +295,11 @@ public class AirBlast extends CoreAbility {
testblock.getWorld().playEffect(testblock.getLocation(), Effect.EXTINGUISH, 0); testblock.getWorld().playEffect(testblock.getLocation(), Effect.EXTINGUISH, 0);
} }
if (GeneralMethods.isRegionProtectedFromBuild(getPlayer(), "AirBlast", block.getLocation())) continue; if (GeneralMethods.isRegionProtectedFromBuild(getPlayer(), "AirBlast", block.getLocation()))
continue;
Material doorTypes[] = { Material.WOODEN_DOOR, Material.SPRUCE_DOOR, Material.BIRCH_DOOR, Material.JUNGLE_DOOR, Material.ACACIA_DOOR, Material.DARK_OAK_DOOR };
Material doorTypes[] = { Material.WOODEN_DOOR, Material.SPRUCE_DOOR, Material.BIRCH_DOOR, Material.JUNGLE_DOOR,
Material.ACACIA_DOOR, Material.DARK_OAK_DOOR };
if (Arrays.asList(doorTypes).contains(block.getType()) && openDoors) { if (Arrays.asList(doorTypes).contains(block.getType()) && openDoors) {
if (block.getData() >= 8) { if (block.getData() >= 8) {
block = block.getRelative(BlockFace.DOWN); block = block.getRelative(BlockFace.DOWN);
@ -425,10 +426,9 @@ public class AirBlast extends CoreAbility {
} }
/* /*
* If a player presses shift and AirBlasts straight down then the * If a player presses shift and AirBlasts straight down then the AirBlast's location gets
* AirBlast's location gets messed up and reading the distance returns * messed up and reading the distance returns Double.NaN. If we don't remove this instance
* Double.NaN. If we don't remove this instance then the AirBlast will * then the AirBlast will never be removed.
* never be removed.
*/ */
double dist = location.distance(origin); double dist = location.distance(origin);
if (Double.isNaN(dist) || dist > range) { if (Double.isNaN(dist) || dist > range) {
@ -443,28 +443,31 @@ public class AirBlast extends CoreAbility {
advanceLocation(); advanceLocation();
return true; return true;
} }
public static boolean removeAirBlastsAroundPoint(Location location, double radius) { public static boolean removeAirBlastsAroundPoint(Location location, double radius) {
boolean removed = false; boolean removed = false;
for (Integer id : getInstances(StockAbility.AirBlast).keySet()) { for (AirBlast airBlast : instances.values()) {
AirBlast airBlast = ((AirBlast)getAbility(id)); Location airBlastlocation = airBlast.location;
Location airBlastlocation = airBlast.location; if (location.getWorld() == airBlastlocation.getWorld()) {
if (location.getWorld() == airBlastlocation.getWorld()) { if (location.distance(airBlastlocation) <= radius)
if (location.distance(airBlastlocation) <= radius) airBlast.remove();
airBlast.remove(); removed = true;
removed = true;
} }
} }
return removed; return removed;
} }
public void remove() {
instances.remove(id);
}
@Override @Override
public void reloadVariables() { public void reloadVariables() {
speed = config.get().getDouble("Abilities.Air.AirBlast.Speed"); speed = config.get().getDouble("Abilities.Air.AirBlast.Speed");
defaultrange = config.get().getDouble("Abilities.Air.AirBlast.Range"); defaultrange = config.get().getDouble("Abilities.Air.AirBlast.Range");
affectingradius = config.get().getDouble("Abilities.Air.AirBlast.Radius"); affectingradius = config.get().getDouble("Abilities.Air.AirBlast.Radius");
defaultpushfactor = config.get().getDouble("Abilities.Air.AirBlast.Push"); defaultpushfactor = config.get().getDouble("Abilities.Air.AirBlast.Push");
flickLevers = config.get().getBoolean("Abilities.Air.AirBlast.CanFlickLevers"); flickLevers = config.get().getBoolean("Abilities.Air.AirBlast.CanFlickLevers");
openDoors = config.get().getBoolean("Abilities.Air.AirBlast.CanOpenDoors"); openDoors = config.get().getBoolean("Abilities.Air.AirBlast.CanOpenDoors");
pressButtons = config.get().getBoolean("Abilities.Air.AirBlast.CanPressButtons"); pressButtons = config.get().getBoolean("Abilities.Air.AirBlast.CanPressButtons");
@ -490,9 +493,4 @@ public class AirBlast extends CoreAbility {
this.showParticles = show; this.showParticles = show;
} }
@Override
public InstanceType getInstanceType() {
return InstanceType.MULTIPLE;
}
} }

View file

@ -16,7 +16,7 @@ import org.bukkit.entity.Player;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class AirBubble extends CoreAbility { public class AirBubble implements ConfigLoadable {
private static double DEFAULT_AIR_RADIUS = config.get().getDouble("Abilities.Air.AirBubble.Radius"); private static double DEFAULT_AIR_RADIUS = config.get().getDouble("Abilities.Air.AirBubble.Radius");
private static double DEFAULT_WATER_RADIUS = config.get().getDouble("Abilities.Water.WaterBubble.Radius"); private static double DEFAULT_WATER_RADIUS = config.get().getDouble("Abilities.Water.WaterBubble.Radius");
@ -28,10 +28,10 @@ public class AirBubble extends CoreAbility {
private ConcurrentHashMap<Block, BlockState> waterorigins; private ConcurrentHashMap<Block, BlockState> waterorigins;
public AirBubble(Player player) { public AirBubble(Player player) {
//reloadVariables(); // reloadVariables();
this.player = player; this.player = player;
waterorigins = new ConcurrentHashMap<Block, BlockState>(); waterorigins = new ConcurrentHashMap<Block, BlockState>();
//instances.put(uuid, this); // instances.put(uuid, this);
putInstance(player, this); putInstance(player, this);
} }
@ -45,13 +45,16 @@ public class AirBubble extends CoreAbility {
} }
public static String getDescription() { public static String getDescription() {
return "To use, the bender must merely have the ability selected." + " All water around the user in a small bubble will vanish," + " replacing itself once the user either gets too far away or selects a different ability."; return "To use, the bender must merely have the ability selected."
+ " All water around the user in a small bubble will vanish,"
+ " replacing itself once the user either gets too far away or selects a different ability.";
} }
public static void handleBubbles(Server server) { public static void handleBubbles(Server server) {
for (Player player : server.getOnlinePlayers()) { for (Player player : server.getOnlinePlayers()) {
if (GeneralMethods.getBoundAbility(player) != null) { if (GeneralMethods.getBoundAbility(player) != null) {
if (GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBubble") || GeneralMethods.getBoundAbility(player).equalsIgnoreCase("WaterBubble")) { if (GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBubble")
|| GeneralMethods.getBoundAbility(player).equalsIgnoreCase("WaterBubble")) {
if (!containsPlayer(player, AirBubble.class) && player.isSneaking()) { if (!containsPlayer(player, AirBubble.class) && player.isSneaking()) {
new AirBubble(player); new AirBubble(player);
} }
@ -88,12 +91,6 @@ public class AirBubble extends CoreAbility {
return radius; return radius;
} }
@Override
public StockAbility getStockAbility() {
return StockAbility.AirBubble;
}
@Override
public boolean progress() { public boolean progress() {
if (player.isDead() || !player.isOnline()) { if (player.isDead() || !player.isOnline()) {
remove(); remove();
@ -105,11 +102,13 @@ public class AirBubble extends CoreAbility {
return false; return false;
} }
if (GeneralMethods.getBoundAbility(player) != null) { if (GeneralMethods.getBoundAbility(player) != null) {
if (GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBubble") && GeneralMethods.canBend(player.getName(), "AirBubble")) { if (GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBubble")
&& GeneralMethods.canBend(player.getName(), "AirBubble")) {
pushWater(); pushWater();
return false; return false;
} }
if (GeneralMethods.getBoundAbility(player).equalsIgnoreCase("WaterBubble") && GeneralMethods.canBend(player.getName(), "WaterBubble")) { if (GeneralMethods.getBoundAbility(player).equalsIgnoreCase("WaterBubble")
&& GeneralMethods.canBend(player.getName(), "WaterBubble")) {
pushWater(); pushWater();
return false; return false;
} }
@ -182,7 +181,7 @@ public class AirBubble extends CoreAbility {
if (block.getType() == Material.AIR || block.isLiquid()) if (block.getType() == Material.AIR || block.isLiquid())
waterorigins.get(block).update(true); waterorigins.get(block).update(true);
} }
//instances.remove(uuid); // instances.remove(uuid);
super.remove(); super.remove();
} }

View file

@ -28,7 +28,6 @@ import com.projectkorra.projectkorra.waterbending.WaterManipulation;
import com.projectkorra.projectkorra.waterbending.WaterMethods; import com.projectkorra.projectkorra.waterbending.WaterMethods;
public class FireBlast implements ConfigLoadable { public class FireBlast implements ConfigLoadable {
public static ConcurrentHashMap<Integer, FireBlast> instances = new ConcurrentHashMap<>(); public static ConcurrentHashMap<Integer, FireBlast> instances = new ConcurrentHashMap<>();
private static double SPEED = config.get().getDouble("Abilities.Fire.FireBlast.Speed"); private static double SPEED = config.get().getDouble("Abilities.Fire.FireBlast.Speed");
@ -37,7 +36,7 @@ public class FireBlast implements ConfigLoadable {
private static int DAMAGE = config.get().getInt("Abilities.Fire.FireBlast.Damage"); private static int DAMAGE = config.get().getInt("Abilities.Fire.FireBlast.Damage");
private static double fireticks = config.get().getDouble("Abilities.Fire.FireBlast.FireTicks"); private static double fireticks = config.get().getDouble("Abilities.Fire.FireBlast.FireTicks");
private static int idCounter = 0; private static int idCounter = 0;
/* Package visible variables */ /* Package visible variables */
static boolean dissipate = config.get().getBoolean("Abilities.Fire.FireBlast.Dissipate"); static boolean dissipate = config.get().getBoolean("Abilities.Fire.FireBlast.Dissipate");
/* End Package visible variables */ /* End Package visible variables */
@ -72,7 +71,7 @@ public class FireBlast implements ConfigLoadable {
return; return;
} }
/* End Initial Checks */ /* End Initial Checks */
//reloadVariables(); // reloadVariables();
safe = safeblocks; safe = safeblocks;
range = FireMethods.getFirebendingDayAugment(range, player.getWorld()); range = FireMethods.getFirebendingDayAugment(range, player.getWorld());
// timers.put(player, System.currentTimeMillis()); // timers.put(player, System.currentTimeMillis());
@ -95,7 +94,7 @@ public class FireBlast implements ConfigLoadable {
return; return;
} }
/* End Initial Checks */ /* End Initial Checks */
//reloadVariables(); // reloadVariables();
range = FireMethods.getFirebendingDayAugment(range, player.getWorld()); range = FireMethods.getFirebendingDayAugment(range, player.getWorld());
this.player = player; this.player = player;
location = player.getEyeLocation(); location = player.getEyeLocation();
@ -139,7 +138,14 @@ public class FireBlast implements ConfigLoadable {
} }
public static String getDescription() { public static String getDescription() {
return "FireBlast is the most fundamental bending technique of a firebender. " + "To use, simply left-click in a direction. A blast of fire will be created at your fingertips. " + "If this blast contacts an enemy, it will dissipate and engulf them in flames, " + "doing additional damage and knocking them back slightly. " + "If the blast hits terrain, it will ignite the nearby area. " + "Additionally, if you hold sneak, you will charge up the fireblast. " + "If you release it when it's charged, it will instead launch a powerful " + "fireball that explodes on contact."; return "FireBlast is the most fundamental bending technique of a firebender. "
+ "To use, simply left-click in a direction. A blast of fire will be created at your fingertips. "
+ "If this blast contacts an enemy, it will dissipate and engulf them in flames, "
+ "doing additional damage and knocking them back slightly. "
+ "If the blast hits terrain, it will ignite the nearby area. "
+ "Additionally, if you hold sneak, you will charge up the fireblast. "
+ "If you release it when it's charged, it will instead launch a powerful "
+ "fireball that explodes on contact.";
} }
public static void removeFireBlastsAroundPoint(Location location, double radius) { public static void removeFireBlastsAroundPoint(Location location, double radius) {
@ -155,7 +161,8 @@ public class FireBlast implements ConfigLoadable {
private void advanceLocation() { private void advanceLocation() {
if (showParticles) { if (showParticles) {
//ParticleEffect.RED_DUST.display((float) 16, (float) 111, (float) 227, 0.01F, 0, location, 256D); // ParticleEffect.RED_DUST.display((float) 16, (float) 111, (float) 227, 0.01F, 0,
// location, 256D);
ParticleEffect.FLAME.display(location, 0.275F, 0.275F, 0.275F, 0, 6); ParticleEffect.FLAME.display(location, 0.275F, 0.275F, 0.275F, 0, 6);
ParticleEffect.SMOKE.display(location, 0.3F, 0.3F, 0.3F, 0, 3); ParticleEffect.SMOKE.display(location, 0.3F, 0.3F, 0.3F, 0, 3);
} }
@ -174,7 +181,8 @@ public class FireBlast implements ConfigLoadable {
} }
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity) {
entity.setFireTicks((int) (fireticks * 20)); entity.setFireTicks((int) (fireticks * 20));
GeneralMethods.damageEntity(player, entity, (int) FireMethods.getFirebendingDayAugment((double) damage, entity.getWorld()), "FireBlast"); GeneralMethods.damageEntity(player, entity,
(int) FireMethods.getFirebendingDayAugment((double) damage, entity.getWorld()), "FireBlast");
AirMethods.breakBreathbendingHold(entity); AirMethods.breakBreathbendingHold(entity);
new Enflamed(entity, player); new Enflamed(entity, player);
remove(); remove();
@ -213,15 +221,16 @@ public class FireBlast implements ConfigLoadable {
private void ignite(Location location) { private void ignite(Location location) {
for (Block block : GeneralMethods.getBlocksAroundPoint(location, affectingradius)) { for (Block block : GeneralMethods.getBlocksAroundPoint(location, affectingradius)) {
if (FireStream.isIgnitable(player, block) && !safe.contains(block)) { if (FireStream.isIgnitable(player, block) && !safe.contains(block)) {
/*if (WaterMethods.isPlantbendable(block)) { /*
new Plantbending(block); * if (WaterMethods.isPlantbendable(block)) { new Plantbending(block); }
}*/ */
if (FireMethods.canFireGrief()) { if (FireMethods.canFireGrief()) {
if (WaterMethods.isPlantbendable(block)) new Plantbending(block); if (WaterMethods.isPlantbendable(block))
new Plantbending(block);
block.setType(Material.FIRE); block.setType(Material.FIRE);
} } else
else FireMethods.createTempFire(block.getLocation()); FireMethods.createTempFire(block.getLocation());
//block.setType(Material.FIRE); // block.setType(Material.FIRE);
if (dissipate) { if (dissipate) {
FireStream.ignitedblocks.put(block, player); FireStream.ignitedblocks.put(block, player);
FireStream.ignitedtimes.put(block, System.currentTimeMillis()); FireStream.ignitedtimes.put(block, System.currentTimeMillis());
@ -275,7 +284,8 @@ public class FireBlast implements ConfigLoadable {
double radius = affectingradius; double radius = affectingradius;
Player source = player; Player source = player;
if (EarthBlast.annihilateBlasts(location, radius, source) || WaterManipulation.annihilateBlasts(location, radius, source) || FireBlast.annihilateBlasts(location, radius, source)) { if (EarthBlast.annihilateBlasts(location, radius, source) || WaterManipulation.annihilateBlasts(location, radius, source)
|| FireBlast.annihilateBlasts(location, radius, source)) {
remove(); remove();
return false; return false;
} }
@ -301,7 +311,7 @@ public class FireBlast implements ConfigLoadable {
return true; return true;
} }
public void remove() { public void remove() {
instances.remove(id); instances.remove(id);
} }

View file

@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.StockAbility;
import com.projectkorra.projectkorra.configuration.ConfigLoadable; import com.projectkorra.projectkorra.configuration.ConfigLoadable;
public class Illumination implements ConfigLoadable { public class Illumination implements ConfigLoadable {

View file

@ -1,13 +1,8 @@
package com.projectkorra.projectkorra.firebending; package com.projectkorra.projectkorra.firebending;
import com.projectkorra.projectkorra.BendingManager; import java.util.ArrayList;
import com.projectkorra.projectkorra.BendingPlayer; import java.util.Arrays;
import com.projectkorra.projectkorra.GeneralMethods; import java.util.concurrent.ConcurrentHashMap;
import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.ability.AvatarState;
import com.projectkorra.projectkorra.ability.StockAbility;
import com.projectkorra.projectkorra.ability.api.CoreAbility;
import com.projectkorra.projectkorra.earthbending.EarthMethods;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -19,10 +14,17 @@ import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.ArrayList; import com.projectkorra.projectkorra.BendingManager;
import java.util.Arrays; import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.ability.AvatarState;
import com.projectkorra.projectkorra.configuration.ConfigLoadable;
import com.projectkorra.projectkorra.earthbending.EarthMethods;
public class Lightning implements ConfigLoadable {
public static ConcurrentHashMap<Integer, Lightning> instances = new ConcurrentHashMap<>();
public class Lightning extends CoreAbility {
public static boolean SELF_HIT_WATER = config.get().getBoolean("Abilities.Fire.Lightning.SelfHitWater"); public static boolean SELF_HIT_WATER = config.get().getBoolean("Abilities.Fire.Lightning.SelfHitWater");
public static boolean SELF_HIT_CLOSE = config.get().getBoolean("Abilities.Fire.Lightning.SelfHitClose"); public static boolean SELF_HIT_CLOSE = config.get().getBoolean("Abilities.Fire.Lightning.SelfHitClose");
public static boolean ARC_ON_ICE = config.get().getBoolean("Abilities.Fire.Lightning.ArcOnIce"); public static boolean ARC_ON_ICE = config.get().getBoolean("Abilities.Fire.Lightning.ArcOnIce");
@ -40,13 +42,14 @@ public class Lightning extends CoreAbility {
public static long CHARGETIME = (long) config.get().getDouble("Abilities.Fire.Lightning.ChargeTime"); public static long CHARGETIME = (long) config.get().getDouble("Abilities.Fire.Lightning.ChargeTime");
public static long COOLDOWN = (long) config.get().getDouble("Abilities.Fire.Lightning.Cooldown"); public static long COOLDOWN = (long) config.get().getDouble("Abilities.Fire.Lightning.Cooldown");
private static final int POINT_GENERATION = 5; private static final int POINT_GENERATION = 5;
private static int idCounter = 0;
private Player player; private Player player;
private BendingPlayer bplayer; private BendingPlayer bplayer;
private Location origin, destination; private Location origin, destination;
private double range, chargeTime, cooldown, subArcChance, damage, chainArcs, chainRange, private int id;
waterRange; private double range, chargeTime, cooldown, subArcChance, damage, chainArcs, chainRange, waterRange;
private double chainArcChance, stunChance, stunDuration; private double chainArcChance, stunChance, stunDuration;
private long time; private long time;
private boolean charged, hitWater, hitIce; private boolean charged, hitWater, hitIce;
@ -58,7 +61,7 @@ public class Lightning extends CoreAbility {
private double newY; private double newY;
public Lightning(Player player) { public Lightning(Player player) {
//reloadVariables(); // reloadVariables();
this.player = player; this.player = player;
bplayer = GeneralMethods.getBendingPlayer(player.getName()); bplayer = GeneralMethods.getBendingPlayer(player.getName());
charged = false; charged = false;
@ -79,8 +82,8 @@ public class Lightning extends CoreAbility {
if (AvatarState.isAvatarState(player)) { if (AvatarState.isAvatarState(player)) {
/* /*
* Some variables aren't considered here because it makes AS too * Some variables aren't considered here because it makes AS too overpowered and causes
* overpowered and causes crashing. * crashing.
*/ */
chargeTime = 0; chargeTime = 0;
cooldown = 0; cooldown = 0;
@ -93,14 +96,14 @@ public class Lightning extends CoreAbility {
chargeTime = 0; chargeTime = 0;
cooldown = 0; cooldown = 0;
} }
//instances.add(this); instances.put(idCounter, this);
putInstance(player, this); this.id = idCounter;
idCounter = (idCounter + 1) % Integer.MAX_VALUE;
} }
public static ArrayList<Arc> getAllArcs() { public static ArrayList<Arc> getAllArcs() {
ArrayList<Arc> a = new ArrayList<Arc>(); ArrayList<Arc> a = new ArrayList<Arc>();
for (Integer id : getInstances(StockAbility.Lightning).keySet()) { for (Lightning light : instances.values()) {
Lightning light = (Lightning) getAbility(id);
for (Arc arcs : light.getArcs()) { for (Arc arcs : light.getArcs()) {
a.add(arcs); a.add(arcs);
} }
@ -115,8 +118,7 @@ public class Lightning extends CoreAbility {
* @return the ability * @return the ability
*/ */
public static Lightning getLightning(Player player) { public static Lightning getLightning(Player player) {
for (Integer id : getInstances(StockAbility.Lightning).keySet()) { for (Lightning light : instances.values()) {
Lightning light = (Lightning) getAbility(id);
if (light.player == player) if (light.player == player)
return light; return light;
} }
@ -227,11 +229,6 @@ public class Lightning extends CoreAbility {
return range; return range;
} }
@Override
public StockAbility getStockAbility() {
return StockAbility.Lightning;
}
public double getStunChance() { public double getStunChance() {
return stunChance; return stunChance;
} }
@ -261,8 +258,7 @@ public class Lightning extends CoreAbility {
} }
/** /**
* Checks if a block is transparent, also considers the ARC_ON_ICE config * Checks if a block is transparent, also considers the ARC_ON_ICE config option.
* option.
* *
* @param player the player that is viewing the block * @param player the player that is viewing the block
* @param block the block * @param block the block
@ -282,19 +278,18 @@ public class Lightning extends CoreAbility {
} }
/** /**
* Progresses the instance of this ability by 1 tick. This is the heart of * Progresses the instance of this ability by 1 tick. This is the heart of the ability, it
* the ability, it checks if it needs to remove itself, and handles the * checks if it needs to remove itself, and handles the initial Lightning Arc generation.
* initial Lightning Arc generation.
* *
* Once all of the arcs have been created then this ability instance gets * Once all of the arcs have been created then this ability instance gets removed, but the
* removed, but the BukkitRunnables continue until they remove themselves. * BukkitRunnables continue until they remove themselves.
**/ **/
@Override
public boolean progress() { public boolean progress() {
if (player.isDead() || !player.isOnline()) { if (player.isDead() || !player.isOnline()) {
removeWithTasks(); removeWithTasks();
return false; return false;
} else if (GeneralMethods.getBoundAbility(player) == null || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("Lightning")) { } else if (GeneralMethods.getBoundAbility(player) == null
|| !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("Lightning")) {
remove(); remove();
return false; return false;
} }
@ -318,7 +313,8 @@ public class Lightning extends CoreAbility {
if (target != null) if (target != null)
destination = target.getLocation(); destination = target.getLocation();
else else
destination = player.getEyeLocation().add(player.getEyeLocation().getDirection().normalize().multiply(range)); destination = player.getEyeLocation().add(
player.getEyeLocation().getDirection().normalize().multiply(range));
} }
} else { } else {
if (!player.isSneaking()) { if (!player.isSneaking()) {
@ -355,7 +351,8 @@ public class Lightning extends CoreAbility {
for (int j = 0; j < arc.getAnimLocs().size() - 1; j++) { for (int j = 0; j < arc.getAnimLocs().size() - 1; j++) {
final Location iterLoc = arc.getAnimLocs().get(j).getLoc().clone(); final Location iterLoc = arc.getAnimLocs().get(j).getLoc().clone();
final Location dest = arc.getAnimLocs().get(j + 1).getLoc().clone(); final Location dest = arc.getAnimLocs().get(j + 1).getLoc().clone();
if (SELF_HIT_CLOSE && player.getLocation().distance(iterLoc) < 3 && !isTransparent(player, iterLoc.getBlock()) && !affectedEntities.contains(player)) { if (SELF_HIT_CLOSE && player.getLocation().distance(iterLoc) < 3
&& !isTransparent(player, iterLoc.getBlock()) && !affectedEntities.contains(player)) {
affectedEntities.add(player); affectedEntities.add(player);
electrocute(player); electrocute(player);
} }
@ -378,6 +375,10 @@ public class Lightning extends CoreAbility {
} }
return true; return true;
} }
public void remove() {
instances.remove(id);
}
@Override @Override
public void reloadVariables() { public void reloadVariables() {
@ -473,9 +474,8 @@ public class Lightning extends CoreAbility {
} }
/** /**
* Represents a Lightning Arc Point particle animation. This basically just * Represents a Lightning Arc Point particle animation. This basically just holds a location and
* holds a location and counts the amount of times that a particle has been * counts the amount of times that a particle has been animated.
* animated.
* **/ * **/
public class AnimLocation { public class AnimLocation {
private Location loc; private Location loc;
@ -504,9 +504,9 @@ public class Lightning extends CoreAbility {
} }
/** /**
* An Arc represents a Lightning arc for the specific ability. These Arcs * An Arc represents a Lightning arc for the specific ability. These Arcs contain a list of
* contain a list of Particles that are used to display the entire arc. Arcs * Particles that are used to display the entire arc. Arcs can also generate a list of subarcs
* can also generate a list of subarcs that chain off of their own instance. * that chain off of their own instance.
**/ **/
public class Arc { public class Arc {
private ArrayList<Location> points; private ArrayList<Location> points;
@ -543,9 +543,9 @@ public class Lightning extends CoreAbility {
/** /**
* Randomly generates subarcs off of this arc. * Randomly generates subarcs off of this arc.
* *
* @param chance The chance that an arc will be generated for each * @param chance The chance that an arc will be generated for each specific point in the
* specific point in the arc. Note: if you generate a lot of * arc. Note: if you generate a lot of points then chance will need to be
* points then chance will need to be lowered. * lowered.
* @param range The length of each subarc. * @param range The length of each subarc.
* *
**/ **/
@ -570,15 +570,14 @@ public class Lightning extends CoreAbility {
} }
/** /**
* Runs an arc generation algorithm by first creating two points, the * Runs an arc generation algorithm by first creating two points, the starting point and the
* starting point and the ending point. Next, it creates a point in the * ending point. Next, it creates a point in the middle that has an offset relative to the
* middle that has an offset relative to the beginning and end points. * beginning and end points. Now that the arc is split into 3 points, we continue this
* Now that the arc is split into 3 points, we continue this processes * processes by generating middle points in the two halfs of this arc. This process
* by generating middle points in the two halfs of this arc. This * continues the amount of times specified.
* process continues the amount of times specified.
* *
* @param times The amount of times that the arc will be split in half * @param times The amount of times that the arc will be split in half causes O(n^2)
* causes O(n^2) complexity * complexity
**/ **/
public void generatePoints(int times) { public void generatePoints(int times) {
for (int i = 0; i < times; i++) { for (int i = 0; i < times; i++) {
@ -645,12 +644,11 @@ public class Lightning extends CoreAbility {
} }
/** /**
* A Runnable Particle that continuously displays itself until it reaches a * A Runnable Particle that continuously displays itself until it reaches a certain time limit.
* certain time limit.
* *
* These LightningParticles do the actual checking for player collision and * These LightningParticles do the actual checking for player collision and handle damaging any
* handle damaging any entities. These Runnables also check to see if they * entities. These Runnables also check to see if they reach water, in which case they will
* reach water, in which case they will generate subarcs to branch out. * generate subarcs to branch out.
* **/ * **/
public class LightningParticle extends BukkitRunnable { public class LightningParticle extends BukkitRunnable {
private Arc arc; private Arc arc;
@ -670,8 +668,8 @@ public class Lightning extends CoreAbility {
} }
/** /**
* Animates the Location, checks for water/player collision and also * Animates the Location, checks for water/player collision and also deals with any chain
* deals with any chain subarcs. * subarcs.
*/ */
public void run() { public void run() {
FireMethods.playLightningbendingParticle(loc, 0F, 0F, 0F); FireMethods.playLightningbendingParticle(loc, 0F, 0F, 0F);
@ -692,7 +690,9 @@ public class Lightning extends CoreAbility {
for (int i = 0; i < WATER_ARCS; i++) { for (int i = 0; i < WATER_ARCS; i++) {
Location origin = loc.clone(); Location origin = loc.clone();
origin.add(new Vector((Math.random() - 0.5) * 2, 0, (Math.random() - 0.5) * 2)); origin.add(new Vector((Math.random() - 0.5) * 2, 0, (Math.random() - 0.5) * 2));
destination = origin.clone().add(new Vector((Math.random() - 0.5) * waterRange, Math.random() - 0.7, (Math.random() - 0.5) * waterRange)); destination = origin.clone().add(
new Vector((Math.random() - 0.5) * waterRange, Math.random() - 0.7, (Math.random() - 0.5)
* waterRange));
Arc newArc = new Arc(origin, destination); Arc newArc = new Arc(origin, destination);
newArc.generatePoints(POINT_GENERATION); newArc.generatePoints(POINT_GENERATION);
arcs.add(newArc); arcs.add(newArc);
@ -701,11 +701,11 @@ public class Lightning extends CoreAbility {
for (Entity entity : GeneralMethods.getEntitiesAroundPoint(loc, 2.5)) { for (Entity entity : GeneralMethods.getEntitiesAroundPoint(loc, 2.5)) {
/* /*
* If the player is in water we will electrocute them only * If the player is in water we will electrocute them only if they are standing
* if they are standing in water. If the lightning hit ice * in water. If the lightning hit ice we can electrocute them all the time.
* we can electrocute them all the time.
*/ */
if (entity.equals(player) && !(SELF_HIT_WATER && hitWater && isWater(player.getLocation())) && !(SELF_HIT_WATER && hitIce)) if (entity.equals(player) && !(SELF_HIT_WATER && hitWater && isWater(player.getLocation()))
&& !(SELF_HIT_WATER && hitIce))
continue; continue;
if (entity instanceof LivingEntity && !affectedEntities.contains(entity)) { if (entity instanceof LivingEntity && !affectedEntities.contains(entity)) {
@ -728,7 +728,8 @@ public class Lightning extends CoreAbility {
if (chainArcs >= 1 && Math.random() <= chainArcChance) { if (chainArcs >= 1 && Math.random() <= chainArcChance) {
chainArcs--; chainArcs--;
for (Entity ent : GeneralMethods.getEntitiesAroundPoint(lent.getLocation(), chainRange)) { for (Entity ent : GeneralMethods.getEntitiesAroundPoint(lent.getLocation(), chainRange)) {
if (!ent.equals(player) && !ent.equals(lent) && ent instanceof LivingEntity && !affectedEntities.contains(ent)) { if (!ent.equals(player) && !ent.equals(lent) && ent instanceof LivingEntity
&& !affectedEntities.contains(ent)) {
origin = lent.getLocation().add(0, 1, 0); origin = lent.getLocation().add(0, 1, 0);
destination = ent.getLocation().add(0, 1, 0); destination = ent.getLocation().add(0, 1, 0);
Arc newArc = new Arc(origin, destination); Arc newArc = new Arc(origin, destination);

View file

@ -1,12 +1,8 @@
package com.projectkorra.projectkorra.firebending; package com.projectkorra.projectkorra.firebending;
import com.projectkorra.projectkorra.BendingPlayer; import java.util.ArrayList;
import com.projectkorra.projectkorra.GeneralMethods; import java.util.List;
import com.projectkorra.projectkorra.ability.AvatarState; import java.util.concurrent.ConcurrentHashMap;
import com.projectkorra.projectkorra.ability.StockAbility;
import com.projectkorra.projectkorra.ability.api.CoreAbility;
import com.projectkorra.projectkorra.airbending.AirMethods;
import com.projectkorra.projectkorra.util.ParticleEffect;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -16,11 +12,16 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.ArrayList; import com.projectkorra.projectkorra.BendingPlayer;
import java.util.List; import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.AvatarState;
public class WallOfFire extends CoreAbility { import com.projectkorra.projectkorra.airbending.AirMethods;
import com.projectkorra.projectkorra.configuration.ConfigLoadable;
import com.projectkorra.projectkorra.util.ParticleEffect;
public class WallOfFire implements ConfigLoadable {
public static final ConcurrentHashMap<Player, WallOfFire> instances = new ConcurrentHashMap<>();
private static double maxangle = 50; private static double maxangle = 50;
private static int RANGE = config.get().getInt("Abilities.Fire.WallOfFire.Range"); private static int RANGE = config.get().getInt("Abilities.Fire.WallOfFire.Range");
@ -50,7 +51,7 @@ public class WallOfFire extends CoreAbility {
public WallOfFire(Player player) { public WallOfFire(Player player) {
/* Initial Checks */ /* Initial Checks */
if (containsPlayer(player, WallOfFire.class) && !AvatarState.isAvatarState(player)) { if (instances.containsKey(player) && !AvatarState.isAvatarState(player)) {
return; return;
} }
BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName()); BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName());
@ -90,8 +91,7 @@ public class WallOfFire extends CoreAbility {
initializeBlocks(); initializeBlocks();
//instances.put(player, this); instances.put(player, this);
putInstance(player, this);
bPlayer.addCooldown("WallOfFire", cooldown); bPlayer.addCooldown("WallOfFire", cooldown);
} }
@ -164,11 +164,6 @@ public class WallOfFire extends CoreAbility {
return range; return range;
} }
@Override
public StockAbility getStockAbility() {
return StockAbility.WallOfFire;
}
public int getWidth() { public int getWidth() {
return width; return width;
} }
@ -200,7 +195,6 @@ public class WallOfFire extends CoreAbility {
} }
@Override
public boolean progress() { public boolean progress() {
time = System.currentTimeMillis(); time = System.currentTimeMillis();
@ -228,6 +222,10 @@ public class WallOfFire extends CoreAbility {
} }
return true; return true;
} }
public void remove() {
instances.remove(player);
}
@Override @Override
public void reloadVariables() { public void reloadVariables() {