Exemple #1
0
		public int GetDistanceSquared(Vector2D Point)
		{
			checked
			{
				int num = this.X - Point.X;
				int num2 = this.Y - Point.Y;
				return num * num + num2 * num2;
			}
		}
Exemple #2
0
		public static List<Vector2D> FindPath(RoomUser User, bool Diag, Gamemap Map, Vector2D Start, Vector2D End)
		{
			List<Vector2D> list = new List<Vector2D>();
			PathFinderNode pathFinderNode = PathFinder.FindPathReversed(User, Diag, Map, Start, End);
			if (pathFinderNode != null)
			{
				list.Add(End);
				while (pathFinderNode.Next != null)
				{
					list.Add(pathFinderNode.Next.Position);
					pathFinderNode = pathFinderNode.Next;
				}
			}
			return list;
		}
Exemple #3
0
		public static PathFinderNode FindPathReversed(RoomUser User, bool Diag, Gamemap Map, Vector2D Start, Vector2D End)
		{
			MinHeap<PathFinderNode> minHeap = new MinHeap<PathFinderNode>(256);
			PathFinderNode[,] array = new PathFinderNode[Map.Model.MapSizeX, Map.Model.MapSizeY];
			PathFinderNode pathFinderNode = new PathFinderNode(Start);
			pathFinderNode.Cost = 0;
			PathFinderNode breadcrumb = new PathFinderNode(End);
			array[pathFinderNode.Position.X, pathFinderNode.Position.Y] = pathFinderNode;
			minHeap.Add(pathFinderNode);
			checked
			{
				while (minHeap.Count > 0)
				{
					pathFinderNode = minHeap.ExtractFirst();
					pathFinderNode.InClosed = true;
					int num = 0;
					while (Diag ? (num < PathFinder.DiagMovePoints.Length) : (num < PathFinder.NoDiagMovePoints.Length))
					{
						Vector2D vector2D = pathFinderNode.Position + (Diag ? PathFinder.DiagMovePoints[num] : PathFinder.NoDiagMovePoints[num]);
						bool endOfPath = vector2D.X == End.X && vector2D.Y == End.Y;
						if (Map.IsValidStep(User, new Vector2D(pathFinderNode.Position.X, pathFinderNode.Position.Y), vector2D, endOfPath, User.AllowOverride))
						{
							PathFinderNode pathFinderNode2;
							if (array[vector2D.X, vector2D.Y] == null)
							{
								pathFinderNode2 = new PathFinderNode(vector2D);
								array[vector2D.X, vector2D.Y] = pathFinderNode2;
							}
							else
							{
								pathFinderNode2 = array[vector2D.X, vector2D.Y];
							}
							if (!pathFinderNode2.InClosed)
							{
								int num2 = 0;
								if (pathFinderNode.Position.X != pathFinderNode2.Position.X)
								{
									num2++;
								}
								if (pathFinderNode.Position.Y != pathFinderNode2.Position.Y)
								{
									num2++;
								}
								int num3 = pathFinderNode.Cost + num2 + pathFinderNode2.Position.GetDistanceSquared(End);
								if (num3 < pathFinderNode2.Cost)
								{
									pathFinderNode2.Cost = num3;
									pathFinderNode2.Next = pathFinderNode;
								}
								if (!pathFinderNode2.InOpen)
								{
									if (pathFinderNode2.Equals(breadcrumb))
									{
										pathFinderNode2.Next = pathFinderNode;
										return pathFinderNode2;
									}
									pathFinderNode2.InOpen = true;
									minHeap.Add(pathFinderNode2);
								}
							}
						}
						num++;
					}
				}
				return null;
			}
		}
Exemple #4
0
 internal bool IsValidStep(RoomUser User, Vector2D From, Vector2D To, bool EndOfPath, bool Override)
 {
     if (!this.ValidTile(To.X, To.Y))
         return false;
     if (Override)
         return true;
     if ((int)this.mGameMap[To.X, To.Y] == 3 && !EndOfPath || (int)this.mGameMap[To.X, To.Y] == 0 || (int)this.mGameMap[To.X, To.Y] == 2 && !EndOfPath || this.SqAbsoluteHeight(To.X, To.Y) - this.SqAbsoluteHeight(From.X, From.Y) > 1.5)
         return false;
     RoomUser userForSquare = this.room.GetRoomUserManager().GetUserForSquare(To.X, To.Y);
     if (userForSquare != null && EndOfPath && this.room.AllowWalkthrough == 0)
     {
         User.HasPathBlocked = true;
         User.Path.Clear();
         User.IsWalking = false;
         User.RemoveStatus("mv");
         this.room.GetRoomUserManager().UpdateUserStatus(User, false);
         if (User.RidingHorse && !User.IsPet && !User.IsBot)
         {
             RoomUser roomUserByVirtualId = this.room.GetRoomUserManager().GetRoomUserByVirtualId(Convert.ToInt32(User.HorseID));
             roomUserByVirtualId.IsWalking = false;
             roomUserByVirtualId.RemoveStatus("mv");
             ServerMessage Message = new ServerMessage(Outgoing.UpdateUserStatusMessageComposer);
             Message.AppendInt32(1);
             roomUserByVirtualId.SerializeStatus(Message, "");
             User.GetClient().GetHabbo().CurrentRoom.SendMessage(Message);
         }
     }
     else if (userForSquare != null && this.room.AllowWalkthrough == 0 && !userForSquare.IsWalking)
         return false;
     return true;
 }