From 2ff6d047e8eb4b80236c57e1b15907e08a02fd7d Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 10 Sep 2016 19:04:35 +1000 Subject: [PATCH] Add a stare instruction for bots that stares at closest players, just cause. Also make it so bots don't hunt hidden players. --- Bots/Instructions/HunterInstructions.cs | 39 ++++++++++++++++++++++++- Bots/Instructions/Instruction.cs | 7 +++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/Bots/Instructions/HunterInstructions.cs b/Bots/Instructions/HunterInstructions.cs index 3c59a1279..cb08cb6e1 100644 --- a/Bots/Instructions/HunterInstructions.cs +++ b/Bots/Instructions/HunterInstructions.cs @@ -34,7 +34,7 @@ namespace MCGalaxy.Bots { Player closest = null; foreach (Player p in players) { - if (p.level != bot.level || p.invincible) continue; + if (p.level != bot.level || p.invincible || p.hidden) continue; int dx = p.pos[0] - bot.pos[0], dy = p.pos[1] - bot.pos[1], dz = p.pos[2] - bot.pos[2]; int playerDist = Math.Abs(dx) + Math.Abs(dy) + Math.Abs(dz); @@ -119,4 +119,41 @@ namespace MCGalaxy.Bots { "%HCauses the bot to kill any players it is touching.", }; } + + public sealed class StareInstruction : BotInstruction { + public override string Name { get { return "stare"; } } + + public override bool Execute(PlayerBot bot, InstructionData data) { + int dist = 20000 * 32; + Player[] players = PlayerInfo.Online.Items; + Player closest = null; + + foreach (Player p in players) { + if (p.level != bot.level || p.hidden) continue; + + int dx = p.pos[0] - bot.pos[0], dy = p.pos[1] - bot.pos[1], dz = p.pos[2] - bot.pos[2]; + int playerDist = Math.Abs(dx) + Math.Abs(dy) + Math.Abs(dz); + if (playerDist >= dist) continue; + + closest = p; + dist = playerDist; + } + + if (closest == null) return true; + FaceTowards(bot, closest); + return true; + } + + static void FaceTowards(PlayerBot bot, Player p) { + int dx = p.pos[0] - bot.pos[0], dy = p.pos[1] - bot.pos[1], dz = p.pos[2] - bot.pos[2]; + Vec3F32 dir = new Vec3F32(dx, dy, dz); + dir = Vec3F32.Normalise(dir); + DirUtils.GetYawPitch(dir, out bot.rot[0], out bot.rot[1]); + } + + public override string[] Help { get { return help; } } + static string[] help = { "%T/botai add [name] stare", + "%HCauses the bot to stare at the closest player.", + }; + } } diff --git a/Bots/Instructions/Instruction.cs b/Bots/Instructions/Instruction.cs index 7f091c14a..43740e9d8 100644 --- a/Bots/Instructions/Instruction.cs +++ b/Bots/Instructions/Instruction.cs @@ -47,9 +47,10 @@ namespace MCGalaxy.Bots { /// All instructions that bots can execute. public static List Instructions = new List() { - new NodInstruction(), new SpinInstruction(), new HuntInstruction(), new KillInstruction(), - new TeleportInstruction(), new WalkInstruction(), new JumpInstruction(), new SpeedInstruction(), - new RemoveInstruction(), new ResetInstruction(), new LinkScriptInstruction(), new WaitInstruction(), + new NodInstruction(), new SpinInstruction(), + new HuntInstruction(), new KillInstruction(), new StareInstruction(), + new TeleportInstruction(), new WalkInstruction(), new JumpInstruction(), new SpeedInstruction(), + new RemoveInstruction(), new ResetInstruction(), new LinkScriptInstruction(), new WaitInstruction(), }; /// Finds the instruction which has the given identifying name.