示例#1
0
 /// <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&lt;Vector2D&gt;.</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;
 }
示例#2
0
文件: Gamemap.cs 项目: BjkGkh/Azure2
        /// <summary>
        /// Determines whether [is valid step3] [the specified user].
        /// </summary>
        /// <param name="RoomUser">The user.</param>
        /// <param name="ActualPosition">From.</param>
        /// <param name="NextPosition">To.</param>
        /// <param name="endOfPath">if set to <c>true</c> [end of path].</param>
        /// <param name="HasOverride">if set to <c>true</c> [override].</param>
        /// <param name="client">The client.</param>
        /// <returns><c>true</c> if [is valid step3] [the specified user]; otherwise, <c>false</c>.</returns>
        internal bool IsValidStep3(RoomUser RoomUser, Vector2D ActualPosition, Vector2D NextPosition, bool endOfPath, bool HasOverride, GameClient client)
        {
            if (RoomUser == null)
                return false;

            Point CurrentPositionSquare = new Point(ActualPosition.X, ActualPosition.Y);
            Point NextPositionSquare = new Point(NextPosition.X, NextPosition.Y);
            RoomUser RoomUsersInTile = UserRoom.GetRoomUserManager().GetUserForSquare(NextPosition.X, NextPosition.Y);
            List<RoomItem> RoomItemsInTile = GetCoordinatedItems(NextPositionSquare);

            if (RoomItemsInTile.Any(item => item.Height > (RoomUser.Z + 1.5))) return false;

            if ((GuildGates.ContainsKey(CurrentPositionSquare)) && (RoomUser.GetClient() != null) && (RoomUser.GetClient().GetHabbo() != null) && (RoomUser.GetClient().GetHabbo().UserGroups != null))
            {
                RoomItem roomItem = GuildGates[CurrentPositionSquare];
                Int32 guildId = roomItem.GroupId;

                // this check probably isn't necessary, but w/e
                if ((guildId > 0) && (RoomUser.GetClient().GetHabbo().UserGroups.Any(member => (member != null) && (member.GroupId == guildId))))
                {
                    roomItem.ExtraData = "0";
                    roomItem.UpdateState(false, true);
                }
            }

            if ((GuildGates.ContainsKey(NextPositionSquare)) && (RoomUser.GetClient() != null) && (RoomUser.GetClient().GetHabbo() != null) && (RoomUser.GetClient().GetHabbo().UserGroups != null))
            {
                RoomItem roomItem = GuildGates[NextPositionSquare];
                Int32 guildId = roomItem.GroupId;

                if ((guildId > 0) && (RoomUser.GetClient().GetHabbo().UserGroups.Any(member => (member != null) && (member.GroupId == guildId))))
                {
                    roomItem.ExtraData = "1";
                    roomItem.UpdateState(false, true);
                    return true;
                }
            }

            if (!ValidTile(NextPosition.X, NextPosition.Y))
                return false;

            if (HasOverride)
                return true;

            if (!CanWalk(NextPosition.X, NextPosition.Y, HasOverride))
                return false;

            if ((RoomUsersInTile != null) && (!RoomUsersInTile.IsWalking) && (endOfPath))
                return false;

            if (((GameMap[NextPosition.X, NextPosition.Y] == 3) && (!endOfPath)) || (GameMap[NextPosition.X, NextPosition.Y] == 0) || ((GameMap[NextPosition.X, NextPosition.Y] == 2) && (!endOfPath)))
                return false;

            if (RoomItemsInTile.All(item => item.GetBaseItem().Walkable))
                return true;

            return ((SqAbsoluteHeight(NextPosition.X, NextPosition.Y) - SqAbsoluteHeight(ActualPosition.X, ActualPosition.Y)) <= 1.5);
        }
