Exemplo n.º 1
0
        private IEnumerator CoJoin(Action <bool> callback)
        {
            Task t = Task.Run(async() =>
            {
                await _hub.JoinAsync();
            });

            yield return(new WaitUntil(() => t.IsCompleted));

            if (t.IsFaulted)
            {
                callback?.Invoke(false);
                yield break;
            }

            Connected = true;

            // 에이전트의 상태를 한 번 동기화 한다.
            Currency goldCurrency = new GoldCurrencyState(
                (Dictionary)GetState(GoldCurrencyState.Address)
                ).Currency;

            States.Instance.SetAgentState(
                GetState(Address) is Bencodex.Types.Dictionary agentDict
                    ? new AgentState(agentDict)
                    : new AgentState(Address));
            States.Instance.SetGoldBalanceState(
                new GoldBalanceState(Address, GetBalance(Address, goldCurrency)));

            // 랭킹의 상태를 한 번 동기화 한다.
            for (var i = 0; i < RankingState.RankingMapCapacity; ++i)
            {
                var address  = RankingState.Derive(i);
                var mapState = GetState(address) is Bencodex.Types.Dictionary serialized
                    ? new RankingMapState(serialized)
                    : new RankingMapState(address);
                States.Instance.SetRankingMapStates(mapState);
            }

            // 상점의 상태를 한 번 동기화 한다.
            States.Instance.SetShopState(
                GetState(ShopState.Address) is Bencodex.Types.Dictionary shopDict
                    ? new ShopState(shopDict)
                    : new ShopState());

            if (GetState(GameConfigState.Address) is Dictionary configDict)
            {
                States.Instance.SetGameConfigState(new GameConfigState(configDict));
            }
            else
            {
                throw new FailedToInstantiateStateException <GameConfigState>();
            }

            if (ArenaHelper.TryGetThisWeekState(BlockIndex, out var weeklyArenaState))
            {
                States.Instance.SetWeeklyArenaState(weeklyArenaState);
            }
            else
            {
                throw new FailedToInstantiateStateException <WeeklyArenaState>();
            }

            ActionRenderHandler.Instance.GoldCurrency = goldCurrency;

            // 그리고 모든 액션에 대한 랜더와 언랜더를 핸들링하기 시작한다.
            BlockRenderHandler.Instance.Start(BlockRenderer);
            ActionRenderHandler.Instance.Start(ActionRenderer);
            ActionUnrenderHandler.Instance.Start(ActionRenderer);

            UpdateSubscribeAddresses();
            callback?.Invoke(true);
        }