Fix bots that have jump AI, having their position set to middle of jump Y on level unload, which causes them to reappear higher up on level load next time

This commit is contained in:
UnknownShadow200 2017-08-30 13:34:33 +10:00
parent d8954e5c38
commit 5c7af8b877
4 changed files with 16 additions and 16 deletions

View File

@ -98,6 +98,7 @@ namespace MCGalaxy.Bots {
public bool Kill { get; set; }
public bool Hunt { get; set; }
public int CurInstruction { get; set; }
public sbyte CurJump { get; set; }
public int X { get; set; }
public int Y { get; set; }
@ -113,7 +114,7 @@ namespace MCGalaxy.Bots {
Model = bot.Model; Color = bot.color;
Kill = bot.kill; Hunt = bot.hunt;
DisplayName = bot.DisplayName;
CurInstruction = bot.cur;
CurInstruction = bot.cur; CurJump = bot.curJump;
ClickedOnText = bot.ClickedOnText;
X = bot.Pos.X; Y = bot.Pos.Y; Z = bot.Pos.Z;
@ -132,7 +133,7 @@ namespace MCGalaxy.Bots {
bot.AIName = AI; bot.hunt = Hunt; bot.kill = Kill;
bot.DisplayName = DisplayName;
bot.cur = CurInstruction;
bot.cur = CurInstruction; bot.curJump = CurJump;
bot.ClickedOnText = ClickedOnText;
}
@ -143,7 +144,7 @@ namespace MCGalaxy.Bots {
copy.Model = Model; copy.Color = Color;
copy.AI = AI; copy.Kill = Kill; copy.Hunt = Hunt;
copy.CurInstruction = CurInstruction;
copy.CurInstruction = CurInstruction; copy.CurJump = CurJump;
copy.ClickedOnText = ClickedOnText;
copy.X = X; copy.Y = Y; copy.Z = Z;

View File

@ -66,7 +66,7 @@ namespace MCGalaxy {
}
}
if (bot.jumping) DoJump(bot);
if (bot.curJump > 0) DoJump(bot);
}
static bool DoInstruction(PlayerBot bot) {
@ -76,15 +76,15 @@ namespace MCGalaxy {
}
static void DoJump(PlayerBot bot) {
bot.currentjump++;
Position pos = bot.Pos;
switch (bot.currentjump) {
switch (bot.curJump) {
case 1: pos.Y += 24; break;
case 2: pos.Y += 12; break;
case 3: break;
case 4: pos.Y -= 12; break;
case 5: pos.Y -= 24; bot.jumping = false; bot.currentjump = 0; break;
case 5: pos.Y -= 24; bot.curJump = -1; break;
}
bot.curJump++;
bot.Pos = pos;
}
}

View File

@ -94,7 +94,7 @@ namespace MCGalaxy.Bots {
public JumpInstruction() { Name = "jump"; }
public override bool Execute(PlayerBot bot, InstructionData data) {
bot.jumping = true;
if (bot.curJump <= 0) bot.curJump = 1;
bot.NextInstruction(); return false;
}

View File

@ -43,8 +43,7 @@ namespace MCGalaxy {
public Position TargetPos;
public bool movement = false;
public int movementSpeed = 3;
internal bool jumping = false;
internal int currentjump = 0;
internal sbyte curJump = 0;
public PlayerBot(string n, Level lvl) { Init(n, lvl); }
@ -78,7 +77,7 @@ namespace MCGalaxy {
public static void Remove(PlayerBot bot, bool save = true) {
bot.level.Bots.Remove(bot);
bot.GlobalDespawn();
bot.jumping = false;
bot.curJump = 0;
if (save) BotsFile.Save(bot.level);
}