コード例 #1
0
        public bool MoveMob(
            Point3d targetPosition)
        {
            bool success = false;

            if (path == null)
            {
                PathComputer pathComputer = new PathComputer();

                success =
                    pathComputer.BlockingPathRequest(
                        moveRequest.Room.runtime_nav_mesh,
                        moveRequest.Room.room_key,
                        new Point3d(mob.Position),
                        new Point3d(targetPosition));

                if (success)
                {
                    RoomKey  roomKey            = moveRequest.Room.room_key;
                    PathStep lastPathStep       = pathComputer.FinalPath[pathComputer.FinalPath.Count - 1];
                    PathStep secondLastPathStep = pathComputer.FinalPath[pathComputer.FinalPath.Count - 2];
                    Vector3d lastPathHeading    = lastPathStep.StepPoint - secondLastPathStep.StepPoint;
                    float    targetAngle        = MathConstants.GetAngleForVector(lastPathHeading);

                    path =
                        new EntityPath()
                    {
                        entity_id = mob.ID,
                        path      = pathComputer.FinalPath
                    };

                    // Post an event that we moved
                    output_game_events.Add(
                        new GameEvent_MobMoved()
                    {
                        mob_id     = mob.ID,
                        room_x     = roomKey.x,
                        room_y     = roomKey.y,
                        room_z     = roomKey.z,
                        from_x     = mob.Position.x,
                        from_y     = mob.Position.y,
                        from_z     = mob.Position.z,
                        from_angle = mob.Angle,
                        to_x       = targetPosition.x,
                        to_y       = targetPosition.y,
                        to_z       = targetPosition.z,
                        to_angle   = targetAngle
                    });

                    // Update the mob position and facing
                    mob.Position = targetPosition;
                    mob.Angle    = targetAngle;

                    // TODO: Update the mob energy based on the distance traveled
                }
            }

            return(success);
        }
コード例 #2
0
        private bool ComputePlayerPaths(
            out string result_code)
        {
            PathComputer pathComputer = new PathComputer();
            bool         success      = true;

            result_code = SuccessMessages.GENERAL_SUCCESS;

            foreach (GameEventParameters gameEvent in m_relevantGameEvents)
            {
                if (gameEvent.GetEventType() == eGameEventType.character_moved)
                {
                    GameEvent_CharacterMoved movedEvent = (GameEvent_CharacterMoved)gameEvent;

                    success =
                        pathComputer.BlockingPathRequest(
                            m_room.runtime_nav_mesh,
                            m_room.room_key,
                            new Point3d((float)movedEvent.from_x, (float)movedEvent.from_y, (float)movedEvent.from_z),
                            new Point3d((float)movedEvent.to_x, (float)movedEvent.to_y, (float)movedEvent.to_z));

                    if (success)
                    {
                        m_playerPaths.Add(
                            new EntityPath()
                        {
                            entity_id = movedEvent.character_id,
                            path      = pathComputer.FinalPath
                        });
                    }
                    else
                    {
                        result_code = ErrorMessages.CANT_COMPUTE_PATH;
                        break;
                    }
                }
            }

            return(success);
        }
コード例 #3
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);
                }
            }
        }
    }