示例#3
0
文件: Gamemap.cs 项目: BjkGkh/Azure2
        /// <summary>
        /// Determines whether [is valid step] [the specified user].
        /// </summary>
        /// <param name="RoomUser">The user.</param>
        /// <param name="StartPosition">From.</param>
        /// <param name="NextPosition">To.</param>
        /// <param name="endOfPath">if set to <c>true</c> [end of path].</param>
        /// <param name="HasOverride">if set to <c>true</c> [override].</param>
        /// <returns><c>true</c> if [is valid step] [the specified user]; otherwise, <c>false</c>.</returns>
        internal bool IsValidStep(RoomUser RoomUser, Vector2D StartPosition, Vector2D NextPosition, bool endOfPath, bool HasOverride)
        {
            if (RoomUser == null)
                return false;

            Point NextPositionSquare = new Point(NextPosition.X, NextPosition.Y);
            RoomUser RoomUsersInTile = UserRoom.GetRoomUserManager().GetUserForSquare(NextPosition.X, NextPosition.Y);
            List<RoomItem> RoomItemsInTile = GetCoordinatedItems(NextPositionSquare);

            if (RoomItemsInTile.Any(item => item.Height > (RoomUser.Z + 1.5))) return false;

            if ((!RoomUser.IsBot) && (!RoomUser.IsPet) && (RoomUser.GetClient() != null))
            {
                if (GuildGates.ContainsKey(NextPositionSquare))
                {
                    int GroupId = GuildGates[NextPositionSquare].GroupId;

                    if (GroupId > 0 && RoomUser.GetClient().GetHabbo().UserGroups.Any(member => ((member != null) && (member.GroupId == GroupId))))
                        return true;
                }
            }

            if (!ValidTile(NextPosition.X, NextPosition.Y))
                return false;

            if (HasOverride)
                return true;

            if (!CanWalk(NextPosition.X, NextPosition.Y, HasOverride))
                return false;

            if ((RoomUsersInTile != null) && (!RoomUsersInTile.IsWalking) && (endOfPath))
                return false;

            if (((GameMap[NextPosition.X, NextPosition.Y] == 3) && (!endOfPath)) || (GameMap[NextPosition.X, NextPosition.Y] == 0) || ((GameMap[NextPosition.X, NextPosition.Y] == 2) && (!endOfPath)))
                return false;

            if ((RoomUsersInTile != null) && (endOfPath) && (!UserRoom.RoomData.AllowWalkThrough))
            {
                RoomUser.HasPathBlocked = true;
                RoomUser.Path.Clear();
                RoomUser.IsWalking = false;
                RoomUser.RemoveStatus("mv");
                UserRoom.GetRoomUserManager().UpdateUserStatus(RoomUser, false);

                if (!RoomUser.RidingHorse || RoomUser.IsPet || RoomUser.IsBot)
                    return true;

                RoomUser roomUserByVirtualId = UserRoom.GetRoomUserManager().GetRoomUserByVirtualId(Convert.ToInt32(RoomUser.HorseId));
                ServerMessage message = new ServerMessage(LibraryParser.OutgoingRequest("UpdateUserStatusMessageComposer"));
                message.AppendInteger(1);

                if (roomUserByVirtualId != null)
                {
                    roomUserByVirtualId.IsWalking = false;
                    roomUserByVirtualId.ClearMovement();
                    roomUserByVirtualId.RemoveStatus("mv");
                    roomUserByVirtualId.SerializeStatus(message, "");
                }

                RoomUser.GetClient().GetHabbo().CurrentRoom.SendMessage(message);
            }
            else if (RoomItemsInTile.All(item => item.GetBaseItem().Walkable))
                return true;
            else if ((RoomUsersInTile != null) && (!UserRoom.RoomData.AllowWalkThrough) && (!RoomUsersInTile.IsWalking))
                return false;

            return ((SqAbsoluteHeight(NextPosition.X, NextPosition.Y) - SqAbsoluteHeight(StartPosition.X, StartPosition.Y)) <= 1.5);
        }
示例#4
0
 /// <summary>
 ///     Gets the distance squared.
 /// </summary>
 /// <param name="point">The point.</param>
 /// <returns>System.Int32.</returns>
 public int GetDistanceSquared(Vector2D point)
 {
     var num = X - point.X;
     var num2 = Y - point.Y;
     return num * num + num2 * num2;
 }
