diff --git a/src/com/projectkorra/ProjectKorra/Ability/AbilityModuleManager.java b/src/com/projectkorra/ProjectKorra/Ability/AbilityModuleManager.java index 65e3cf48..364c03a7 100644 --- a/src/com/projectkorra/ProjectKorra/Ability/AbilityModuleManager.java +++ b/src/com/projectkorra/ProjectKorra/Ability/AbilityModuleManager.java @@ -90,6 +90,7 @@ public class AbilityModuleManager { if (a == StockAbilities.Torrent) shiftabilities.add(a.name()); if (a == StockAbilities.WaterManipulation) shiftabilities.add(a.name()); if (a == StockAbilities.IceSpike) shiftabilities.add(a.name()); + if (a == StockAbilities.WaterWave) shiftabilities.add(a.name()); } } else if (StockAbilities.isEarthbending(a)) { diff --git a/src/com/projectkorra/ProjectKorra/Ability/StockAbilities.java b/src/com/projectkorra/ProjectKorra/Ability/StockAbilities.java index d4238b39..51240f78 100644 --- a/src/com/projectkorra/ProjectKorra/Ability/StockAbilities.java +++ b/src/com/projectkorra/ProjectKorra/Ability/StockAbilities.java @@ -18,14 +18,14 @@ public enum StockAbilities { AvatarState, // Project Korra - Extraction, Smokescreen, Combustion, LavaSurge, LavaFlow, Suffocate; + Extraction, Smokescreen, Combustion, LavaSurge, LavaFlow, Suffocate, WaterWave; private enum AirbendingAbilities { AirBlast, AirBubble, AirShield, AirSuction, AirSwipe, Tornado, AirScooter, AirSpout, AirBurst, Suffocate; } private enum WaterbendingAbilities { - WaterBubble, PhaseChange, HealingWaters, WaterManipulation, Surge, Bloodbending, WaterSpout, IceSpike, OctopusForm, Torrent; + WaterBubble, PhaseChange, HealingWaters, WaterManipulation, Surge, Bloodbending, WaterSpout, IceSpike, OctopusForm, Torrent, WaterWave; } private enum EarthbendingAbilities { diff --git a/src/com/projectkorra/ProjectKorra/PKListener.java b/src/com/projectkorra/ProjectKorra/PKListener.java index 8f11ed4d..f3b627f8 100644 --- a/src/com/projectkorra/ProjectKorra/PKListener.java +++ b/src/com/projectkorra/ProjectKorra/PKListener.java @@ -119,6 +119,7 @@ import com.projectkorra.ProjectKorra.waterbending.WaterManipulation; import com.projectkorra.ProjectKorra.waterbending.WaterPassive; import com.projectkorra.ProjectKorra.waterbending.WaterSpout; import com.projectkorra.ProjectKorra.waterbending.WaterWall; +import com.projectkorra.ProjectKorra.waterbending.WaterWave; import com.projectkorra.ProjectKorra.waterbending.Wave; public class PKListener implements Listener { @@ -401,6 +402,9 @@ public class PKListener implements Listener { if (abil.equalsIgnoreCase("Torrent")) { Torrent.create(player); } + if (abil.equalsIgnoreCase("WaterWave")) { + new WaterWave(player, WaterWave.AbilityType.SHIFT); + } } if (Methods.isEarthAbility(abil)) { @@ -730,6 +734,9 @@ public class PKListener implements Listener { if (abil.equalsIgnoreCase("Torrent")) { new Torrent(player); } + if (abil.equalsIgnoreCase("WaterWave")) { + new WaterWave(player, WaterWave.AbilityType.CLICK); + } } if (Methods.isEarthAbility(abil)) { @@ -956,7 +963,8 @@ public class PKListener implements Listener { Player player = event.getPlayer(); if (WaterWall.wasBrokenFor(player, block) || OctopusForm.wasBrokenFor(player, block) - || Torrent.wasBrokenFor(player, block)) { + || Torrent.wasBrokenFor(player, block) + || WaterWave.wasBrokenFor(player, block)){ event.setCancelled(true); return; } diff --git a/src/com/projectkorra/ProjectKorra/waterbending/WaterWave.java b/src/com/projectkorra/ProjectKorra/waterbending/WaterWave.java new file mode 100644 index 00000000..e7076a63 --- /dev/null +++ b/src/com/projectkorra/ProjectKorra/waterbending/WaterWave.java @@ -0,0 +1,326 @@ +package com.projectkorra.ProjectKorra.waterbending; + +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.concurrent.ConcurrentHashMap; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.util.Vector; + +import com.projectkorra.ProjectKorra.Methods; +import com.projectkorra.ProjectKorra.ProjectKorra; +import com.projectkorra.ProjectKorra.TempBlock; +import com.projectkorra.ProjectKorra.Ability.AvatarState; + +public class WaterWave +{ + public static enum AbilityType{ + CLICK, SHIFT, RELEASE + } + public static enum AnimateState{ + RISE, TOWARDPLAYER, CIRCLE, SHRINK + } + public static ArrayList instances = new ArrayList(); + + public static boolean ICE_ONLY = false; + public static double RANGE = ProjectKorra.plugin.getConfig().getDouble("Abilities.Water.WaterWave.Range"); + public static double MAX_SPEED = ProjectKorra.plugin.getConfig().getDouble("Abilities.Water.WaterWave.Speed"); + public static long CHARGE_TIME = ProjectKorra.plugin.getConfig().getLong("Abilities.Water.WaterWave.ChargeTime"); + public static long FLIGHT_TIME = ProjectKorra.plugin.getConfig().getLong("Abilities.Water.WaterWave.FlightTime"); + + private Player player; + private long time; + private AbilityType type; + private Location origin, currentLoc; + private Vector direction; + private double radius = 3.8; + private boolean charging = false; + private AnimateState anim; + private ConcurrentHashMap affectedBlocks = new ConcurrentHashMap(); + + public WaterWave(Player player, AbilityType type) + { + this.player = player; + this.time = System.currentTimeMillis(); + this.type = type; + instances.add(this); + + if(type == AbilityType.CLICK) + this.progress(); + } + public void progress() + { + if (player.isDead() || !player.isOnline()) { + remove(); + return; + } + if(type != AbilityType.RELEASE) + { + if(!Methods.canBend(player.getName(), "WaterWave")){ + remove(); + return; + } + String ability = Methods.getBoundAbility(player); + if(ability == null || !ability.equalsIgnoreCase("WaterWave")){ + remove(); + return; + } + } + + if(type == AbilityType.CLICK) + { + if(origin == null) + { + removeType(player, AbilityType.CLICK); + instances.add(this); + + Block block = Methods.getWaterSourceBlock(player, RANGE, Methods.canPlantbend(player)); + if(block == null || block.getLocation().clone().add(0,1,0).getBlock().getType() != Material.AIR){ + remove(); + return; + } + origin = block.getLocation(); + + if(!Methods.isWaterbendable(block, player) || Methods.isRegionProtectedFromBuild(player, "WaterWave", origin)){ + remove(); + return; + } + if(ICE_ONLY && !(block.getType() == Material.ICE || block.getType() == Material.SNOW || block.getType() == Material.PACKED_ICE)) + { + remove(); + return; + } + } + if(player.getLocation().distance(origin) > RANGE){ + remove(); + return; + } + Methods.playFocusWaterEffect(origin.getBlock()); + } + else if(type == AbilityType.SHIFT) + { + if(!charging) + { + if(!containsType(player, AbilityType.CLICK)){ + removeType(player, AbilityType.CLICK); + remove(); + return; + } + charging = true; + anim = AnimateState.RISE; + + WaterWave clickSpear = getType(player, AbilityType.CLICK).get(0); + origin = clickSpear.origin.clone(); + currentLoc = origin.clone(); + if(Methods.isPlant(origin.getBlock())) + new Plantbending(origin.getBlock()); + else + Methods.addTempAirBlock(origin.getBlock()); + + } + + removeType(player, AbilityType.CLICK); + if(!player.isSneaking()){ + if(System.currentTimeMillis() - time > CHARGE_TIME) + { + WaterWave wwave = new WaterWave(player, AbilityType.RELEASE); + wwave.anim = AnimateState.SHRINK; + wwave.direction = direction; + } + remove(); + return; + } + + double animSpeed = 1.2; + if(anim == AnimateState.RISE){ + revertBlocks(); + currentLoc.add(0,animSpeed,0); + Block block = currentLoc.getBlock(); + if(block.getType() != Material.AIR || Methods.isRegionProtectedFromBuild(player, "WaterWave", block.getLocation())){ + remove(); + return; + } + createBlock(block, Material.STATIONARY_WATER); + if(currentLoc.distance(origin) > 2) + anim = AnimateState.TOWARDPLAYER; + } + else if(anim == AnimateState.TOWARDPLAYER) + { + revertBlocks(); + Location eyeLoc = player.getTargetBlock(null, 2).getLocation(); + eyeLoc.setY(player.getEyeLocation().getY()); + Vector vec = Methods.getDirection(currentLoc, eyeLoc); + currentLoc.add(vec.normalize().multiply(animSpeed)); + + Block block = currentLoc.getBlock(); + if(block.getType() != Material.AIR || Methods.isRegionProtectedFromBuild(player, "WaterWave", block.getLocation())){ + remove(); + return; + } + + createBlock(block, Material.STATIONARY_WATER); + if(currentLoc.distance(eyeLoc) < 1.3) + { + anim = AnimateState.CIRCLE; + Vector tempDir = player.getLocation().getDirection(); + tempDir.setY(0); + direction = tempDir.normalize(); + revertBlocks(); + } + } + else if(anim == AnimateState.CIRCLE) + { + drawCircle(120,5); + } + } + else if(type == AbilityType.RELEASE) + { + if(anim == AnimateState.SHRINK) + { + radius-=0.20; + drawCircle(360,15); + if(radius < 1){ + revertBlocks(); + time = System.currentTimeMillis(); + anim = null; + } + } + else + { + if((System.currentTimeMillis() - time > FLIGHT_TIME && !AvatarState.isAvatarState(player)) + || player.isSneaking()) + { + remove(); + return; + } + double currentSpeed = MAX_SPEED - (MAX_SPEED * (double)(System.currentTimeMillis() - time) / (double)FLIGHT_TIME); + double nightSpeed = Methods.waterbendingNightAugment(currentSpeed * 0.9, player.getWorld()); + currentSpeed = nightSpeed > currentSpeed ? nightSpeed : currentSpeed; + if(AvatarState.isAvatarState(player)) + currentSpeed = Methods.waterbendingNightAugment(MAX_SPEED, player.getWorld()); + + player.setVelocity(player.getEyeLocation().getDirection().normalize().multiply(currentSpeed)); + for(Block block : Methods.getBlocksAroundPoint(player.getLocation().add(0,-1,0), 1.5)) + if(block.getType() == Material.AIR && !Methods.isRegionProtectedFromBuild(player, "WaterWave", block.getLocation())) + createBlock(block,Material.STATIONARY_WATER,(byte)0); + revertBlocksDelay(20L); + } + } + } + public void drawCircle(double theta, double increment) + { + double rotateSpeed = 45; + revertBlocks(); + direction = rotateXZ(direction, rotateSpeed); + for(double i = 0; i < theta; i+=increment) + { + Vector dir = rotateXZ(direction, i - theta / 2).normalize().multiply(radius); + dir.setY(0); + Block block = player.getEyeLocation().add(dir).getBlock(); + currentLoc = block.getLocation(); + if(block.getType() == Material.AIR && !Methods.isRegionProtectedFromBuild(player, "WaterWave", block.getLocation())) + createBlock(block,Material.STATIONARY_WATER,(byte)8); + } + } + public void remove() + { + instances.remove(this); + revertBlocks(); + } + public void createBlock(Block block, Material mat){ + createBlock(block,mat,(byte)0); + } + public void createBlock(Block block, Material mat, byte data){ + affectedBlocks.put(block, new TempBlock(block, mat, data)); + } + public void revertBlocks() + { + Enumeration keys = affectedBlocks.keys(); + while(keys.hasMoreElements()) + { + Block block = keys.nextElement(); + affectedBlocks.get(block).revertBlock(); + affectedBlocks.remove(block); + } + } + public void revertBlocksDelay(long delay) + { + Enumeration keys = affectedBlocks.keys(); + while(keys.hasMoreElements()) + { + final Block block = keys.nextElement(); + final TempBlock tblock = affectedBlocks.get(block); + affectedBlocks.remove(block); + new BukkitRunnable(){ + public void run() + { + tblock.revertBlock(); + } + }.runTaskLater(ProjectKorra.plugin, delay); + } + } + public static void progressAll() + { + //Bukkit.broadcastMessage("Instances:" + instances.size()); + for(int i = 0; i < instances.size(); i++) + instances.get(i).progress(); + } + public static void removeAll() + { + for(int i = 0; i < instances.size(); i++){ + instances.get(i).remove(); + i--; + } + } + public static boolean containsType(Player player, AbilityType type) + { + for(int i = 0; i < instances.size(); i++){ + WaterWave spear = instances.get(i); + if(spear.player.equals(player) && spear.type.equals(type)) + return true; + } + return false; + } + public static void removeType(Player player, AbilityType type) + { + for(int i = 0; i < instances.size(); i++){ + WaterWave spear = instances.get(i); + if(spear.player.equals(player) && spear.type.equals(type)){ + instances.remove(i); + i--; + } + } + } + public static ArrayList getType(Player player, AbilityType type) + { + ArrayList list = new ArrayList(); + for(WaterWave spear : instances){ + if(spear.player.equals(player) && spear.type.equals(type)) + list.add(spear); + } + return list; + } + public static boolean wasBrokenFor(Player player, Block block) { + if (containsType(player,AbilityType.CLICK)) { + WaterWave wwave = getType(player,AbilityType.CLICK).get(0); + if (wwave.origin == null) + return false; + if (wwave.origin.getBlock().equals(block)) + return true; + } + return false; + } + public static Vector rotateXZ(Vector vec, double theta) + { + Vector vec2 = vec.clone(); + double x = vec2.getX(); + double z = vec2.getZ(); + vec2.setX(x * Math.cos(Math.toRadians(theta)) - z * Math.sin(Math.toRadians(theta))); + vec2.setZ(x * Math.sin(Math.toRadians(theta)) + z * Math.cos(Math.toRadians(theta))); + return vec2; + } +} diff --git a/src/com/projectkorra/ProjectKorra/waterbending/WaterbendingManager.java b/src/com/projectkorra/ProjectKorra/waterbending/WaterbendingManager.java index cd5316ab..e5b51470 100644 --- a/src/com/projectkorra/ProjectKorra/waterbending/WaterbendingManager.java +++ b/src/com/projectkorra/ProjectKorra/waterbending/WaterbendingManager.java @@ -29,6 +29,7 @@ public class WaterbendingManager implements Runnable { Wave.progressAll(); IceSpike.progressAll(); IceSpike2.progressAll(); + WaterWave.progressAll(); } } diff --git a/src/config.yml b/src/config.yml index a9a4a3c6..4fa6774a 100644 --- a/src/config.yml +++ b/src/config.yml @@ -220,6 +220,13 @@ Abilities: Enabled: true Description: "To use this ability, click while over or in water. You will spout water up from beneath you to experience controlled levitation. This ability is a toggle, so you can activate it then use other abilities and it will remain on. If you try to spout over an area with no water, snow, or ice, the spout will dissipate and you will fall. Click again with this ability selected to deactivate it." Height: 20 + WaterWave: + Enabled: true + Description: "WaterWave provides a waterbender with extreme mobility and transportation. To use, first click a source block to select it; then hold sneak (Default: Shift) to begin streaming the water around you. While the water is streaming around you let go of sneak and the water will form underneath your feet, blasting you off into the direction that you are facing. Press shift while riding the wave to stop it." + Range: 6 + ChargeTime: 1000 + FlightTime: 2000 + Speed: 1.2 Earth: Passive: Duration: 2500 diff --git a/src/plugin.yml b/src/plugin.yml index fe1396f2..5d4cdbd3 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -70,6 +70,7 @@ permissions: bending.ability.WaterManipulation: true bending.ability.WaterSpout: true bending.ability.Plantbending: true + bending.ability.WaterWave: true bending.message.nightmessage: true bending.water.passive: true bending.earth: