private bool VerifyNavMeshConnectivity(
            out string result_code)
        {
            bool success;

            // Player has to walk to the portal target
            NavRef characterNavRef = m_room.runtime_nav_mesh.ComputeNavRefAtPoint(m_current_character_position);
            NavRef targetNavRef    = m_room.runtime_nav_mesh.ComputeNavRefAtPoint(m_energy_tank.Position);

            if (m_room.runtime_nav_mesh.AreNavRefsConnected(characterNavRef, targetNavRef))
            {
                // It's possible to traverse the nav mesh to get to the target
                m_move_to_target = true;

                result_code = SuccessMessages.GENERAL_SUCCESS;
                success     = true;
            }
            else
            {
                // It isn't possible to reach the target on the nav mesh from where the player is standing
                result_code = ErrorMessages.TARGET_UNREACHABLE;
                success     = false;
            }

            return(success);
        }
        private bool VerifyNavMeshConnectivity(out string result_code)
        {
            bool success;

            if (Point3d.DistanceSquared(m_current_character_position, m_target_position) > MathConstants.POSITIONAL_EPSILON_SQUARED)
            {
                // Player has to walk to the portal target
                NavRef characterNavRef = m_room.runtime_nav_mesh.ComputeNavRefAtPoint(m_current_character_position);
                NavRef targetNavRef    = m_room.runtime_nav_mesh.ComputeNavRefAtPoint(m_target_position);

                if (m_room.runtime_nav_mesh.AreNavRefsConnected(characterNavRef, targetNavRef))
                {
                    result_code = SuccessMessages.GENERAL_SUCCESS;
                    success     = true;
                }
                else
                {
                    // It isn't possible to reach the target on the nav mesh from where the player is standing
                    result_code = ErrorMessages.TARGET_UNREACHABLE;
                    success     = false;
                }
            }
            else
            {
                // Character already on top of the portal
                result_code = SuccessMessages.GENERAL_SUCCESS;
                success     = true;
            }

            return(success);
        }
Exemplo n.º 3
0
 public ContextOverlayView(ContextOverlayController contextOverlayController)
 {
     m_contextOverlayController = contextOverlayController;
     m_hotspotWidgets           = new List <HotspotWidget>();
     m_currentNavRef            = new NavRef(-1, null);
     CurrentHotspot             = null;
     m_style = contextOverlayController.ParentController.contextOverlayStyle;
 }
        private bool ValidatePortalAccessibility(
            RoomTemplate roomTemplate)
        {
            bool success = true;

            // Room has nav mesh
            if (!roomTemplate.NavMeshTemplate.IsNavCellDataEmpty)
            {
                int sharedPortalConnectivityId = NavMesh.EMPTY_NAV_CELL;

                // All doors, stairs, and teleporters are on the nav mesh
                // All doors, stairs, and teleporters are accessible to each other on the nav mesh
                foreach (PortalTemplate portalTemplate in roomTemplate.PortalTemplates)
                {
                    Point3d portalCenter         = portalTemplate.BoundingBox.Center;
                    NavRef  portalNavRef         = roomTemplate.NavMeshTemplate.ComputeNavRefAtPoint(portalCenter);
                    int     portalConnectivityId = roomTemplate.NavMeshTemplate.GetNavRefConnectivityID(portalNavRef);

                    if (portalConnectivityId != NavMesh.EMPTY_NAV_CELL)
                    {
                        if (sharedPortalConnectivityId != NavMesh.EMPTY_NAV_CELL)
                        {
                            if (sharedPortalConnectivityId != portalConnectivityId)
                            {
                                _logger.LogError(
                                    string.Format(
                                        "RoomTemplateParser: Template {0}, portal id={1} is not connected to all other portals on the nav mesh",
                                        roomTemplate.TemplateName, portalTemplate.PortalID));
                                success = false;
                            }
                        }
                        else
                        {
                            sharedPortalConnectivityId = portalConnectivityId;
                        }
                    }
                    else
                    {
                        _logger.LogError(
                            string.Format(
                                "RoomTemplateParser: Template {0}, portal id={1} has center not on the nav mesh",
                                roomTemplate.TemplateName, portalTemplate.PortalID));
                        success = false;
                    }
                }
            }
            else
            {
                _logger.LogError(
                    string.Format("RoomTemplateParser: Template {0} missing a nav mesh",
                                  roomTemplate.TemplateName));
                success = false;
            }

            return(success);
        }
        public static NavRef GetNextNavAid(NavRef inNavAidRef)
        {
            IL.DeclareLocals(false);
            Guard.NotNull(GetNextNavAidPtr);
            NavRef result;

            IL.Push(inNavAidRef);
            IL.Push(GetNextNavAidPtr);
            IL.Emit.Calli(new StandAloneMethodSig(CallingConvention.Cdecl, typeof(NavRef), typeof(NavRef)));
            IL.Pop(out result);
            return(result);
        }
Exemplo n.º 6
0
    private void UpdateCurrentNavRef()
    {
        SessionData sessionData = SessionData.GetInstance();
        GameData    gameData    = sessionData.CurrentGameData;
        RoomData    roomData    = gameData.GetCachedRoomData(gameData.CurrentRoomKey);

        if (roomData != null)
        {
            AsyncRPGSharedLib.Navigation.NavMesh navMesh = roomData.StaticRoomData.NavMesh;

            Point2d pixelPoint = WidgetEventDispatcher.GetMousePosition();
            Point3d roomPoint  = GameConstants.ConvertPixelPositionToRoomPosition(pixelPoint);

            m_currentNavRef = navMesh.ComputeNavRefAtPoint(roomPoint);
        }
    }
Exemplo n.º 7
0
        public static bool CanMobSeePoint(
            NavMesh navMesh,
            Mob mob,
            Point3d point)
        {
            bool canSee = false;

            if (IsPointInMobVisionCone(mob, point))
            {
                NavRef mobNavRef  = navMesh.ComputeNavRefAtPoint(mob.Position);
                NavRef propNavRef = navMesh.ComputeNavRefAtPoint(point);

                canSee = navMesh.NavRefCanSeeOtherNavRef(mobNavRef, propNavRef);
            }

            return(canSee);
        }
Exemplo n.º 8
0
    private void DebugCursorPosition()
    {
        Point2d pixelPosition  = GetMousePixelPosition();
        Point2d screenPosition = ClientGameConstants.ConvertPixelPositionToScreenPosition(pixelPosition);
        Point3d roomPosition   = GameConstants.ConvertPixelPositionToRoomPosition(pixelPosition);
        Vector3 vertexPosition = ClientGameConstants.ConvertPixelPositionToVertexPosition(pixelPosition.x, pixelPosition.y, 0.0f);
        NavRef  navRef         = _gameWorldController.OverlayController.View.CurrentNavRef;

        _positionLabel.Text =
            string.Format(
                "Pixel: {0},{1}\nScreen: {2}, {3}\nRoom: {4}, {5}, {6}\nVertex: {7}, {8}, {9}\nNavRef: {10}",
                pixelPosition.x, pixelPosition.y,
                screenPosition.x, screenPosition.y,
                roomPosition.x, roomPosition.y, roomPosition.z,
                vertexPosition.x, vertexPosition.y, vertexPosition.z,
                navRef.NavCellIndex);
        _positionLabel.Visible = true;
    }
Exemplo n.º 9
0
    // Utilities
    public bool IsWorldPointOnNavMesh(Point3d testPoint)
    {
        GameData gameData       = CurrentGame;
        RoomData roomData       = gameData.GetCachedRoomData(gameData.CurrentRoomKey);
        bool     pointOnNavMesh = false;

        if (roomData != null)
        {
            AsyncRPGSharedLib.Navigation.NavMesh navMesh = roomData.StaticRoomData.NavMesh;
            NavRef navRef = navMesh.ComputeNavRefAtPoint(testPoint);

            if (navRef != null && navRef.IsValid)
            {
                pointOnNavMesh = true;
            }
        }

        return(pointOnNavMesh);
    }
Exemplo n.º 10
0
 public bool Equals(NavRef other)
 {
     return this.m_navCellIndex == other.m_navCellIndex
         && ((this.m_roomKey != null && this.m_roomKey.Equals(other.m_roomKey))
             || (this.m_roomKey == null && other.m_roomKey == null));
 }
Exemplo n.º 11
0
 public NavRef(NavRef navRef)
 {
     m_navCellIndex = navRef.m_navCellIndex;
     m_roomKey = new RoomKey(navRef.m_roomKey);
 }
Exemplo n.º 12
0
 public NavRef(NavRef navRef)
 {
     m_navCellIndex = navRef.m_navCellIndex;
     m_roomKey      = new RoomKey(navRef.m_roomKey);
 }
Exemplo n.º 13
0
 public bool Equals(NavRef other)
 {
     return(this.m_navCellIndex == other.m_navCellIndex &&
            ((this.m_roomKey != null && this.m_roomKey.Equals(other.m_roomKey)) ||
             (this.m_roomKey == null && other.m_roomKey == null)));
 }
Exemplo n.º 14
0
    private void DebugDrawTestVisibility()
    {
        int             characterID = _gameWorldController.Model.CurrentCharacterID;
        RoomKey         roomKey     = _gameWorldController.Model.CurrentGame.CurrentRoomKey;
        CharacterEntity entity      = _gameWorldController.Model.GetCharacterEntity(characterID);

        if (entity != null)
        {
            Point3d startWorldPos = entity.Position;

            Point2d endPixelPos = GetMousePixelPosition();
            Point3d endWorldPos = GameConstants.ConvertPixelPositionToRoomPosition(endPixelPos);

            // Draw the target nav cell
            AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey);

            if (navMesh != null)
            {
                NavRef startNavRef = navMesh.ComputeNavRefAtPoint(startWorldPos);
                NavRef endNavRef   = navMesh.ComputeNavRefAtPoint(endWorldPos);

                if (startNavRef.IsValid && endNavRef.IsValid)
                {
                    bool  canSee     = navMesh.NavRefCanSeeOtherNavRef(startNavRef, endNavRef);
                    Color debugColor = canSee ? Color.green : Color.red;

                    // Draw a box around the nav cell
                    {
                        Point3d endCenterWorldPos = navMesh.ComputeNavCellCenter((uint)endNavRef.NavCellIndex);
                        Point2d endCenterPixelPos = GameConstants.ConvertRoomPositionToPixelPosition(endCenterWorldPos);
                        float   halfWidth         = (float)GameConstants.NAV_MESH_PIXEL_SIZE / 2.0f;

                        Vector3 boxUL =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x - halfWidth, endCenterPixelPos.y - halfWidth, 0.0f);
                        Vector3 boxUR =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x + halfWidth, endCenterPixelPos.y - halfWidth, 0.0f);
                        Vector3 boxLR =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x + halfWidth, endCenterPixelPos.y + halfWidth, 0.0f);
                        Vector3 boxLL =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x - halfWidth, endCenterPixelPos.y + halfWidth, 0.0f);

                        Debug.DrawLine(boxUL, boxUR, debugColor);
                        Debug.DrawLine(boxUR, boxLR, debugColor);
                        Debug.DrawLine(boxLR, boxLL, debugColor);
                        Debug.DrawLine(boxLL, boxUL, debugColor);
                    }

                    // Update the visibility status label
                    _visibilityStatusLabel.Text = canSee ? "VISIBLE" : "INVISIBLE";
                    _visibilityStatusLabel.SetLocalPosition(endPixelPos.x, endPixelPos.y);
                    _visibilityStatusLabel.Color   = debugColor;
                    _visibilityStatusLabel.Visible = true;

                    // Render the ray-cast line
                    {
                        Vector3 startVertex = ClientGameConstants.ConvertRoomPositionToVertexPosition(startWorldPos);
                        Vector3 endVertex   = ClientGameConstants.ConvertRoomPositionToVertexPosition(endWorldPos);

                        Debug.DrawLine(startVertex, endVertex, debugColor);
                    }
                }
            }
        }
    }
