示例#1
0
        public NecklaceTest()
        {
            var tableSheets = new TableSheets(TableSheetsImporter.ImportSheets());

            _necklaceRow = tableSheets.EquipmentItemSheet.OrderedList.FirstOrDefault(row =>
                                                                                     row.ItemSubType == ItemSubType.Necklace);
        }
示例#2
0
        public StageSimulator(
            IRandom random,
            AvatarState avatarState,
            List <Guid> foods,
            int worldId,
            int stageId,
            TableSheets tableSheets) : base(random, avatarState, foods, tableSheets)
        {
            _waves = new List <Wave>();

            WorldId   = worldId;
            StageId   = stageId;
            IsCleared = avatarState.worldInformation.IsStageCleared(StageId);

            var stageSheet = TableSheets.StageSheet;

            if (!stageSheet.TryGetValue(StageId, out var stageRow))
            {
                throw new SheetRowNotFoundException(nameof(stageSheet), StageId);
            }

            var stageWaveSheet = TableSheets.StageWaveSheet;

            if (!stageWaveSheet.TryGetValue(StageId, out var stageWaveRow))
            {
                throw new SheetRowNotFoundException(nameof(stageWaveSheet), StageId);
            }

            Exp       = StageRewardExpHelper.GetExp(avatarState.level, stageId);
            TurnLimit = stageRow.TurnLimit;

            SetWave(stageRow, stageWaveRow);
            _waveRewards = SetReward(stageRow, random, tableSheets);
        }
示例#3
0
        public RapidCombinationTest()
        {
            _initialState = new State();

            var sheets = TableSheetsImporter.ImportSheets();

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

            _tableSheets = new TableSheets(sheets);

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

            _avatarAddress = new PrivateKey().ToAddress();
            var avatarState = new AvatarState(
                _avatarAddress,
                _agentAddress,
                0,
                _tableSheets.GetAvatarSheets(),
                new GameConfigState(),
                default
                );

            agentState.avatarAddresses[0] = _avatarAddress;

            _initialState = _initialState
                            .SetState(Addresses.GameConfig, new GameConfigState(sheets[nameof(GameConfigSheet)]).Serialize())
                            .SetState(_agentAddress, agentState.Serialize())
                            .SetState(_avatarAddress, avatarState.Serialize());
        }
示例#4
0
        public StageSimulator(
            IRandom random,
            AvatarState avatarState,
            List <Guid> foods,
            int worldId,
            int stageId,
            TableSheets tableSheets,
            Model.Skill.Skill skill)
            : this(random, avatarState, foods, worldId, stageId, tableSheets)
        {
            var stageSheet = TableSheets.StageSheet;

            if (!stageSheet.TryGetValue(StageId, out var stageRow))
            {
                throw new SheetRowNotFoundException(nameof(stageSheet), StageId);
            }

            Exp       = StageRewardExpHelper.GetExp(avatarState.level, stageId);
            TurnLimit = stageRow.TurnLimit;

            if (!ReferenceEquals(skill, null))
            {
                Player.OverrideSkill(skill);
            }
        }
        public StandaloneMutationTest(ITestOutputHelper output) : base(output)
        {
            var fixturePath = Path.Combine("..", "..", "..", "..", "Lib9c", ".Lib9c.Tests", "Data", "TableCSV");

            _sheets      = TableSheetsImporter.ImportSheets(fixturePath);
            _tableSheets = new TableSheets(_sheets);
        }
示例#6
0
文件: Player.cs 项目: x86chi/lib9c
 private void PostConstruction(TableSheets sheets)
 {
     AttackCountMax      = AttackCountHelper.GetCountMax(Level);
     characterLevelSheet = sheets.CharacterLevelSheet;
     UpdateExp();
     Equip(Inventory.Items, sheets.EquipmentItemSetEffectSheet);
 }
