2015-05-16 18:58:58 +02:00
package mineplex.game.clans.items.legendaries ;
2015-05-25 20:22:06 +02:00
import org.bukkit.Material ;
2015-11-03 20:49:14 +01:00
import org.bukkit.Sound ;
2015-05-16 18:58:58 +02:00
import org.bukkit.entity.Player ;
2015-05-25 20:22:06 +02:00
import org.bukkit.util.Vector ;
2015-05-16 18:58:58 +02:00
2015-11-03 20:49:14 +01:00
import mineplex.core.common.util.C ;
import mineplex.core.common.util.F ;
2015-10-30 23:13:19 +01:00
import mineplex.core.common.util.UtilEnt ;
2015-10-26 16:37:44 +01:00
import mineplex.core.common.util.UtilMath ;
2015-10-30 23:13:19 +01:00
import mineplex.core.common.util.UtilParticle ;
import mineplex.core.common.util.UtilParticle.ParticleType ;
import mineplex.core.common.util.UtilParticle.ViewDist ;
2015-11-03 20:49:14 +01:00
import mineplex.core.common.util.UtilPlayer ;
2015-10-26 16:37:44 +01:00
import mineplex.core.common.util.UtilTextBottom ;
2015-11-03 20:49:14 +01:00
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 ;
2015-10-26 16:37:44 +01:00
2015-05-16 18:58:58 +02:00
public class WindBlade extends LegendaryItem
{
2015-06-01 18:25:20 +02:00
public static final double FLIGHT_VELOCITY = 0 . 75d ;
2015-05-16 18:58:58 +02:00
2015-10-26 16:37:44 +01:00
private double _power ;
2015-11-03 20:49:14 +01:00
private double _burnoutThreshold ;
private int _messageTimer ;
2015-05-16 18:58:58 +02:00
public WindBlade ( )
{
2015-11-26 05:07:33 +01:00
super ( " Wind Blade " , " Activate flying ability to take flight! " , Material . RECORD_8 ) ; // TODO:
2015-10-26 16:37:44 +01:00
// Configurable?
2015-05-16 18:58:58 +02:00
}
@Override
public void update ( Player wielder )
{
2015-11-03 20:49:14 +01:00
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 ( ) ;
}
2015-05-25 20:22:06 +02:00
// Check if player is attempting to fly and activate
2015-11-03 20:49:14 +01:00
if ( isHoldingRightClick ( ) )
2015-05-16 18:58:58 +02:00
{
2015-11-03 20:49:14 +01:00
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-03 20:49:14 +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 ) ;
2015-05-16 18:58:58 +02:00
}
2015-05-25 20:22:06 +02:00
2015-11-26 08:29:39 +01:00
if ( UtilEnt . isGrounded ( wielder , wielder . getLocation ( ) ) | | UtilEnt . isGrounded ( wielder , wielder . getLocation ( ) . subtract ( 0 , 1 , 0 ) ) )
2015-05-25 20:22:06 +02:00
{
2015-11-03 20:49:14 +01:00
addPower ( 0 . 4 ) ;
}
if ( _burnoutThreshold > 15 & & burnoutRemaining < = 0 )
{
Recharge . Instance . use ( wielder , " clans_legendary_windblade_burnout " , 2500 , false , false ) ;
2015-05-25 20:22:06 +02:00
}
2015-10-26 16:37:44 +01:00
2015-10-30 23:13:19 +01:00
UtilTextBottom . displayProgress ( UtilMath . clamp ( _power , . 0 , 80 . ) / 80 . , wielder ) ;
2015-05-16 18:58:58 +02:00
}
2015-10-26 16:37:44 +01:00
2015-11-26 03:49:01 +01:00
@Override
public void onAttack ( CustomDamageEvent event , Player wielder )
{
event . AddMod ( " Wind Blade " , 7 ) ;
}
2015-05-16 18:58:58 +02:00
private void propelPlayer ( Player player )
{
2015-05-25 20:22:06 +02:00
Vector direction = player . getLocation ( ) . getDirection ( ) . normalize ( ) ;
2015-10-26 16:37:44 +01:00
direction . multiply ( FLIGHT_VELOCITY ) ;
2015-05-25 20:22:06 +02:00
player . setVelocity ( direction ) ;
2015-10-26 16:37:44 +01:00
player . setFallDistance ( 0f ) ;
2015-05-16 18:58:58 +02:00
}
private boolean canPropel ( )
{
2015-10-26 16:37:44 +01:00
return _power > 0 ;
}
private void addPower ( double power )
{
2015-10-30 23:13:19 +01:00
_power = UtilMath . clamp ( _power + power , - 20 , 80 ) ;
2015-10-26 16:37:44 +01:00
}
private void removePower ( double power )
{
2015-10-30 23:13:19 +01:00
_power = UtilMath . clamp ( _power - power , - 20 , 80 ) ;
2015-05-16 18:58:58 +02:00
}
}