Improve the path finding ai

This commit is contained in:
Sam 2017-05-23 22:57:13 +01:00
parent 78b10e3cb8
commit 6f48d0ee43
6 changed files with 100 additions and 11 deletions

View File

@ -567,4 +567,9 @@ public class Moba extends TeamGame
{
return _capturePoint;
}
public BossManager getBossManager()
{
return _boss;
}
}

View File

@ -16,6 +16,11 @@ public class MobaDirectAIMethod implements MobaAIMethod
{
Location entityLocation = entity.getLocation();
if (UtilMath.offsetSquared(entity.getLocation(), goal) < 6)
{
return false;
}
float entityYaw = entityLocation.getYaw();
// Speed is blocks per second

View File

@ -9,7 +9,9 @@ import nautilus.game.arcade.world.WorldData;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BossManager implements Listener
@ -69,4 +71,13 @@ public class BossManager implements Listener
{
return _teamBosses.get(team);
}
public List<MobaBoss> getBosses()
{
List<MobaBoss> bosses = new ArrayList<>();
bosses.addAll(_teamBosses.values());
return bosses;
}
}

View File

@ -87,4 +87,9 @@ public abstract class MobaBoss implements Listener
{
return _entity;
}
public boolean isDead()
{
return _entity == null || _entity.isDead() || !_entity.isValid();
}
}

View File

@ -173,4 +173,9 @@ public class WitherBoss extends MobaBoss
{
_disguise.setName(MobaUtil.getHealthBar(_entity, 40));
}
public GameTeam getTeam()
{
return _team;
}
}

View File

@ -9,8 +9,11 @@ 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.ai.goal.MobaDirectAIMethod;
import nautilus.game.arcade.game.games.moba.boss.MobaBoss;
import nautilus.game.arcade.game.games.moba.boss.wither.WitherBoss;
import nautilus.game.arcade.game.games.moba.structure.tower.Tower;
import nautilus.game.arcade.game.games.moba.util.MobaConstants;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
@ -29,7 +32,7 @@ import java.util.List;
public class MinionWave implements Listener
{
private static final int MAX_MINIONS_PER_WAVE = 6;
private static final int MAX_MINIONS_PER_WAVE = 1;
private static final MobaAIMethod AI_METHOD = new MobaDirectAIMethod();
private final Moba _host;
@ -93,22 +96,44 @@ public class MinionWave implements Listener
for (Minion minion : _minions)
{
LivingEntity entity = minion.getEntity();
Location target = null;
Location towerTarget = targetTower(minion);
Location witherTarget = targetWither(minion);
if (targetTower(minion))
if (towerTarget != null)
{
target = towerTarget;
}
else if (!AI_METHOD.updateMovement(entity, minion.getTarget(), 0.1F))
else if (witherTarget != null)
{
target = witherTarget;
}
if (target != null)
{
minion.setTarget(target);
// Too close
if (UtilMath.offsetSquared(entity.getLocation(), target) < 12)
{
Bukkit.broadcastMessage("Too close");
continue;
}
}
if (!AI_METHOD.updateMovement(entity, minion.getTarget(), 4F))
{
int newTarget = minion.getTargetIndex() + 1;
if (newTarget == _path.size())
{
// TODO target wither, probably...
Bukkit.broadcastMessage("Done");
continue;
}
minion.setTargetIndex(newTarget);
minion.setTarget(_path.get(newTarget));
Bukkit.broadcastMessage("Advance target " + newTarget);
}
}
@ -121,7 +146,7 @@ public class MinionWave implements Listener
}
}
private boolean targetTower(Minion minion)
private Location targetTower(Minion minion)
{
for (Tower tower : _host.getTowerManager().getTowers())
{
@ -130,27 +155,60 @@ public class MinionWave implements Listener
continue;
}
Location location = tower.getCrystal().getLocation();
double distSquared = UtilMath.offsetSquared(minion.getEntity(), tower.getCrystal());
if (distSquared < 3)
{
return true;
return location;
}
else if (distSquared > Tower.TARGET_RANGE_SQUARED)
{
continue;
}
minion.setTarget(tower.getCrystal().getLocation());
return true;
return location;
}
return false;
return null;
}
private void targetWither(Minion minion)
private Location targetWither(Minion minion)
{
for (MobaBoss boss : _host.getBossManager().getBosses())
{
if (boss.isDead())
{
continue;
}
if (boss instanceof WitherBoss)
{
WitherBoss witherBoss = (WitherBoss) boss;
if (witherBoss.getTeam().equals(_owner))
{
continue;
}
}
Location location = boss.getEntity().getLocation();
double distSquared = UtilMath.offsetSquared(minion.getEntity(), boss.getEntity());
if (distSquared < 3)
{
return location;
}
else if (distSquared > Tower.TARGET_RANGE_SQUARED)
{
continue;
}
minion.setTarget(boss.getEntity().getLocation());
return location;
}
return null;
}
@EventHandler(priority = EventPriority.HIGHEST)