示例#7
0
        public BeltTest()
        {
            var tableSheets = new TableSheets(TableSheetsImporter.ImportSheets());

            _beltRow = tableSheets.EquipmentItemSheet.OrderedList.FirstOrDefault(row =>
                                                                                 row.ItemSubType == ItemSubType.Belt);
        }
        public ClaimMonsterCollectionReward0Test()
        {
            _signer        = default;
            _avatarAddress = _signer.Derive("avatar");
            _state         = new State();
            Dictionary <string, string> sheets = TableSheetsImporter.ImportSheets();

            _tableSheets = new TableSheets(sheets);
            var rankingMapAddress = new PrivateKey().ToAddress();
            var agentState        = new AgentState(_signer);
            var avatarState       = new AvatarState(
                _avatarAddress,
                _signer,
                0,
                _tableSheets.GetAvatarSheets(),
                new GameConfigState(),
                rankingMapAddress);

            agentState.avatarAddresses[0] = _avatarAddress;

            var currency          = new Currency("NCG", 2, minters: null);
            var goldCurrencyState = new GoldCurrencyState(currency);

            _state = _state
                     .SetState(_signer, agentState.Serialize())
                     .SetState(_avatarAddress, avatarState.Serialize())
                     .SetState(Addresses.GoldCurrency, goldCurrencyState.Serialize());

            foreach ((string key, string value) in sheets)
            {
                _state = _state
                         .SetState(Addresses.TableSheet.Derive(key), value.Serialize());
            }
        }
示例#9
0
        public override IAccountStateDelta Execute(IActionContext context)
        {
            var states = context.PreviousStates;

            if (context.Rehearsal)
            {
                return(states.SetState(avatarAddress, MarkChanged));
            }

            if (!states.TryGetAgentAvatarStates(context.Signer, avatarAddress, out var _, out var avatarState))
            {
                return(states);
            }

            var tableSheets = TableSheets.FromActionContext(context);
            var row         = tableSheets.MaterialItemSheet.Values.FirstOrDefault(r => r.ItemSubType == ItemSubType.ApStone);
            var apStone     = ItemFactory.CreateMaterial(row);

            if (!avatarState.inventory.RemoveFungibleItem(apStone))
            {
                Log.Error($"Not enough item {apStone}");
                return(states);
            }

            var gameConfigState = states.GetGameConfigState();

            if (gameConfigState is null)
            {
                return(states);
            }

            avatarState.actionPoint = gameConfigState.ActionPointMax;
            return(states.SetState(avatarAddress, avatarState.Serialize()));
        }
示例#10
0
        public ChestTest()
        {
            var tableSheets = new TableSheets(TableSheetsImporter.ImportSheets());

            _chestRow = tableSheets.MaterialItemSheet.OrderedList.FirstOrDefault(row =>
                                                                                 row.ItemSubType == ItemSubType.Chest);
        }
示例#11
0
        public RewardGoldTest()
        {
            _tableSheets = new TableSheets();
            _tableSheets.SetToSheet(nameof(WorldSheet), "test");
            _tableSheets.SetToSheet(nameof(QuestSheet), "test");
            _tableSheets.SetToSheet(nameof(QuestRewardSheet), "test");
            _tableSheets.SetToSheet(nameof(QuestItemRewardSheet), "test");
            _tableSheets.SetToSheet(nameof(EquipmentItemRecipeSheet), "test");
            _tableSheets.SetToSheet(nameof(EquipmentItemSubRecipeSheet), "test");
            _tableSheets.SetToSheet(
                nameof(CharacterSheet),
                "id,_name,size_type,elemental_type,hp,atk,def,cri,hit,spd,lv_hp,lv_atk,lv_def,lv_cri,lv_hit,lv_spd,attack_range,run_speed\n100010,전사,S,0,300,20,10,10,90,70,12,0.8,0.4,0,3.6,2.8,2,3");

            var privateKey   = new PrivateKey();
            var agentAddress = privateKey.PublicKey.ToAddress();

            var avatarAddress = agentAddress.Derive("avatar");

            _avatarState = new AvatarState(avatarAddress, agentAddress, 0, _tableSheets, new GameConfigState());

            var gold = new GoldCurrencyState(new Currency("NCG", minter: null));

            _baseState = (State) new State()
                         .SetState(GoldCurrencyState.Address, gold.Serialize())
                         .SetState(Addresses.GoldDistribution, GoldDistributionTest.Fixture.Select(v => v.Serialize()).Serialize())
                         .MintAsset(GoldCurrencyState.Address, gold.Currency, 100000000000);
        }
