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

67 lines
1.9 KiB
Java
Raw Normal View History

package mineplex.game.clans.items.legendaries;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.util.Vector;
public class MagneticBlade extends LegendaryItem
{
public static final double PULL_RANGE = 10d;
public MagneticBlade()
{
super("Magnetic Blade", "Pull enemies closer with special abilities!", Material.STICK);
}
@Override
public void update(Player wielder)
{
if (isHoldingRightClick() && canPull())
{
pullPlayers(wielder);
}
}
@Override
public void onAttack(CustomDamageEvent event, Player wielder)
{
event.AddKnockback("Magnetic Blade", -0.5d); // Pull players with negative knockback
log("Negative knockback!");
// TODO: Apply negative knockback with [???] velocity/power to victims of attacks
}
private void pullPlayers(Player player)
{
log("Pulling players!");
Vector direction = player.getLocation().getDirection().normalize().multiply(10.0d);
Location target = player.getEyeLocation().add(direction);
double targetDistance = player.getLocation().distance(target);
for (Player other : player.getWorld().getPlayers())
{
double otherDistance = player.getLocation().distance(other.getLocation());
double otherTargetDistance = target.distance(other.getLocation());
// If player is in-front of us and within pulling range
if (otherTargetDistance < targetDistance && otherDistance <= PULL_RANGE)
{
UtilAction.velocity(other, UtilAlg.getTrajectory(other, player), 0.3, false, 0, 0, 1, true);
}
}
}
private boolean canPull()
{
return true; // TODO: Implement cooldown? (Sounds OP without one)
}
}