mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Add a stare instruction for bots that stares at closest players, just cause. Also make it so bots don't hunt hidden players.
This commit is contained in:
parent
1bae8b15c4
commit
2ff6d047e8
@ -34,7 +34,7 @@ namespace MCGalaxy.Bots {
|
|||||||
Player closest = null;
|
Player closest = null;
|
||||||
|
|
||||||
foreach (Player p in players) {
|
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 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);
|
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.",
|
"%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.",
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,9 +47,10 @@ namespace MCGalaxy.Bots {
|
|||||||
|
|
||||||
/// <summary> All instructions that bots can execute. </summary>
|
/// <summary> All instructions that bots can execute. </summary>
|
||||||
public static List<BotInstruction> Instructions = new List<BotInstruction>() {
|
public static List<BotInstruction> Instructions = new List<BotInstruction>() {
|
||||||
new NodInstruction(), new SpinInstruction(), new HuntInstruction(), new KillInstruction(),
|
new NodInstruction(), new SpinInstruction(),
|
||||||
new TeleportInstruction(), new WalkInstruction(), new JumpInstruction(), new SpeedInstruction(),
|
new HuntInstruction(), new KillInstruction(), new StareInstruction(),
|
||||||
new RemoveInstruction(), new ResetInstruction(), new LinkScriptInstruction(), new WaitInstruction(),
|
new TeleportInstruction(), new WalkInstruction(), new JumpInstruction(), new SpeedInstruction(),
|
||||||
|
new RemoveInstruction(), new ResetInstruction(), new LinkScriptInstruction(), new WaitInstruction(),
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary> Finds the instruction which has the given identifying name. </summary>
|
/// <summary> Finds the instruction which has the given identifying name. </summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user