Esempio n. 1
0
        public void Execute(int avatarLevel, int worldId, int stageId, int playCount, bool backward, bool isLock, bool isClearedBefore)
        {
            Assert.True(_tableSheets.WorldSheet.TryGetValue(worldId, out var worldRow));
            Assert.True(stageId >= worldRow.StageBegin);
            Assert.True(stageId <= worldRow.StageEnd);
            Assert.True(_tableSheets.StageSheet.TryGetValue(stageId, out _));

            var previousAvatarState = _initialState.GetAvatarStateV2(_avatarAddress);

            previousAvatarState.level = avatarLevel;
            var clearedStageId = _tableSheets.StageSheet.First?.Id ?? 0;

            clearedStageId = isClearedBefore ? Math.Max(clearedStageId, stageId - 1) : stageId - 1;
            clearedStageId = playCount > 1 ? clearedStageId + 1 : clearedStageId;
            previousAvatarState.worldInformation = new WorldInformation(
                0,
                _tableSheets.WorldSheet,
                clearedStageId);

            List <Guid> costumes = new List <Guid>();
            IRandom     random   = new TestRandom();

            if (avatarLevel >= GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot)
            {
                var costumeId = _tableSheets
                                .CostumeItemSheet
                                .Values
                                .First(r => r.ItemSubType == ItemSubType.FullCostume)
                                .Id;

                var costume = (Costume)ItemFactory.CreateItem(
                    _tableSheets.ItemSheet[costumeId], random);
                previousAvatarState.inventory.AddItem(costume);
                costumes.Add(costume.ItemId);
            }

            List <Guid> equipments = new List <Guid>();

            if (avatarLevel >= GameConfig.RequireCharacterLevel.CharacterEquipmentSlotWeapon)
            {
                var weaponId = _tableSheets
                               .EquipmentItemSheet
                               .Values
                               .Where(r => r.ItemSubType == ItemSubType.Weapon)
                               .OrderBy(r => r.Stat.ValueAsInt)
                               .Last()
                               .Id;

                var weapon = ItemFactory.CreateItem(
                    _tableSheets.EquipmentItemSheet[weaponId],
                    random)
                             as Equipment;
                equipments.Add(weapon.ItemId);
                OrderLock?orderLock = null;
                if (isLock)
                {
                    orderLock = new OrderLock(Guid.NewGuid());
                }

                previousAvatarState.inventory.AddItem(weapon, iLock: orderLock);
            }

            if (avatarLevel >= GameConfig.RequireCharacterLevel.CharacterEquipmentSlotArmor)
            {
                var armorId = _tableSheets
                              .EquipmentItemSheet
                              .Values
                              .Where(r => r.ItemSubType == ItemSubType.Armor)
                              .OrderBy(r => r.Stat.ValueAsInt)
                              .Last()
                              .Id;

                var armor = ItemFactory.CreateItem(
                    _tableSheets.EquipmentItemSheet[armorId],
                    random)
                            as Equipment;
                equipments.Add(armor.ItemId);
                previousAvatarState.inventory.AddItem(armor);
            }

            var mailEquipmentRow = _tableSheets.EquipmentItemSheet.Values.First();
            var mailEquipment    = ItemFactory.CreateItemUsable(mailEquipmentRow, default, 0);
Esempio n. 2
0
        public void Execute(int avatarLevel, int worldId, int stageId, bool contains, bool backward)
        {
            Assert.True(_tableSheets.WorldSheet.TryGetValue(worldId, out var worldRow));
            Assert.True(stageId >= worldRow.StageBegin);
            Assert.True(stageId <= worldRow.StageEnd);
            Assert.True(_tableSheets.StageSheet.TryGetValue(stageId, out _));

            var previousAvatarState = _initialState.GetAvatarState(_avatarAddress);

            previousAvatarState.level            = avatarLevel;
            previousAvatarState.worldInformation = new WorldInformation(
                0,
                _tableSheets.WorldSheet,
                Math.Max(_tableSheets.StageSheet.First?.Id ?? 1, stageId - 1));

            List <Guid> costumes = new List <Guid>();
            IRandom     random   = new TestRandom();

            if (avatarLevel >= GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot)
            {
                var costumeId = _tableSheets
                                .CostumeItemSheet
                                .Values
                                .First(r => r.ItemSubType == ItemSubType.FullCostume)
                                .Id;

                var costume = (Costume)ItemFactory.CreateItem(
                    _tableSheets.ItemSheet[costumeId], random);
                previousAvatarState.inventory.AddItem2(costume);
                costumes.Add(costume.ItemId);
            }

            List <Guid> equipments = new List <Guid>();

            if (avatarLevel >= GameConfig.RequireCharacterLevel.CharacterEquipmentSlotWeapon)
            {
                var weaponId = _tableSheets
                               .EquipmentItemSheet
                               .Values
                               .Where(r => r.ItemSubType == ItemSubType.Weapon)
                               .OrderBy(r => r.Stat.ValueAsInt)
                               .Last()
                               .Id;

                var weapon = ItemFactory.CreateItem(
                    _tableSheets.EquipmentItemSheet[weaponId],
                    random)
                             as Equipment;
                equipments.Add(weapon.ItemId);
                previousAvatarState.inventory.AddItem2(weapon);
            }

            if (avatarLevel >= GameConfig.RequireCharacterLevel.CharacterEquipmentSlotArmor)
            {
                var armorId = _tableSheets
                              .EquipmentItemSheet
                              .Values
                              .Where(r => r.ItemSubType == ItemSubType.Armor)
                              .OrderBy(r => r.Stat.ValueAsInt)
                              .Last()
                              .Id;

                var armor = ItemFactory.CreateItem(
                    _tableSheets.EquipmentItemSheet[armorId],
                    random)
                            as Equipment;
                equipments.Add(armor.ItemId);
                previousAvatarState.inventory.AddItem2(armor);
            }

            var mailEquipmentRow = _tableSheets.EquipmentItemSheet.Values.First();
            var mailEquipment    = ItemFactory.CreateItemUsable(mailEquipmentRow, default, 0);
Esempio n. 3
0
        public void Execute()
        {
            var shopState = _initialState.GetShopState();

            Assert.Empty(shopState.Products);

            var avatarState = _initialState.GetAvatarState(_avatarAddress);

            Assert.Single(avatarState.inventory.Equipments);

            var equipment = avatarState.inventory.Equipments.FirstOrDefault();

            Assert.NotNull(equipment);

            var consumable = avatarState.inventory.Consumables.FirstOrDefault();

            Assert.NotNull(equipment);

            var costume = avatarState.inventory.Costumes.FirstOrDefault();

            Assert.NotNull(costume);

            var items = new INonFungibleItem[] { equipment, consumable, costume };

            var previousStates = _initialState;
            var currencyState  = previousStates.GetGoldCurrency();
            var price          = new FungibleAssetValue(currencyState, ProductPrice, 0);

            var productCount = 0;
            var random       = new TestRandom();

            foreach (var nonFungibleItem in items)
            {
                var sellAction = new Sell3
                {
                    itemId = nonFungibleItem.ItemId,
                    price  = price,
                    sellerAvatarAddress = _avatarAddress,
                };

                var nextState = sellAction.Execute(new ActionContext
                {
                    BlockIndex     = 0,
                    PreviousStates = previousStates,
                    Rehearsal      = false,
                    Signer         = _agentAddress,
                    Random         = random,
                });

                productCount++;

                var nextAvatarState = nextState.GetAvatarState(_avatarAddress);
                Assert.Empty(nextAvatarState.inventory.Equipments);

                var nextShopState = nextState.GetShopState();

                Assert.Equal(productCount, nextShopState.Products.Count);

                var products = nextShopState.Products.Values;
                Assert.NotNull(products);

                var shopItem = nonFungibleItem is Costume?
                               products.First(x => x.Costume != null) :
                                   products.First(x => x.ItemUsable != null);

                Assert.Equal(price, shopItem.Price);
                Assert.Equal(_agentAddress, shopItem.SellerAgentAddress);
                Assert.Equal(_avatarAddress, shopItem.SellerAvatarAddress);

                previousStates = nextState;
            }
        }
Esempio n. 4
0
        public void Execute(bool isAdmin, bool expire, Type exc)
        {
            var adminAddress = new Address("399bddF9F7B6d902ea27037B907B2486C9910730");
            var adminState = new AdminState(adminAddress, 100);
            var states = new State().SetState(Addresses.Admin, adminState.Serialize());
            var signer = isAdmin ? adminAddress : default;
            var blockIndex = expire ? 200 : 100;

            var action = new MigrationLegacyShop();

            var avatarAddress = new Address(action.AvatarAddressesHex.First());

            if (exc is null)
            {
                var agentState = new AgentState(adminAddress);
                var avatarState = new AvatarState(
                    avatarAddress,
                    adminAddress,
                    0,
                    _tableSheets.GetAvatarSheets(),
                    new GameConfigState(),
                    default);
                agentState.avatarAddresses[0] = avatarAddress;

                var shopState = new ShopState();
                var itemSubTypes = new[] { ItemSubType.Weapon, ItemSubType.FullCostume };
                var random = new TestRandom();
                var itemIds = new List<Guid>();
                foreach (var itemSubType in itemSubTypes)
                {
                    var item = (ITradableItem)ItemFactory.CreateItem(_tableSheets.ItemSheet.Values.First(r => r.ItemSubType == itemSubType), random);
                    var shopItem = new ShopItem(
                        adminAddress,
                        avatarAddress,
                        Guid.NewGuid(),
                        new FungibleAssetValue(new Currency("NCG", 2, minter: null), 100, 0),
                        item);
                    shopState.Register(shopItem);
                    itemIds.Add(item.TradableId);
                }

                states = states
                    .SetState(Addresses.Shop, shopState.Serialize())
                    .SetState(adminAddress, agentState.Serialize())
                    .SetState(avatarAddress, avatarState.Serialize());

                var nextState = action.Execute(new ActionContext
                {
                    BlockIndex = blockIndex,
                    PreviousStates = states,
                    Signer = signer,
                });

                var nextShopState = nextState.GetShopState();
                Assert.Empty(nextShopState.Products);
                var nextAvatarState = nextState.GetAvatarState(avatarAddress);
                Assert.All(itemIds, id => nextAvatarState.inventory.HasNonFungibleItem(id));
            }
            else
            {
                Assert.Throws(exc, () => action.Execute(new ActionContext
                {
                    BlockIndex = blockIndex,
                    PreviousStates = states,
                    Signer = signer,
                }));
            }
        }