示例#12
0
        public static (AgentState, AvatarState) GetAgentStateWithAvatarState(
            IReadOnlyDictionary <string, string> sheets,
            TableSheets tableSheets,
            Address rankingMapAddress)
        {
            var agentAddress = new PrivateKey().ToAddress();
            var agentState   = new AgentState(agentAddress);

            var avatarAddress = agentAddress.Derive("avatar");
            var avatarState   = new AvatarState(
                avatarAddress,
                agentAddress,
                0,
                tableSheets.GetAvatarSheets(),
                new GameConfigState(sheets[nameof(GameConfigSheet)]),
                rankingMapAddress)
            {
                worldInformation = new WorldInformation(
                    0,
                    tableSheets.WorldSheet,
                    Math.Max(
                        tableSheets.StageSheet.First?.Id ?? 1,
                        GameConfig.RequireClearedStageLevel.ActionsInRankingBoard)),
            };

            agentState.avatarAddresses.Add(0, avatarAddress);

            return(agentState, avatarState);
        }
示例#13
0
        public ArmorTest()
        {
            var tableSheets = new TableSheets(TableSheetsImporter.ImportSheets());

            _armorRow = tableSheets.EquipmentItemSheet.OrderedList.FirstOrDefault(row =>
                                                                                  row.ItemSubType == ItemSubType.Armor);
        }
示例#14
0
 public void TearDown()
 {
     _avatarState      = null;
     _goldBalanceState = null;
     _agentState       = null;
     _tableSheets      = null;
 }
示例#15
0
 public WeeklyArenaStateTest()
 {
     _sheets = TableSheetsImporter.ImportSheets();
     _sheets[nameof(CharacterSheet)] =
         "id,_name,size_type,elemental_type,hp,atk,def,cri,hit,spd,lv_hp,lv_atk,lv_def,lv_cri,lv_hit,lv_spd,attack_range,run_speed\n100010,전사,S,0,300,20,10,10,90,70,12,0.8,0.4,0,3.6,2.8,2,3";
     _tableSheets = new TableSheets(_sheets);
 }
示例#16
0
        public void GetArenaInfos_By_Upper_And_Lower_Range(int infoCount, int targetRank, int upperRange, int lowerRange, int expected)
        {
            var tableState =
                TableSheets.FromTableSheetsState(TableSheetsImporter.ImportTableSheets());
            var     weeklyArenaState = new WeeklyArenaState(new PrivateKey().ToAddress());
            Address targetAddress;

            for (var i = 0; i < infoCount; i++)
            {
                var avatarAddress = new PrivateKey().ToAddress();
                if (i + 1 == targetRank)
                {
                    targetAddress = avatarAddress;
                }

                var avatarState = new AvatarState(
                    avatarAddress,
                    new PrivateKey().ToAddress(),
                    0L,
                    tableState,
                    new GameConfigState(),
                    i.ToString());
                weeklyArenaState.Add(
                    new PrivateKey().ToAddress(),
                    new ArenaInfo(avatarState, tableState.CharacterSheet, true));
            }

            var arenaInfos = weeklyArenaState.GetArenaInfos(targetAddress, upperRange, lowerRange);

            Assert.Equal(expected, arenaInfos.Count);
        }
示例#17
0
        public RewardGoldTest()
        {
            var sheets = TableSheetsImporter.ImportSheets();

            sheets[nameof(CharacterSheet)] = string.Join(
                Environment.NewLine,
                "id,_name,size_type,elemental_type,hp,atk,def,cri,hit,spd,lv_hp,lv_atk,lv_def,lv_cri,lv_hit,lv_spd,attack_range,run_speed",
                "100010,전사,S,0,300,20,10,10,90,70,12,0.8,0.4,0,3.6,2.8,2,3");

            var privateKey   = new PrivateKey();
            var agentAddress = privateKey.PublicKey.ToAddress();

            var avatarAddress = agentAddress.Derive("avatar");

            _tableSheets = new TableSheets(sheets);

            _avatarState = new AvatarState(
                avatarAddress,
                agentAddress,
                0,
                _tableSheets.GetAvatarSheets(),
                new GameConfigState(),
                default
                );

            var gold = new GoldCurrencyState(new Currency("NCG", 2, minter: null));

            _baseState = (State) new State()
                         .SetState(GoldCurrencyState.Address, gold.Serialize())
                         .SetState(Addresses.GoldDistribution, GoldDistributionTest.Fixture.Select(v => v.Serialize()).Serialize())
                         .MintAsset(GoldCurrencyState.Address, gold.Currency * 100000000000);
        }
