Пример #1
0
        static void StartDownload(string url)
        {
            try
            {
                UpdateState = eUpdateState.Downloading;
                UpdaterWindow.StatusLabel.Content = "Starting Download...";

                if (File.Exists(GetSavePath()))
                {
                    File.Delete(GetSavePath());
                }
                if (!Directory.Exists(GetTempDirectory()))
                {
                    Directory.CreateDirectory(GetTempDirectory());
                }

                Client = new WebClient();
                Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);
                Client.DownloadFileCompleted   += new System.ComponentModel.AsyncCompletedEventHandler(DownloadCompletedCallback);

                Uri uri = new Uri(url);
                Client.DownloadFileAsync(uri, GetSavePath());
            }
            catch (Exception e)
            {
                UpdaterWindow.StatusLabel.Content = "Error Downloading: " + e.Message;
            }
        }
Пример #2
0
    public override void Start()
    {
        base.Start();

        _targetTileCell = _character.GetTargetTileCell();
        _updateState    = eUpdateState.PATHFINDING;

        _reverseTileCell = null;

        if (_targetTileCell != null)
        {
            GameManager.Instance.GetMap().ResetPathFinding();
            TileCell startTileCell = GameManager.Instance.GetMap().GetTileCell(_character.GetTileX(), _character.GetTileY());

            sPathCommand command;
            command.tileCell  = startTileCell;
            command.heuristic = 0.0f;
            PushCommand(command);
        }

        else
        {
            _nextState = eStateType.IDLE;
        }
    }
Пример #3
0
        private static void DownloadCompletedCallback(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                UpdateState = eUpdateState.Error;
                UpdaterWindow.StatusLabel.Content = "Download was interrupted";
            }
            else if (e.Error != null)
            {
                UpdateState = eUpdateState.Error;
                UpdaterWindow.StatusLabel.Content = e.Error.Message;
            }
            else
            {
                UpdaterWindow.StatusLabel.Content = "Download Finished; verifying...";

                // Generate SHA256 hash of the download
                Task <string> hash_task = RXPatchLib.SHA256.GetFileHashAsync(GetSavePath());
                hash_task.Wait();

                // Verify the hash of the download
                if (hash_task.Result == PatchHash || PatchHash == "")
                {
                    // Download valid; begin extraction
                    StartExtract();
                }
                else
                {
                    // Hash mismatch; set an error
                    UpdateState = eUpdateState.Error;
                    UpdaterWindow.StatusLabel.Content = "Hash mismatch";
                }
            }
        }
Пример #4
0
        static void StartExtract()
        {
            try
            {
                if (Directory.Exists(GetExtractDirectory()))
                {
                    Directory.Delete(GetExtractDirectory(), true);
                }

                UpdateState = eUpdateState.Extracting;
                UpdaterWindow.StatusLabel.Content = "Extracting...";
                ZipFile.ExtractToDirectory(GetSavePath(), GetExtractDirectory());
                ReadyToInstall();
            }
            catch (Exception e)
            {
                UpdaterWindow.StatusLabel.Content = "Error Extracting: " + e.Message;
            }
        }
Пример #5
0
    public void UpdatePathFinding()
    {
        if (_pathFindingQueue.Count != 0)
        {
            sPathCommand command = PopCommand();

            if (command.tileCell.Marked() == false)
            {
                command.tileCell.Mark();
                if (command.tileCell.CanMove() == true)
                {
                    command.tileCell.SetPathFindingTestMark(Color.blue);
                }

                else if (command.tileCell.CanMove() == false)
                {
                    command.tileCell.SetPathFindingTestMark(Color.red);
                }

                if (command.tileCell.GetDistanceFromStart() > 5)
                {
                    _reverseTileCell = command.tileCell;
                    _updateState     = eUpdateState.BUILD;
                    return;
                }

                // 목표 도달?
                if (command.tileCell.GetTileX() == _targetTileCell.GetTileX() && command.tileCell.GetTileY() == _targetTileCell.GetTileY())
                {
                    _updateState     = eUpdateState.BUILD;
                    _reverseTileCell = _targetTileCell;
                    return;
                }
                // 주변 타일 검사
                for (int direction = (int)eMoveDirection.UP; direction < (int)eMoveDirection.NONE; direction++)
                {
                    sPosition currentTilePosition;
                    currentTilePosition.x = command.tileCell.GetTileX();
                    currentTilePosition.y = command.tileCell.GetTileY();

                    sPosition nextTilePos = GetPositionByDirection(currentTilePosition, (eMoveDirection)direction);

                    TileCell nextTileCell = GameManager.Instance.GetMap().GetTileCell(nextTilePos.x, nextTilePos.y);

                    //nextTileCell.SetPathFindingTestMark(Color.red);


                    // 검사 한타일인지 && 이동 가능한 타일 인지 && 갈수 없는 노드의 타입이 혹시 몬스터? -> 리팩토링하고싶다ㅏㅏ
                    if ((nextTileCell.IsPathFindable() == true && nextTileCell.Marked() == false))
                    {
                        float distanceFromStart = command.tileCell.GetDistanceFromStart() + command.tileCell.GetDistanceWeight() + 1;
                        //float heuristic = CalcAStarHeuristic(distanceFromStart, nextTileCell, _targetTileCell);
                        float heuristic = 0;

                        switch (_character.GetPathFindingType())
                        {
                        case ePathFindingType.DISTANCE:
                            heuristic = distanceFromStart;
                            break;

                        case ePathFindingType.SIMPLE:
                            heuristic = CalcSimpleHeuristic(command.tileCell, nextTileCell, _targetTileCell);
                            break;

                        case ePathFindingType.COMPLEX:
                            heuristic = CalcComplexHeuristic(nextTileCell, _targetTileCell);
                            break;

                        case ePathFindingType.ASTAR:
                            heuristic = CalcAStarHeuristic(distanceFromStart, nextTileCell, _targetTileCell);
                            break;
                        }

                        if (nextTileCell.GetPrevTileCell() == null)
                        {
                            nextTileCell.SetDistanceFromStart(distanceFromStart);
                            nextTileCell.SetPrevTileCell(command.tileCell);

                            sPathCommand newCommand;
                            newCommand.heuristic = heuristic;
                            newCommand.tileCell  = nextTileCell;
                            PushCommand(newCommand);
                        }
                    }
                }
            }
        }
    }
