Mineplex2018-withcommit/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/WindBlade.java

144 lines
3.8 KiB
Java
Raw Normal View History

package mineplex.game.clans.items.legendaries;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.recharge.Recharge;
2015-11-26 03:49:01 +01:00
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class WindBlade extends LegendaryItem
{
public static final double FLIGHT_VELOCITY = 0.75d;
private double _power;
private double _burnoutThreshold;
private int _messageTimer;
public WindBlade()
{
2015-11-26 08:51:10 +01:00
super("Wind Blade", "Activate flying ability to take flight!", Material.RECORD_8);
}
@Override
public void update(Player wielder)
{
long burnoutRemaining = -1L;
if (Recharge.Instance.Get(wielder) != null && Recharge.Instance.Get(wielder).containsKey("clans_legendary_windblade_burnout"))
{
burnoutRemaining = Recharge.Instance.Get(wielder).get("clans_legendary_windblade_burnout").GetRemaining();
}
// Check if player is attempting to fly and activate
if (isHoldingRightClick())
{
if (canPropel())
{
if (burnoutRemaining > 0)
{
_messageTimer++;
if (_messageTimer % 4 == 0)
{
UtilParticle.PlayParticle(ParticleType.SMOKE, wielder.getLocation(), 0.f, 0.f, 0.f, .1f, 1, ViewDist.NORMAL);
wielder.playSound(wielder.getLocation(), Sound.FIZZ, .5f, 1.f);
removePower(0.15);
_burnoutThreshold = 0;
}
if (_messageTimer % 20 == 0)
{
2015-11-26 06:30:13 +01:00
UtilPlayer.message(wielder, F.main("Wind Blade", "Flight power damaged whilst scraping the ground! Repairs will be finish in " + F.time(UtilTime.MakeStr(burnoutRemaining)) + "."));
}
2015-11-26 08:51:10 +01:00
if (_messageTimer % 10 == 0)
{
wielder.playSound(wielder.getLocation(), Sound.ANVIL_USE, .5f, 1.5f);
}
return;
}
removePower(UtilEnt.isGrounded(wielder) ? 1.17 : .88);
propelPlayer(wielder);
UtilParticle.PlayParticle(ParticleType.EXPLODE, wielder.getLocation().add(0, 1, 0), 0, 0, 0, .1f, 3, ViewDist.NORMAL);
wielder.playSound(wielder.getLocation(), Sound.FIRE, .25f, 1.75f);
}
if (UtilEnt.isGrounded(wielder))
{
_burnoutThreshold++;
wielder.playSound(wielder.getLocation(), Sound.NOTE_STICKS, .75f, 2.f);
}
else
{
_burnoutThreshold = 0;
}
}
else
{
_burnoutThreshold = UtilMath.clamp(_burnoutThreshold - .5, 0, _burnoutThreshold);
}
if (UtilEnt.isGrounded(wielder, wielder.getLocation()) || UtilEnt.isGrounded(wielder, wielder.getLocation().subtract(0, 1, 0)))
{
addPower(0.4);
}
if (_burnoutThreshold > 15 && burnoutRemaining <= 0)
{
Recharge.Instance.use(wielder, "clans_legendary_windblade_burnout", 2500, false, false);
}
UtilTextBottom.displayProgress(UtilMath.clamp(_power, .0, 80.) / 80., wielder);
}
2015-11-26 03:49:01 +01:00
@Override
public void onAttack(CustomDamageEvent event, Player wielder)
{
event.AddMod("Wind Blade", 7);
}
private void propelPlayer(Player player)
{
Vector direction = player.getLocation().getDirection().normalize();
direction.multiply(FLIGHT_VELOCITY);
player.setVelocity(direction);
player.setFallDistance(0f);
}
private boolean canPropel()
{
return _power > 0;
}
private void addPower(double power)
{
_power = UtilMath.clamp(_power + power, -20, 80);
}
private void removePower(double power)
{
_power = UtilMath.clamp(_power - power, -20, 80);
}
}