示例#18
0
        public static HashSet <int> SelectOption(
            TableSheets tableSheets,
            EquipmentItemSubRecipeSheet.Row subRecipe,
            IRandom random,
            Equipment equipment
            )
        {
            var optionSheet    = tableSheets.EquipmentItemOptionSheet;
            var optionSelector = new WeightedSelector <EquipmentItemOptionSheet.Row>(random);
            var optionIds      = new HashSet <int>();

            foreach (var optionInfo in subRecipe.Options)
            {
                if (!optionSheet.TryGetValue(optionInfo.Id, out var optionRow))
                {
                    continue;
                }

                optionSelector.Add(optionRow, optionInfo.Ratio);
            }

            IEnumerable <EquipmentItemOptionSheet.Row> optionRows =
                new EquipmentItemOptionSheet.Row[0];

            try
            {
                optionRows = optionSelector.Select(subRecipe.MaxOptionLimit);
            }
            catch (Exception e) when(
                e is InvalidCountException ||
                e is ListEmptyException
                )
            {
                return(optionIds);
            }
            finally
            {
                foreach (var optionRow in optionRows)
                {
                    if (optionRow.StatType != StatType.NONE)
                    {
                        var statMap = GetStat(optionRow, random);
                        equipment.StatsMap.AddStatAdditionalValue(statMap.StatType, statMap.Value);
                    }
                    else
                    {
                        var skill = GetSkill(optionRow, tableSheets, random);
                        if (!(skill is null))
                        {
                            equipment.Skills.Add(skill);
                        }
                    }

                    optionIds.Add(optionRow.Id);
                }
            }

            return(optionIds);
        }
示例#19
0
        public static Costume CreateFirstCostume(TableSheets tableSheets, Guid guid = default)
        {
            var row = tableSheets.CostumeItemSheet.First;

            Assert.NotNull(row);

            return(new Costume(row, guid == default ? Guid.NewGuid() : guid));
        }
示例#20
0
        private BigInteger GetRequiredNCG(TableSheets tableSheets, int grade, int level)
        {
            var row = tableSheets
                      .EnhancementCostSheet.Values
                      .FirstOrDefault(x => x.Grade == grade && x.Level == level);

            return(row is null ? 0 : row.Cost);
        }
示例#21
0
        public AvatarState(Address address,
                           Address agentAddress,
                           long blockIndex,
                           TableSheets sheets,
                           GameConfigState gameConfigState,
                           string name = null) : base(address)
        {
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            this.name         = name ?? string.Empty;
            characterId       = GameConfig.DefaultAvatarCharacterId;
            level             = 1;
            exp               = 0;
            inventory         = new Inventory();
            worldInformation  = new WorldInformation(blockIndex, sheets.WorldSheet, GameConfig.IsEditor);
            updatedAt         = DateTimeOffset.UtcNow;
            this.agentAddress = agentAddress;
            questList         = new QuestList(
                sheets.QuestSheet,
                sheets.QuestRewardSheet,
                sheets.QuestItemRewardSheet,
                sheets.EquipmentItemRecipeSheet,
                sheets.EquipmentItemSubRecipeSheet
                );
            mailBox         = new MailBox();
            this.blockIndex = blockIndex;
            actionPoint     = gameConfigState.ActionPointMax;
            stageMap        = new CollectionMap();
            monsterMap      = new CollectionMap();
            itemMap         = new CollectionMap();
            const QuestEventType createEvent = QuestEventType.Create;
            const QuestEventType levelEvent  = QuestEventType.Level;

            eventMap = new CollectionMap
            {
                new KeyValuePair <int, int>((int)createEvent, 1),
                new KeyValuePair <int, int>((int)levelEvent, level),
            };
            combinationSlotAddresses = new List <Address>(CombinationSlotCapacity);
            for (var i = 0; i < CombinationSlotCapacity; i++)
            {
                var slotAddress = address.Derive(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        CombinationSlotState.DeriveFormat,
                        i
                        )
                    );
                combinationSlotAddresses.Add(slotAddress);
            }
            UpdateGeneralQuest(new[] { createEvent, levelEvent });
            UpdateCompletedQuest();

            PostConstructor();
        }
