Fix mobtarget and obstacles
-Fix trapdoors -Fix mobtarget (and make the setting global)
This commit is contained in:
@@ -929,7 +929,7 @@ public class LegacyAgent extends Agent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkObstacles(Terminator bot, Block block, LivingEntity player) {
|
private boolean checkObstacles(Terminator bot, Block block, LivingEntity player) {
|
||||||
if (LegacyMats.OBSTACLES.contains(block.getType())) {
|
if (LegacyMats.OBSTACLES.contains(block.getType()) || isDoorObstacle(block)) {
|
||||||
preBreak(bot, player, block, LegacyLevel.AT_D);
|
preBreak(bot, player, block, LegacyLevel.AT_D);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -937,6 +937,14 @@ public class LegacyAgent extends Agent {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isDoorObstacle(Block block) {
|
||||||
|
if (block.getType().data == Door.class)
|
||||||
|
return true;
|
||||||
|
if (block.getType().data == TrapDoor.class && ((TrapDoor)block.getBlockData()).isOpen())
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean checkAt(Terminator bot, Block block, LivingEntity player) {
|
private boolean checkAt(Terminator bot, Block block, LivingEntity player) {
|
||||||
if (LegacyMats.BREAK.contains(block.getType())) {
|
if (LegacyMats.BREAK.contains(block.getType())) {
|
||||||
return false;
|
return false;
|
||||||
@@ -1503,12 +1511,12 @@ public class LegacyAgent extends Agent {
|
|||||||
if (region == null)
|
if (region == null)
|
||||||
return 0;
|
return 0;
|
||||||
double diffX = Math.max(0, Math.abs(region.getCenterX() - loc.getX()) - region.getWidthX() * 0.5);
|
double diffX = Math.max(0, Math.abs(region.getCenterX() - loc.getX()) - region.getWidthX() * 0.5);
|
||||||
double diffY = Math.max(0, Math.abs(region.getCenterY() - loc.getY()) - region.getHeight() * 0.5);
|
double diffY = Math.max(0, Math.abs(region.getCenterY() - loc.getY()) - region.getHeight() * 0.5);
|
||||||
double diffZ = Math.max(0, Math.abs(region.getCenterZ() - loc.getZ()) - region.getWidthZ() * 0.5);
|
double diffZ = Math.max(0, Math.abs(region.getCenterZ() - loc.getZ()) - region.getWidthZ() * 0.5);
|
||||||
if (regionWeightX == 0 && regionWeightY == 0 && regionWeightZ == 0)
|
if (regionWeightX == 0 && regionWeightY == 0 && regionWeightZ == 0)
|
||||||
if (diffX > 0 || diffY > 0 || diffZ > 0)
|
if (diffX > 0 || diffY > 0 || diffZ > 0)
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
return diffX * diffX * regionWeightX + diffY * diffY * regionWeightY + diffZ * diffZ * regionWeightZ;
|
return diffX * diffX * regionWeightX + diffY * diffY * regionWeightY + diffZ * diffZ * regionWeightZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -921,12 +921,4 @@ public class Bot extends ServerPlayer implements Terminator {
|
|||||||
this.yRotO = this.getYRot();
|
this.yRotO = this.getYRot();
|
||||||
this.xRotO = this.getXRot();
|
this.xRotO = this.getXRot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIgnoredByMobs() {
|
|
||||||
return ignoredByMobs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIgnoredByMobs(boolean ignoredByMobs) {
|
|
||||||
this.ignoredByMobs = ignoredByMobs;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,10 +60,10 @@ public class BotManagerImpl implements BotManager, Listener {
|
|||||||
if (target != null) {
|
if (target != null) {
|
||||||
Terminator closest = null;
|
Terminator closest = null;
|
||||||
for (Terminator bot : bots) {
|
for (Terminator bot : bots) {
|
||||||
if (name.equals(bot.getBotName()) && (closest == null
|
if (name.equals(bot.getBotName()) && (closest == null
|
||||||
|| target.distanceSquared(bot.getLocation()) < target.distanceSquared(closest.getLocation()))) {
|
|| target.distanceSquared(bot.getLocation()) < target.distanceSquared(closest.getLocation()))) {
|
||||||
closest = bot;
|
closest = bot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return closest;
|
return closest;
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,6 @@ public class BotManagerImpl implements BotManager, Listener {
|
|||||||
} else if (i > 1) {
|
} else if (i > 1) {
|
||||||
bot.setVelocity(randomVelocity().multiply(f));
|
bot.setVelocity(randomVelocity().multiply(f));
|
||||||
}
|
}
|
||||||
bot.setIgnoredByMobs(!mobTarget);
|
|
||||||
|
|
||||||
bots.add(bot);
|
bots.add(bot);
|
||||||
i++;
|
i++;
|
||||||
@@ -232,8 +231,10 @@ public class BotManagerImpl implements BotManager, Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onMobTarget(EntityTargetLivingEntityEvent event) {
|
public void onMobTarget(EntityTargetLivingEntityEvent event) {
|
||||||
Bot bot = (Bot) getBot(event.getEntity().getUniqueId());
|
if (mobTarget || event.getTarget() == null)
|
||||||
if (bot != null && bot.isIgnoredByMobs()) {
|
return;
|
||||||
|
Bot bot = (Bot) getBot(event.getTarget().getUniqueId());
|
||||||
|
if (bot != null) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -291,8 +291,8 @@ public class BotCommand extends CommandInstance {
|
|||||||
sender.sendMessage(ChatUtils.LINE);
|
sender.sendMessage(ChatUtils.LINE);
|
||||||
sender.sendMessage(ChatColor.GOLD + "Bot Settings" + extra);
|
sender.sendMessage(ChatColor.GOLD + "Bot Settings" + extra);
|
||||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "setgoal" + ChatUtils.BULLET_FORMATTED + "Set the global bot target selection method.");
|
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "setgoal" + ChatUtils.BULLET_FORMATTED + "Set the global bot target selection method.");
|
||||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "mobtarget" + ChatUtils.BULLET_FORMATTED + "Allow all future bots spawned to be targeted by hostile mobs.");
|
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "mobtarget" + ChatUtils.BULLET_FORMATTED + "Allow all bots to be targeted by hostile mobs.");
|
||||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "playertarget" + ChatUtils.BULLET_FORMATTED + "Sets a player name for the bots to focus on if the goal is PLAYER.");
|
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "playertarget" + ChatUtils.BULLET_FORMATTED + "Sets a player name for spawned bots to focus on if the goal is PLAYER.");
|
||||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "region" + ChatUtils.BULLET_FORMATTED + "Sets a region for the bots to prioritize entities inside.");
|
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "region" + ChatUtils.BULLET_FORMATTED + "Sets a region for the bots to prioritize entities inside.");
|
||||||
sender.sendMessage(ChatUtils.LINE);
|
sender.sendMessage(ChatUtils.LINE);
|
||||||
return;
|
return;
|
||||||
@@ -325,7 +325,7 @@ public class BotCommand extends CommandInstance {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
manager.setMobTarget(Boolean.parseBoolean(arg2));
|
manager.setMobTarget(Boolean.parseBoolean(arg2));
|
||||||
sender.sendMessage("Mob targeting is now " + (manager.isMobTarget() ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled") + ChatColor.RESET + ". (for all future bots)");
|
sender.sendMessage("Mob targeting is now " + (manager.isMobTarget() ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled") + ChatColor.RESET + ".");
|
||||||
} else if (arg1.equalsIgnoreCase("playertarget")) {
|
} else if (arg1.equalsIgnoreCase("playertarget")) {
|
||||||
if (args.size() < 2) {
|
if (args.size() < 2) {
|
||||||
sender.sendMessage(ChatColor.RED + "You must specify a player name!");
|
sender.sendMessage(ChatColor.RED + "You must specify a player name!");
|
||||||
|
|||||||
Reference in New Issue
Block a user