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); dx = Math.Abs(dx); dy = Math.Abs(dy); dz = Math.Abs(dz); // If we are very close to a player, switch from trying to look // at them to just facing the opposite direction to them if (dx < 4 && dz < 4) { rot.RotY = (byte)(p.Rot.RotY + 128); } bot.Rot = rot; return(dx <= 8 && dy <= 16 && dz <= 8); }
static bool MoveTowards(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]; bot.foundPos = p.pos; bot.movement = true; Vec3F32 dir = new Vec3F32(dx, dy, dz); dir = Vec3F32.Normalise(dir); byte yaw, pitch; DirUtils.GetYawPitch(dir, out yaw, out pitch); // 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) { bot.rot[0] = yaw; } else if (p.rot[0] < 128) { bot.rot[0] = (byte)(p.rot[0] + 128); } else { bot.rot[0] = (byte)(p.rot[0] - 128); } bot.rot[1] = pitch; return(dx <= 8 && dy <= 16 && dz <= 8); }
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]); }
static void RideCallback(SchedulerTask task) { Player p = (Player)task.State; if (!p.onTrain) { p.trainGrab = false; p.Message("Dismounted"); Server.MainScheduler.QueueOnce(TrainInvincibleCallback, p, TimeSpan.FromSeconds(1)); task.Repeating = false; return; } Vec3S32 P = p.Pos.FeetBlockCoords; for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { for (int dz = -1; dz <= 1; dz++) { ushort xx = (ushort)(P.X + dx), yy = (ushort)(P.Y + dy), zz = (ushort)(P.Z + dz); if (p.level.GetBlock(xx, yy, zz) != Block.Train) { continue; } p.trainGrab = true; byte yaw, pitch; Vec3F32 dir = new Vec3F32(dx, 0, dz); DirUtils.GetYawPitch(dir, out yaw, out pitch); if (dy == 1) { pitch = 240; } else if (dy == 0) { pitch = 0; } else { pitch = 8; } if (dx != 0 || dy != 0 || dz != 0) { Position pos = Position.FromFeetBlockCoords(P.X + dx, P.Y + dy, P.Z + dz); p.SendPos(Entities.SelfID, pos, new Orientation(yaw, pitch)); } return; } } } p.trainGrab = false; }
static void FaceTowards(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; 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; }
public override int Update() { Player p = Helpers.getClosestPlayerFrom(_pos.X, _pos.Y, _pos.Z, _survivalPlayers, _curMap); if (p != null) { int dist = Helpers.calculDistance(p.Pos, _pos); if (dist > 2048) { _survivalMobs.Remove(ID); return(1); } if (dist > 256 || !_beenHurted) { _count++; if (_count > 100) { _count = 0; Random rnd = new Random(); _speedX = rnd.Next(-2, 3); _speedZ = rnd.Next(-2, 3); } int a2 = _pos.X - _pos.X + _speedX; int b2 = _pos.Z - _pos.Z + _speedZ; Vec3F32 dir2 = new Vec3F32(a2, 0, b2); dir2 = Vec3F32.Normalise(dir2); DirUtils.GetYawPitch(dir2, out _rot.RotY, out _rot.HeadX); UpdatePosition(); return(0); } int a = _pos.X - p.Pos.X; int b = _pos.Z - p.Pos.Z; int angle = (int)(Math.Atan2(b, a)); _speedX = (int)(Math.Cos(angle) * 5); _speedZ = (int)(Math.Sin(angle) * 5); Vec3F32 dir = new Vec3F32(a, 0, b); dir = Vec3F32.Normalise(dir); DirUtils.GetYawPitch(dir, out _rot.RotY, out _rot.HeadX); } UpdatePosition(); return(0); }
static void FaceTowards(PlayerBot bot, Player p) { int srcHeight = ModelInfo.CalcEyeHeight(p); int dstHeight = ModelInfo.CalcEyeHeight(bot); int dx = p.Pos.X - bot.Pos.X, dy = (p.Pos.Y + srcHeight) - (bot.Pos.Y + dstHeight), dz = p.Pos.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; }
public override bool Execute(PlayerBot bot, InstructionData data) { bot.TargetPos.X = (ushort)(Core.Ball.Position3d.X - 64); bot.TargetPos.Y = (ushort)32 + 51; bot.TargetPos.Z = (ushort)Constants.TouchLineTop; bot.movement = true; int dx = (ushort)(Core.Ball.Position3d.X) - bot.pos[0], dy = (ushort)Core.Ball.Position3d.Z - bot.pos[1], dz = (ushort)Core.Ball.Position3d.Y - bot.pos[2]; 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; return(true); }
public override int Update() { _attackCount++; if (_attackCount > 15) { _attackCount = 0; Attack(); } Player p = Helpers.getClosestPlayerFrom(_pos.X, _pos.Y, _pos.Z, _survivalPlayers, _curMap); if (p != null) { int dist = Helpers.calculDistance(p.Pos, _pos); if (dist > 2048) { _survivalMobs.Remove(ID); return(1); } if (dist > 740) { _speedX = 0; _speedZ = 0; UpdatePosition(); return(0); } int a = p.Pos.X - _pos.X; int b = p.Pos.Z - _pos.Z; int angle = (int)(Math.Atan2(b, a)); _speedX = (int)(Math.Cos(angle) * 5); _speedZ = (int)(Math.Sin(angle) * 5); Vec3F32 dir = new Vec3F32(a, 0, b); dir = Vec3F32.Normalise(dir); DirUtils.GetYawPitch(dir, out _rot.RotY, out _rot.HeadX); } UpdatePosition(); return(0); }
static void MoveTowards(PlayerBot bot) { int dx = (int)Core.Ball.Position3d.X - bot.pos[0], dy = (int)Core.Ball.Position3d.Z - bot.pos[1], dz = (int)Core.Ball.Position3d.Y - bot.pos[2]; bot.TargetPos.X = (ushort)(Core.Ball.Position3d.X - 64); bot.TargetPos.Y = (ushort)32 + 51; bot.TargetPos.Z = (ushort)Constants.TouchLineTop; bot.movement = true; Vec3F32 dir = new Vec3F32(dx, dy, dz); dir = Vec3F32.Normalise(dir); byte yaw, pitch; DirUtils.GetYawPitch(dir, out yaw, out pitch); // 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) { bot.rot[0] = yaw; } bot.rot[1] = pitch; }