示例#5
0
        internal void UserSetPositionData(RoomUser RoomUsers, Vector2D nextStep)
        {
            // Check if the User is in a Horse or Not..
            if ((RoomUsers.RidingHorse) && (!RoomUsers.IsPet))
            {
                RoomUser HorseRidingPet = GetRoomUserByVirtualId(Convert.ToInt32(RoomUsers.HorseId));

                // If exists a Horse and is Ridding.. Let's Create data for they..
                if (HorseRidingPet != null)
                {
                    RoomUsers.RotBody = HorseRidingPet.RotBody;
                    RoomUsers.RotHead = HorseRidingPet.RotHead;
                    RoomUsers.SetStep = true;

                    RoomUsers.SetX = nextStep.X;
                    RoomUsers.SetY = nextStep.Y;
                    RoomUsers.SetZ = (UserRoom.GetGameMap().SqAbsoluteHeight(nextStep.X, nextStep.Y) + 1);

                    HorseRidingPet.SetX = RoomUsers.SetX;
                    HorseRidingPet.SetY = RoomUsers.SetY;
                    HorseRidingPet.SetZ = UserRoom.GetGameMap().SqAbsoluteHeight(RoomUsers.SetX, RoomUsers.SetY);
                }
            }
            else
            {
                // Is a Normal User, Let's Create Data for They.
                RoomUsers.RotBody = Rotation.Calculate(RoomUsers.X, RoomUsers.Y, nextStep.X, nextStep.Y, RoomUsers.IsMoonwalking);
                RoomUsers.RotHead = Rotation.Calculate(RoomUsers.X, RoomUsers.Y, nextStep.X, nextStep.Y, RoomUsers.IsMoonwalking);
                RoomUsers.SetStep = true;

                RoomUsers.SetX = nextStep.X;
                RoomUsers.SetY = nextStep.Y;
                RoomUsers.SetZ = UserRoom.GetGameMap().SqAbsoluteHeight(nextStep.X, nextStep.Y);
            }
        }
示例#6
0
        /// <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;
        }
示例#7
0
        /// <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)
        {
            var minSpanTreeCost = new MinHeap<PathFinderNode>(256);
            var pathFinderMap = new PathFinderNode[gameLocalMap.Model.MapSizeX, gameLocalMap.Model.MapSizeY];
            var pathFinderStart = new PathFinderNode(startMap) {Cost = 0};
            var pathFinderEnd = new PathFinderNode(endMap);

            pathFinderMap[pathFinderStart.Position.X, pathFinderStart.Position.Y] = pathFinderStart;
            minSpanTreeCost.Add(pathFinderStart);

            while (minSpanTreeCost.Count > 0)
            {
                pathFinderStart = minSpanTreeCost.ExtractFirst();
                pathFinderStart.InClosed = true;

                for (var index = 0; (whatIsDiag ? (index < DiagMovePoints.Length ? 1 : 0) : (index < NoDiagMovePoints.Length ? 1 : 0)) != 0; index++)
                {
                    var realEndPosition = pathFinderStart.Position + (whatIsDiag ? DiagMovePoints[index] : NoDiagMovePoints[index]);

                    var 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)
                        {
                            var internalSpanTreeCost = 0;

                            if (pathFinderStart.Position.X != pathFinderSecondNodeCalculation.Position.X) internalSpanTreeCost++;

                            if (pathFinderStart.Position.Y != pathFinderSecondNodeCalculation.Position.Y) internalSpanTreeCost++;

                            var loopTotalCost = pathFinderStart.Cost + internalSpanTreeCost + pathFinderSecondNodeCalculation.Position.GetDistanceSquared(endMap);

                            if (loopTotalCost < pathFinderSecondNodeCalculation.Cost)
                            {
                                pathFinderSecondNodeCalculation.Cost = loopTotalCost;
                                pathFinderSecondNodeCalculation.Next = pathFinderStart;
                            }

                            if (!pathFinderSecondNodeCalculation.InOpen)
                            {
                                if (pathFinderSecondNodeCalculation.Equals(pathFinderEnd))
                                {
                                    pathFinderSecondNodeCalculation.Next = pathFinderStart;

                                    return pathFinderSecondNodeCalculation;
                                }

                                pathFinderSecondNodeCalculation.InOpen = true;

                                minSpanTreeCost.Add(pathFinderSecondNodeCalculation);
                            }
                        }
                    }
                }
            }

            return null;
        }
