Modify Barrage perk to support setting levels to indicate arrows
This commit is contained in:
parent
6439fc93c2
commit
e3b0843b2c
@ -40,14 +40,20 @@ public class PerkBarrage extends Perk
|
||||
private long _tick;
|
||||
private boolean _remove;
|
||||
private boolean _noDelay;
|
||||
private boolean _useExp;
|
||||
|
||||
public PerkBarrage(int max, long tick, boolean remove, boolean noDelay)
|
||||
{
|
||||
this(max, tick, remove, noDelay, false);
|
||||
}
|
||||
|
||||
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;
|
||||
@ -75,7 +81,7 @@ public class PerkBarrage extends Perk
|
||||
if (UtilBlock.usable(event.getClickedBlock()))
|
||||
return;
|
||||
|
||||
//Start Charge
|
||||
// Start Charge
|
||||
_charge.put(player, 0);
|
||||
_chargeLast.put(player, System.currentTimeMillis());
|
||||
_firing.remove(player);
|
||||
@ -89,18 +95,18 @@ public class PerkBarrage extends Perk
|
||||
|
||||
for (Player cur : UtilServer.getPlayers())
|
||||
{
|
||||
//Not Charging
|
||||
// Not Charging
|
||||
if (!_charge.containsKey(cur))
|
||||
continue;
|
||||
|
||||
if (_firing.contains(cur))
|
||||
continue;
|
||||
|
||||
//Max Charge
|
||||
// Max Charge
|
||||
if (_charge.get(cur) >= _max)
|
||||
continue;
|
||||
|
||||
//Charge Interval
|
||||
// Charge Interval
|
||||
if (_charge.get(cur) == 0)
|
||||
{
|
||||
if (!UtilTime.elapsed(_chargeLast.get(cur), 1000))
|
||||
@ -112,19 +118,28 @@ public class PerkBarrage extends Perk
|
||||
continue;
|
||||
}
|
||||
|
||||
//No Longer Holding Bow
|
||||
// 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
|
||||
// Increase Charge
|
||||
_charge.put(cur, _charge.get(cur) + 1);
|
||||
|
||||
if (_useExp)
|
||||
{
|
||||
cur.setLevel(_charge.get(cur));
|
||||
}
|
||||
_chargeLast.put(cur, System.currentTimeMillis());
|
||||
|
||||
//Effect
|
||||
// Effect
|
||||
cur.playSound(cur.getLocation(), Sound.CLICK, 1f, 1f + (0.1f * _charge.get(cur)));
|
||||
}
|
||||
}
|
||||
@ -144,12 +159,12 @@ public class PerkBarrage extends Perk
|
||||
if (!(event.getProjectile() instanceof Arrow))
|
||||
return;
|
||||
|
||||
Player player = (Player)event.getEntity();
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if (!_charge.containsKey(player))
|
||||
return;
|
||||
|
||||
//Start Barrage
|
||||
// Start Barrage
|
||||
_firing.add(player);
|
||||
_chargeLast.put(player, System.currentTimeMillis());
|
||||
}
|
||||
@ -183,10 +198,14 @@ public class PerkBarrage extends Perk
|
||||
continue;
|
||||
}
|
||||
|
||||
_charge.put(cur, arrows-1);
|
||||
_charge.put(cur, arrows - 1);
|
||||
if (_useExp)
|
||||
{
|
||||
cur.setLevel(_charge.get(cur));
|
||||
}
|
||||
|
||||
//Fire Arrow
|
||||
Vector random = new Vector((Math.random()-0.5)/10, (Math.random()-0.5)/10, (Math.random()-0.5)/10);
|
||||
// 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);
|
||||
@ -195,6 +214,10 @@ public class PerkBarrage extends Perk
|
||||
|
||||
for (Player cur : remove)
|
||||
{
|
||||
if (_useExp)
|
||||
{
|
||||
cur.setLevel(0);
|
||||
}
|
||||
_charge.remove(cur);
|
||||
_chargeLast.remove(cur);
|
||||
_firing.remove(cur);
|
||||
@ -225,10 +248,9 @@ public class PerkBarrage extends Perk
|
||||
|
||||
event.GetProjectile().remove();
|
||||
|
||||
//Damage Event
|
||||
Manager.GetDamage().NewDamageEvent(event.GetDamageeEntity(), damager, null,
|
||||
DamageCause.THORNS, event.GetDamage(), true, true, false,
|
||||
damager.getName(), GetName());
|
||||
// Damage Event
|
||||
Manager.GetDamage().NewDamageEvent(event.GetDamageeEntity(), damager, null, DamageCause.THORNS, event.GetDamage(), true,
|
||||
true, false, damager.getName(), GetName());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
Loading…
Reference in New Issue
Block a user