From 675200ccd1312aedea67e566688154b14b60a63a Mon Sep 17 00:00:00 2001 From: Brendan Wilson Date: Thu, 5 Feb 2015 17:38:21 -0500 Subject: [PATCH] Modified the HorizontalCollision damage calculation. Instead of solely relying on delta velocity, the equation now incorporates a configurable minimum distance to give damage and also gives the distance travelled a say. --- .gitignore | 7 ++++- .../ProjectKorra/ConfigManager.java | 1 + .../Objects/HorizontalVelocityTracker.java | 14 ++++++--- .../projectkorra/ProjectKorra/PKListener.java | 9 +++--- .../HorizontalVelocityChangeEvent.java | 30 +++++++++++++++++++ 5 files changed, 51 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 896e76f6..9cf427c9 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,9 @@ Icon .Trashes bin/ -*.classpath \ No newline at end of file +*.classpath +.idea/.name +*.xml +*.class +*.class +ProjectKorra.iml \ No newline at end of file diff --git a/src/com/projectkorra/ProjectKorra/ConfigManager.java b/src/com/projectkorra/ProjectKorra/ConfigManager.java index dafee7f2..a63a346a 100644 --- a/src/com/projectkorra/ProjectKorra/ConfigManager.java +++ b/src/com/projectkorra/ProjectKorra/ConfigManager.java @@ -65,6 +65,7 @@ public class ConfigManager { config.addDefault("Properties.BendingAffectFallingSand.TNTStrengthMultiplier", 1.0); config.addDefault("Properties.GlobalCooldown", 500); config.addDefault("Properties.SeaLevel", 62); + config.addDefault("Properties.HorizontalCollisionPhysics.WallDamageMinimumDistance", 5.0); config.addDefault("Properties.CustomItems.GrapplingHook.Enable", true); config.addDefault("Properties.CustomItems.GrapplingHook.IronUses", 25); diff --git a/src/com/projectkorra/ProjectKorra/Objects/HorizontalVelocityTracker.java b/src/com/projectkorra/ProjectKorra/Objects/HorizontalVelocityTracker.java index 2e0dc373..05917b77 100644 --- a/src/com/projectkorra/ProjectKorra/Objects/HorizontalVelocityTracker.java +++ b/src/com/projectkorra/ProjectKorra/Objects/HorizontalVelocityTracker.java @@ -3,6 +3,7 @@ package com.projectkorra.ProjectKorra.Objects; import com.projectkorra.ProjectKorra.Methods; import com.projectkorra.ProjectKorra.ProjectKorra; import com.projectkorra.ProjectKorra.Utilities.HorizontalVelocityChangeEvent; +import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -24,6 +25,8 @@ public class HorizontalVelocityTracker private Player instigator; private Vector lastVelocity; private Vector thisVelocity; + private Location launchLocation; + private Location impactLocation; public HorizontalVelocityTracker(Entity e, Player instigator, long delay) { @@ -31,7 +34,9 @@ public class HorizontalVelocityTracker this.instigator = instigator; fireTime = System.currentTimeMillis(); this.delay = delay; - thisVelocity = e.getVelocity(); + thisVelocity = e.getVelocity().clone(); + launchLocation = e.getLocation().clone(); + impactLocation = launchLocation.clone(); this.delay = delay; update(); instances.put(entity, this); @@ -69,11 +74,12 @@ public class HorizontalVelocityTracker if((diff.getX() > 1 || diff.getX() < -1) || (diff.getZ() > 1 || diff.getZ() < -1)) { - for(Block b : blocks) + impactLocation = entity.getLocation(); + for (Block b : blocks) { - if(!Methods.isTransparentToEarthbending(instigator, b)) + if (!Methods.isTransparentToEarthbending(instigator, b)) { - ProjectKorra.plugin.getServer().getPluginManager().callEvent(new HorizontalVelocityChangeEvent(entity, instigator, lastVelocity, thisVelocity, diff)); + ProjectKorra.plugin.getServer().getPluginManager().callEvent(new HorizontalVelocityChangeEvent(entity, instigator, lastVelocity, thisVelocity, diff, launchLocation, impactLocation)); remove(); return; } diff --git a/src/com/projectkorra/ProjectKorra/PKListener.java b/src/com/projectkorra/ProjectKorra/PKListener.java index fea38e14..57b631e6 100644 --- a/src/com/projectkorra/ProjectKorra/PKListener.java +++ b/src/com/projectkorra/ProjectKorra/PKListener.java @@ -13,10 +13,7 @@ import com.projectkorra.ProjectKorra.earthbending.LavaFlow.AbilityType; import com.projectkorra.ProjectKorra.firebending.*; import com.projectkorra.ProjectKorra.firebending.Fireball; import com.projectkorra.ProjectKorra.waterbending.*; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.*; import org.bukkit.event.EventHandler; @@ -71,7 +68,9 @@ public class PKListener implements Listener { { if(e.getEntity().getEntityId() != e.getInstigator().getEntityId()) { - Methods.damageEntity(e.getInstigator(), e.getEntity(), e.getDifference().length() * 2); + double minimumDistance = plugin.getConfig().getDouble("Properties.HorizontalCollisionPhysics.WallDamageMinimumDistance"); + double damage = ((e.getDistanceTravelled() - minimumDistance) < 0 ? 0 : e.getDistanceTravelled() - minimumDistance) / (e.getDifference().length()); + Methods.damageEntity(e.getInstigator(), e.getEntity(), damage); } } } diff --git a/src/com/projectkorra/ProjectKorra/Utilities/HorizontalVelocityChangeEvent.java b/src/com/projectkorra/ProjectKorra/Utilities/HorizontalVelocityChangeEvent.java index 61de98d8..d3aa8d97 100644 --- a/src/com/projectkorra/ProjectKorra/Utilities/HorizontalVelocityChangeEvent.java +++ b/src/com/projectkorra/ProjectKorra/Utilities/HorizontalVelocityChangeEvent.java @@ -1,5 +1,6 @@ package com.projectkorra.ProjectKorra.Utilities; +import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; @@ -21,7 +22,10 @@ public class HorizontalVelocityChangeEvent extends Event implements Cancellable private Vector from; private Vector to; private Vector difference; + private Location start; + private Location end; + @Deprecated public HorizontalVelocityChangeEvent(Entity entity, Player instigator, Vector from, Vector to, Vector difference) { this.entity = entity; @@ -31,6 +35,17 @@ public class HorizontalVelocityChangeEvent extends Event implements Cancellable this.difference = difference; } + public HorizontalVelocityChangeEvent(Entity entity, Player instigator, Vector from, Vector to, Vector difference, Location start, Location end) + { + this.entity = entity; + this.instigator = instigator; + this.from = from; + this.to = to; + this.difference = difference; + this.start = start; + this.end = end; + } + public Entity getEntity() { return entity; @@ -51,6 +66,21 @@ public class HorizontalVelocityChangeEvent extends Event implements Cancellable return to; } + public Location getStartPoint() + { + return start; + } + + public Location getEndPoint() + { + return end; + } + + public double getDistanceTravelled() + { + return start.distance(end); + } + public Vector getDifference() { return difference;