示例#8
0
        /// <summary>
        ///     Determines whether [is valid step3] [the specified user].
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <param name="endOfPath">if set to <c>true</c> [end of path].</param>
        /// <param name="Override">if set to <c>true</c> [override].</param>
        /// <param name="client">The client.</param>
        /// <returns><c>true</c> if [is valid step3] [the specified user]; otherwise, <c>false</c>.</returns>
        internal bool IsValidStep3(RoomUser user, Vector2D @from, Vector2D to, bool endOfPath, bool Override,
            GameClient client)
        {
            if (user == null)
                return false;

            var square = new Point(to.X, to.Y);
            if (GuildGates.ContainsKey(square) && user.GetClient() != null && user.GetClient().GetHabbo() != null &&
                user.GetClient().GetHabbo().UserGroups != null)
            {
                var roomItem = GuildGates[square];
                var guildId = roomItem.GroupId;
                if (guildId > 0 &&
                    user.GetClient().GetHabbo().UserGroups.Any(member => member != null && member.GroupId == guildId))
                {
                    roomItem.ExtraData = "1";
                    roomItem.UpdateState();
                    return true;
                }
            }

            if (!ValidTile(to.X, to.Y))
                return false;

            if (Override)
                return true;

            if (((GameMap[to.X, to.Y] == 3 && !endOfPath) || GameMap[to.X, to.Y] == 0 ||
                 (GameMap[to.X, to.Y] == 2 && !endOfPath)))
            {
                user.Path.Clear();
                user.PathRecalcNeeded = false;

                return false;
            }

            var userRoom = _room.GetRoomUserManager().GetUserForSquare(to.X, to.Y);
            if (userRoom != null && !userRoom.IsWalking && endOfPath)
                return false;

            return SqAbsoluteHeight(to.X, to.Y) - SqAbsoluteHeight(@from.X, @from.Y) <= 1.5;
        }
示例#9
0
        /// <summary>
        ///     Determines whether [is valid step] [the specified user].
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <param name="endOfPath">if set to <c>true</c> [end of path].</param>
        /// <param name="Override">if set to <c>true</c> [override].</param>
        /// <returns><c>true</c> if [is valid step] [the specified user]; otherwise, <c>false</c>.</returns>
        internal bool IsValidStep(RoomUser user, Vector2D @from, Vector2D to, bool endOfPath, bool Override)
        {
            if (user == null)
                return false;
            var square = new Point(to.X, to.Y);
            if (user.IsBot == false && user.GetClient() != null)
            {
                if (GuildGates.ContainsKey(square))
                {
                    var guildId = GuildGates[square].GroupId;
                    if (guildId > 0 &&
                        user.GetClient()
                            .GetHabbo()
                            .UserGroups.Any(member => member != null && member.GroupId == guildId)) return true;
                }
            }

            if (!ValidTile(to.X, to.Y))
                return false;
            if (Override)
                return true;
            if (GameMap[to.X, to.Y] == 3 && !endOfPath || GameMap[to.X, to.Y] == 0 ||
                GameMap[to.X, to.Y] == 2 && !endOfPath)
                return false;
            var userForSquare = _room.GetRoomUserManager().GetUserForSquare(to.X, to.Y);
            if (userForSquare != null && endOfPath && !_room.RoomData.AllowWalkThrough)
            {
                user.HasPathBlocked = true;
                user.Path.Clear();
                user.IsWalking = false;
                user.RemoveStatus("mv");
                _room.GetRoomUserManager().UpdateUserStatus(user, false);
                if (!user.RidingHorse || user.IsPet || user.IsBot)
                    return true;
                var roomUserByVirtualId =
                    _room.GetRoomUserManager().GetRoomUserByVirtualId(Convert.ToInt32(user.HorseId));

                var message = new ServerMessage(LibraryParser.OutgoingRequest("UpdateUserStatusMessageComposer"));
                message.AppendInteger(1);
                if (roomUserByVirtualId != null)
                {
                    roomUserByVirtualId.IsWalking = false;
                    roomUserByVirtualId.ClearMovement();
                    roomUserByVirtualId.RemoveStatus("mv");
                    roomUserByVirtualId.SerializeStatus(message, "");
                }
                user.GetClient().GetHabbo().CurrentRoom.SendMessage(message);
            }
            else if (userForSquare != null && !_room.RoomData.AllowWalkThrough && !userForSquare.IsWalking)
                return false;
            return SqAbsoluteHeight(to.X, to.Y) - SqAbsoluteHeight(@from.X, @from.Y) <= 1.5;
        }