Modify Barrage perk to support setting levels to indicate arrows
This commit is contained in:
parent
6439fc93c2
commit
e3b0843b2c
@ -30,237 +30,259 @@ import nautilus.game.arcade.kit.Perk;
|
||||
|
||||
public class PerkBarrage extends Perk
|
||||
{
|
||||
private WeakHashMap<Player, Integer> _charge = new WeakHashMap<Player, Integer>();
|
||||
private WeakHashMap<Player, Long> _chargeLast = new WeakHashMap<Player, Long>();
|
||||
private WeakHashMap<Player, Integer> _charge = new WeakHashMap<Player, Integer>();
|
||||
private WeakHashMap<Player, Long> _chargeLast = new WeakHashMap<Player, Long>();
|
||||
|
||||
private HashSet<Player> _firing = new HashSet<Player>();
|
||||
private HashSet<Projectile> _arrows = new HashSet<Projectile>();
|
||||
private HashSet<Player> _firing = new HashSet<Player>();
|
||||
private HashSet<Projectile> _arrows = new HashSet<Projectile>();
|
||||
|
||||
private int _max;
|
||||
private long _tick;
|
||||
private boolean _remove;
|
||||
private boolean _noDelay;
|
||||
private int _max;
|
||||
private long _tick;
|
||||
private boolean _remove;
|
||||
private boolean _noDelay;
|
||||
private boolean _useExp;
|
||||
|
||||
public PerkBarrage(int max, long tick, boolean remove, boolean noDelay)
|
||||
{
|
||||
super("Barrage", new String[]
|
||||
{
|
||||
C.cYellow + "Charge" + C.cGray + " your Bow to use " + C.cGreen + "Barrage"
|
||||
});
|
||||
public PerkBarrage(int max, long tick, boolean remove, boolean noDelay)
|
||||
{
|
||||
this(max, tick, remove, noDelay, false);
|
||||
}
|
||||
|
||||
_max = max;
|
||||
_tick = tick;
|
||||
_remove = remove;
|
||||
_noDelay = noDelay;
|
||||
}
|
||||
public PerkBarrage(int max, long tick, boolean remove, boolean noDelay, boolean useExpAndBar)
|
||||
{
|
||||
super("Barrage", new String[]
|
||||
{
|
||||
C.cYellow + "Charge" + C.cGray + " your Bow to use " + C.cGreen + "Barrage"
|
||||
});
|
||||
_useExp = useExpAndBar;
|
||||
_max = max;
|
||||
_tick = tick;
|
||||
_remove = remove;
|
||||
_noDelay = noDelay;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void BarrageDrawBow(PlayerInteractEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
@EventHandler
|
||||
public void BarrageDrawBow(PlayerInteractEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||
return;
|
||||
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||
return;
|
||||
|
||||
if (player.getItemInHand() == null || player.getItemInHand().getType() != Material.BOW)
|
||||
return;
|
||||
if (player.getItemInHand() == null || player.getItemInHand().getType() != Material.BOW)
|
||||
return;
|
||||
|
||||
if (!Kit.HasKit(player))
|
||||
return;
|
||||
if (!Kit.HasKit(player))
|
||||
return;
|
||||
|
||||
if (!player.getInventory().contains(Material.ARROW))
|
||||
return;
|
||||
if (!player.getInventory().contains(Material.ARROW))
|
||||
return;
|
||||
|
||||
if (event.getClickedBlock() != null)
|
||||
if (UtilBlock.usable(event.getClickedBlock()))
|
||||
return;
|
||||
if (event.getClickedBlock() != null)
|
||||
if (UtilBlock.usable(event.getClickedBlock()))
|
||||
return;
|
||||
|
||||
//Start Charge
|
||||
_charge.put(player, 0);
|
||||
_chargeLast.put(player, System.currentTimeMillis());
|
||||
_firing.remove(player);
|
||||
}
|
||||
// Start Charge
|
||||
_charge.put(player, 0);
|
||||
_chargeLast.put(player, System.currentTimeMillis());
|
||||
_firing.remove(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void BarrageCharge(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
return;
|
||||
@EventHandler
|
||||
public void BarrageCharge(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
return;
|
||||
|
||||
for (Player cur : UtilServer.getPlayers())
|
||||
{
|
||||
//Not Charging
|
||||
if (!_charge.containsKey(cur))
|
||||
continue;
|
||||
for (Player cur : UtilServer.getPlayers())
|
||||
{
|
||||
// Not Charging
|
||||
if (!_charge.containsKey(cur))
|
||||
continue;
|
||||
|
||||
if (_firing.contains(cur))
|
||||
continue;
|
||||
if (_firing.contains(cur))
|
||||
continue;
|
||||
|
||||
//Max Charge
|
||||
if (_charge.get(cur) >= _max)
|
||||
continue;
|
||||
// Max Charge
|
||||
if (_charge.get(cur) >= _max)
|
||||
continue;
|
||||
|
||||
//Charge Interval
|
||||
if (_charge.get(cur) == 0)
|
||||
{
|
||||
if (!UtilTime.elapsed(_chargeLast.get(cur), 1000))
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!UtilTime.elapsed(_chargeLast.get(cur), _tick))
|
||||
continue;
|
||||
}
|
||||
// Charge Interval
|
||||
if (_charge.get(cur) == 0)
|
||||
{
|
||||
if (!UtilTime.elapsed(_chargeLast.get(cur), 1000))
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!UtilTime.elapsed(_chargeLast.get(cur), _tick))
|
||||
continue;
|
||||
}
|
||||
|
||||
//No Longer Holding Bow
|
||||
if (cur.getItemInHand() == null || cur.getItemInHand().getType() != Material.BOW)
|
||||
{
|
||||
_charge.remove(cur);
|
||||
_chargeLast.remove(cur);
|
||||
continue;
|
||||
}
|
||||
// No Longer Holding Bow
|
||||
if (cur.getItemInHand() == null || cur.getItemInHand().getType() != Material.BOW)
|
||||
{
|
||||
if (_useExp)
|
||||
{
|
||||
cur.setLevel(_charge.get(cur));
|
||||
}
|
||||
_charge.remove(cur);
|
||||
_chargeLast.remove(cur);
|
||||
continue;
|
||||
}
|
||||
|
||||
//Increase Charge
|
||||
_charge.put(cur, _charge.get(cur) + 1);
|
||||
_chargeLast.put(cur, System.currentTimeMillis());
|
||||
// Increase Charge
|
||||
_charge.put(cur, _charge.get(cur) + 1);
|
||||
|
||||
//Effect
|
||||
cur.playSound(cur.getLocation(), Sound.CLICK, 1f, 1f + (0.1f * _charge.get(cur)));
|
||||
}
|
||||
}
|
||||
if (_useExp)
|
||||
{
|
||||
cur.setLevel(_charge.get(cur));
|
||||
}
|
||||
_chargeLast.put(cur, System.currentTimeMillis());
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void BarrageFireBow(EntityShootBowEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
// Effect
|
||||
cur.playSound(cur.getLocation(), Sound.CLICK, 1f, 1f + (0.1f * _charge.get(cur)));
|
||||
}
|
||||
}
|
||||
|
||||
if (!Manager.GetGame().IsLive())
|
||||
return;
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void BarrageFireBow(EntityShootBowEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
if (!(event.getEntity() instanceof Player))
|
||||
return;
|
||||
if (!Manager.GetGame().IsLive())
|
||||
return;
|
||||
|
||||
if (!(event.getProjectile() instanceof Arrow))
|
||||
return;
|
||||
if (!(event.getEntity() instanceof Player))
|
||||
return;
|
||||
|
||||
Player player = (Player)event.getEntity();
|
||||
if (!(event.getProjectile() instanceof Arrow))
|
||||
return;
|
||||
|
||||
if (!_charge.containsKey(player))
|
||||
return;
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
//Start Barrage
|
||||
_firing.add(player);
|
||||
_chargeLast.put(player, System.currentTimeMillis());
|
||||
}
|
||||
if (!_charge.containsKey(player))
|
||||
return;
|
||||
|
||||
@EventHandler
|
||||
public void BarrageArrows(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
return;
|
||||
// Start Barrage
|
||||
_firing.add(player);
|
||||
_chargeLast.put(player, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
HashSet<Player> remove = new HashSet<Player>();
|
||||
@EventHandler
|
||||
public void BarrageArrows(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
return;
|
||||
|
||||
for (Player cur : _firing)
|
||||
{
|
||||
if (!_charge.containsKey(cur) || !_chargeLast.containsKey(cur))
|
||||
{
|
||||
remove.add(cur);
|
||||
continue;
|
||||
}
|
||||
HashSet<Player> remove = new HashSet<Player>();
|
||||
|
||||
if (cur.getItemInHand() == null || cur.getItemInHand().getType() != Material.BOW)
|
||||
{
|
||||
remove.add(cur);
|
||||
continue;
|
||||
}
|
||||
for (Player cur : _firing)
|
||||
{
|
||||
if (!_charge.containsKey(cur) || !_chargeLast.containsKey(cur))
|
||||
{
|
||||
remove.add(cur);
|
||||
continue;
|
||||
}
|
||||
|
||||
int arrows = _charge.get(cur);
|
||||
if (arrows <= 0)
|
||||
{
|
||||
remove.add(cur);
|
||||
continue;
|
||||
}
|
||||
if (cur.getItemInHand() == null || cur.getItemInHand().getType() != Material.BOW)
|
||||
{
|
||||
remove.add(cur);
|
||||
continue;
|
||||
}
|
||||
|
||||
_charge.put(cur, arrows-1);
|
||||
int arrows = _charge.get(cur);
|
||||
if (arrows <= 0)
|
||||
{
|
||||
remove.add(cur);
|
||||
continue;
|
||||
}
|
||||
|
||||
//Fire Arrow
|
||||
Vector random = new Vector((Math.random()-0.5)/10, (Math.random()-0.5)/10, (Math.random()-0.5)/10);
|
||||
Projectile arrow = cur.launchProjectile(Arrow.class);
|
||||
arrow.setVelocity(cur.getLocation().getDirection().add(random).multiply(3));
|
||||
_arrows.add(arrow);
|
||||
cur.getWorld().playSound(cur.getLocation(), Sound.SHOOT_ARROW, 1f, 1f);
|
||||
}
|
||||
_charge.put(cur, arrows - 1);
|
||||
if (_useExp)
|
||||
{
|
||||
cur.setLevel(_charge.get(cur));
|
||||
}
|
||||
|
||||
for (Player cur : remove)
|
||||
{
|
||||
_charge.remove(cur);
|
||||
_chargeLast.remove(cur);
|
||||
_firing.remove(cur);
|
||||
}
|
||||
}
|
||||
// Fire Arrow
|
||||
Vector random = new Vector((Math.random() - 0.5) / 10, (Math.random() - 0.5) / 10, (Math.random() - 0.5) / 10);
|
||||
Projectile arrow = cur.launchProjectile(Arrow.class);
|
||||
arrow.setVelocity(cur.getLocation().getDirection().add(random).multiply(3));
|
||||
_arrows.add(arrow);
|
||||
cur.getWorld().playSound(cur.getLocation(), Sound.SHOOT_ARROW, 1f, 1f);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void BarrageDamageTime(CustomDamageEvent event)
|
||||
{
|
||||
if (!_noDelay)
|
||||
return;
|
||||
for (Player cur : remove)
|
||||
{
|
||||
if (_useExp)
|
||||
{
|
||||
cur.setLevel(0);
|
||||
}
|
||||
_charge.remove(cur);
|
||||
_chargeLast.remove(cur);
|
||||
_firing.remove(cur);
|
||||
}
|
||||
}
|
||||
|
||||
if (event.GetProjectile() == null)
|
||||
return;
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void BarrageDamageTime(CustomDamageEvent event)
|
||||
{
|
||||
if (!_noDelay)
|
||||
return;
|
||||
|
||||
if (event.GetDamagerPlayer(true) == null)
|
||||
return;
|
||||
if (event.GetProjectile() == null)
|
||||
return;
|
||||
|
||||
if (!(event.GetProjectile() instanceof Arrow))
|
||||
return;
|
||||
if (event.GetDamagerPlayer(true) == null)
|
||||
return;
|
||||
|
||||
Player damager = event.GetDamagerPlayer(true);
|
||||
if (!(event.GetProjectile() instanceof Arrow))
|
||||
return;
|
||||
|
||||
if (!Kit.HasKit(damager))
|
||||
return;
|
||||
Player damager = event.GetDamagerPlayer(true);
|
||||
|
||||
event.SetCancelled("Barrage Cancel");
|
||||
if (!Kit.HasKit(damager))
|
||||
return;
|
||||
|
||||
event.GetProjectile().remove();
|
||||
event.SetCancelled("Barrage Cancel");
|
||||
|
||||
//Damage Event
|
||||
Manager.GetDamage().NewDamageEvent(event.GetDamageeEntity(), damager, null,
|
||||
DamageCause.THORNS, event.GetDamage(), true, true, false,
|
||||
damager.getName(), GetName());
|
||||
}
|
||||
event.GetProjectile().remove();
|
||||
|
||||
@EventHandler
|
||||
public void BarrageProjectileHit(ProjectileHitEvent event)
|
||||
{
|
||||
if (_remove)
|
||||
if (_arrows.remove(event.getEntity()))
|
||||
event.getEntity().remove();
|
||||
}
|
||||
// Damage Event
|
||||
Manager.GetDamage().NewDamageEvent(event.GetDamageeEntity(), damager, null, DamageCause.THORNS, event.GetDamage(), true,
|
||||
true, false, damager.getName(), GetName());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void BarrageClean(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC)
|
||||
return;
|
||||
@EventHandler
|
||||
public void BarrageProjectileHit(ProjectileHitEvent event)
|
||||
{
|
||||
if (_remove)
|
||||
if (_arrows.remove(event.getEntity()))
|
||||
event.getEntity().remove();
|
||||
}
|
||||
|
||||
for (Iterator<Projectile> arrowIterator = _arrows.iterator(); arrowIterator.hasNext();)
|
||||
{
|
||||
Projectile arrow = arrowIterator.next();
|
||||
@EventHandler
|
||||
public void BarrageClean(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC)
|
||||
return;
|
||||
|
||||
if (arrow.isDead() || !arrow.isValid())
|
||||
arrowIterator.remove();
|
||||
}
|
||||
}
|
||||
for (Iterator<Projectile> arrowIterator = _arrows.iterator(); arrowIterator.hasNext();)
|
||||
{
|
||||
Projectile arrow = arrowIterator.next();
|
||||
|
||||
@EventHandler
|
||||
public void Quit(PlayerQuitEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
if (arrow.isDead() || !arrow.isValid())
|
||||
arrowIterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
_charge.remove(player);
|
||||
_chargeLast.remove(player);
|
||||
_firing.remove(player);
|
||||
}
|
||||
@EventHandler
|
||||
public void Quit(PlayerQuitEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
_charge.remove(player);
|
||||
_chargeLast.remove(player);
|
||||
_firing.remove(player);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user