Ejemplo n.º 1
0
        private void UpdatePlayerHistory()
        {
            string accountId = ChosenPlayer.accountId;

            bool fileExists = File.Exists(FilePaths.PLAYER_HISTORY(accountId, Server));

            if (fileExists)
            {
                History savedHistory = DataManager.LoadPlayerHistory(accountId, Server);

                if (savedHistory.LastGameId == -1)
                {
                    Console.WriteLine($"Player {ChosenPlayer.name} has no history saved. A new one will be created.");
                }
                else
                {
                    Instant lastMatch = Instant.FromEpochSeconds(savedHistory.matches[0].timestamp / 1000);
                    Console.WriteLine($"Player {ChosenPlayer.name} has a history saved," +
                                      $" with the last game played on {lastMatch.ToString("dddd, MMMM d, yyyy - HH:mm")}." +
                                      $" Their history will now be updated.");
                }

                savedHistory = UpdateHistoryFromApi(savedHistory, ChosenPlayer, Server);
                DataManager.SavePlayerHistory(savedHistory, accountId, Server);
            }
            else
            {
                Console.WriteLine($"Player {ChosenPlayer.name} has no history saved. A new one will be created.");
                History history = GetFullHistoryFromApi(ChosenPlayer, Server);
                DataManager.SavePlayerHistory(history, accountId, Server);
            }
        }