示例#22
0
        public SellCancellation2Test(ITestOutputHelper outputHelper)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Verbose()
                         .WriteTo.TestOutput(outputHelper)
                         .CreateLogger();

            _initialState = new State();
            var sheets = TableSheetsImporter.ImportSheets();

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

            var tableSheets = new TableSheets(sheets);

            var currency          = new Currency("NCG", 2, minters: null);
            var goldCurrencyState = new GoldCurrencyState(currency);

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

            _avatarAddress = new PrivateKey().ToAddress();
            var rankingMapAddress = 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 equipment = ItemFactory.CreateItemUsable(
                tableSheets.EquipmentItemSheet.First,
                Guid.NewGuid(),
                0);
            var shopState = new ShopState();

            shopState.Register(new ShopItem(
                                   _agentAddress,
                                   _avatarAddress,
                                   Guid.NewGuid(),
                                   new FungibleAssetValue(goldCurrencyState.Currency, 100, 0),
                                   equipment));

            var result = new CombinationConsumable.ResultModel()
            {
                id          = default,
示例#23
0
        public Sell0Test(ITestOutputHelper outputHelper)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Verbose()
                         .WriteTo.TestOutput(outputHelper)
                         .CreateLogger();

            _initialState = new State();
            var sheets = TableSheetsImporter.ImportSheets();

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

            _tableSheets = new TableSheets(sheets);

            _currency = new Currency("NCG", 2, minters: null);
            var goldCurrencyState = new GoldCurrencyState(_currency);

            var shopState = new ShopState();

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

            _avatarAddress = new PrivateKey().ToAddress();
            var rankingMapAddress = new PrivateKey().ToAddress();

            _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 equipment = ItemFactory.CreateItemUsable(
                _tableSheets.EquipmentItemSheet.First,
                Guid.NewGuid(),
                0);

            _avatarState.inventory.AddItem2(equipment);

            _initialState = _initialState
                            .SetState(GoldCurrencyState.Address, goldCurrencyState.Serialize())
                            .SetState(Addresses.Shop, shopState.Serialize())
                            .SetState(_agentAddress, agentState.Serialize())
                            .SetState(_avatarAddress, _avatarState.Serialize());
        }
示例#24
0
        public ItemNotificationTest()
        {
            var sheets = TableSheetsImporter.ImportSheets();

            var privateKey = new PrivateKey();

            _agentAddress = privateKey.PublicKey.ToAddress();
            _tableSheets  = new TableSheets(sheets);
        }
示例#25
0
        public HackAndSlash10Test()
        {
            _sheets      = TableSheetsImporter.ImportSheets();
            _tableSheets = new TableSheets(_sheets);

            var privateKey = new PrivateKey();

            _agentAddress = privateKey.PublicKey.ToAddress();
            var agentState = new AgentState(_agentAddress);

            _avatarAddress = _agentAddress.Derive("avatar");
            var gameConfigState = new GameConfigState(_sheets[nameof(GameConfigSheet)]);

            _rankingMapAddress = _avatarAddress.Derive("ranking_map");
            _avatarState       = new AvatarState(
                _avatarAddress,
                _agentAddress,
                0,
                _tableSheets.GetAvatarSheets(),
                gameConfigState,
                _rankingMapAddress
                )
            {
                level = 100,
            };
            _inventoryAddress        = _avatarAddress.Derive(LegacyInventoryKey);
            _worldInformationAddress = _avatarAddress.Derive(LegacyWorldInformationKey);
            _questListAddress        = _avatarAddress.Derive(LegacyQuestListKey);
            agentState.avatarAddresses.Add(0, _avatarAddress);

            _weeklyArenaState = new WeeklyArenaState(0);

            _initialState = new State()
                            .SetState(_weeklyArenaState.address, _weeklyArenaState.Serialize())
                            .SetState(_agentAddress, agentState.SerializeV2())
                            .SetState(_avatarAddress, _avatarState.SerializeV2())
                            .SetState(_inventoryAddress, _avatarState.inventory.Serialize())
                            .SetState(_worldInformationAddress, _avatarState.worldInformation.Serialize())
                            .SetState(_questListAddress, _avatarState.questList.Serialize())
                            .SetState(_rankingMapAddress, new RankingMapState(_rankingMapAddress).Serialize())
                            .SetState(gameConfigState.address, gameConfigState.Serialize());

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

            foreach (var address in _avatarState.combinationSlotAddresses)
            {
                var slotState = new CombinationSlotState(
                    address,
                    GameConfig.RequireClearedStageLevel.CombinationEquipmentAction);
                _initialState = _initialState.SetState(address, slotState.Serialize());
            }
        }
