public async Task <IActionResult> UploadMatchResults([FromBody] MatchContainer matchResults) { var requiredSubmissionIds = matchResults.Measurements.Select(x => x.SubmissionId).ToList(); var submissions = await myDb.Submissions .Where(x => requiredSubmissionIds.Contains(x.Id)) .ToDictionaryAsync(x => x.Id, x => x); var match = new Match { MatchDate = DateTime.Now, JsonResult = JsonSerializer.Serialize(matchResults) }; await myDb.Matches.AddAsync(match); foreach (var mContainer in matchResults.Measurements) { var measurement = new Measurement { Match = match, Submission = submissions[mContainer.SubmissionId], JsonResult = JsonSerializer.Serialize(mContainer) }; await myDb.Measurements.AddAsync(measurement); } await myDb.SaveChangesAsync(); return(Ok()); }
void ReleaseDesignerOutlets() { if (LeagueName != null) { LeagueName.Dispose(); LeagueName = null; } if (MatchContainer != null) { MatchContainer.Dispose(); MatchContainer = null; } if (StatContainer != null) { StatContainer.Dispose(); StatContainer = null; } if (TableContainer != null) { TableContainer.Dispose(); TableContainer = null; } }
private async Task <MatchContainer> RunMatch(List <DownloadedSubmission> downloadedSubmissions) { MatchContainer lastResult = null !; var submissionsById = downloadedSubmissions.Select(x => x.Data).ToDictionary(x => x.Id, x => x); var results = new List <DownloadedSubmission>(); myMatchManager.OnSubmissionEnd += MyMatchManager_OnSubmissionEnd; await foreach (var currentResult in myMatchManager.RunMatch(downloadedSubmissions)) { lastResult = currentResult; var items = currentResult.Measurements .Where(x => !myCompletedSubmissions.Contains(submissionsById[x.SubmissionId]) || x.Rounds.Count == currentResult.Measurements.Max(x => x.Rounds.Count)) .Select(x => (" " + submissionsById[x.SubmissionId].UserName, x.Rounds.Last().TotalMilliseconds)) .OrderBy(x => x.Item2).ToList(); Console.Clear(); Console.WriteLine(); //Console.WriteLine(); DrawTimeDiagram(currentResult.Measurements.Max(x => x.Rounds.Count) - 1, 25, items); Console.WriteLine(); DrawResultsTable(currentResult, downloadedSubmissions.Count - downloadedSubmissions.Count(x => x.Data.IsAdmin)); Console.ReadLine(); SaveMatchResult(currentResult); } myMatchManager.OnSubmissionEnd -= MyMatchManager_OnSubmissionEnd; return(lastResult); }
void UpdateGameUi(MatchContainer match) { Refresh(); winsToWinGame = 5; gamesToWinRoundText.text = winsToWinGame.ToString(); foreach (var game in match.CompletedGames) { logController.LogNewRound(game.Value.Number, game.Value.OpponentGesture, game.Value.MeGesture, game.Value.Result); switch (game.Value.Result) { case GameResult.Win: counterController.CountWin(); winsToWinGame--; gamesToWinRoundText.text = winsToWinGame.ToString(); break; case GameResult.Lose: counterController.CountLose(); break; case GameResult.Draw: counterController.CountTie(); break; } } winsToWinTournament = (((int)Math.Log(GameManager.Instance.GetTournamentNumberOfPlayers(match.Tournament), 2) - GameManager.Instance.GetCompletedMatches(match.Tournament)) * 5 - (5 - winsToWinGame)); gamesToWinTournamentText.text = winsToWinTournament < 0 ? 0.ToString() : winsToWinTournament.ToString(); }
IEnumerator MatcheCompleteCoroutine(MatchContainer match) { yield return(new WaitForSecondsRealtime(2f)); if (match.Equals(GameManager.Instance.CurrentMatch)) { UpdateHistory(match); } }
void UpdateBattleLog(MatchContainer match) { history.Clear(); gameRoundOverView.ClearHistory(); foreach (var game in match.CompletedGames) { history.Add(GetNewStep(game.Value)); } gameRoundOverView.Show(history); }
void UpdateJackpot(MatchContainer match) { ApiManager.Instance.Database.GetMatche(match.Id.Id) .Then(matchResult => { ApiManager.Instance.Database.GetTournament(matchResult.Tournament.Id) .Then(tournament => { TournamentManager.Instance.GetAssetObject(tournament.Options.BuyIn.Asset.Id) .Then(asset => jackpoText.text = Utils.GetFormatedDecimaNumber((tournament.PrizePool / Math.Pow(10, asset.Precision)).ToString()) + " " + asset.Symbol); }); }); }
void UpdateHistory(MatchContainer match) { winsToWinGame = 0; gamesToWinRoundText.text = winsToWinGame.ToString(); if (!match.Winner.Equals(match.Me)) { gameRoundOverView.CurrentGameRoundOverState = GameRoundOverState.Lose; gameRoundOverView.UpdateOpponentUsername(match.Opponent.Name); AudioManager.Instance.PlayTotalLooseSound(); winsToWinTournament = winsToWinGame = 0; gamesToWinRoundText.text = gamesToWinTournamentText.text = "0"; UpdateBattleLog(match); GameManager.Instance.OnGameComplete -= GameComplete; GameManager.Instance.OnMatchComplete -= MatcheComplete; GameManager.Instance.OnNewMatch -= MatcheStart; return; } ApiManager.Instance.Database.GetTournament(match.Tournament.Id) .Then(tournament => { TournamentManager.Instance.GetMatchesPromise(tournament.Id.Id) .Then(matches => { if (matches[matches.Length - 1].Id.Equals(match.Id) && matches[matches.Length - 1].MatchWinners.Contains(match.Me.Id)) { gameRoundOverView.CurrentGameRoundOverState = GameRoundOverState.Win; AudioManager.Instance.PlayTotalWinSound(); winsToWinTournament = winsToWinGame = 0; gamesToWinRoundText.text = gamesToWinTournamentText.text = "0"; } else { var count = 0; foreach (var matche in matches) { if (matche.State == ChainTypes.MatchState.InProgress) { count++; } } gameRoundOverView.SetMatchesInProgressCount(count); gameRoundOverView.CurrentGameRoundOverState = GameRoundOverState.RoundOver; winsToWinGame = 0; gamesToWinRoundText.text = "0"; winsToWinTournament = (((int)Math.Log(GameManager.Instance.GetTournamentNumberOfPlayers(match.Tournament), 2) - GameManager.Instance.GetCompletedMatches(match.Tournament)) * 5 - (5 - winsToWinGame)); gamesToWinTournamentText.text = winsToWinTournament < 0 ? 0.ToString() : winsToWinTournament.ToString(); } UpdateBattleLog(match); gameRoundOverView.UpdateOpponentUsername(match.Opponent.Name); }); }); }
void ExpectingMove(MatchContainer match, GameContainer game) { if (!match.Tournament.Equals(TournamentManager.Instance.CurrentTournament.Id)) { return; } nextTimeout = game.NextTimeout.Value.AddSeconds(-2); if (gameObject.activeInHierarchy) { StartCoroutine(NewGameStart()); } }
void MatcheComplete(MatchContainer match) { if (TournamentManager.Instance.CurrentTournament == null) { return; } if (!match.Tournament.Equals(TournamentManager.Instance.CurrentTournament.Id)) { return; } GameManager.Instance.OnGameExpectedMove -= ExpectingMove; StartCoroutine(MatcheCompleteCoroutine(match)); }
void MatcheStart(MatchContainer match) { if (TournamentManager.Instance.CurrentTournament == null) { return; } if (match.IsNull() || !match.Tournament.Equals(TournamentManager.Instance.CurrentTournament.Id)) { return; } GameManager.Instance.SetCurrentTournament(match.Tournament); GameManager.Instance.OnGameExpectedMove -= ExpectingMove; GameManager.Instance.OnGameExpectedMove += ExpectingMove; StopCoroutine("MatcheCompleteCoroutine"); gameRoundOverView.gameObject.SetActive(false); gameStartPreview.gameObject.SetActive(false); GameManager.Instance.UpdateMetches(TournamentManager.Instance.CurrentTournament) .Then(() => { base.Show(); UIController.Instance.CloseNotGamingPanels(); if (!match.CurrentGame.IsNull()) { nextTimeout = match.CurrentGame.NextTimeout == null ? DateTime.UtcNow.AddSeconds(12) : match.CurrentGame.NextTimeout.Value.AddSeconds(-2); if (match.CurrentGame.GameState == ChainTypes.GameState.ExpectingCommitMoves || match.CurrentGame.GameState == ChainTypes.GameState.ExpectingRevealMoves) { AudioManager.Instance.PlayWaitingSound(); } if (PlayerPrefs.GetInt(match.Id.ToString()) == 0) { AudioManager.Instance.PlayNoticeSound(); PlayerPrefs.SetInt(match.Id.ToString(), (int)match.Id.Id); } UpdateMoveButtons(); } UpdateGameUi(GameManager.Instance.CurrentMatch); playerHand.enabled = true; opponentHand.enabled = true; StopTimer(); UpdateTimer(); UpdateJackpot(GameManager.Instance.CurrentMatch); UpdateUsernameText(GameManager.Instance.CurrentMatch.Me.Name, GameManager.Instance.CurrentMatch.Opponent.Name); }); }
IEnumerator BackToIdleCoroutine(float delay, MatchContainer match, GameContainer game) { yield return(new WaitForSecondsRealtime(1f)); if (game.Result == GameResult.Win) { AudioManager.Instance.PlayWinSound(); } else if (game.Result == GameResult.Lose) { AudioManager.Instance.PlayLooseSound(); } UpdateGameUi(match); playerHand.SetTrigger("idle"); opponentHand.SetTrigger("idle"); yield return(new WaitForSecondsRealtime(1f)); }
public void NewMatch(MatchObject newMatch, AccountObject me, AccountObject opponent, Action <MatchContainer, GameContainer> newGameCallback, Action <MatchContainer, GameContainer> gameCompleteCallback, Action <MatchContainer, GameContainer> gameExpectedMoveCallback) { startedMatches.Add(newMatch); var game = newMatch.Games.Last(); Repository.GetInPromise(game, () => ApiManager.Instance.Database.GetGame(game.Id)).Then(newGame => { if (!currentMatch.IsNull() && !currentMatch.Id.Equals(newMatch.Id)) { completedMatches[currentMatch.Id] = currentMatch; } currentMatch = new MatchContainer(completedMatches.Count + 1, newMatch, me, opponent, completedMatch => { matchCompleteCallback.Invoke(completedMatches[completedMatch.Id] = completedMatch); }); newMatchCallback.Invoke(currentMatch); currentMatch.OnNewGame += newGameCallback; currentMatch.OnGameComplete += gameCompleteCallback; currentMatch.OnGameExpectedMove += gameExpectedMoveCallback; currentMatch.NewGame(newGame).CheckState(); }).Catch(error => Unity.Console.Error(Unity.Console.SetRedColor(error))); }
void GameComplete(MatchContainer match, GameContainer game) { if (!gameObject.activeSelf || TournamentManager.Instance.CurrentTournament == null || !match.Tournament.Equals(TournamentManager.Instance.CurrentTournament.Id)) { return; } AudioManager.Instance.StopPlaying(); StopTimer(); buttonsObject.SetActive(false); if (game.MeGesture.HasValue) { playerHand.SetTrigger(RockPaperScissorsGestureEnumConverter.ConvertTo(game.MeGesture.Value)); } if (game.OpponentGesture.HasValue) { opponentHand.SetTrigger(RockPaperScissorsGestureEnumConverter.ConvertTo(game.OpponentGesture.Value)); } StartCoroutine(BackToIdleCoroutine(2f, match, game)); }
public async Task UploadMatchResults(MatchContainer matchResult) { try { using var request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = myUploadMatchResultsUri, Content = new StringContent(JsonSerializer.Serialize(matchResult), Encoding.UTF8, "application/json") }; using var response = await myHttpClient.SendAsync(request); if (response.StatusCode != HttpStatusCode.OK) { throw new InvalidOperationException(); } } catch (Exception ex) { Console.WriteLine($"Error during upload!!! {ex}"); } }
/// <summary> /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RefilterGames(object sender, BindableValueChangedEventArgs <bool> e) => MatchContainer.FilterGames(Searchbox.RawText, true);