예제 #1
0
    /// <summary>
    /// A Unity Animation event hook
    /// Is called when the hide animation is finished.
    /// Instantiates a new match and converts player setting UI values
    /// into new Side instances and re-assigns the ruleset from the
    /// dialog to the match.
    /// Finally, <see cref="OnNewMatch"/> is invoked
    /// </summary>
    public void HideFinished()
    {
        OnHideFinished?.Invoke();

        GameObject matchInstance = Object.Instantiate <GameObject>(matchPrefab);
        Match      m             = matchInstance.GetComponent <Match>();

        foreach (PlayerSettings playerSetting in playerSettings)
        {
            Side s = new Side();
            s.color         = playerSetting.SelectedColor();
            s.role          = playerSetting.SelectedRole();
            s.iconName      = playerSetting.SelectedIcon();
            s.pieceResource = playerSetting.SelectedPieceResource();
            s.name          = playerSetting.SelectedName();
            s.aiStrategy    = playerSetting.SelectedAIRoleStrategy();

            m.RegisterSide(s);
        }
        r.SetMatch(m);
        m.ruleset = r;

        OnNewMatch?.Invoke(m);
    }
예제 #2
0
    public void ToAfterMatch()
    {
        spawnPickupsScript.StopSpawning();
        audioManager.audioSource.Stop();
        if (screenNum == 3)
        {
            audioSrc.PlayOneShot(roundEndSFX);
            readyPlayersNum = 0;
            OnNewMatch.Invoke();

            if (matchNum <= 2)
            {
                StartCoroutine(SwitchControllers());
                StartCoroutine(DestroyPickups(2.1f));
            }
            else
            {
                screenNum       = 5;
                readyPlayersNum = 0;
                StartCoroutine(ToFinal());
                StartCoroutine(DestroyPickups(1f));
            }
        }
    }
예제 #3
0
    public Promise UpdateMetches(TournamentObject info)
    {
        return(new Promise((action, exeption) => {
            SetCurrentTournament(info.Id);

            TournamentManager.Instance.GetDetailsTournamentObject(info.TournamentDetails.Id)
            .Then(detail => {
                ApiManager.Instance.Database.GetMatches(Array.ConvertAll(detail.Matches, match => match.Id))
                .Then(matches => {
                    var myMatch = Array.Find(matches, match => match.State.Equals(ChainTypes.MatchState.InProgress) && match.Players.Contains(me.Id));
                    ApiManager.Instance.Database.GetGames(Array.ConvertAll(myMatch.Games, game => game.Id))
                    .Then(games => {
                        var existTournament = IsTournamentExist(myMatch.Tournament);
                        var existMatch = existTournament && myTournaments[myMatch.Tournament].StartedMatches.Contains(myMatch.Id);
                        if (!existTournament)
                        {
                            myTournaments[myMatch.Tournament] = new TournamentContainer(match => OnNewMatch.Invoke(match), match => OnMatchComplete.Invoke(match));
                        }
                        myTournaments[myMatch.Tournament].UpdateTournamentInfo(info, detail);
                        var opponent = Array.Find(myMatch.Players, account => !me.Id.Equals(account));
                        Repository.GetInPromise(opponent, () => ApiManager.Instance.Database.GetAccount(opponent.Id))
                        .Then(account => {
                            if (!existMatch)
                            {
                                myTournaments[myMatch.Tournament]
                                .NewMatch(myMatch, me, account,
                                          (match, game) => OnNewGame.Invoke(match, game),
                                          (match, game) => OnGameComplete.Invoke(match, game),
                                          (match, game) => OnGameExpectedMove.Invoke(match, game));
                            }
                            var completedGames = myTournaments[myMatch.Tournament].CurrentMatch.CompletedGames;
                            foreach (var game in games)
                            {
                                if (!completedGames.ContainsKey(game.Id))
                                {
                                    if (game.State.Equals(ChainTypes.GameState.Complete))
                                    {
                                        (completedGames[game.Id] = new GameContainer(completedGames.Count + 1, game, me, account))
                                        .CheckState();
                                    }
                                    else
                                    {
                                        myTournaments[myMatch.Tournament].CurrentMatch.NewGame(game).CheckState();
                                    }
                                }
                            }
                            action();
                        });
                    });
                });
            });
        }));
    }
예제 #4
0
    void Repository_OnObjectUpdate(IdObject idObject)
    {
        if (!idObject.SpaceType.Equals(SpaceType.Match))
        {
            return;
        }
        var updatedMatch = idObject as MatchObject;

        if (!updatedMatch.Players.Contains(me.Id))
        {
            return;
        }
        if (updatedMatch.State.Equals(ChainTypes.MatchState.WaitingOnPreviousMatches))
        {
            return;
        }
        Repository.GetInPromise(updatedMatch.Tournament, () => TournamentManager.Instance.LoadTournament(updatedMatch.Tournament.Id)).Then(tournament => {
            Repository.GetInPromise(tournament.TournamentDetails, () => TournamentManager.Instance.GetDetailsTournamentObject(tournament.TournamentDetails.Id)).Then(tournamentDetails => {
                var existTournament = IsTournamentExist(updatedMatch.Tournament);
                var existMatch      = existTournament && myTournaments[updatedMatch.Tournament].StartedMatches.Contains(updatedMatch.Id);
                if (!existTournament)
                {
                    myTournaments[updatedMatch.Tournament] = new TournamentContainer(match => OnNewMatch.Invoke(match), match => OnMatchComplete.Invoke(match));
                }
                myTournaments[updatedMatch.Tournament].UpdateTournamentInfo(tournament, tournamentDetails);
                if (!existMatch && updatedMatch.State.Equals(ChainTypes.MatchState.InProgress))
                {
                    var opponent = Array.Find(updatedMatch.Players, account => !me.Id.Equals(account));
                    Repository.GetInPromise(opponent, () => ApiManager.Instance.Database.GetAccount(opponent.Id)).Then(account => {
                        myTournaments[updatedMatch.Tournament].NewMatch(updatedMatch, me, account,
                                                                        (match, game) => OnNewGame.Invoke(match, game),
                                                                        (match, game) => OnGameComplete.Invoke(match, game),
                                                                        (match, game) => OnGameExpectedMove.Invoke(match, game));
                    });
                }
            });
        });
    }