Пример #1
0
    private void SubscribeSequence(PlayerSquenceReactiveProperty squence)
    {
        var tlane = _lane == 0
            ? TargetLane.Lane1
            : _lane == 1
                ? TargetLane.Lane2
                : _lane == 2
                    ? TargetLane.Lane3
                    : TargetLane.Lane4;

        squence.Debug(Verbose && (GameManager.TargetLane_External & tlane) == tlane, "Player-{_lane}")
        .Subscribe(state =>
        {
            switch (state)
            {
            case AnimSequence.OnReadyEnter:
                break;

            case AnimSequence.OnReadyExit:
                break;

            case AnimSequence.CatchEnter:
                Observable
                .Timer(TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(100))
                .TakeWhile(condition =>
                {
                    var b = false;
                    switch (_roundStream.Value)
                    {
                    case Rounds.R1_Hike:
                        b = thisPlayer.R1Throw;
                        break;

                    case Rounds.R2_Hike:
                        b = thisPlayer.R2Throw;
                        break;

                    case Rounds.R3_Hike:
                        b = thisPlayer.R3Throw;
                        break;
                    }
                    return(b != true);
                })
                .DoOnCompleted(() =>
                {
                    switch (_roundStream.Value)
                    {
                    case Rounds.R1_Hike:
                        if (thisPlayer.Results[0].Hit)
                        {
                            SetToHit();
                        }
                        else
                        {
                            SetToMiss();
                        }
                        break;

                    case Rounds.R2_Hike:
                        if (thisPlayer.Results[1].Hit)
                        {
                            SetToHit();
                        }
                        else
                        {
                            SetToMiss();
                        }
                        break;

                    case Rounds.R3_Hike:
                        if (thisPlayer.Results[2].Hit)
                        {
                            SetToHit();
                        }
                        else
                        {
                            SetToMiss();
                        }
                        break;
                    }
                })
                .Subscribe()
                .AddTo(_actor);
                break;

            case AnimSequence.CatchExit:
                break;

            case AnimSequence.HitEnter:
                _footBall.SetActive(true);
                Observable
                .Timer(TimeSpan.FromSeconds(1f))
                .DoOnCompleted(() =>
                {
                    switch (_roundStream.Value)
                    {
                    case Rounds.R1_Hike:
                        Ref.MakeCallBasedOnResult(thisPlayer.Results[0].Hit, _lane);
                        _appStateBroker.ComOutGoingStream.OnNext(CommunicationModule.BuildRound1Msg(thisPlayer.Lane, thisPlayer.Result1, thisPlayer.Results[0].Hit));
                        break;

                    case Rounds.R2_Hike:
                        Ref.MakeCallBasedOnResult(thisPlayer.Results[1].Hit, _lane);
                        _appStateBroker.ComOutGoingStream.OnNext(
                            CommunicationModule.BuildRound2Msg(thisPlayer.Lane, thisPlayer.Result1, thisPlayer.Results[0].Hit, thisPlayer.Result2, thisPlayer.Results[1].Hit));
                        break;

                    case Rounds.R3_Hike:
                        Ref.MakeCallBasedOnResult(thisPlayer.Results[2].Hit, _lane);
                        _appStateBroker.ComOutGoingStream
                        .OnNext(CommunicationModule
                                .BuildRound3Msg(thisPlayer.Lane, thisPlayer.Result1, thisPlayer.Results[0].Hit, thisPlayer.Result2, thisPlayer.Results[1].Hit, thisPlayer.Result3, thisPlayer.Results[2].Hit, thisPlayer.PlayerName, thisPlayer.PlayerPercentage));
                        break;
                    }
                    Ref.RefAniStream
                    .Take(1)
                    .DoOnCompleted(SetToCallRef)
                    .Subscribe()
                    .AddTo(_actor);
                })
                .Subscribe()
                .AddTo(_actor);
                break;

            case AnimSequence.HitExit:
                break;

            case AnimSequence.MissEnter:
                Observable
                .Timer(TimeSpan.FromSeconds(0.1f))
                .DoOnCompleted(() =>
                {
                    switch (_roundStream.Value)
                    {
                    case Rounds.R1_Hike:
                        Ref.MakeCallBasedOnResult(thisPlayer.Results[0].Hit, _lane);
                        _appStateBroker.ComOutGoingStream.OnNext(CommunicationModule.BuildRound1Msg(thisPlayer.Lane, thisPlayer.Result1, thisPlayer.Results[0].Hit));
                        break;

                    case Rounds.R2_Hike:
                        Ref.MakeCallBasedOnResult(thisPlayer.Results[1].Hit, _lane);
                        _appStateBroker.ComOutGoingStream.OnNext(
                            CommunicationModule.BuildRound2Msg(thisPlayer.Lane, thisPlayer.Result1, thisPlayer.Results[0].Hit, thisPlayer.Result2, thisPlayer.Results[1].Hit));
                        break;

                    case Rounds.R3_Hike:
                        Ref.MakeCallBasedOnResult(thisPlayer.Results[2].Hit, _lane);
                        _appStateBroker.ComOutGoingStream
                        .OnNext(CommunicationModule
                                .BuildRound3Msg(thisPlayer.Lane, thisPlayer.Result1, thisPlayer.Results[0].Hit, thisPlayer.Result2, thisPlayer.Results[1].Hit, thisPlayer.Result3, thisPlayer.Results[2].Hit, thisPlayer.PlayerName, thisPlayer.PlayerPercentage));
                        break;
                    }
                    Ref.RefAniStream
                    .Take(1)
                    .DoOnCompleted(SetToCallRef)
                    .Subscribe(_ => _footBall.SetActive(false))
                    .AddTo(_actor);
                })
                .Subscribe()
                .AddTo(_actor);
                break;

            case AnimSequence.MissExit:
                break;

            case AnimSequence.FinishEnter:
                _roundStream
                .Take(1)
                .Subscribe(round =>
                {
                    switch (round)
                    {
                    case Rounds.R1_Hike:
                        thisPlayer.R1Done = true;
                        break;

                    case Rounds.R2_Hike:
                        thisPlayer.R2Done = true;
                        break;

                    case Rounds.R3_Hike:
                        thisPlayer.R3Done = true;
                        break;
                    }
                })
                .AddTo(_actor);
                break;

            case AnimSequence.FinishExit:
                _footBall.SetActive(false);
                break;
            }
        })
        .AddTo(_actor);
    }