Пример #6
0
 public static void CancelUpdate()
 {
     UpdateState = eUpdateState.Cancelled;
     // TODO: Cancel whichever state is currently happening.
 }
Пример #7
0
 static void ReadyToInstall()
 {
     UpdateState = eUpdateState.ReadyToInstall;
     UpdaterWindow.UpdateFinished      = true;
     UpdaterWindow.StatusLabel.Content = "Ready to install. Press close to install and restart.";
 }
Пример #8
0
    protected void UpdatePathfinding()
    {
        // 길찾기 알고리즘이 시작
        if (0 != _pathfindingQueue.Count)
        {
            sPathCommand command = _pathfindingQueue[0];
            _pathfindingQueue.RemoveAt(0);
            if (false == command.tileCell.IsPathfided())
            {
                command.tileCell.Pathfinded();

                // 목표에 도달 했나?
                if (command.tileCell.GetTileX() == _goalTileCell.GetTileX() &&
                    command.tileCell.GetTileY() == _goalTileCell.GetTileY())
                {
                    _reverseTileCell = command.tileCell;
                    _updateState     = eUpdateState.BUILD_PATH;
                    return;
                }

                for (int direction = (int)eMoveDirection.LEFT;
                     direction < (int)eMoveDirection.DOWN + 1; direction++)
                {
                    sPosition curPosition;
                    curPosition.x = command.tileCell.GetTileX();
                    curPosition.y = command.tileCell.GetTileY();
                    sPosition nextPosition = GetPositionByDirection(curPosition, (eMoveDirection)direction);

                    TileCell searchTileCell =
                        GameManager.Instance.GetMap().GetTileCell(nextPosition.x, nextPosition.y);
                    if (null != searchTileCell && searchTileCell.IsPathfindable() && false == searchTileCell.IsPathfided())
                    {
                        float distance = command.tileCell.GetDistanceFromStart() +
                                         searchTileCell.GetDistanceWeight();

                        if (null == searchTileCell.GetPrevPathfindingCell())
                        {
                            searchTileCell.SetDistanceFromStart(distance);
                            searchTileCell.SetPrevPathfindingCell(command.tileCell);
                            searchTileCell.SetPathfindingTestMark();

                            sPathCommand newCommand;
                            newCommand.tileCell = searchTileCell;

                            /*
                             * newCommand.heuristic = CalcSimpleHeuristic(
                             *                              command.tileCell,
                             *                              searchTileCell,
                             *                              _goalTileCell);
                             */
                            newCommand.heuristic = CalcAStarHeuristic(distance,
                                                                      searchTileCell,
                                                                      _goalTileCell);
                            PushCommand(newCommand);
                        }
                        else
                        {
                            if (distance < searchTileCell.GetDistanceFromStart())
                            {
                                searchTileCell.SetDistanceFromStart(distance);
                                searchTileCell.SetPrevPathfindingCell(command.tileCell);

                                sPathCommand newCommand;
                                newCommand.tileCell = searchTileCell;

                                /*
                                 * newCommand.heuristic = CalcSimpleHeuristic(
                                 *                                  command.tileCell,
                                 *                                  searchTileCell,
                                 *                                  _goalTileCell);
                                 */
                                newCommand.heuristic = CalcAStarHeuristic(distance,
                                                                          searchTileCell,
                                                                          _goalTileCell);
                                PushCommand(newCommand);
                            }
                        }
                    }
                }
            }
        }
    }