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