From 3db97a4c75d89416761c4172626aab83950ca582 Mon Sep 17 00:00:00 2001 From: MistPhizzle Date: Thu, 26 Jun 2014 22:35:36 -0400 Subject: [PATCH] EarthTunnel --- .../ProjectKorra/BendingManager.java | 4 + .../ProjectKorra/ConfigManager.java | 8 ++ .../projectkorra/ProjectKorra/PKListener.java | 4 + .../earthbending/EarthTunnel.java | 124 ++++++++++++++++++ src/config.yml | 8 ++ 5 files changed, 148 insertions(+) create mode 100644 src/com/projectkorra/ProjectKorra/earthbending/EarthTunnel.java diff --git a/src/com/projectkorra/ProjectKorra/BendingManager.java b/src/com/projectkorra/ProjectKorra/BendingManager.java index 2e10a15e..8d178131 100644 --- a/src/com/projectkorra/ProjectKorra/BendingManager.java +++ b/src/com/projectkorra/ProjectKorra/BendingManager.java @@ -29,6 +29,7 @@ import com.projectkorra.ProjectKorra.earthbending.EarthArmor; import com.projectkorra.ProjectKorra.earthbending.EarthBlast; import com.projectkorra.ProjectKorra.earthbending.EarthColumn; import com.projectkorra.ProjectKorra.earthbending.EarthPassive; +import com.projectkorra.ProjectKorra.earthbending.EarthTunnel; import com.projectkorra.ProjectKorra.earthbending.Shockwave; import com.projectkorra.ProjectKorra.firebending.Cook; import com.projectkorra.ProjectKorra.firebending.FireBlast; @@ -106,6 +107,9 @@ public class BendingManager implements Runnable { AirSuction.progressAll(); Fireball.progressAll(); HealingWaters.heal(Bukkit.getServer()); + for (Player player : EarthTunnel.instances.keySet()) { + EarthTunnel.progress(player); + } for (Player player : EarthArmor.instances.keySet()) { EarthArmor.moveArmor(player); } diff --git a/src/com/projectkorra/ProjectKorra/ConfigManager.java b/src/com/projectkorra/ProjectKorra/ConfigManager.java index 548f3961..a8944fc3 100644 --- a/src/com/projectkorra/ProjectKorra/ConfigManager.java +++ b/src/com/projectkorra/ProjectKorra/ConfigManager.java @@ -280,6 +280,14 @@ public class ConfigManager { + "This ability will erect a circle of earth to trap the creature in."); config.addDefault("Abilities.Earth.EarthGrab.Range", 15); + config.addDefault("Abilities.Earth.EarthTunnel.Enabled", true); + config.addDefault("Abilities.Earth.EarthTunnel.Description", "Earth Tunnel is a completely utility ability for earthbenders. To use, simply sneak (default: shift) in the direction you want to tunnel. You will slowly begin tunneling in the direction you're facing for as long as you sneak or if the tunnel has been dug long enough. This ability will be interrupted if it hits a block that cannot be earthbent."); + config.addDefault("Abilities.Earth.EarthTunnel.MaxRadius", 1); + config.addDefault("Abilities.Earth.EarthTunnel.Range", 10); + config.addDefault("Abilities.Earth.EarthTunnel.Radius", 0.25); + config.addDefault("Abilities.Earth.EarthTunnel.Revert", true); + config.addDefault("Abilities.Earth.EarthTunnel.Interval", 30); + config.addDefault("Abilities.Earth.RaiseEarth.Enabled", true); config.addDefault("Abilities.Earth.RaiseEarth.Description", "To use, simply left-click on an earthbendable block. " + "A column of earth will shoot upwards from that location. " diff --git a/src/com/projectkorra/ProjectKorra/PKListener.java b/src/com/projectkorra/ProjectKorra/PKListener.java index dce1dd39..5319c6a1 100644 --- a/src/com/projectkorra/ProjectKorra/PKListener.java +++ b/src/com/projectkorra/ProjectKorra/PKListener.java @@ -68,6 +68,7 @@ import com.projectkorra.ProjectKorra.earthbending.EarthBlast; import com.projectkorra.ProjectKorra.earthbending.EarthColumn; import com.projectkorra.ProjectKorra.earthbending.EarthGrab; import com.projectkorra.ProjectKorra.earthbending.EarthPassive; +import com.projectkorra.ProjectKorra.earthbending.EarthTunnel; import com.projectkorra.ProjectKorra.earthbending.EarthWall; import com.projectkorra.ProjectKorra.earthbending.Shockwave; import com.projectkorra.ProjectKorra.firebending.Cook; @@ -252,6 +253,9 @@ public class PKListener implements Listener { if (abil.equalsIgnoreCase("EarthGrab")) { EarthGrab.EarthGrabSelf(player); } + if (abil.equalsIgnoreCase("EarthTunnel")) { + new EarthTunnel(player); + } } if (Methods.isFireAbility(abil)) { diff --git a/src/com/projectkorra/ProjectKorra/earthbending/EarthTunnel.java b/src/com/projectkorra/ProjectKorra/earthbending/EarthTunnel.java new file mode 100644 index 00000000..9c2c9fc1 --- /dev/null +++ b/src/com/projectkorra/ProjectKorra/earthbending/EarthTunnel.java @@ -0,0 +1,124 @@ +package com.projectkorra.ProjectKorra.earthbending; + +import java.util.concurrent.ConcurrentHashMap; + +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import com.projectkorra.ProjectKorra.Methods; +import com.projectkorra.ProjectKorra.ProjectKorra; + +public class EarthTunnel { + + public static ConcurrentHashMap instances = new ConcurrentHashMap(); + + private static final double maxradius = ProjectKorra.plugin.getConfig().getDouble("Abilities.Earth.EarthTunnel.MaxRadius"); + private static final double range = ProjectKorra.plugin.getConfig().getDouble("Abilities.Earth.EarthTunnel.Range"); + private static final double radiusinc = ProjectKorra.plugin.getConfig().getDouble("Abilities.Earth.EarthTunnel.Radius"); + // private static final double speed = 10; + + private static boolean revert = ProjectKorra.plugin.getConfig().getBoolean("Abilities.Earth.EarthTunnel.Revert"); + + private static final long interval = ProjectKorra.plugin.getConfig().getLong("Abilities.Earth.EarthTunnel.Interval"); + + private Player player; + private Block block; + private Location origin, location; + private Vector direction; + private double depth, radius, angle; + private long time; + + public EarthTunnel(Player player) { + this.player = player; + location = player.getEyeLocation().clone(); + origin = player.getTargetBlock(null, (int) range).getLocation(); + block = origin.getBlock(); + direction = location.getDirection().clone().normalize(); + depth = origin.distance(location) - 1; + if (depth < 0) + depth = 0; + angle = 0; + radius = radiusinc; + // ortho = new Vector(direction.getY(), -direction.getX(), + // 0).normalize(); + // Methods.verbose(ortho.clone().dot(direction)); + time = System.currentTimeMillis(); + + instances.put(player, this); + } + + public boolean progress() { + if (player.isDead() || !player.isOnline()) { + instances.remove(player); + return false; + } + if (System.currentTimeMillis() - time >= interval) { + time = System.currentTimeMillis(); + // Methods.verbose("progressing"); + if (Math.abs(Math.toDegrees(player.getEyeLocation().getDirection() + .angle(direction))) > 20 + || !player.isSneaking()) { + instances.remove(player); + return false; + } else { + while (!Methods.isEarthbendable(player, block)) { + // Methods.verbose("going"); + if (!Methods.isTransparentToEarthbending(player, block)) { + // Methods.verbose("false! at" + angle + " " + radius + + // " " + // + depth); + instances.remove(player); + return false; + } + if (angle >= 360) { + angle = 0; + if (radius >= maxradius) { + radius = radiusinc; + if (depth >= range) { + instances.remove(player); + return false; + } else { + depth += .5; + } + } else { + radius += radiusinc; + } + } else { + angle += 20; + } + // block.setType(Material.GLASS); + Vector vec = Methods.getOrthogonalVector(direction, angle, + radius); + block = location.clone() + .add(direction.clone().normalize().multiply(depth)) + .add(vec).getBlock(); + } + + if (revert) { + Methods.addTempAirBlock(block); + } else { + block.breakNaturally(); + } + + return true; + } + } else { + return false; + } + } + + public static boolean progress(Player player) { + return instances.get(player).progress(); + } + + public static String getDescription() { + return "Earth Tunnel is a completely utility ability for earthbenders. " + + "To use, simply sneak (default: shift) in the direction you want to tunnel. " + + "You will slowly begin tunneling in the direction you're facing for as long as you " + + "sneak or if the tunnel has been dug long enough. This ability will be interupted " + + "if it hits a block that cannot be earthbent."; + } + +} \ No newline at end of file diff --git a/src/config.yml b/src/config.yml index a57aecf6..2792dcb2 100644 --- a/src/config.yml +++ b/src/config.yml @@ -189,6 +189,14 @@ Abilities: Enabled: true Description: "To use, simply left-click while targeting a creature within range. This ability will erect a circle of earth to trap the creature in." Range: 15 + EarthTunnel: + Enabled: true + Description: "Earth Tunnel is a completely utility ability for earthbenders. To use, simply sneak (default: shift) in the direction you want to tunnel. You will slowly begin tunneling in the direction you're facing for as long as you sneak or if the tunnel has been dug long enough. This ability will be interrupted if it hits a block that cannot be earthbent." + MaxRadius: 1 + Range: 10 + Radius: 0.25 + Revert: true + Interval: 30 RaiseEarth: Enabled: true Description: "To use, simply left-click on an earthbendable block. A column of earth will shoot upwards from that location. Anything in the way of the column will be brought up with it, leaving talented benders the ability to trap brainless entities up there. Additionally, simply sneak (default shift) looking at an earthbendable block. A wall of earth will shoot upwards from that location. Anything in the way of the wall will be brought up with it."