Esempio n. 1
0
 public MakeInitialStateResult(
     IAccountStateDelta state,
     CreateTestbed testbed,
     AgentState agentState,
     AvatarState avatarState,
     GoldCurrencyState goldCurrencyState,
     Address rankingMapAddress,
     TableSheets tableSheets,
     FungibleAssetValue currencyGold,
     FungibleAssetValue agentCurrencyGold)
 {
     _state             = state;
     _testbed           = testbed;
     _agentState        = agentState;
     _avatarState       = avatarState;
     _goldCurrencyState = goldCurrencyState;
     _rankingMapAddress = rankingMapAddress;
     _tableSheets       = tableSheets;
     _currencyGold      = currencyGold;
     _agentCurrencyGold = agentCurrencyGold;
 }
Esempio n. 2
0
        public static MakeInitialStateResult MakeInitialState()
        {
            var goldCurrencyState = new GoldCurrencyState(new Currency("NCG", 2, minter: null));
            var ranking           = new RankingState1();

            for (var i = 0; i < RankingState1.RankingMapCapacity; i++)
            {
                ranking.RankingMap[RankingState1.Derive(i)] = new HashSet <Address>().ToImmutableHashSet();
            }

            var sheets             = TableSheetsImporter.ImportSheets();
            var weeklyArenaAddress = WeeklyArenaState.DeriveAddress(0);
            var initialState       = new Tests.Action.State()
                                     .SetState(GoldCurrencyState.Address, goldCurrencyState.Serialize())
                                     .SetState(
                Addresses.GoldDistribution,
                GoldDistributionTest.Fixture.Select(v => v.Serialize()).Serialize()
                )
                                     .SetState(
                Addresses.GameConfig,
                new GameConfigState(sheets[nameof(GameConfigSheet)]).Serialize()
                )
                                     .SetState(Addresses.Ranking, ranking.Serialize())
                                     .SetState(weeklyArenaAddress, new WeeklyArenaState(0).Serialize());

            foreach (var(key, value) in sheets)
            {
                initialState = initialState.SetState(Addresses.TableSheet.Derive(key), value.Serialize());
            }

            var tableSheets       = new TableSheets(sheets);
            var rankingMapAddress = new PrivateKey().ToAddress();

            var agentAddress = new PrivateKey().ToAddress();
            var agentState   = new AgentState(agentAddress);

            var avatarAddress = new PrivateKey().ToAddress();
            var avatarState   = new AvatarState(
                avatarAddress,
                agentAddress,
                0,
                tableSheets.GetAvatarSheets(),
                new GameConfigState(),
                rankingMapAddress)
            {
                worldInformation = new WorldInformation(
                    0,
                    tableSheets.WorldSheet,
                    GameConfig.RequireClearedStageLevel.ActionsInShop),
            };

            agentState.avatarAddresses[0] = avatarAddress;

            var initCurrencyGold   = goldCurrencyState.Currency * 100000000000;
            var agentCurrencyGold  = goldCurrencyState.Currency * 1000;
            var remainCurrencyGold = initCurrencyGold - agentCurrencyGold;

            initialState = initialState
                           .SetState(GoldCurrencyState.Address, goldCurrencyState.Serialize())
                           .SetState(agentAddress, agentState.Serialize())
                           .SetState(avatarAddress, avatarState.Serialize())
                           .SetState(Addresses.Shop, new ShopState().Serialize())
                           .MintAsset(GoldCurrencyState.Address, initCurrencyGold)
                           .TransferAsset(Addresses.GoldCurrency, agentAddress, agentCurrencyGold);

            var action = new CreateTestbed
            {
                weeklyArenaAddress = weeklyArenaAddress,
            };
            var nextState = action.Execute(new ActionContext()
            {
                BlockIndex     = 0,
                PreviousStates = initialState,
                Random         = new TestRandom(),
                Rehearsal      = false,
            });

            return(new MakeInitialStateResult(
                       nextState,
                       action,
                       agentState,
                       avatarState,
                       goldCurrencyState,
                       rankingMapAddress,
                       tableSheets,
                       remainCurrencyGold,
                       agentCurrencyGold));
        }