Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/net/nuggetmc/tplus/bot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public boolean hasNeuralNetwork() {
}

public ItemStack defaultItem;
public int attackRange;

private boolean shield;
private boolean blocking;
Expand Down Expand Up @@ -83,6 +84,7 @@ private Bot(MinecraftServer minecraftServer, WorldServer worldServer, GameProfil
this.scheduler = Bukkit.getScheduler();
this.agent = plugin.getManager().getAgent();
this.defaultItem = new ItemStack(Material.AIR);
this.attackRange = 3;
this.velocity = new Vector(0, 0, 0);
this.oldVelocity = velocity.clone();
this.noFallTicks = 60;
Expand Down Expand Up @@ -117,6 +119,7 @@ public void sendPacket(Packet<?> packet, @Nullable GenericFutureListener<? exten

bot.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
bot.getBukkitEntity().setNoDamageTicks(0);
bot.setAttackRange(bot.getAttackRange());
nmsWorld.addEntity(bot);

bot.renderAll();
Expand Down Expand Up @@ -160,6 +163,14 @@ public void setDefaultItem(ItemStack item) {
this.defaultItem = item;
}

public void setAttackRange(int radius) {
this.attackRange = radius;
}

public int getAttackRange() {
return attackRange;
}

public Vector getOffset() {
return offset;
}
Expand Down Expand Up @@ -410,9 +421,11 @@ public void walk(Vector vel) {
}

public void attack(org.bukkit.entity.Entity entity) {
Location loc = this.getLocation();
faceLocation(entity.getLocation());
punch();

if (loc.distance(entity.getLocation()) >= this.getAttackRange()) return;
double damage = ItemUtils.getLegacyAttackDamage(defaultItem);

if (entity instanceof Damageable) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/nuggetmc/tplus/bot/BotManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void createBots(Player sender, String name, String skinName, int n, Neura

skinName = skinName == null ? name : skinName;

createBots(sender.getLocation(), name, MojangAPI.getSkin(skinName), n, network);
createBots(sender.getTargetBlock(null, 32).getLocation(), name, MojangAPI.getSkin(skinName), n, network);

sender.sendMessage("Process completed (" + ChatColor.RED + ((System.currentTimeMillis() - timestamp) / 1000D) + "s" + ChatColor.RESET + ").");
}
Expand Down Expand Up @@ -111,6 +111,7 @@ public Set<Bot> createBots(Location loc, String name, String[] skin, List<Neural
bot.setNeuralNetwork(network == NeuralNetwork.RANDOM ? NeuralNetwork.generateRandomNetwork() : network);
bot.setShield(true);
bot.setDefaultItem(new ItemStack(Material.WOODEN_AXE));
bot.setAttackRange(bot.getAttackRange());
//bot.setRemoveOnDeath(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ private void tickBot(Bot bot) {
move(bot, player, loc, target);
}*/

if (bot.tickDelay(3)) attack(bot, player, loc);
if (bot.tickDelay(5)) attack(bot, player, loc);
}

private void attack(Bot bot, Player player, Location loc) {
if (PlayerUtils.isInvincible(player.getGameMode()) || player.getNoDamageTicks() >= 5 || loc.distance(player.getLocation()) >= 4) return;
if (PlayerUtils.isInvincible(player.getGameMode()) || player.getNoDamageTicks() >= 5 || loc.distance(player.getLocation()) >= bot.getAttackRange()) return;

bot.attack(player);
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/net/nuggetmc/tplus/command/commands/BotCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,29 @@ public List<String> armorAutofill(CommandSender sender, String[] args) {
return args.length == 2 ? new ArrayList<>(armorTiers.keySet()) : null;
}

@Command(
name = "range",
desc = "Change the attack range for all bots.",
usage = "<attack-Range>"
)
public void range(CommandSender sender, List<String> args) {
int radius;

if (args.isEmpty()) {
commandHandler.sendUsage(sender, this, "range <attackRange>");
return;
}

try {
radius = Integer.parseInt(args.get(0));
} catch (NumberFormatException e) {
sender.sendMessage("The range must be an integer!");
return;
}
manager.fetch().forEach(bot -> bot.setAttackRange(radius));
sender.sendMessage("Successfully set the attack range to " + ChatColor.YELLOW + radius + ChatColor.RESET + " for all bots.");
}

@Command(
name = "info",
desc = "Information about loaded bots.",
Expand Down Expand Up @@ -277,12 +300,14 @@ public void info(CommandSender sender, List<String> args) {
String strLoc = ChatColor.YELLOW + formatter.format(loc.getBlockX()) + ", " + formatter.format(loc.getBlockY()) + ", " + formatter.format(loc.getBlockZ());
Vector vel = bot.getVelocity();
String strVel = ChatColor.AQUA + formatter.format(vel.getX()) + ", " + formatter.format(vel.getY()) + ", " + formatter.format(vel.getZ());
int attackRange = bot.getAttackRange();

sender.sendMessage(ChatUtils.LINE);
sender.sendMessage(ChatColor.GREEN + botName);
sender.sendMessage(ChatUtils.BULLET_FORMATTED + "World: " + world);
sender.sendMessage(ChatUtils.BULLET_FORMATTED + "Position: " + strLoc);
sender.sendMessage(ChatUtils.BULLET_FORMATTED + "Velocity: " + strVel);
sender.sendMessage(ChatUtils.BULLET_FORMATTED + "Attack Range: " + attackRange);
sender.sendMessage(ChatUtils.LINE);
}

Expand Down