示例#26
0
 public FungibleOrderTest()
 {
     _tableSheets = new TableSheets(TableSheetsImporter.ImportSheets());
     _currency    = new Currency("NCG", 2, minter: null);
     _avatarState = new AvatarState(
         Addresses.Blacksmith,
         Addresses.Admin,
         0,
         _tableSheets.GetAvatarSheets(),
         new GameConfigState(),
        public CombinationEquipment6Test(ITestOutputHelper outputHelper)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Verbose()
                         .WriteTo.TestOutput(outputHelper)
                         .CreateLogger();

            _agentAddress  = default;
            _avatarAddress = _agentAddress.Derive("avatar");
            var slotAddress = _avatarAddress.Derive(
                string.Format(
                    CultureInfo.InvariantCulture,
                    CombinationSlotState.DeriveFormat,
                    0
                    )
                );
            var sheets = TableSheetsImporter.ImportSheets();

            _random      = new TestRandom();
            _tableSheets = new TableSheets(sheets);
            var agentState = new AgentState(_agentAddress);

            agentState.avatarAddresses[0] = _avatarAddress;

            var gameConfigState = new GameConfigState();

            _avatarState = new AvatarState(
                _avatarAddress,
                _agentAddress,
                1,
                _tableSheets.GetAvatarSheets(),
                gameConfigState,
                default
                );
            var gold = new GoldCurrencyState(new Currency("NCG", 2, minter: null));

            _initialState = new State()
                            .SetState(_agentAddress, agentState.Serialize())
                            .SetState(_avatarAddress, _avatarState.Serialize())
                            .SetState(
                slotAddress,
                new CombinationSlotState(
                    slotAddress,
                    GameConfig.RequireClearedStageLevel.CombinationEquipmentAction
                    ).Serialize())
                            .SetState(GoldCurrencyState.Address, gold.Serialize())
                            .MintAsset(_agentAddress, gold.Currency * 300);

            foreach (var(key, value) in sheets)
            {
                _initialState =
                    _initialState.SetState(Addresses.TableSheet.Derive(key), value.Serialize());
            }
        }
示例#28
0
        public static Equipment CreateFirstEquipment(
            TableSheets tableSheets,
            Guid guid = default,
            long requiredBlockIndex = default)
        {
            var row = tableSheets.EquipmentItemSheet.First;

            Assert.NotNull(row);

            return(new Equipment(row, guid == default ? Guid.NewGuid() : guid, requiredBlockIndex));
        }
示例#29
0
 public void SetUp()
 {
     _tableSheets = TableSheetsHelper.MakeTableSheets();
     _avatarState = new AvatarState(
         new PrivateKey().ToAddress(),
         new PrivateKey().ToAddress(),
         0,
         _tableSheets.GetAvatarSheets(),
         new GameConfigState(),
         new PrivateKey().ToAddress());
 }
示例#30
0
        public override IAccountStateDelta Execute(IActionContext context)
        {
            var states = context.PreviousStates;

            if (context.Rehearsal)
            {
                states = states.SetState(RedeemCodeState.Address, MarkChanged);
                states = states.SetState(avatarAddress, MarkChanged);
                states = states.SetState(context.Signer, MarkChanged);
                return(states);
            }

            if (!states.TryGetAgentAvatarStates(context.Signer, avatarAddress, out AgentState agentState,
                                                out AvatarState avatarState))
            {
                return(states);
            }

            var redeemState = states.GetRedeemCodeState();

            if (redeemState is null)
            {
                return(states);
            }

            int redeemId;

            try
            {
                redeemId = redeemState.Redeem(code, avatarAddress);
            }
            catch (InvalidRedeemCodeException)
            {
                Log.Error("Invalid Code");
                throw;
            }
            catch (DuplicateRedeemException e)
            {
                Log.Warning(e.Message);
                throw;
            }

            var tableSheets = TableSheets.FromActionContext(context);
            var row         = tableSheets.RedeemRewardSheet.Values.First(r => r.Id == redeemId);
            var rewards     = row.Rewards;
            var materialRow = tableSheets.MaterialItemSheet.Values.First(r => r.ItemSubType == ItemSubType.Chest);
            var chest       = ItemFactory.CreateChest(materialRow, rewards);

            avatarState.inventory.AddItem(chest, 1);
            states = states.SetState(avatarAddress, avatarState.Serialize());
            states = states.SetState(RedeemCodeState.Address, redeemState.Serialize());
            states = states.SetState(context.Signer, agentState.Serialize());
            return(states);
        }