Skip to content

Commit

Permalink
Add move bot AI instruction (same as walk, but doesn't adjust yaw/pit…
Browse files Browse the repository at this point in the history
…ch to direction walking in
  • Loading branch information
UnknownShadow200 committed Oct 26, 2023
1 parent a8c096c commit 7b20917
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
6 changes: 4 additions & 2 deletions MCGalaxy/Bots/Instructions/Instruction.cs
Expand Up @@ -49,13 +49,15 @@ public abstract class BotInstruction
public static List<BotInstruction> Instructions = new List<BotInstruction>() {
new NodInstruction(), new SpinInstruction(),
new HuntInstruction(), new KillInstruction(), new StareInstruction(),
new TeleportInstruction(), new WalkInstruction(), new JumpInstruction(), new SpeedInstruction(),
new TeleportInstruction(), new WalkInstruction(), new MoveInstruction(),
new JumpInstruction(), new SpeedInstruction(),
new RemoveInstruction(), new ResetInstruction(), new LinkScriptInstruction(), new WaitInstruction(),
};

/// <summary> Finds the instruction which has the given identifying name. </summary>
public static BotInstruction Find(string name) {
foreach (BotInstruction ins in Instructions) {
foreach (BotInstruction ins in Instructions)
{
if (ins.Name.CaselessEq(name)) return ins;
}
return null;
Expand Down
27 changes: 23 additions & 4 deletions MCGalaxy/Bots/Instructions/MoveInstructions.cs
Expand Up @@ -64,10 +64,10 @@ protected struct Coords {
};
}

/// <summary> Causes the bot to gradually move to to a position. </summary>
public sealed class WalkInstruction : TeleportInstruction
/// <summary> Causes the bot to gradually move towards a position. </summary>
public class MoveInstruction : TeleportInstruction
{
public WalkInstruction() { Name = "walk"; }
public MoveInstruction() { Name = "move"; }

public override bool Execute(PlayerBot bot, InstructionData data) {
Coords target = (Coords)data.Metadata;
Expand All @@ -80,10 +80,29 @@ public sealed class WalkInstruction : TeleportInstruction
bot.NextInstruction(); return false;
}

bot.FaceTowards(bot.Pos, bot.TargetPos);
StartMoving(bot);
return true;
}

protected virtual void StartMoving(PlayerBot bot) { }

public override string[] Help { get { return help; } }
static string[] help = new string[] {
"&T/BotAI add [name] walk",
"&HCauses the bot to move towards to a position.",
"&H Note: The position saved to the AI is your current position.",
};
}

/// <summary> Causes the bot to gradually walk towards to a position. </summary>
public sealed class WalkInstruction : MoveInstruction
{
public WalkInstruction() { Name = "walk"; }

protected override void StartMoving(PlayerBot bot) {
bot.FaceTowards(bot.Pos, bot.TargetPos);
}

public override string[] Help { get { return help; } }
static string[] help = new string[] {
"&T/BotAI add [name] walk",
Expand Down

0 comments on commit 7b20917

Please sign in to comment.