static bool MoveTowards(PlayerBot bot, Player p, Metadata meta) { if (p == null) { return(false); } int dist = (int)(0.875 * 32); int dx = p.Pos.X - bot.Pos.X, dy = p.Pos.Y - bot.Pos.Y, dz = p.Pos.Z - bot.Pos.Z; bot.TargetPos = p.Pos; bot.movement = true; Vec3F32 dir = new Vec3F32(dx, dy, dz); dir = Vec3F32.Normalise(dir); Orientation rot = bot.Rot; DirUtils.GetYawPitch(dir, out rot.RotY, out rot.HeadX); MobAI.SetDirectionalSpeeds(bot); dx = Math.Abs(dx); dy = Math.Abs(dy); dz = Math.Abs(dz); if (InRange(p, bot, dist)) { p.Message("%cInfect"); } bot.Rot = rot; return(dx <= 8 && dy <= 16 && dz <= 8); }
static bool MoveTowards(PlayerBot bot, Player p, Metadata meta) { if (p == null) { return(false); } int dx = p.Pos.X - bot.Pos.X, dy = p.Pos.Y - bot.Pos.Y, dz = p.Pos.Z - bot.Pos.Z; bot.TargetPos = p.Pos; bot.movement = true; Vec3F32 dir = new Vec3F32(dx, dy, dz); dir = Vec3F32.Normalise(dir); Orientation rot = bot.Rot; DirUtils.GetYawPitch(dir, out rot.RotY, out rot.HeadX); MobAI.SetDirectionalSpeeds(bot); p.Message("I am facing: %b" + MobAI.CalculateCardinal(bot)); p.Message("sp " + bot.movementSpeed); //p.Message("The block in front of me is: %b"); dx = Math.Abs(dx); dy = Math.Abs(dy); dz = Math.Abs(dz); bot.Rot = rot; return(dx <= 8 && dy <= 16 && dz <= 8); }
static bool MoveTowards(PlayerBot bot, Player p, Metadata meta) { if (p == null) { return(false); } int dx = p.Pos.X - bot.Pos.X, dy = p.Pos.Y - bot.Pos.Y, dz = p.Pos.Z - bot.Pos.Z; bot.TargetPos = p.Pos; bot.movement = true; Vec3F32 dir = new Vec3F32(dx, dy, dz); dir = Vec3F32.Normalise(dir); Orientation rot = bot.Rot; DirUtils.GetYawPitch(dir, out rot.RotY, out rot.HeadX); MobAI.SetDirectionalSpeeds(bot); dx = Math.Abs(dx); dy = Math.Abs(dy); dz = Math.Abs(dz); if (bot.Model == "creeper") { if (dx < (3 * 32) && dz < (3 * 32)) { if (meta.explodeTime == 0) { meta.explodeTime = 10; } } else { meta.explodeTime = 0; } } else { if ((dx <= 8 && dy <= 16 && dz <= 8)) { HitPlayer(bot, p, rot); } } bot.Rot = rot; return(dx <= 8 && dy <= 16 && dz <= 8); }
/// <summary> /// Face bot towards target position. /// </summary> /// <param name="bot"></param> public static void FaceTowards(PlayerBot bot) { int dstHeight = ModelInfo.CalcEyeHeight(bot); int dx = (bot.TargetPos.X) - bot.Pos.X, dy = bot.Rot.RotY, dz = (bot.TargetPos.Z) - bot.Pos.Z; Vec3F32 dir = new Vec3F32(dx, dy, dz); dir = Vec3F32.Normalise(dir); Orientation rot = bot.Rot; DirUtils.GetYawPitch(dir, out rot.RotY, out rot.HeadX); bot.Rot = rot; }
static bool MoveTowards(PlayerBot bot, Player p, Metadata meta) { if (p == null) { return(false); } int dist = (int)(0.875 * 32); int dx = p.Pos.X - bot.Pos.X, dy = p.Pos.Y - bot.Pos.Y, dz = p.Pos.Z - bot.Pos.Z; bot.TargetPos = p.Pos; bot.movement = true; Vec3F32 dir = new Vec3F32(dx, dy, dz); dir = Vec3F32.Normalise(dir); Orientation rot = bot.Rot; DirUtils.GetYawPitch(dir, out rot.RotY, out rot.HeadX); MobAI.SetDirectionalSpeeds(bot); dx = Math.Abs(dx); dy = Math.Abs(dy); dz = Math.Abs(dz); //if (InRange(p, bot, dist)) p.Message("%cInfect"); bot.Rot = rot; if (dx < (5 * 32) && dz < (5 * 32)) // 5 block reach { Random rnd = new Random(); // This code serves as a sort of 'CPS mechanism' to ensure that the bot does not perfectly delete every single block int chance = rnd.Next(0, 4); // 33% chance of deleting the block if (chance < 3) { bot.level.UpdateBlock(Player.Console, (ushort)(p.Pos.X / 32), (ushort)((p.Pos.Y / 32) - 2), (ushort)(p.Pos.Z / 32), Block.Air); if ((p.Pos.Y / 32) > lastY) { bot.level.UpdateBlock(Player.Console, (ushort)(p.Pos.X / 32), (ushort)((p.Pos.Y / 32) - 3), (ushort)(p.Pos.Z / 32), Block.Air); } } lastY = (p.Pos.Y / 32); } return(dx <= 8 && dy <= 16 && dz <= 8); }
static bool MoveTowards(PlayerBot bot, Player p) { int dx = p.Pos.X - bot.Pos.X, dy = p.Pos.Y - bot.Pos.Y, dz = p.Pos.Z - bot.Pos.Z; bot.TargetPos = p.Pos; bot.movement = true; Vec3F32 dir = new Vec3F32(dx, dy, dz); dir = Vec3F32.Normalise(dir); Orientation rot = bot.Rot; DirUtils.GetYawPitch(dir, out rot.RotY, out rot.HeadX); // If we are very close to a player, switch from trying to look // at them to just facing the opposite direction to them if (Math.Abs(dx) < 4 && Math.Abs(dz) < 4) { rot.RotY = (byte)(p.Rot.RotY + 128); } bot.Rot = rot; return(dx <= 8 && dy <= 16 && dz <= 8); }