Also reworked damaging passives. (No Fall Damage / Decreased Fall
Damage)
This commit is contained in:
MistPhizzle 2014-06-24 19:43:28 -04:00
parent ead0c812d1
commit 47c78ef8d0
3 changed files with 290 additions and 29 deletions

View file

@ -13,6 +13,7 @@ import org.bukkit.entity.Player;
import com.projectkorra.ProjectKorra.Ability.AvatarState;
import com.projectkorra.ProjectKorra.airbending.AirBlast;
import com.projectkorra.ProjectKorra.airbending.AirBurst;
import com.projectkorra.ProjectKorra.airbending.AirPassive;
import com.projectkorra.ProjectKorra.airbending.Tornado;
import com.projectkorra.ProjectKorra.chiblocking.ChiPassive;
@ -57,6 +58,7 @@ public class BendingManager implements Runnable {
FirePassive.handlePassive();
EarthPassive.revertSands();
Plantbending.regrow();
AirBurst.progressAll();
handleDayNight();
for (int ID: Tornado.instances.keySet()) {
Tornado.progress(ID);

View file

@ -29,6 +29,7 @@ import org.kitteh.tag.AsyncPlayerReceiveNameTagEvent;
import com.projectkorra.ProjectKorra.Ability.AvatarState;
import com.projectkorra.ProjectKorra.airbending.AirBlast;
import com.projectkorra.ProjectKorra.airbending.AirBurst;
import com.projectkorra.ProjectKorra.airbending.Tornado;
import com.projectkorra.ProjectKorra.chiblocking.ChiPassive;
import com.projectkorra.ProjectKorra.earthbending.EarthPassive;
@ -105,12 +106,15 @@ public class PKListener implements Listener {
if (Methods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Air.CanBendWithWeapons")) {
return;
}
if (abil == "Tornado") {
if (abil.equalsIgnoreCase("Tornado")) {
new Tornado(player);
}
if (abil == "AirBlast") {
if (abil.equalsIgnoreCase("AirBlast")) {
AirBlast.setOrigin(player);
}
if (abil.equalsIgnoreCase("AirBurst")) {
new AirBurst(player);
}
}
}
}
@ -125,16 +129,19 @@ public class PKListener implements Listener {
String abil = Methods.getBoundAbility(player);
if (abil == null) return;
if (Methods.canBend(player.getName(), abil)) {
if (abil == "AvatarState") {
if (abil.equalsIgnoreCase("AvatarState")) {
new AvatarState(player);
}
if (Methods.isAirAbility(abil)) {
if (Methods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Air.CanBendWithWeapons")) {
return;
}
if (abil == "AirBlast") {
if (abil.equalsIgnoreCase("AirBlast")) {
new AirBlast(player);
}
if (abil.equalsIgnoreCase("AirBurst")) {
AirBurst.coneBurst(player);
}
}
}
}
@ -160,6 +167,7 @@ public class PKListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityDamageEvent(EntityDamageEvent event) {
Entity entity = event.getEntity();
if (event.getCause() == DamageCause.FIRE && FireStream.ignitedblocks.containsKey(entity.getLocation().getBlock())) {
new Enflamed(entity, FireStream.ignitedblocks.get(entity.getLocation().getBlock()));
}
@ -203,33 +211,76 @@ public class PKListener implements Listener {
}
}
@EventHandler
public void onPlayerDamage(EntityDamageEvent e) {
Entity en = e.getEntity();
if (en instanceof Player) { // Player is the one being hurt.
Player p = (Player) en;
if (e.getCause() == DamageCause.FALL) { // Result is Fall Damage
if (Methods.canBendPassive(p.getName(), Element.Air)) {
e.setDamage(0.0);
}
if (Methods.canBendPassive(p.getName(), Element.Chi)) {
double initdamage = e.getDamage();
double newdamage = e.getDamage() * ChiPassive.FallReductionFactor;
double finaldamage = initdamage - newdamage;
e.setDamage(finaldamage);
}
if (Methods.canBendPassive(p.getName(), Element.Water)) {
if (WaterPassive.applyNoFall(p)) {
e.setDamage(0.0);
}
}
if (Methods.canBendPassive(p.getName(), Element.Earth)) {
if (EarthPassive.softenLanding(p)) {
e.setDamage(0.0);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerDamage(EntityDamageEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
if (Methods.isBender(player.getName(), Element.Earth) && event.getCause() == DamageCause.FALL) {
Shockwave.fallShockwave(player);
}
if (Methods.isBender(player.getName(), Element.Air) && event.getCause() == DamageCause.FALL && Methods.canBendPassive(player.getName(), Element.Air)) {
new Flight(player);
player.setAllowFlight(true);
AirBurst.fallBurst(player);
player.setFallDistance(0);
event.setDamage(0);
event.setCancelled(true);
}
if (!event.isCancelled() && Methods.isBender(player.getName(), Element.Water) && event.getCause() == DamageCause.FALL && Methods.canBendPassive(player.getName(), Element.Water)) {
if (WaterPassive.applyNoFall(player)) {
new Flight(player);
player.setAllowFlight(true);
player.setFallDistance(0);
event.setDamage(0);
event.setCancelled(true);
}
}
if (!event.isCancelled()
&& Methods.isBender(player.getName(), Element.Earth)
&& event.getCause() == DamageCause.FALL
&& Methods.canBendPassive(player.getName(), Element.Earth)) {
if (EarthPassive.softenLanding(player)) {
new Flight(player);
player.setAllowFlight(true);
player.setFallDistance(0);
event.setDamage(0);
event.setCancelled(true);
}
}
if (!event.isCancelled()
&& Methods.isBender(player.getName(), Element.Chi)
&& event.getCause() == DamageCause.FALL
&& Methods.canBendPassive(player.getName(), Element.Chi)) {
double initdamage = event.getDamage();
double newdamage = event.getDamage() * ChiPassive.FallReductionFactor;
double finaldamage = initdamage - newdamage;
event.setDamage(finaldamage);
}
if (!event.isCancelled() && event.getCause() == DamageCause.FALL) {
Player source = Flight.getLaunchedBy(player);
if (source != null) {
event.setCancelled(true);
Methods.damageEntity(source, player, event.getDamage());
}
}
if (Methods.canBendPassive(player.getName(), Element.Fire)
&& Methods.isBender(player.getName(), Element.Fire)
&& (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK)) {
event.setCancelled(!Extinguish.canBurn(player));
}
if (Methods.isBender(player.getName(), Element.Earth)
&& event.getCause() == DamageCause.SUFFOCATION && TempBlock.isTempBlock(player.getEyeLocation().getBlock())) {
event.setDamage(0);
event.setCancelled(true);
}
}
}

View file

@ -0,0 +1,208 @@
package com.projectkorra.ProjectKorra.airbending;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import com.projectkorra.ProjectKorra.Methods;
import com.projectkorra.ProjectKorra.ProjectKorra;
import com.projectkorra.ProjectKorra.Ability.AvatarState;
public class AirBurst {
private static ConcurrentHashMap<Player, AirBurst> instances = new ConcurrentHashMap<Player, AirBurst>();
private static ConcurrentHashMap<String, Long> cooldowns = new ConcurrentHashMap<String, Long>();
private static double threshold = 10;
private static double pushfactor = 1.5;
private static double deltheta = 10;
private static double delphi = 10;
private Player player;
private long starttime;
private long chargetime = 1750;
private boolean charged = false;
private ArrayList<Entity> affectedentities = new ArrayList<Entity>();
public AirBurst(Player player) {
if (cooldowns.containsKey(player.getName())) {
if (cooldowns.get(player.getName()) + ProjectKorra.plugin.getConfig().getLong("Properties.GlobalCooldown") >= System.currentTimeMillis()) {
return;
} else {
cooldowns.remove(player.getName());
}
}
if (instances.containsKey(player))
return;
starttime = System.currentTimeMillis();
if (AvatarState.isAvatarState(player))
chargetime = 0;
this.player = player;
instances.put(player, this);
}
public AirBurst() {
}
public static void coneBurst(Player player) {
if (instances.containsKey(player))
instances.get(player).coneBurst();
}
private void coneBurst() {
if (charged) {
Location location = player.getEyeLocation();
Vector vector = location.getDirection();
double angle = Math.toRadians(30);
double x, y, z;
double r = 1;
for (double theta = 0; theta <= 180; theta += deltheta) {
double dphi = delphi / Math.sin(Math.toRadians(theta));
for (double phi = 0; phi < 360; phi += dphi) {
double rphi = Math.toRadians(phi);
double rtheta = Math.toRadians(theta);
x = r * Math.cos(rphi) * Math.sin(rtheta);
y = r * Math.sin(rphi) * Math.sin(rtheta);
z = r * Math.cos(rtheta);
Vector direction = new Vector(x, z, y);
if (direction.angle(vector) <= angle) {
// Methods.verbose(direction.angle(vector));
// Methods.verbose(direction);
new AirBlast(location, direction.normalize(), player,
pushfactor, this);
}
}
}
}
// Methods.verbose("--" + AirBlast.instances.size() + "--");
instances.remove(player);
}
private void sphereBurst() {
if (charged) {
Location location = player.getEyeLocation();
double x, y, z;
double r = 1;
for (double theta = 0; theta <= 180; theta += deltheta) {
double dphi = delphi / Math.sin(Math.toRadians(theta));
for (double phi = 0; phi < 360; phi += dphi) {
double rphi = Math.toRadians(phi);
double rtheta = Math.toRadians(theta);
x = r * Math.cos(rphi) * Math.sin(rtheta);
y = r * Math.sin(rphi) * Math.sin(rtheta);
z = r * Math.cos(rtheta);
Vector direction = new Vector(x, z, y);
new AirBlast(location, direction.normalize(), player,
pushfactor, this);
}
}
}
// Methods.verbose("--" + AirBlast.instances.size() + "--");
instances.remove(player);
}
public static void fallBurst(Player player) {
if (!Methods.canBend(player.getName(), "AirBurst")) {
return;
}
if (player.getFallDistance() < threshold) {
return;
}
if (Methods.getBoundAbility(player) == null) {
return;
}
if (instances.containsKey(player)) {
return;
}
if (!Methods.getBoundAbility(player).equalsIgnoreCase("AirBurst")) {
return;
}
Location location = player.getLocation();
double x, y, z;
double r = 1;
for (double theta = 75; theta < 105; theta += deltheta) {
double dphi = delphi / Math.sin(Math.toRadians(theta));
for (double phi = 0; phi < 360; phi += dphi) {
double rphi = Math.toRadians(phi);
double rtheta = Math.toRadians(theta);
x = r * Math.cos(rphi) * Math.sin(rtheta);
y = r * Math.sin(rphi) * Math.sin(rtheta);
z = r * Math.cos(rtheta);
Vector direction = new Vector(x, z, y);
new AirBlast(location, direction.normalize(), player,
pushfactor, new AirBurst());
}
}
}
void addAffectedEntity(Entity entity) {
affectedentities.add(entity);
}
boolean isAffectedEntity(Entity entity) {
return affectedentities.contains(entity);
}
private void progress() {
if (!Methods.canBend(player.getName(), "AirBurst")) {
instances.remove(player);
return;
}
if (Methods.getBoundAbility(player) == null) {
instances.remove(player);
return;
}
if (!Methods.getBoundAbility(player).equalsIgnoreCase("AirBurst")) {
instances.remove(player);
return;
}
if (System.currentTimeMillis() > starttime + chargetime && !charged) {
charged = true;
}
if (!player.isSneaking()) {
if (charged) {
sphereBurst();
} else {
instances.remove(player);
}
} else if (charged) {
Location location = player.getEyeLocation();
// location = location.add(location.getDirection().normalize());
location.getWorld().playEffect(
location,
Effect.SMOKE,
Methods.getIntCardinalDirection(player.getEyeLocation()
.getDirection()), 3);
}
}
public static void progressAll() {
for (Player player : instances.keySet())
instances.get(player).progress();
}
public static String getDescription() {
return "AirBurst is one of the most powerful abilities in the airbender's arsenal. "
+ "To use, press and hold sneak to charge your burst. "
+ "Once charged, you can either release sneak to launch a cone-shaped burst "
+ "of air in front of you, or click to release the burst in a sphere around you. "
+ "Additionally, having this ability selected when you land on the ground from a "
+ "large enough fall will create a burst of air around you.";
}
public static void removeAll() {
instances.clear();
}
}