/// <summary> /// Finds the path. /// </summary> /// <param name="user">The user.</param> /// <param name="diag">if set to <c>true</c> [diag].</param> /// <param name="map">The map.</param> /// <param name="start">The start.</param> /// <param name="end">The end.</param> /// <returns>List<Vector2D>.</returns> public static List<Vector2D> FindPath(RoomUser user, bool diag, Gamemap map, Vector2D start, Vector2D end) { var list = new List<Vector2D>(); var pathFinderNode = FindPathReversed(user, diag, map, start, end); if (pathFinderNode == null) return list; list.Add(end); while (pathFinderNode.Next != null) { list.Add(pathFinderNode.Next.Position); pathFinderNode = pathFinderNode.Next; } return list; }
/// <summary> /// Finds the path reversed. /// </summary> /// <param name="RoomUserable">The user.</param> /// <param name="WhatIsDiag">if set to <c>true</c> [diag].</param> /// <param name="GameLocalMap">The map.</param> /// <param name="StartMap">The start.</param> /// <param name="EndMap">The end.</param> /// <returns>PathFinderNode.</returns> public static PathFinderNode FindPathReversed(RoomUser RoomUserable, bool WhatIsDiag, Gamemap GameLocalMap, Vector2D StartMap, Vector2D EndMap) { MinHeap<PathFinderNode> MinSpanTreeCost = new MinHeap<PathFinderNode>(256); PathFinderNode[,] PathFinderMap = new PathFinderNode[GameLocalMap.Model.MapSizeX, GameLocalMap.Model.MapSizeY]; PathFinderNode PathFinderStart = new PathFinderNode(StartMap) { Cost = 0 }; PathFinderNode PathFinderEnd = new PathFinderNode(EndMap); PathFinderMap[PathFinderStart.Position.X, PathFinderStart.Position.Y] = PathFinderStart; MinSpanTreeCost.Add(PathFinderStart); int loop_variable_one, InternalSpanTreeCost, loop_total_cost; while (MinSpanTreeCost.Count > 0) { PathFinderStart = MinSpanTreeCost.ExtractFirst(); PathFinderStart.InClosed = true; loop_variable_one = 0; while ((WhatIsDiag ? (loop_variable_one < DiagMovePoints.Length) : (loop_variable_one < NoDiagMovePoints.Length))) { Vector2D RealEndPosition = PathFinderStart.Position + (WhatIsDiag ? DiagMovePoints[loop_variable_one] : NoDiagMovePoints[loop_variable_one]); bool IsEndOfPath = ((RealEndPosition.X == EndMap.X) && (RealEndPosition.Y == EndMap.Y)); if (GameLocalMap.IsValidStep(RoomUserable, new Vector2D(PathFinderStart.Position.X, PathFinderStart.Position.Y), RealEndPosition, IsEndOfPath, RoomUserable.AllowOverride)) { PathFinderNode PathFinderSecondNodeCalculation; if (PathFinderMap[RealEndPosition.X, RealEndPosition.Y] == null) { PathFinderSecondNodeCalculation = new PathFinderNode(RealEndPosition); PathFinderMap[RealEndPosition.X, RealEndPosition.Y] = PathFinderSecondNodeCalculation; } else { PathFinderSecondNodeCalculation = PathFinderMap[RealEndPosition.X, RealEndPosition.Y]; } if (!PathFinderSecondNodeCalculation.InClosed) { InternalSpanTreeCost = 0; if (PathFinderStart.Position.X != PathFinderSecondNodeCalculation.Position.X) InternalSpanTreeCost++; if (PathFinderStart.Position.Y != PathFinderSecondNodeCalculation.Position.Y) InternalSpanTreeCost++; loop_total_cost = PathFinderStart.Cost + InternalSpanTreeCost + PathFinderSecondNodeCalculation.Position.GetDistanceSquared(EndMap); if (loop_total_cost < PathFinderSecondNodeCalculation.Cost) { PathFinderSecondNodeCalculation.Cost = loop_total_cost; PathFinderSecondNodeCalculation.Next = PathFinderStart; } if (!PathFinderSecondNodeCalculation.InOpen) { if (PathFinderSecondNodeCalculation.Equals(PathFinderEnd)) { PathFinderSecondNodeCalculation.Next = PathFinderStart; return PathFinderSecondNodeCalculation; } PathFinderSecondNodeCalculation.InOpen = true; MinSpanTreeCost.Add(PathFinderSecondNodeCalculation); } } } loop_variable_one++; } } return null; }
/// <summary> /// Initializes the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <param name="roomData">The room data.</param> /// <param name="rightOverride">if set to <c>true</c> [right override].</param> /// <param name="wordFilter">The word filter.</param> private void Initialize(uint id, RoomData roomData, bool rightOverride, List<string> wordFilter) { RoomData = roomData; Disposed = false; RoomId = id; Bans = new Dictionary<long, double>(); MutedUsers = new Dictionary<uint, uint>(); ActiveTrades = new ArrayList(); MutedBots = false; MutedPets = false; _mCycleEnded = false; EveryoneGotRights = rightOverride; LoadedGroups = new Dictionary<int, string>(); UserRoomQueue = new Dictionary<uint, uint>(); _roomKick = new Queue(); _idleTime = 0; RoomMuted = false; _gameMap = new Gamemap(this); _roomItemHandling = new RoomItemHandling(this); _roomUserManager = new RoomUserManager(this); WordFilter = wordFilter; LoadRights(); LoadMusic(); LoadBans(); InitUserBots(); _roomThread = new Thread(StartRoomProcessing); _roomThread.Name = "Room Loader"; _roomThread.Start(); AzureEmulator.GetGame().GetRoomManager().QueueActiveRoomAdd(RoomData); }
/// <summary> /// Resets the game map. /// </summary> /// <param name="newModelName">New name of the model.</param> /// <param name="wallHeight">Height of the wall.</param> /// <param name="wallThick">The wall thick.</param> /// <param name="floorThick">The floor thick.</param> internal void ResetGameMap(string newModelName, int wallHeight, int wallThick, int floorThick) { RoomData.ModelName = newModelName; RoomData.ModelName = newModelName; RoomData.ResetModel(); RoomData.WallHeight = wallHeight; RoomData.WallThickness = wallThick; RoomData.FloorThickness = floorThick; _gameMap = new Gamemap(this); }