mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-11 03:30:10 +00:00
Lightning
This commit is contained in:
parent
208842d02e
commit
d73bc4dea7
5 changed files with 268 additions and 28 deletions
|
@ -42,6 +42,7 @@ import com.projectkorra.ProjectKorra.firebending.FireShield;
|
|||
import com.projectkorra.ProjectKorra.firebending.FireStream;
|
||||
import com.projectkorra.ProjectKorra.firebending.Fireball;
|
||||
import com.projectkorra.ProjectKorra.firebending.Illumination;
|
||||
import com.projectkorra.ProjectKorra.firebending.Lightning;
|
||||
import com.projectkorra.ProjectKorra.waterbending.Bloodbending;
|
||||
import com.projectkorra.ProjectKorra.waterbending.FreezeMelt;
|
||||
import com.projectkorra.ProjectKorra.waterbending.HealingWaters;
|
||||
|
@ -113,6 +114,7 @@ public class BendingManager implements Runnable {
|
|||
HealingWaters.heal(Bukkit.getServer());
|
||||
FireBurst.progressAll();
|
||||
FireShield.progressAll();
|
||||
Lightning.progressAll();
|
||||
|
||||
for (Player p : RapidPunch.instance.keySet())
|
||||
RapidPunch.instance.get(p).startPunch(p);
|
||||
|
|
|
@ -400,6 +400,12 @@ public class ConfigManager {
|
|||
+ "dismisses this torch.");
|
||||
config.addDefault("Abilities.Fire.Illumination.Range", 5);
|
||||
|
||||
config.addDefault("Abilities.Fire.Lightning.Enabled", true);
|
||||
config.addDefault("Abilities.Fire.Lightning.Description", "Hold sneak while selecting this ability to charge up a lightning strike. Once charged, release sneak to discharge the lightning to the targeted location.");
|
||||
config.addDefault("Abilities.Fire.Lightning.Distance", 15);
|
||||
config.addDefault("Abilities.Fire.Lightning.Warmup", 3500);
|
||||
config.addDefault("Abilities.Fire.Lightning.MissChance", 10);
|
||||
|
||||
plugin.getConfig().addDefault("Abilities.Chi.Passive.FallReductionFactor", 0.5);
|
||||
plugin.getConfig().addDefault("Abilities.Chi.Passive.Speed", 1);
|
||||
plugin.getConfig().addDefault("Abilities.Chi.Passive.Jump", 2);
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
@ -19,6 +18,8 @@ import org.bukkit.event.block.BlockBreakEvent;
|
|||
import org.bukkit.event.block.BlockFadeEvent;
|
||||
import org.bukkit.event.block.BlockFormEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
|
@ -41,7 +42,6 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||
|
@ -88,6 +88,7 @@ import com.projectkorra.ProjectKorra.firebending.FireShield;
|
|||
import com.projectkorra.ProjectKorra.firebending.FireStream;
|
||||
import com.projectkorra.ProjectKorra.firebending.Fireball;
|
||||
import com.projectkorra.ProjectKorra.firebending.Illumination;
|
||||
import com.projectkorra.ProjectKorra.firebending.Lightning;
|
||||
import com.projectkorra.ProjectKorra.firebending.RingOfFire;
|
||||
import com.projectkorra.ProjectKorra.waterbending.Bloodbending;
|
||||
import com.projectkorra.ProjectKorra.waterbending.FreezeMelt;
|
||||
|
@ -162,26 +163,26 @@ public class PKListener implements Listener {
|
|||
} else if (Methods.isBender(player.getName(), Element.Chi) && chatEnabled) {
|
||||
append = plugin.getConfig().getString("Properties.Chat.Prefixes.Chi");
|
||||
}
|
||||
|
||||
|
||||
if (chatEnabled) {
|
||||
player.setDisplayName(append + player.getName());
|
||||
}
|
||||
|
||||
// List<Element> elements = Methods.getBendingPlayer(e.getPlayer().getName()).getElements();
|
||||
// if (plugin.getConfig().getBoolean("Properties.Chat.ChatPrefixes")) {
|
||||
// if (elements.size() > 1)
|
||||
// player.setDisplayName(plugin.getConfig().getString("Properties.Chat.AvatarPrefix") + player.getName());
|
||||
// else if (elements.get(0).equals(Element.Earth))
|
||||
// player.setDisplayName(plugin.getConfig().getString("Properties.Chat.EarthPrefix") + player.getName());
|
||||
// else if (elements.get(0).equals(Element.Air))
|
||||
// player.setDisplayName(plugin.getConfig().getString("Properties.Chat.AirPrefix") + player.getName());
|
||||
// else if (elements.get(0).equals(Element.Water))
|
||||
// player.setDisplayName(plugin.getConfig().getString("Properties.Chat.WaterPrefix") + player.getName());
|
||||
// else if (elements.get(0).equals(Element.Fire))
|
||||
// player.setDisplayName(plugin.getConfig().getString("Properties.Chat.FirePrefix") + player.getName());
|
||||
// else if (elements.get(0).equals(Element.Chi))
|
||||
// player.setDisplayName(plugin.getConfig().getString("Properties.Chat.ChiPrefix") + player.getName());
|
||||
// }
|
||||
|
||||
// List<Element> elements = Methods.getBendingPlayer(e.getPlayer().getName()).getElements();
|
||||
// if (plugin.getConfig().getBoolean("Properties.Chat.ChatPrefixes")) {
|
||||
// if (elements.size() > 1)
|
||||
// player.setDisplayName(plugin.getConfig().getString("Properties.Chat.AvatarPrefix") + player.getName());
|
||||
// else if (elements.get(0).equals(Element.Earth))
|
||||
// player.setDisplayName(plugin.getConfig().getString("Properties.Chat.EarthPrefix") + player.getName());
|
||||
// else if (elements.get(0).equals(Element.Air))
|
||||
// player.setDisplayName(plugin.getConfig().getString("Properties.Chat.AirPrefix") + player.getName());
|
||||
// else if (elements.get(0).equals(Element.Water))
|
||||
// player.setDisplayName(plugin.getConfig().getString("Properties.Chat.WaterPrefix") + player.getName());
|
||||
// else if (elements.get(0).equals(Element.Fire))
|
||||
// player.setDisplayName(plugin.getConfig().getString("Properties.Chat.FirePrefix") + player.getName());
|
||||
// else if (elements.get(0).equals(Element.Chi))
|
||||
// player.setDisplayName(plugin.getConfig().getString("Properties.Chat.ChiPrefix") + player.getName());
|
||||
// }
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -286,7 +287,7 @@ public class PKListener implements Listener {
|
|||
if (abil.equalsIgnoreCase("EarthTunnel")) {
|
||||
new EarthTunnel(player);
|
||||
}
|
||||
|
||||
|
||||
if (abil.equalsIgnoreCase("Tremorsense")) {
|
||||
Methods.getBendingPlayer(player.getName()).toggleTremorsense();
|
||||
}
|
||||
|
@ -312,6 +313,19 @@ public class PKListener implements Listener {
|
|||
if (abil.equalsIgnoreCase("FireShield")) {
|
||||
FireShield.shield(player);
|
||||
}
|
||||
if (abil.equalsIgnoreCase("Lightning")) {
|
||||
new Lightning(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
if (event.getCause() == IgniteCause.LIGHTNING) {
|
||||
if (Lightning.isNearbyChannel(event.getBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -553,11 +567,11 @@ public class PKListener implements Listener {
|
|||
if (abil.equalsIgnoreCase("EarthArmor")) {
|
||||
new EarthArmor(player);
|
||||
}
|
||||
|
||||
|
||||
if (abil.equalsIgnoreCase("EarthGrab")) {
|
||||
new EarthGrab(player);
|
||||
}
|
||||
|
||||
|
||||
if (abil.equalsIgnoreCase("Tremorsense")) {
|
||||
new Tremorsense(player);
|
||||
}
|
||||
|
@ -589,7 +603,7 @@ public class PKListener implements Listener {
|
|||
new FireShield(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (Methods.isChiAbility(abil)) {
|
||||
if (Methods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Chi.CanBendWithWeapons")) {
|
||||
return;
|
||||
|
@ -732,16 +746,16 @@ public class PKListener implements Listener {
|
|||
TempBlock.revertBlock(block, Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
if (!plugin.getConfig().getBoolean("Properties.Chat.Enable")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Player player = event.getPlayer();
|
||||
ChatColor color = ChatColor.WHITE;
|
||||
|
||||
|
||||
if (player.hasPermission("bending.avatar") || Methods.getBendingPlayer(player.getName()).elements.size() > 1) {
|
||||
color = ChatColor.valueOf(plugin.getConfig().getString("Properties.Chat.Colors.Avatar"));
|
||||
} else if (Methods.isBender(player.getName(), Element.Air)) {
|
||||
|
@ -755,16 +769,45 @@ public class PKListener implements Listener {
|
|||
} else if (Methods.isBender(player.getName(), Element.Chi)) {
|
||||
color = ChatColor.valueOf(plugin.getConfig().getString("Properties.Chat.Colors.Chi"));
|
||||
}
|
||||
|
||||
|
||||
String format = plugin.getConfig().getString("Properties.Chat.Format");
|
||||
format = format.replace("<message>", "%2$s");
|
||||
format = format.replace("<name>", color + player.getDisplayName() + ChatColor.RESET);
|
||||
event.setFormat(format);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDamageByPlayer(EntityDamageByEntityEvent e) {
|
||||
Entity source = e.getDamager();
|
||||
Entity entity = e.getEntity();
|
||||
Fireball fireball = Fireball.getFireball(source);
|
||||
Lightning lightning = Lightning.getLightning(source);
|
||||
|
||||
if (fireball != null) {
|
||||
e.setCancelled(true);
|
||||
fireball.dealDamage(entity);
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getCause() == DamageCause.LIGHTNING) {
|
||||
if (Lightning.isNearbyChannel(source.getLocation())) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (lightning != null) {
|
||||
e.setCancelled(true);
|
||||
lightning.dealDamage(entity);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Paralyze.isParalyzed(e.getDamager())) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Entity en = e.getEntity();
|
||||
if (en instanceof Player) {
|
||||
Player p = (Player) en; // This is the player getting hurt.
|
||||
|
|
183
src/com/projectkorra/ProjectKorra/firebending/Lightning.java
Normal file
183
src/com/projectkorra/ProjectKorra/firebending/Lightning.java
Normal file
|
@ -0,0 +1,183 @@
|
|||
package com.projectkorra.ProjectKorra.firebending;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LightningStrike;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.projectkorra.ProjectKorra.Methods;
|
||||
import com.projectkorra.ProjectKorra.ProjectKorra;
|
||||
import com.projectkorra.ProjectKorra.Ability.AvatarState;
|
||||
|
||||
public class Lightning {
|
||||
|
||||
public static int defaultdistance = ProjectKorra.plugin.getConfig().getInt("Abilities.Fire.Lightning.Distance");
|
||||
private static long defaultwarmup = ProjectKorra.plugin.getConfig().getLong("Abilities.Fire.Lightning.Warmup");
|
||||
private static double misschance = ProjectKorra.plugin.getConfig().getLong("Abilities.Fire.Lightning.MissChance");
|
||||
private static double threshold = 0.1;
|
||||
private static double blockdistance = 4;
|
||||
|
||||
private int maxdamage = 6;
|
||||
private double strikeradius = 4;
|
||||
|
||||
private Player player;
|
||||
private long starttime;
|
||||
private boolean charged = false;
|
||||
private LightningStrike strike = null;
|
||||
public static ConcurrentHashMap<Player, Lightning> instances = new ConcurrentHashMap<Player, Lightning>();
|
||||
private static ConcurrentHashMap<Entity, Lightning> strikes = new ConcurrentHashMap<Entity, Lightning>();
|
||||
private ArrayList<Entity> hitentities = new ArrayList<Entity>();
|
||||
|
||||
public Lightning(Player player) {
|
||||
if (instances.containsKey(player)) {
|
||||
return;
|
||||
}
|
||||
this.player = player;
|
||||
starttime = System.currentTimeMillis();
|
||||
instances.put(player, this);
|
||||
|
||||
}
|
||||
|
||||
public static Lightning getLightning(Entity entity) {
|
||||
if (strikes.containsKey(entity))
|
||||
return strikes.get(entity);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void strike() {
|
||||
Location targetlocation = getTargetLocation();
|
||||
if (AvatarState.isAvatarState(player))
|
||||
maxdamage = AvatarState.getValue(maxdamage);
|
||||
// if (!Methods.isRegionProtectedFromBuild(player, Abilities.Lightning,
|
||||
// targetlocation)) {
|
||||
strike = player.getWorld().strikeLightning(targetlocation);
|
||||
strikes.put(strike, this);
|
||||
// }
|
||||
instances.remove(player);
|
||||
}
|
||||
|
||||
private Location getTargetLocation() {
|
||||
int distance = (int) Methods.firebendingDayAugment(defaultdistance,
|
||||
player.getWorld());
|
||||
|
||||
Location targetlocation;
|
||||
targetlocation = Methods.getTargetedLocation(player, distance);
|
||||
Entity target = Methods.getTargetedEntity(player, distance, new ArrayList<Entity>());
|
||||
if (target != null) {
|
||||
if (target instanceof LivingEntity
|
||||
&& player.getLocation().distance(targetlocation) > target
|
||||
.getLocation().distance(player.getLocation())) {
|
||||
targetlocation = target.getLocation();
|
||||
if (target.getVelocity().length() < threshold)
|
||||
misschance = 0;
|
||||
}
|
||||
} else {
|
||||
misschance = 0;
|
||||
}
|
||||
|
||||
if (targetlocation.getBlock().getType() == Material.AIR)
|
||||
targetlocation.add(0, -1, 0);
|
||||
if (targetlocation.getBlock().getType() == Material.AIR)
|
||||
targetlocation.add(0, -1, 0);
|
||||
|
||||
if (misschance != 0 && !AvatarState.isAvatarState(player)) {
|
||||
double A = Math.random() * Math.PI * misschance * misschance;
|
||||
double theta = Math.random() * Math.PI * 2;
|
||||
double r = Math.sqrt(A) / Math.PI;
|
||||
double x = r * Math.cos(theta);
|
||||
double z = r * Math.sin(theta);
|
||||
|
||||
targetlocation = targetlocation.add(x, 0, z);
|
||||
}
|
||||
|
||||
return targetlocation;
|
||||
}
|
||||
|
||||
private void progress() {
|
||||
if (player.isDead() || !player.isOnline()) {
|
||||
instances.remove(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Methods.getBoundAbility(player) == null || !Methods.getBoundAbility(player).equalsIgnoreCase("Lightning")) {
|
||||
instances.remove(player);
|
||||
return;
|
||||
}
|
||||
|
||||
int distance = (int) Methods.firebendingDayAugment(defaultdistance,
|
||||
player.getWorld());
|
||||
long warmup = (int) ((double) defaultwarmup / ProjectKorra.plugin.getConfig().getDouble("Properties.Fire.DayFactor"));
|
||||
if (AvatarState.isAvatarState(player))
|
||||
warmup = 0;
|
||||
if (System.currentTimeMillis() > starttime + warmup)
|
||||
charged = true;
|
||||
|
||||
if (charged) {
|
||||
if (player.isSneaking()) {
|
||||
player.getWorld().playEffect(
|
||||
player.getEyeLocation(),
|
||||
Effect.SMOKE,
|
||||
Methods.getIntCardinalDirection(player.getEyeLocation()
|
||||
.getDirection()), distance);
|
||||
} else {
|
||||
strike();
|
||||
}
|
||||
} else {
|
||||
if (!player.isSneaking()) {
|
||||
instances.remove(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void dealDamage(Entity entity) {
|
||||
if (strike == null) {
|
||||
// Methods.verbose("Null strike");
|
||||
return;
|
||||
}
|
||||
// if (Methods.isObstructed(strike.getLocation(), entity.getLocation())) {
|
||||
// Methods.verbose("Is Obstructed");
|
||||
// return 0;
|
||||
// }
|
||||
if (hitentities.contains(entity)) {
|
||||
// Methods.verbose("Already hit");
|
||||
return;
|
||||
}
|
||||
double distance = entity.getLocation().distance(strike.getLocation());
|
||||
if (distance > strikeradius)
|
||||
return;
|
||||
double damage = maxdamage - (distance / strikeradius) * .5;
|
||||
hitentities.add(entity);
|
||||
Methods.damageEntity(player, entity, (int) damage);
|
||||
}
|
||||
|
||||
public static boolean isNearbyChannel(Location location) {
|
||||
boolean value = false;
|
||||
for (Player player : instances.keySet()) {
|
||||
if (!player.getWorld().equals(location.getWorld()))
|
||||
continue;
|
||||
if (player.getLocation().distance(location) <= blockdistance) {
|
||||
value = true;
|
||||
instances.get(player).starttime = 0;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void progressAll() {
|
||||
for (Player player : instances.keySet()) {
|
||||
instances.get(player).progress();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDescription() {
|
||||
return "Hold sneak while selecting this ability to charge up a lightning strike. Once "
|
||||
+ "charged, release sneak to discharge the lightning to the targetted location.";
|
||||
}
|
||||
|
||||
}
|
|
@ -271,6 +271,12 @@ Abilities:
|
|||
Enabled: true
|
||||
Description: "This ability gives firebenders a means of illuminating the area. It is a toggle - clicking will create a torch that follows you around. The torch will only appear on objects that are ignitable and can hold a torch (e.g. not leaves or ice). If you get too far away from the torch, it will disappear, but will reappear when you get on another ignitable block. Clicking again dismisses this torch."
|
||||
Range: 5
|
||||
Lightning:
|
||||
Enabled: true
|
||||
Description: "Hold sneak while selecting this ability to charge up a lightning strike. once charged, release sneak to discharge the lightning to the targeted location."
|
||||
Distance: 15
|
||||
Warmup: 3500
|
||||
MissChance: 10
|
||||
Chi:
|
||||
Passive:
|
||||
FallReductionFactor: 0.5
|
||||
|
|
Loading…
Reference in a new issue