bool IsPlayerJoined(TournamentDetailsObject tournamentDetails) { foreach (var player in tournamentDetails.RegisteredPlayers) { if (player.Id == AuthorizationManager.Instance.UserData.FullAccount.Account.Id.Id) { return(true); } } return(false); }
public IEnumerator GetMatcheWinnerAccountsObjects(TournamentDetailsObject details, List <AccountObject> accountWinners) { List <AccountObject> loadedAccounts = null; ApiManager.Instance.Database.GetMatche(details.Matches[details.Matches.Length - 1].Id) .Then(matchResult => { ApiManager.Instance.Database.GetAccounts(Array.ConvertAll(matchResult.MatchWinners, winner => winner.Id)) .Then(accountResult => loadedAccounts = new List <AccountObject>(accountResult)) .Catch(exception => loadedAccounts = new List <AccountObject>()); }) .Catch(exception => loadedAccounts = new List <AccountObject>()); while (loadedAccounts == null) { yield return(null); } if (loadedAccounts.Count > 0) { accountWinners.AddRange(loadedAccounts); } }
public virtual IEnumerator UpdateItem(TournamentObject info) { if (gameObject.activeSelf && gameObject.activeInHierarchy) { CurrentTournament = info; if (tournamentDetailsObject.IsNull() || !tournamentDetailsObject.Tournament.Equals(info.Id)) { var detailsObject = new List <TournamentDetailsObject>(); yield return(TournamentManager.Instance.GetTournamentDetailsObject(info.Id.Id, detailsObject)); tournamentDetailsObject = detailsObject[0]; } ID = "#RPS" + info.Id; PlayerRegistered = info.RegisteredPlayers.ToString(); MaxPlayers = info.Options.NumberOfPlayers.ToString(); if (currentAsset.IsNull() || !currentAsset.Id.Equals(currentTournament.Options.BuyIn.Asset)) { AssetObject asset = null; TournamentManager.Instance.GetAssetObject(currentTournament.Options.BuyIn.Asset.Id) .Then(assetResult => asset = assetResult); while (asset.IsNull()) { yield return(null); } currentAsset = asset; } var buyIn = Decimal.Parse((info.Options.BuyIn.Amount / Math.Pow(10, currentAsset.Precision)).ToString(), NumberStyles.Float); BuyIn = buyIn + currentAsset.Symbol; Jackpot = buyIn * info.Options.NumberOfPlayers + currentAsset.Symbol; UpdateStartTime(); } }
public void UpdateFooter(TournamentObject tournament, TournamentDetailsObject details, bool isHover) { if (isHover) { footerTargetImage.color = hoverColor; itemBgColor.color = myTournamentsItemBgColor; startTimeText.color = myTournamentsItemBgColor; UpdateButtonColor(joinButton, ButtonViewState.Alternative); UpdateButtonColor(activePlayButton, ButtonViewState.Alternative); } else { footerTargetImage.color = currenTournamentViewState.Equals(TournamentViewState.PlayerInTournament) ? playerInTournamentColor : otherTournamentsColor; itemBgColor.color = currenTournamentViewState.Equals(TournamentViewState.PlayerInTournament) ? myTournamentsItemBgColor : otherTournamentsItemBgColor; startTimeText.color = normalTextColor; UpdateButtonColor(joinButton, ButtonViewState.Normal); UpdateButtonColor(activePlayButton, ButtonViewState.Normal); } switch (tournament.State) { case ChainTypes.TournamentState.InProgress: break; case ChainTypes.TournamentState.AcceptingRegistrations: if (!IsPlayerJoined(details)) { joinButton.gameObject.SetActive(isHover); registerTimeText.gameObject.SetActive(!isHover); } break; case ChainTypes.TournamentState.AwaitingStart: break; } }
public IEnumerator SetUp(TournamentObject tournament, TournamentDetailsObject details) { currenTournamentObject = tournament; currenTournamentDetailsObject = details; var me = AuthorizationManager.Instance.UserData; activePlayButton.gameObject.SetActive(false); inActivePlayButton.gameObject.SetActive(false); joinButton.gameObject.SetActive(false); cancelButton.gameObject.SetActive(false); startTimeText.gameObject.SetActive(false); registerTimeText.gameObject.SetActive(false); opponentText.gameObject.SetActive(false); liveMessage.gameObject.SetActive(false); headerItemView.gameObject.SetActive(false); if (IsPlayerJoined(details)) { currenTournamentViewState = TournamentViewState.PlayerInTournament; footerTargetImage.color = playerInTournamentColor; itemBgColor.color = myTournamentsItemBgColor; } else { footerTargetImage.color = otherTournamentsColor; itemBgColor.color = otherTournamentsItemBgColor; currenTournamentViewState = TournamentViewState.OtherTournament; } switch (tournament.State) { case ChainTypes.TournamentState.Concluded: break; case ChainTypes.TournamentState.InProgress: if (!IsPlayerJoined(details)) { liveMessage.SetActive(true); } else { var matchesList = new List <MatchObject>(); yield return(TournamentManager.Instance.GetMatcheObjects(Array.ConvertAll(details.Matches, matche => matche.Id), matchesList)); var matchesInProgress = Array.FindAll(matchesList.ToArray(), match => match.State.Equals(ChainTypes.MatchState.InProgress)); var playerInMatches = Array.Find(matchesInProgress, match => match.Players.Contains(me.FullAccount.Account.Id)); if (playerInMatches == null) { inActivePlayButton.gameObject.SetActive(true); headerItemView.gameObject.SetActive(true); headerItemView.color = awaitingColor; } else { opponentText.gameObject.SetActive(true); activePlayButton.gameObject.SetActive(true); headerItemView.gameObject.SetActive(true); headerItemView.color = playColor; var opponentAccount = new List <AccountObject>(); yield return(TournamentManager.Instance.GetAccount(Array.Find(playerInMatches.Players, opponent => !opponent.Id.Equals(me.FullAccount.Account.Id.Id)), opponentAccount)); opponentText.text = Utils.GetFormatedString(opponentAccount[0].Name); } } break; case ChainTypes.TournamentState.AcceptingRegistrations: startTimeText.gameObject.SetActive(true); UpdateStartTime(tournament.Options.StartTime); if (IsPlayerJoined(details)) { cancelButton.gameObject.SetActive(true); } else { registerTimeText.gameObject.SetActive(true); UpdateRegisterTime(tournament.Options.RegistrationDeadline); } break; case ChainTypes.TournamentState.AwaitingStart: if (IsPlayerJoined(details)) { headerItemView.gameObject.SetActive(true); headerItemView.color = awaitingColor; if ((tournament.StartTime.Value - DateTime.UtcNow).TotalMinutes <= 2) { activePlayButton.gameObject.SetActive(true); } else { inActivePlayButton.gameObject.SetActive(true); TournamentManager.Instance.AddAwaitingStartTournaments(tournament); } } break; } }
bool IsPlayerJoined(TournamentDetailsObject details) { return(details.RegisteredPlayers.Contains(AuthorizationManager.Instance.Authorization.UserNameData.FullAccount.Account.Id)); }
public void UpdateTournamentInfo(TournamentObject tournament, TournamentDetailsObject tournamentDetails) { this.tournament = tournament; this.tournamentDetails = tournamentDetails; }