public void MoveBot() { Position oldPos = Pos; //curent pos Position delta = new Position( (short)(nextPos.X - oldPos.X), (short)(nextPos.Y - oldPos.Y), (short)(nextPos.Z - oldPos.Z)); //set the packet Packet packet = PacketWriter.MakeMoveRotate(ID, new Position { X = delta.X, Y = delta.Y, Z = delta.Z, R = Pos.R, L = 0 }); //send packet to everyone in the world if (nextPos == oldPos && oldPos != null) { world.Players.Send(PacketWriter.MakeTeleport(ID, new Position(world.Map.Spawn.X, world.Map.Spawn.Y, world.Map.Spawn.Z))); Pos = new Position(world.Map.Spawn.X, world.Map.Spawn.Y, world.Map.Spawn.Z, Pos.R, Pos.L); } else { world.Players.Send(packet); Pos = nextPos; } world.Players.Message(Pos.ToBlockCoords().ToString()); }
/// <summary> /// Creates the shortest route between two points, used in Move() /// </summary> private void Path(Vector3I targetPosition) { //create a grid with all blocks in the 2d plane byte[,] grid = new byte[World.Map.Width, World.Map.Length]; PathFinder pathFinder; Vector3I botPos = Position.ToBlockCoords(); //Loop through all XZ coordinates of the map for (int y = 0; y < World.Map.Length; y++) { for (int x = 0; x < World.Map.Width; x++) { //Find all valid positions, set as either an available tile or blocked tile if (ValidBlock(new Vector3I(x, y, botPos.Z)) && ValidBlock(new Vector3I(x, y, botPos.Z - 1))) { grid[x, y] = PathFinderHelper.EMPTY_TILE; } else { grid[x, y] = PathFinderHelper.BLOCKED_TILE; } } } //set pathFinder to the grid just created, disallow diagonals pathFinder = new PathFinder(grid); pathFinder.Diagonals = false; pathFinder.PunishChangeDirection = false; Point botInitPoint = new Point(botPos.X, botPos.Y); Point botFinalPoint = new Point(NewPosition.ToBlockCoords().X, NewPosition.ToBlockCoords().Y); //Implement A* to determine optimal path between two spots List <PathFinderNode> path = new PathFinderFast(grid).FindPath(botInitPoint, botFinalPoint); if (path == null) { //There is no path, stop moving beganMoving = false; isMoving = false; return; } //Convert node to block positions foreach (PathFinderNode node in path) { PositionList.Add(new Vector3I(node.X, node.Y, botPos.Z)); } //A* returns points in the opposite order needed, reverse in order to get proper order PositionList.Reverse(); }
public static void gunMove(Player player) { World world = player.World; if (null == world) { return; } try { lock (world.SyncRoot) { if (null == world.Map) { return; } if (player.IsOnline) { Position p = player.Position; double ksi = 2.0 * Math.PI * (-player.Position.L) / 256.0; double phi = 2.0 * Math.PI * (player.Position.R - 64) / 256.0; double sphi = Math.Sin(phi); double cphi = Math.Cos(phi); double sksi = Math.Sin(ksi); double cksi = Math.Cos(ksi); if (player.IsOnline) { if (player.GunCache.Values.Count > 0) { foreach (Vector3I block in player.GunCache.Values) { if (player.IsOnline) { player.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, world.Map.GetBlock(block))); Vector3I removed; player.GunCache.TryRemove(block.ToString(), out removed); } } } } for (int y = -1; y < 2; ++y) { for (int z = -1; z < 2; ++z) { if (player.IsOnline) { //4 is the distance betwen the player and the glass wall Vector3I glassBlockPos = new Vector3I((int)(cphi * cksi * 4 - sphi * (0.5 + y) - cphi * sksi * (0.5 + z)), (int)(sphi * cksi * 4 + cphi * (0.5 + y) - sphi * sksi * (0.5 + z)), (int)(sksi * 4 + cksi * (0.5 + z))); glassBlockPos += p.ToBlockCoords(); if (world.Map.GetBlock(glassBlockPos) == Block.Air) { player.Send(PacketWriter.MakeSetBlock(glassBlockPos, Block.Glass)); player.GunCache.TryAdd(glassBlockPos.ToString(), glassBlockPos); } } } } } } } catch (Exception ex) { Logger.Log(LogType.SeriousError, "GunGlass: " + ex); } }