Towers
This commit is contained in:
parent
4b6b04d4eb
commit
f9cdddf1ad
@ -31,6 +31,7 @@ import nautilus.game.arcade.game.games.moba.recall.Recall;
|
||||
import nautilus.game.arcade.game.games.moba.shop.MobaShop;
|
||||
import nautilus.game.arcade.game.games.moba.structure.point.CapturePoint;
|
||||
import nautilus.game.arcade.game.games.moba.structure.tower.Tower;
|
||||
import nautilus.game.arcade.game.games.moba.structure.tower.TowerManager;
|
||||
import nautilus.game.arcade.game.modules.CustomScoreboardModule;
|
||||
import nautilus.game.arcade.game.modules.compass.CompassModule;
|
||||
import nautilus.game.arcade.kit.Kit;
|
||||
@ -67,7 +68,6 @@ public class Moba extends TeamGame
|
||||
private final HeroKit[] _kits;
|
||||
|
||||
private final List<CapturePoint> _capturePoints = new ArrayList<>(3);
|
||||
private final List<Tower> _towers = new ArrayList<>(12);
|
||||
|
||||
private final Set<MobaPlayer> _playerData = new HashSet<>();
|
||||
|
||||
@ -119,6 +119,9 @@ public class Moba extends TeamGame
|
||||
_boss = boss;
|
||||
_listeners.add(boss);
|
||||
|
||||
Listener tower = new TowerManager(this);
|
||||
_listeners.add(tower);
|
||||
|
||||
new CompassModule()
|
||||
.setGiveCompass(true)
|
||||
.setGiveCompassToSpecs(true)
|
||||
@ -223,44 +226,6 @@ public class Moba extends TeamGame
|
||||
_capturePoints.add(new CapturePoint(this, location));
|
||||
}
|
||||
|
||||
Map<String, Location> towers = getLocationStartsWith("TOWER");
|
||||
|
||||
for (Entry<String, Location> entry : towers.entrySet())
|
||||
{
|
||||
String key = entry.getKey();
|
||||
Location location = entry.getValue();
|
||||
String[] components = key.split(" ");
|
||||
|
||||
if (components.length < 4)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
String team = components[1];
|
||||
MobaLane lane = MobaLane.valueOf(components[2]);
|
||||
|
||||
boolean firstTower;
|
||||
|
||||
try
|
||||
{
|
||||
firstTower = components[3].equalsIgnoreCase("1");
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int health = firstTower ? 250 : 500;
|
||||
GameTeam gameTeam = getTeam(team);
|
||||
|
||||
if (gameTeam == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_towers.add(new Tower(this, location, gameTeam, lane, health, firstTower));
|
||||
}
|
||||
|
||||
_listeners.forEach(UtilServer::RegisterEvents);
|
||||
}
|
||||
|
||||
@ -351,13 +316,6 @@ public class Moba extends TeamGame
|
||||
{
|
||||
_playerData.add(new MobaPlayer(player));
|
||||
}
|
||||
|
||||
CreatureAllowOverride = true;
|
||||
for (Tower tower : _towers)
|
||||
{
|
||||
tower.setup();
|
||||
}
|
||||
CreatureAllowOverride = false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -382,11 +340,11 @@ public class Moba extends TeamGame
|
||||
((HeroSkill) perk).useSkill(mobaPlayer.Player);
|
||||
}
|
||||
|
||||
// Teleport players to their respective spawns
|
||||
GameTeam team = GetTeam(player);
|
||||
Location toTeleport = WorldData.GetCustomLocs("SPAWN " + team.GetName().toUpperCase() + " " + mobaPlayer.Role.getLane().toString()).get(0);
|
||||
toTeleport.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(toTeleport, GetSpectatorLocation())));
|
||||
player.teleport(toTeleport);
|
||||
// // Teleport players to their respective spawns
|
||||
// GameTeam team = GetTeam(player);
|
||||
// Location toTeleport = WorldData.GetCustomLocs("SPAWN " + team.GetName().toUpperCase() + " " + mobaPlayer.Role.getLane().toString()).get(0);
|
||||
// toTeleport.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(toTeleport, GetSpectatorLocation())));
|
||||
// player.teleport(toTeleport);
|
||||
}
|
||||
}
|
||||
|
||||
@ -684,7 +642,7 @@ public class Moba extends TeamGame
|
||||
return map;
|
||||
}
|
||||
|
||||
private GameTeam getTeam(String name)
|
||||
public GameTeam getTeam(String name)
|
||||
{
|
||||
for (GameTeam team : GetTeamList())
|
||||
{
|
||||
|
@ -6,6 +6,7 @@ import mineplex.core.common.util.UtilPlayer;
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
import nautilus.game.arcade.game.games.moba.Moba;
|
||||
import nautilus.game.arcade.game.games.moba.ai.goal.MobaAIMethod;
|
||||
import nautilus.game.arcade.game.games.moba.util.MobaUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -46,7 +47,7 @@ public class MobaAI
|
||||
|
||||
if (_target == null)
|
||||
{
|
||||
_target = getBestEntityTarget();
|
||||
_target = MobaUtil.getBestEntityTarget(_host, _owner, _entity, _home, TARGET_RANGE);
|
||||
|
||||
if (_target == null)
|
||||
{
|
||||
@ -76,42 +77,6 @@ public class MobaAI
|
||||
_aiMethod.updateMovement(_entity, _home, 3.5F);
|
||||
}
|
||||
|
||||
private LivingEntity getBestEntityTarget()
|
||||
{
|
||||
LivingEntity highest = null;
|
||||
double bestDist = 0;
|
||||
|
||||
for (Entry<LivingEntity, Double> entry : UtilEnt.getInRadius(_home, TARGET_RANGE).entrySet())
|
||||
{
|
||||
LivingEntity entity = entry.getKey();
|
||||
double dist = entry.getValue();
|
||||
|
||||
if (_entity.equals(entity))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Make players more desirable
|
||||
if (entity instanceof Player)
|
||||
{
|
||||
if (_owner.equals(_host.GetTeam((Player) entity)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
dist += 0.5;
|
||||
}
|
||||
|
||||
if (bestDist < dist)
|
||||
{
|
||||
highest = entity;
|
||||
bestDist = dist;
|
||||
}
|
||||
}
|
||||
|
||||
return highest;
|
||||
}
|
||||
|
||||
public void setEntity(LivingEntity entity)
|
||||
{
|
||||
_entity = entity;
|
||||
|
@ -100,7 +100,7 @@ public class PregameSelection implements Listener, IPacketHandler
|
||||
|
||||
_roleStands.put(stand, role);
|
||||
}
|
||||
}, 5);
|
||||
}, 20);
|
||||
}
|
||||
|
||||
private void spawnKitUI(Player player, String dataKey)
|
||||
|
@ -3,26 +3,48 @@ package nautilus.game.arcade.game.games.moba.structure.tower;
|
||||
import mineplex.core.common.util.*;
|
||||
import mineplex.core.common.util.UtilParticle.ParticleType;
|
||||
import mineplex.core.common.util.UtilParticle.ViewDist;
|
||||
import mineplex.core.disguise.disguises.DisguiseGuardian;
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
import nautilus.game.arcade.game.games.moba.Moba;
|
||||
import nautilus.game.arcade.game.games.moba.MobaLane;
|
||||
import nautilus.game.arcade.game.games.moba.util.MobaUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Guardian;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EnderCrystal;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
|
||||
public class Tower
|
||||
{
|
||||
|
||||
private static final int DAMAGE = 3;
|
||||
private static final int TARGET_RANGE = 10;
|
||||
public static final int TARGET_RANGE_SQUARED = TARGET_RANGE * TARGET_RANGE;
|
||||
|
||||
private final Moba _host;
|
||||
|
||||
private final Location _location;
|
||||
private final GameTeam _team;
|
||||
private MobaLane _lane;
|
||||
private final MobaLane _lane;
|
||||
|
||||
private double _health;
|
||||
private int _maxHealth;
|
||||
private boolean _firstTower;
|
||||
private Guardian _guardian;
|
||||
|
||||
private ArmorStand _stand;
|
||||
private DisguiseGuardian _guardian;
|
||||
private EnderCrystal _crystal;
|
||||
|
||||
private boolean _dead;
|
||||
|
||||
private float _fallbackYaw;
|
||||
|
||||
private LivingEntity _target;
|
||||
|
||||
public Tower(Moba host, Location location, GameTeam team, MobaLane lane, int health, boolean firstTower)
|
||||
{
|
||||
_host = host;
|
||||
@ -36,26 +58,78 @@ public class Tower
|
||||
|
||||
public void setup()
|
||||
{
|
||||
// if (_firstTower)
|
||||
// {
|
||||
_guardian = _location.getWorld().spawn(_location, Guardian.class);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _guardian = UtilVariant.spawnElderGuardian(_location);
|
||||
// }
|
||||
_fallbackYaw = UtilAlg.GetYaw(UtilAlg.getTrajectory(_location, _host.GetSpectatorLocation()));
|
||||
_location.setYaw(_fallbackYaw);
|
||||
_stand = _location.getWorld().spawn(_location, ArmorStand.class);
|
||||
_stand.setGravity(false);
|
||||
_stand.setMaxHealth(_maxHealth);
|
||||
_stand.setHealth(_health);
|
||||
|
||||
_guardian = new DisguiseGuardian(_stand);
|
||||
_host.getArcadeManager().GetDisguise().disguise(_guardian);
|
||||
|
||||
if (!_firstTower)
|
||||
{
|
||||
_guardian.setElder(true);
|
||||
}
|
||||
|
||||
UtilEnt.vegetate(_guardian);
|
||||
UtilEnt.setFakeHead(_guardian, true);
|
||||
UtilEnt.silence(_guardian, true);
|
||||
_guardian.setRemoveWhenFarAway(false);
|
||||
_guardian.setCustomNameVisible(true);
|
||||
|
||||
_crystal = _location.getWorld().spawn(getTowerBase(), EnderCrystal.class);
|
||||
_crystal.setCustomNameVisible(true);
|
||||
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
public void updateTarget()
|
||||
{
|
||||
if (_target == null)
|
||||
{
|
||||
LivingEntity target = MobaUtil.getBestEntityTarget(_host, _team, _stand, _location, TARGET_RANGE, false);
|
||||
_target = target;
|
||||
setLaserTarget(target);
|
||||
}
|
||||
else
|
||||
{
|
||||
double dist = UtilMath.offsetSquared(_location, _target.getLocation());
|
||||
|
||||
if (dist > TARGET_RANGE_SQUARED || UtilPlayer.isSpectator(_target))
|
||||
{
|
||||
_target = null;
|
||||
setLaserTarget(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDamage()
|
||||
{
|
||||
if (_target == null || _dead)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_target.getWorld().playSound(_target.getLocation(), Sound.EXPLODE, 1, 0.2F);
|
||||
UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, _target.getLocation().add(0, 1.5, 0), 0, 0, 0, 0.2F, 1, ViewDist.LONG);
|
||||
_host.getArcadeManager().GetDamage().NewDamageEvent(_target, null, null, DamageCause.CUSTOM, DAMAGE, false, true, false, "Tower", "Tower");
|
||||
}
|
||||
|
||||
private void setLaserTarget(LivingEntity target)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
_guardian.setTarget(0);
|
||||
|
||||
Location standLocation = _stand.getLocation();
|
||||
standLocation.setYaw(_fallbackYaw);
|
||||
|
||||
_guardian.getEntity().setLocation(standLocation.getX(), standLocation.getY(), standLocation.getZ(), standLocation.getYaw(), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
_guardian.setTarget(target.getEntityId());
|
||||
}
|
||||
|
||||
_host.getArcadeManager().GetDisguise().updateDisguise(_guardian);
|
||||
}
|
||||
|
||||
public void damage(double damage)
|
||||
@ -65,73 +139,60 @@ public class Tower
|
||||
if (_health <= 0)
|
||||
{
|
||||
UtilServer.CallEvent(new TowerDestroyEvent(this));
|
||||
_target = null;
|
||||
setLaserTarget(null);
|
||||
_dead = true;
|
||||
_guardian.remove();
|
||||
_stand.remove();
|
||||
_crystal.remove();
|
||||
explode();
|
||||
}
|
||||
else
|
||||
{
|
||||
_stand.setHealth(_health);
|
||||
updateDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDisplay()
|
||||
{
|
||||
float percentage = (float) _health / (float) _maxHealth;
|
||||
String out = MobaUtil.getHealthBar(_stand, 40);
|
||||
|
||||
_guardian.setCustomName(getHealthBar(40));
|
||||
_guardian.setName(out);
|
||||
_crystal.setCustomName(out);
|
||||
}
|
||||
|
||||
private void explode()
|
||||
{
|
||||
_host.getArcadeManager().GetExplosion().BlockExplosion(UtilBlock.getBlocksInRadius(_location.clone().subtract(0, 4, 0), 4), _location, false);
|
||||
_host.getArcadeManager().GetExplosion().BlockExplosion(UtilBlock.getBlocksInRadius(_location.clone().subtract(0, 3, 0), 3), _location, false);
|
||||
_location.getWorld().playSound(_location, Sound.EXPLODE, 2, 0.6F);
|
||||
UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, _location, 0, 0, 0, 0.1F, 1, ViewDist.LONG);
|
||||
}
|
||||
|
||||
public boolean isDead()
|
||||
private Location getTowerBase()
|
||||
{
|
||||
return _dead;
|
||||
Block last = _location.getBlock();
|
||||
boolean firstAir = false;
|
||||
|
||||
while (true)
|
||||
{
|
||||
last = last.getRelative(BlockFace.DOWN);
|
||||
|
||||
if (!firstAir && last.getType() == Material.AIR)
|
||||
{
|
||||
firstAir = true;
|
||||
}
|
||||
else if (firstAir && last.getType() != Material.AIR)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return last.getLocation().add(0.5, 0.5, 0.5);
|
||||
}
|
||||
|
||||
private String getHealthBar(int bars)
|
||||
public Location getLocation()
|
||||
{
|
||||
String out = "";
|
||||
String colour;
|
||||
double health = _guardian.getHealth() / _guardian.getMaxHealth();
|
||||
|
||||
if (health < 0.25)
|
||||
{
|
||||
colour = C.cRedB;
|
||||
}
|
||||
else if (health < 0.5)
|
||||
{
|
||||
colour = C.cGoldB;
|
||||
}
|
||||
else if (health < 0.75)
|
||||
{
|
||||
colour = C.cYellowB;
|
||||
}
|
||||
else
|
||||
{
|
||||
colour = C.cGreenB;
|
||||
}
|
||||
|
||||
for (int i = 0; i < bars; i++)
|
||||
{
|
||||
double cur = i * (1D / (double) bars);
|
||||
|
||||
if (cur < health)
|
||||
{
|
||||
out += colour + "|";
|
||||
}
|
||||
else
|
||||
{
|
||||
out += C.cGrayB + "|";
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
return _location;
|
||||
}
|
||||
|
||||
public GameTeam getOwner()
|
||||
@ -139,8 +200,24 @@ public class Tower
|
||||
return _team;
|
||||
}
|
||||
|
||||
public MobaLane getLane()
|
||||
{
|
||||
return _lane;
|
||||
}
|
||||
|
||||
public EnderCrystal getCrystal()
|
||||
{
|
||||
return _crystal;
|
||||
}
|
||||
|
||||
public boolean isFirstTower()
|
||||
{
|
||||
return _firstTower;
|
||||
}
|
||||
|
||||
public boolean isDead()
|
||||
{
|
||||
return _dead;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,252 @@
|
||||
package nautilus.game.arcade.game.games.moba.structure.tower;
|
||||
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||
import nautilus.game.arcade.game.Game.GameState;
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
import nautilus.game.arcade.game.games.moba.Moba;
|
||||
import nautilus.game.arcade.game.games.moba.MobaLane;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.EnderCrystal;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class TowerManager implements Listener
|
||||
{
|
||||
|
||||
private static final int FIRST_TOWER_HEALTH = 250;
|
||||
private static final int SECOND_TOWER_HEALTH = 500;
|
||||
|
||||
private final Moba _host;
|
||||
|
||||
private final List<Tower> _towers;
|
||||
|
||||
public TowerManager(Moba host)
|
||||
{
|
||||
_host = host;
|
||||
|
||||
_towers = new ArrayList<>(12);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void prepare(GameStateChangeEvent event)
|
||||
{
|
||||
if (event.GetState() != GameState.Prepare)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Location> towers = _host.getLocationStartsWith("TOWER");
|
||||
|
||||
for (Entry<String, Location> entry : towers.entrySet())
|
||||
{
|
||||
String key = entry.getKey();
|
||||
Location location = entry.getValue();
|
||||
String[] components = key.split(" ");
|
||||
|
||||
if (components.length < 4)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
String team = components[1];
|
||||
MobaLane lane = MobaLane.valueOf(components[2]);
|
||||
|
||||
boolean firstTower;
|
||||
|
||||
try
|
||||
{
|
||||
firstTower = components[3].equalsIgnoreCase("1");
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int health = firstTower ? FIRST_TOWER_HEALTH : SECOND_TOWER_HEALTH;
|
||||
GameTeam gameTeam = _host.getTeam(team);
|
||||
|
||||
if (gameTeam == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_towers.add(new Tower(_host, location, gameTeam, lane, health, firstTower));
|
||||
}
|
||||
|
||||
_host.CreatureAllowOverride = true;
|
||||
for (Tower tower : _towers)
|
||||
{
|
||||
tower.setup();
|
||||
}
|
||||
_host.CreatureAllowOverride = false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateTower(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() == UpdateType.FASTEST)
|
||||
{
|
||||
for (Tower tower : _towers)
|
||||
{
|
||||
tower.updateTarget();
|
||||
}
|
||||
}
|
||||
else if (event.getType() == UpdateType.SEC)
|
||||
{
|
||||
for (Tower tower : _towers)
|
||||
{
|
||||
tower.updateDamage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void crystalDamage(EntityDamageEvent event)
|
||||
{
|
||||
if (event.getEntity() instanceof EnderCrystal)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void crystalDamage(EntityDamageByEntityEvent event)
|
||||
{
|
||||
if (!(event.getEntity() instanceof EnderCrystal))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = event.getDamager();
|
||||
Player player = null;
|
||||
|
||||
if (entity instanceof Player)
|
||||
{
|
||||
player = (Player) entity;
|
||||
}
|
||||
else if (entity instanceof Projectile)
|
||||
{
|
||||
Projectile projectile = (Projectile) entity;
|
||||
ProjectileSource source = projectile.getShooter();
|
||||
|
||||
if (source instanceof Player)
|
||||
{
|
||||
player = (Player) source;
|
||||
|
||||
// TODO TEMP
|
||||
if (UtilMath.offsetSquared(player.getLocation(), event.getEntity().getLocation()) > Tower.TARGET_RANGE_SQUARED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameTeam team = _host.GetTeam(player);
|
||||
|
||||
if (UtilPlayer.isSpectator(player) || team == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Tower tower : _towers)
|
||||
{
|
||||
if (!event.getEntity().equals(tower.getCrystal()) || !canDamage(tower, team))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
tower.damage(event.getDamage());
|
||||
|
||||
if (Recharge.Instance.use(player, "Tower Sound", 1500, false, false))
|
||||
{
|
||||
player.playSound(tower.getCrystal().getLocation(), Sound.BLAZE_HIT, 1, 0.8F);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// /*
|
||||
// Hacky work arounds!!!!
|
||||
// */
|
||||
// @EventHandler
|
||||
// public void updateAnathBlazePowder(UpdateEvent event)
|
||||
// {
|
||||
// if (event.getType() != UpdateType.FASTEST)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// for (Tower tower : _towers)
|
||||
// {
|
||||
// for (Entity entity : UtilEnt.getAllInRadius(tower.getCrystal().getLocation(), 1.5).keySet())
|
||||
// {
|
||||
// if (entity instanceof Item)
|
||||
// {
|
||||
// Item item = (Item) entity;
|
||||
// if (item.getItemStack().getType() == Material.BLAZE_POWDER)
|
||||
// {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private boolean canDamage(Tower tower, GameTeam team)
|
||||
{
|
||||
// Dead tower, nothing
|
||||
// Same team
|
||||
if (tower.isDead() || team.equals(tower.getOwner()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
MobaLane lane = tower.getLane();
|
||||
|
||||
// First tower, all it
|
||||
if (tower.isFirstTower())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Second tower
|
||||
// Need to check if previous was destroyed
|
||||
for (Tower other : _towers)
|
||||
{
|
||||
// Is other team
|
||||
// Is first tower
|
||||
// Is same lane
|
||||
// Is dead
|
||||
if (team.equals(other.getOwner()) && other.isFirstTower() && lane == other.getLane() && other.isDead())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
package nautilus.game.arcade.game.games.moba.util;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
import nautilus.game.arcade.game.games.moba.Moba;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class MobaUtil
|
||||
{
|
||||
|
||||
public static LivingEntity getBestEntityTarget(Moba host, GameTeam owner, LivingEntity source, Location location, int targetRange)
|
||||
{
|
||||
return getBestEntityTarget(host, owner, source, location, targetRange, true);
|
||||
}
|
||||
|
||||
public static LivingEntity getBestEntityTarget(Moba host, GameTeam owner, LivingEntity source, Location location, int targetRange, boolean targetPlayersMore)
|
||||
{
|
||||
LivingEntity highest = null;
|
||||
double bestDist = 0;
|
||||
|
||||
for (Entry<LivingEntity, Double> entry : UtilEnt.getInRadius(location, targetRange).entrySet())
|
||||
{
|
||||
LivingEntity entity = entry.getKey();
|
||||
double dist = entry.getValue();
|
||||
|
||||
if (source.equals(entity))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Make players more desirable
|
||||
if (entity instanceof Player)
|
||||
{
|
||||
if (owner.equals(host.GetTeam((Player) entity)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (targetPlayersMore)
|
||||
{
|
||||
dist += 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestDist < dist)
|
||||
{
|
||||
highest = entity;
|
||||
bestDist = dist;
|
||||
}
|
||||
}
|
||||
|
||||
return highest;
|
||||
}
|
||||
|
||||
public static String getHealthBar(LivingEntity entity, int bars)
|
||||
{
|
||||
String out = "";
|
||||
String colour;
|
||||
double health = entity.getHealth() / entity.getMaxHealth();
|
||||
|
||||
if (health < 0.25)
|
||||
{
|
||||
colour = C.cRedB;
|
||||
}
|
||||
else if (health < 0.5)
|
||||
{
|
||||
colour = C.cGoldB;
|
||||
}
|
||||
else if (health < 0.75)
|
||||
{
|
||||
colour = C.cYellowB;
|
||||
}
|
||||
else
|
||||
{
|
||||
colour = C.cGreenB;
|
||||
}
|
||||
|
||||
for (int i = 0; i < bars; i++)
|
||||
{
|
||||
double cur = i * (1D / (double) bars);
|
||||
|
||||
if (cur < health)
|
||||
{
|
||||
out += colour + "|";
|
||||
}
|
||||
else
|
||||
{
|
||||
out += C.cGrayB + "|";
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user