Exemplo n.º 15
0
    private void DebugDrawTestPath()
    {
        int             characterID = _gameWorldController.Model.CurrentCharacterID;
        RoomKey         roomKey     = _gameWorldController.Model.CurrentGame.CurrentRoomKey;
        CharacterEntity entity      = _gameWorldController.Model.GetCharacterEntity(characterID);

        if (entity != null)
        {
            Point2d mousePixelPos = GetMousePixelPosition();
            Point3d mouseWorldPos = GameConstants.ConvertPixelPositionToRoomPosition(mousePixelPos);

            // Draw the target nav cell
            string targetLabel = "";
            AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey);

            if (navMesh != null)
            {
                NavRef navRef = navMesh.ComputeNavRefAtPoint(mouseWorldPos);

                if (navRef.IsValid)
                {
                    Point3d centerWorldPos = navMesh.ComputeNavCellCenter((uint)navRef.NavCellIndex);
                    Point2d centerPixelPos = GameConstants.ConvertRoomPositionToPixelPosition(centerWorldPos);
                    float   halfWidth      = (float)GameConstants.NAV_MESH_PIXEL_SIZE / 2.0f;

                    Vector3 boxUL =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x - halfWidth, centerPixelPos.y - halfWidth, 0.0f);
                    Vector3 boxUR =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x + halfWidth, centerPixelPos.y - halfWidth, 0.0f);
                    Vector3 boxLR =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x + halfWidth, centerPixelPos.y + halfWidth, 0.0f);
                    Vector3 boxLL =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x - halfWidth, centerPixelPos.y + halfWidth, 0.0f);

                    Debug.DrawLine(boxUL, boxUR, Color.blue);
                    Debug.DrawLine(boxUR, boxLR, Color.blue);
                    Debug.DrawLine(boxLR, boxLL, Color.blue);
                    Debug.DrawLine(boxLL, boxUL, Color.blue);

                    targetLabel = "\nNavCell=" + navRef.NavCellIndex.ToString();
                }

                // Attempt to compute a path from the active player to the mouse
                _pathComputer.BlockingPathRequest(navMesh, roomKey, entity.Position, mouseWorldPos);

                // Update the path status label
                {
                    if (_pathComputer.ResultCode == PathComputer.eResult.success)
                    {
                        _pathStatusLabel.Text  = "VALID" + targetLabel;
                        _pathStatusLabel.Color = Color.green;
                    }
                    else
                    {
                        _pathStatusLabel.Text  = _pathComputer.ResultCode + targetLabel;
                        _pathStatusLabel.Color = Color.red;
                    }

                    _pathStatusLabel.SetLocalPosition(mousePixelPos.x, mousePixelPos.y);
                    _pathStatusLabel.Visible = true;
                }

                // Render the raw path
                for (int stepIndex = 1; stepIndex < _pathComputer.FinalPath.Count; stepIndex++)
                {
                    Point3d previousPoint      = _pathComputer.FinalPath[stepIndex - 1].StepPoint;
                    Point3d currentPoint       = _pathComputer.FinalPath[stepIndex].StepPoint;
                    Vector3 previousPixelPoint = ClientGameConstants.ConvertRoomPositionToVertexPosition(previousPoint);
                    Vector3 currentPixelPoint  = ClientGameConstants.ConvertRoomPositionToVertexPosition(currentPoint);

                    Debug.DrawLine(previousPixelPoint, currentPixelPoint, Color.green);
                }
            }
        }
    }