public void Execute(int avatarStateSerializedVersion) { IAccountStateDelta previousStates = null; switch (avatarStateSerializedVersion) { case 1: previousStates = _initialState; break; case 2: var avatarState = _initialState.GetAvatarState(_avatarAddress); previousStates = SetAvatarStateAsV2To(_initialState, avatarState); break; } var nextState = ExecuteInternal(previousStates, 1800); var nextGameConfigState = nextState.GetGameConfigState(); var nextAvatarState = avatarStateSerializedVersion switch { 1 => nextState.GetAvatarState(_avatarAddress), 2 => nextState.GetAvatarStateV2(_avatarAddress), _ => null }; if (nextAvatarState is null) { return; } Assert.Equal(nextGameConfigState.ActionPointMax, nextAvatarState.actionPoint); }
public void Execute(int avatarStateSerializedVersion) { IAccountStateDelta previousStates = null; switch (avatarStateSerializedVersion) { case 1: previousStates = _initialState; break; case 2: var avatarState = _initialState.GetAvatarState(_avatarAddress); previousStates = SetAvatarStateAsV2To(_initialState, avatarState); break; } var nextState = ExecuteInternal(previousStates, 1800); var nextGameConfigState = nextState.GetGameConfigState(); var nextAvatarState = nextState.GetAvatarStateV2(_avatarAddress); Assert.NotNull(nextAvatarState); Assert.NotNull(nextAvatarState.inventory); Assert.NotNull(nextAvatarState.questList); Assert.NotNull(nextAvatarState.worldInformation); Assert.Equal(nextGameConfigState.ActionPointMax, nextAvatarState.actionPoint); }
public void Execute(ItemType itemType, string guid, long requiredBlockIndex, bool contain) { var sellerAvatarState = _initialState.GetAvatarState(_sellerAvatarAddress); var buyerAvatarState = _initialState.GetAvatarState(_buyerAvatarAddress); INonFungibleItem nonFungibleItem; Guid itemId = new Guid(guid); if (itemType == ItemType.Equipment) { var itemUsable = ItemFactory.CreateItemUsable( _tableSheets.EquipmentItemSheet.First, itemId, requiredBlockIndex); nonFungibleItem = itemUsable; } else { var costume = ItemFactory.CreateCostume(_tableSheets.CostumeItemSheet.First, itemId); costume.Update(requiredBlockIndex); nonFungibleItem = costume; } // Case for backward compatibility. if (contain) { sellerAvatarState.inventory.AddItem((ItemBase)nonFungibleItem); } var result = new DailyReward.DailyRewardResult() { id = default,
public void Execute(bool useTradable, bool backward) { var avatarState = _initialState.GetAvatarState(_avatarAddress); var row = _tableSheets.MaterialItemSheet.Values.First(r => r.ItemSubType == ItemSubType.ApStone); if (useTradable) { var apStone = ItemFactory.CreateTradableMaterial(row); avatarState.inventory.AddItem(apStone); } else { var apStone = ItemFactory.CreateItem(row, new TestRandom()); avatarState.inventory.AddItem(apStone); } Assert.Equal(0, avatarState.actionPoint); IAccountStateDelta state; if (backward) { state = _initialState.SetState(_avatarAddress, avatarState.Serialize()); } else { state = _initialState .SetState(_avatarAddress.Derive(LegacyInventoryKey), avatarState.inventory.Serialize()) .SetState(_avatarAddress.Derive(LegacyWorldInformationKey), avatarState.worldInformation.Serialize()) .SetState(_avatarAddress.Derive(LegacyQuestListKey), avatarState.questList.Serialize()) .SetState(_avatarAddress, avatarState.SerializeV2()); } foreach (var(key, value) in _sheets) { state = state.SetState(Addresses.TableSheet.Derive(key), value.Serialize()); } var action = new ChargeActionPoint() { avatarAddress = _avatarAddress, }; var nextState = action.Execute(new ActionContext() { PreviousStates = state, Signer = _agentAddress, Random = new TestRandom(), Rehearsal = false, }); var nextAvatarState = nextState.GetAvatarStateV2(_avatarAddress); var gameConfigState = nextState.GetGameConfigState(); Assert.Equal(gameConfigState.ActionPointMax, nextAvatarState.actionPoint); }
public void Execute(bool backward) { var avatarState = _initialState.GetAvatarState(_avatarAddress); var row = _tableSheets.ConsumableItemRecipeSheet.Values.First(); foreach (var materialInfo in row.Materials) { var materialRow = _tableSheets.MaterialItemSheet[materialInfo.Id]; var material = ItemFactory.CreateItem(materialRow, _random); avatarState.inventory.AddItem(material, count: materialInfo.Count); } const int requiredStage = GameConfig.RequireClearedStageLevel.CombinationConsumableAction; for (var i = 1; i < requiredStage + 1; i++) { avatarState.worldInformation.ClearStage( 1, i, 0, _tableSheets.WorldSheet, _tableSheets.WorldUnlockSheet ); } var equipment = ItemFactory.CreateItemUsable(_tableSheets.EquipmentItemSheet.First, default, 0);
public static bool TryGetAgentAvatarStatesV2( this IAccountStateDelta states, Address agentAddress, Address avatarAddress, out AgentState agentState, out AvatarState avatarState ) { avatarState = null; agentState = states.GetAgentState(agentAddress); if (agentState is null) { return(false); } if (!agentState.avatarAddresses.ContainsValue(avatarAddress)) { throw new AgentStateNotContainsAvatarAddressException( $"The avatar {avatarAddress.ToHex()} does not belong to the agent {agentAddress.ToHex()}."); } try { avatarState = states.GetAvatarStateV2(avatarAddress); } catch (FailedLoadStateException) { // BackWardCompatible. avatarState = states.GetAvatarState(avatarAddress); } return(!(avatarState is null)); }
public void Execute(ItemType itemType, string guid, bool contain) { var avatarState = _initialState.GetAvatarState(_avatarAddress); INonFungibleItem nonFungibleItem; Guid itemId = new Guid(guid); Guid productId = itemId; ItemSubType itemSubType; const long requiredBlockIndex = 0; ShopState legacyShopState = _initialState.GetShopState(); if (itemType == ItemType.Equipment) { var itemUsable = ItemFactory.CreateItemUsable( _tableSheets.EquipmentItemSheet.First, itemId, requiredBlockIndex); nonFungibleItem = itemUsable; itemSubType = itemUsable.ItemSubType; } else { var costume = ItemFactory.CreateCostume(_tableSheets.CostumeItemSheet.First, itemId); costume.Update(requiredBlockIndex); nonFungibleItem = costume; itemSubType = costume.ItemSubType; } var result = new DailyReward2.DailyRewardResult() { id = default,
public void Execute(int avatarLevel, int worldId, int stageId, int clearStageId) { 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, clearStageId); var costumeId = _tableSheets .CostumeItemSheet .Values .First(r => r.ItemSubType == ItemSubType.FullCostume) .Id; var costume = ItemFactory.CreateItem(_tableSheets.ItemSheet[costumeId], new TestRandom()); previousAvatarState.inventory.AddItem(costume); var mimisbrunnrSheet = _tableSheets.MimisbrunnrSheet; if (!mimisbrunnrSheet.TryGetValue(stageId, out var mimisbrunnrSheetRow)) { throw new SheetRowNotFoundException("MimisbrunnrSheet", stageId); } var equipmentRow = _tableSheets.EquipmentItemSheet.Values.First(x => x.ElementalType == ElementalType.Fire); var equipment = ItemFactory.CreateItemUsable(equipmentRow, default, 0);
public void Execute(int avatarLevel, int worldId, int stageId, bool contains) { 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)); var costumeId = _tableSheets .CostumeItemSheet .Values .First(r => r.ItemSubType == ItemSubType.FullCostume) .Id; var costume = ItemFactory.CreateItem(_tableSheets.ItemSheet[costumeId], new TestRandom()); previousAvatarState.inventory.AddItem(costume); var equipmentRow = _tableSheets.EquipmentItemSheet.Values.First(); var equipment = ItemFactory.CreateItemUsable(equipmentRow, default, 0);
public static bool TryGetAgentAvatarStates( this IAccountStateDelta states, Address agentAddress, Address avatarAddress, out AgentState agentState, out AvatarState avatarState ) { avatarState = null; agentState = states.GetAgentState(agentAddress); if (agentState is null) { return(false); } if (!agentState.avatarAddresses.ContainsValue(avatarAddress)) { Log.Error( "The avatar {0} does not belong to the agent {1}.", avatarAddress.ToHex(), agentAddress.ToHex() ); return(false); } avatarState = states.GetAvatarState(avatarAddress); return(!(avatarState is null)); }
public void Execute() { var previousWeeklyState = _initialState.GetWeeklyArenaState(0); var previousAvatar1State = _initialState.GetAvatarState(_avatar1Address); previousAvatar1State.level = 10; var previousState = _initialState.SetState( _avatar1Address, previousAvatar1State.Serialize()); var itemIds = _tableSheets.WeeklyArenaRewardSheet.Values .Select(r => r.Reward.ItemId) .ToList(); Assert.All(itemIds, id => Assert.False(previousAvatar1State.inventory.HasItem(id))); var action = new RankingBattle4 { AvatarAddress = _avatar1Address, EnemyAddress = _avatar2Address, WeeklyArenaAddress = _weeklyArenaAddress, costumeIds = new List <int>(), equipmentIds = new List <Guid>(), consumableIds = new List <Guid>(), }; Assert.Null(action.Result); var nextState = action.Execute(new ActionContext() { PreviousStates = previousState, Signer = _agent1Address, Random = new TestRandom(), Rehearsal = false, }); var nextAvatar1State = nextState.GetAvatarState(_avatar1Address); var nextWeeklyState = nextState.GetWeeklyArenaState(0); Assert.Contains(nextAvatar1State.inventory.Materials, i => itemIds.Contains(i.Id)); Assert.NotNull(action.Result); Assert.Contains(typeof(GetReward), action.Result.Select(e => e.GetType())); Assert.Equal(BattleLog.Result.Win, action.Result.result); Assert.True(nextWeeklyState[_avatar1Address].Score > previousWeeklyState[_avatar1Address].Score); }
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 currencyState = _initialState.GetGoldCurrency(); var price = new FungibleAssetValue(currencyState, 100, 0); var sellAction = new Sell0 { itemId = equipment.ItemId, price = price, sellerAvatarAddress = _avatarAddress, }; var nextState = sellAction.Execute(new ActionContext { BlockIndex = 0, PreviousStates = _initialState, Rehearsal = false, Signer = _agentAddress, Random = new TestRandom(), }); var nextAvatarState = nextState.GetAvatarState(_avatarAddress); Assert.Empty(nextAvatarState.inventory.Equipments); var nextShopState = nextState.GetShopState(); Assert.Single(nextShopState.Products); var(_, shopItem) = nextShopState.Products.FirstOrDefault(); Assert.NotNull(shopItem); Assert.Equal(equipment.ItemId, shopItem.ItemUsable.ItemId); Assert.Equal(price, shopItem.Price); Assert.Equal(_agentAddress, shopItem.SellerAgentAddress); Assert.Equal(_avatarAddress, shopItem.SellerAvatarAddress); }
public void Execute(params ShopItemData[] shopItemMembers) { AvatarState buyerAvatarState = _initialState.GetAvatarState(_buyerAvatarAddress); List <PurchaseInfo0> purchaseInfos = new List <PurchaseInfo0>(); Dictionary <Address, ShardedShopState> shardedShopStates = new Dictionary <Address, ShardedShopState>(); ShopState legacyShopState = _initialState.GetShopState(); foreach (var shopItemData in shopItemMembers) { (AvatarState sellerAvatarState, AgentState sellerAgentState) = CreateAvatarState( shopItemData.SellerAgentAddress, shopItemData.SellerAvatarAddress ); ITradableItem tradableItem; Guid productId = shopItemData.ProductId; Guid itemId = shopItemData.ItemId; long requiredBlockIndex = shopItemData.RequiredBlockIndex; ItemSubType itemSubType; if (shopItemData.ItemType == ItemType.Equipment) { var itemUsable = ItemFactory.CreateItemUsable( _tableSheets.EquipmentItemSheet.First, itemId, requiredBlockIndex); tradableItem = itemUsable; itemSubType = itemUsable.ItemSubType; } else if (shopItemData.ItemType == ItemType.Costume) { var costume = ItemFactory.CreateCostume(_tableSheets.CostumeItemSheet.First, itemId); costume.Update(requiredBlockIndex); tradableItem = costume; itemSubType = costume.ItemSubType; } else { var material = ItemFactory.CreateTradableMaterial( _tableSheets.MaterialItemSheet.OrderedList.First(r => r.ItemSubType == ItemSubType.Hourglass)); material.RequiredBlockIndex = requiredBlockIndex; tradableItem = material; itemSubType = ItemSubType.Hourglass; } var result = new DailyReward2.DailyRewardResult() { id = default,
public void Execute(bool backward) { var dailyRewardAction = new DailyReward4 { avatarAddress = _avatarAddress, }; if (!backward) { AvatarState avatarState = _initialState.GetAvatarState(_avatarAddress); _initialState = _initialState .SetState(_avatarAddress.Derive(LegacyInventoryKey), avatarState.inventory.Serialize()) .SetState(_avatarAddress.Derive(LegacyWorldInformationKey), avatarState.worldInformation.Serialize()) .SetState(_avatarAddress.Derive(LegacyQuestListKey), avatarState.questList.Serialize()) .SetState(_avatarAddress, avatarState.SerializeV2()); } var nextState = dailyRewardAction.Execute(new ActionContext { BlockIndex = 0, PreviousStates = _initialState, Random = new TestRandom(), Rehearsal = false, Signer = _agentAddress, }); var gameConfigState = nextState.GetGameConfigState(); var nextAvatarState = nextState.GetAvatarStateV2(_avatarAddress); Assert.Equal(gameConfigState.ActionPointMax, nextAvatarState.actionPoint); Assert.Single(nextAvatarState.mailBox); var mail = nextAvatarState.mailBox.First(); var rewardMail = mail as DailyRewardMail; Assert.NotNull(rewardMail); var rewardResult = rewardMail.attachment as DailyReward2.DailyRewardResult; Assert.NotNull(rewardResult); Assert.Single(rewardResult.materials); var material = rewardResult.materials.First(); Assert.Equal(400000, material.Key.Id); Assert.Equal(10, material.Value); }
public void Execute( ItemType itemType, string guid, int itemCount, int inventoryCount, int expectedCount, bool backward ) { var avatarState = _initialState.GetAvatarState(_avatarAddress); ITradableItem tradableItem; Guid itemId = new Guid(guid); Guid orderId = Guid.NewGuid(); ItemSubType itemSubType; const long requiredBlockIndex = Order.ExpirationInterval; if (itemType == ItemType.Equipment) { var itemUsable = ItemFactory.CreateItemUsable( _tableSheets.EquipmentItemSheet.First, itemId, requiredBlockIndex); tradableItem = itemUsable; itemSubType = itemUsable.ItemSubType; } else if (itemType == ItemType.Costume) { var costume = ItemFactory.CreateCostume(_tableSheets.CostumeItemSheet.First, itemId); costume.Update(requiredBlockIndex); tradableItem = costume; itemSubType = costume.ItemSubType; } else { var material = ItemFactory.CreateTradableMaterial( _tableSheets.MaterialItemSheet.OrderedList.First(r => r.ItemSubType == ItemSubType.Hourglass)); itemSubType = material.ItemSubType; material.RequiredBlockIndex = requiredBlockIndex; tradableItem = material; } var result = new DailyReward2.DailyRewardResult() { id = default,
public void Execute(params OrderData[] orderDataList) { AvatarState buyerAvatarState = _initialState.GetAvatarState(_buyerAvatarAddress); List <PurchaseInfo> purchaseInfos = new List <PurchaseInfo>(); ShopState legacyShopState = _initialState.GetShopState(); foreach (var orderData in orderDataList) { (AvatarState sellerAvatarState, AgentState sellerAgentState) = CreateAvatarState( orderData.SellerAgentAddress, orderData.SellerAvatarAddress ); ITradableItem tradableItem; Guid orderId = orderData.OrderId; Guid itemId = orderData.TradableId; ItemSubType itemSubType; if (orderData.ItemType == ItemType.Equipment) { var itemUsable = ItemFactory.CreateItemUsable( _tableSheets.EquipmentItemSheet.First, itemId, 0); tradableItem = itemUsable; itemSubType = itemUsable.ItemSubType; } else if (orderData.ItemType == ItemType.Costume) { var costume = ItemFactory.CreateCostume(_tableSheets.CostumeItemSheet.First, itemId); tradableItem = costume; itemSubType = costume.ItemSubType; } else { var material = ItemFactory.CreateTradableMaterial( _tableSheets.MaterialItemSheet.OrderedList.First(r => r.ItemSubType == ItemSubType.Hourglass)); tradableItem = material; itemSubType = ItemSubType.Hourglass; } var result = new DailyReward2.DailyRewardResult() { id = default,
public void Execute(bool backward) { const int slotStateUnlockStage = 1; var avatarState = _initialState.GetAvatarState(_avatarAddress); avatarState.worldInformation = new WorldInformation( 0, _initialState.GetSheet <WorldSheet>(), slotStateUnlockStage); var row = _tableSheets.MaterialItemSheet.Values.First(r => r.ItemSubType == ItemSubType.Hourglass); avatarState.inventory.AddItem(ItemFactory.CreateMaterial(row), 83); avatarState.inventory.AddItem(ItemFactory.CreateTradableMaterial(row), 100); Assert.True(avatarState.inventory.HasFungibleItem(row.ItemId, 0, 183)); var firstEquipmentRow = _tableSheets.EquipmentItemSheet.First; Assert.NotNull(firstEquipmentRow); var gameConfigState = _initialState.GetGameConfigState(); var requiredBlockIndex = gameConfigState.HourglassPerBlock * 200; var equipment = (Equipment)ItemFactory.CreateItemUsable( firstEquipmentRow, Guid.NewGuid(), requiredBlockIndex); avatarState.inventory.AddItem(equipment); var result = new CombinationConsumable5.ResultModel { actionPoint = 0, gold = 0, materials = new Dictionary <Material, int>(), itemUsable = equipment, recipeId = 0, itemType = ItemType.Equipment, }; var mail = new CombinationMail(result, 0, default, requiredBlockIndex);
public void Execute() { var shopState = _initialState.GetShopState(); Assert.Single(shopState.Products); var(_, shopItem) = shopState.Products.FirstOrDefault(); Assert.NotNull(shopItem); var avatarState = _initialState.GetAvatarState(_avatarAddress); Assert.False(avatarState.inventory.TryGetNonFungibleItem( shopItem.ItemUsable.ItemId, out ItemUsable _)); var sellCancellationAction = new SellCancellation { productId = shopItem.ProductId, sellerAvatarAddress = _avatarAddress, }; var nextState = sellCancellationAction.Execute(new ActionContext { BlockIndex = 0, PreviousStates = _initialState, Random = new ItemEnhancementTest.TestRandom(), Rehearsal = false, Signer = _agentAddress, }); var nextShopState = nextState.GetShopState(); Assert.Empty(nextShopState.Products); var nextAvatarState = nextState.GetAvatarState(_avatarAddress); Assert.True(nextAvatarState.inventory.TryGetNonFungibleItem( shopItem.ItemUsable.ItemId, out ItemUsable _)); }
public static bool TryGetAgentAvatarStates( this IAccountStateDelta states, Address agentAddress, Address avatarAddress, out AgentState agentState, out AvatarState avatarState ) { avatarState = null; agentState = states.GetAgentState(agentAddress); if (agentState is null) { return(false); } if (!agentState.avatarAddresses.ContainsValue(avatarAddress)) { throw new AgentStateNotContainsAvatarAddressException( $"The avatar {avatarAddress.ToHex()} does not belong to the agent {agentAddress.ToHex()}."); } avatarState = states.GetAvatarState(avatarAddress); return(!(avatarState is null)); }
public void Execute( ItemType itemType, bool shopItemExist, long blockIndex, int itemCount, int prevCount, int expectedProductsCount ) { var avatarState = _initialState.GetAvatarState(_avatarAddress); ITradableItem tradableItem; switch (itemType) { case ItemType.Consumable: tradableItem = ItemFactory.CreateItemUsable( _tableSheets.ConsumableItemSheet.First, Guid.NewGuid(), 0); break; case ItemType.Costume: tradableItem = ItemFactory.CreateCostume( _tableSheets.CostumeItemSheet.First, Guid.NewGuid()); break; case ItemType.Equipment: tradableItem = ItemFactory.CreateItemUsable( _tableSheets.EquipmentItemSheet.First, Guid.NewGuid(), 0); break; case ItemType.Material: var tradableMaterialRow = _tableSheets.MaterialItemSheet.OrderedList .First(row => row.ItemSubType == ItemSubType.Hourglass); tradableItem = ItemFactory.CreateTradableMaterial(tradableMaterialRow); break; default: throw new ArgumentOutOfRangeException(nameof(itemType), itemType, null); } Assert.Equal(0, tradableItem.RequiredBlockIndex); avatarState.inventory.AddItem2((ItemBase)tradableItem, itemCount); var previousStates = _initialState; previousStates = previousStates.SetState(_avatarAddress, avatarState.Serialize()); var currencyState = previousStates.GetGoldCurrency(); var price = new FungibleAssetValue(currencyState, ProductPrice, 0); var expectedProductId = new Guid("6f460c1a755d48e4ad6765d5f519dbc8"); var productId = new Guid("229e5f8c-fabe-4c04-bab9-45325cfa69a4"); var shardedShopAddress = ShardedShopState.DeriveAddress( tradableItem.ItemSubType, expectedProductId); if (shopItemExist) { tradableItem.RequiredBlockIndex = blockIndex; Assert.Equal(blockIndex, tradableItem.RequiredBlockIndex); var shopItem = new ShopItem( _agentAddress, _avatarAddress, productId, new FungibleAssetValue(currencyState, 1, 0), blockIndex, tradableItem, prevCount ); var shardedShopState = new ShardedShopState(shardedShopAddress); shardedShopState.Register(shopItem); Assert.Single(shardedShopState.Products); previousStates = previousStates.SetState( shardedShopAddress, shardedShopState.Serialize()); } else { Assert.Null(previousStates.GetState(shardedShopAddress)); } var sellAction = new Sell6 { sellerAvatarAddress = _avatarAddress, tradableId = tradableItem.TradableId, count = itemCount, price = price, itemSubType = tradableItem.ItemSubType, }; var nextState = sellAction.Execute(new ActionContext { BlockIndex = 1, PreviousStates = previousStates, Rehearsal = false, Signer = _agentAddress, Random = new TestRandom(), }); const long expiredBlockIndex = Sell6.ExpiredBlockIndex + 1; // Check AvatarState and Inventory var nextAvatarState = nextState.GetAvatarState(_avatarAddress); Assert.Single(nextAvatarState.inventory.Items); Assert.True(nextAvatarState.inventory.TryGetTradableItems( tradableItem.TradableId, expiredBlockIndex, 1, out var inventoryItems)); Assert.Single(inventoryItems); ITradableItem nextTradableItem = (ITradableItem)inventoryItems.First().item; Assert.Equal(expiredBlockIndex, nextTradableItem.RequiredBlockIndex); // Check ShardedShopState and ShopItem var nextSerializedShardedShopState = nextState.GetState(shardedShopAddress); Assert.NotNull(nextSerializedShardedShopState); var nextShardedShopState = new ShardedShopState((Dictionary)nextSerializedShardedShopState); Assert.Equal(expectedProductsCount, nextShardedShopState.Products.Count); var nextShopItem = nextShardedShopState.Products.Values.First(s => s.ExpiredBlockIndex == expiredBlockIndex); ITradableItem nextTradableItemInShopItem; switch (itemType) { case ItemType.Consumable: case ItemType.Equipment: nextTradableItemInShopItem = nextShopItem.ItemUsable; break; case ItemType.Costume: nextTradableItemInShopItem = nextShopItem.Costume; break; case ItemType.Material: nextTradableItemInShopItem = nextShopItem.TradableFungibleItem; break; default: throw new ArgumentOutOfRangeException(nameof(itemType), itemType, null); } Assert.Equal(price, nextShopItem.Price); Assert.Equal(expectedProductId, nextShopItem.ProductId); Assert.Equal(expiredBlockIndex, nextShopItem.ExpiredBlockIndex); Assert.Equal(_agentAddress, nextShopItem.SellerAgentAddress); Assert.Equal(_avatarAddress, nextShopItem.SellerAvatarAddress); Assert.Equal(expiredBlockIndex, nextTradableItemInShopItem.RequiredBlockIndex); var mailList = nextAvatarState.mailBox.Where(m => m is SellCancelMail).ToList(); Assert.Single(mailList); var mail = mailList.First() as SellCancelMail; Assert.NotNull(mail); Assert.Equal(expiredBlockIndex, mail.requiredBlockIndex); ITradableItem attachmentItem; int attachmentCount = 0; switch (itemType) { case ItemType.Consumable: case ItemType.Equipment: Assert.NotNull(mail.attachment.itemUsable); attachmentItem = mail.attachment.itemUsable; Assert.Equal(tradableItem, mail.attachment.itemUsable); break; case ItemType.Costume: Assert.NotNull(mail.attachment.costume); attachmentItem = mail.attachment.costume; Assert.Equal(tradableItem, mail.attachment.costume); break; case ItemType.Material: Assert.NotNull(mail.attachment.tradableFungibleItem); attachmentItem = mail.attachment.tradableFungibleItem; attachmentCount = mail.attachment.tradableFungibleItemCount; break; default: throw new ArgumentOutOfRangeException(nameof(itemType), itemType, null); } Assert.Equal(attachmentCount, nextShopItem.TradableFungibleItemCount); Assert.Equal(nextTradableItem, attachmentItem); Assert.Equal(nextTradableItemInShopItem, attachmentItem); }
public void Execute(int avatarLevel, int worldId, int stageId, int clearStageId) { 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, clearStageId); var costumeId = _tableSheets .CostumeItemSheet .Values .First(r => r.ItemSubType == ItemSubType.FullCostume) .Id; var costume = ItemFactory.CreateItem(_tableSheets.ItemSheet[costumeId], new TestRandom()); previousAvatarState.inventory.AddItem2(costume); var mimisbrunnrSheet = _tableSheets.MimisbrunnrSheet; if (!mimisbrunnrSheet.TryGetValue(stageId, out var mimisbrunnrSheetRow)) { throw new SheetRowNotFoundException("MimisbrunnrSheet", stageId); } var equipments = new List <Guid>(); var equipmentRow = _tableSheets.EquipmentItemSheet.Values.Last(x => x.Id == 10151001); var equipment = ItemFactory.CreateItemUsable(equipmentRow, Guid.NewGuid(), 0); previousAvatarState.inventory.AddItem(equipment); var armorEquipmentRow = _tableSheets.EquipmentItemSheet.Values.Last(x => x.Id == 10251001); var armorEquipment = ItemFactory.CreateItemUsable(armorEquipmentRow, Guid.NewGuid(), 0); previousAvatarState.inventory.AddItem(armorEquipment); var beltEquipment = ItemFactory.CreateItemUsable( _tableSheets.EquipmentItemSheet.Values.Last(x => x.Id == 10351000), Guid.NewGuid(), 0); previousAvatarState.inventory.AddItem(beltEquipment); var necklaceEquipment = ItemFactory.CreateItemUsable( _tableSheets.EquipmentItemSheet.Values.Last(x => x.Id == 10451000), Guid.NewGuid(), 0); previousAvatarState.inventory.AddItem(necklaceEquipment); equipments.Add(equipment.ItemId); equipments.Add(armorEquipment.ItemId); equipments.Add(beltEquipment.ItemId); equipments.Add(necklaceEquipment.ItemId); foreach (var equipmentId in previousAvatarState.inventory.Equipments) { if (previousAvatarState.inventory.TryGetNonFungibleItem(equipmentId, out ItemUsable itemUsable)) { var elementalType = ((Equipment)itemUsable).ElementalType; Assert.True(mimisbrunnrSheetRow.ElementalTypes.Exists(x => x == elementalType)); } } var result = new CombinationConsumable5.ResultModel() { id = default,
public void Execute(int rewardLevel, int prevRewardLevel, int collectionLevel) { Address collectionAddress = MonsterCollectionState0.DeriveAddress(_signer, 0); List <MonsterCollectionRewardSheet.RewardInfo> rewards = _tableSheets.MonsterCollectionRewardSheet[1].Rewards; MonsterCollectionState0 monsterCollectionState = new MonsterCollectionState0(collectionAddress, 1, 0, _tableSheets.MonsterCollectionRewardSheet); for (int i = 0; i < prevRewardLevel; i++) { int level = i + 1; MonsterCollectionResult result = new MonsterCollectionResult(Guid.NewGuid(), _avatarAddress, rewards); monsterCollectionState.UpdateRewardMap(level, result, i * MonsterCollectionState0.RewardInterval); } List <MonsterCollectionRewardSheet.RewardInfo> collectionRewards = _tableSheets.MonsterCollectionRewardSheet[collectionLevel].Rewards; monsterCollectionState.Update(collectionLevel, rewardLevel, _tableSheets.MonsterCollectionRewardSheet); for (long i = rewardLevel; i < 4; i++) { Assert.Equal(collectionRewards, monsterCollectionState.RewardLevelMap[i + 1]); } Dictionary <int, int> rewardExpectedMap = new Dictionary <int, int>(); foreach (var(key, value) in monsterCollectionState.RewardLevelMap) { if (monsterCollectionState.RewardMap.ContainsKey(key) || key > rewardLevel) { continue; } foreach (var info in value) { if (rewardExpectedMap.ContainsKey(info.ItemId)) { rewardExpectedMap[info.ItemId] += info.Quantity; } else { rewardExpectedMap[info.ItemId] = info.Quantity; } } } AvatarState prevAvatarState = _state.GetAvatarState(_avatarAddress); Assert.Empty(prevAvatarState.mailBox); Currency currency = _state.GetGoldCurrency(); int collectionRound = _state.GetAgentState(_signer).MonsterCollectionRound; _state = _state .SetState(collectionAddress, monsterCollectionState.Serialize()); FungibleAssetValue balance = 0 * currency; if (rewardLevel == 4) { foreach (var row in _tableSheets.MonsterCollectionSheet) { if (row.Level <= collectionLevel) { balance += row.RequiredGold * currency; } } collectionRound += 1; _state = _state .MintAsset(collectionAddress, balance); } Assert.Equal(prevRewardLevel, monsterCollectionState.RewardLevel); Assert.Equal(0, _state.GetAgentState(_signer).MonsterCollectionRound); ClaimMonsterCollectionReward0 action = new ClaimMonsterCollectionReward0 { avatarAddress = _avatarAddress, collectionRound = 0, }; IAccountStateDelta nextState = action.Execute(new ActionContext { PreviousStates = _state, Signer = _signer, BlockIndex = rewardLevel * MonsterCollectionState0.RewardInterval, Random = new TestRandom(), }); MonsterCollectionState0 nextMonsterCollectionState = new MonsterCollectionState0((Dictionary)nextState.GetState(collectionAddress)); Assert.Equal(rewardLevel, nextMonsterCollectionState.RewardLevel); AvatarState nextAvatarState = nextState.GetAvatarState(_avatarAddress); foreach (var(itemId, qty) in rewardExpectedMap) { Assert.True(nextAvatarState.inventory.HasItem(itemId, qty)); } Assert.Equal(rewardLevel - prevRewardLevel, nextAvatarState.mailBox.Count); Assert.All(nextAvatarState.mailBox, mail => { Assert.IsType <MonsterCollectionMail>(mail); MonsterCollectionMail monsterCollectionMail = (MonsterCollectionMail)mail; Assert.IsType <MonsterCollectionResult>(monsterCollectionMail.attachment); MonsterCollectionResult result = (MonsterCollectionResult)monsterCollectionMail.attachment; Assert.Equal(result.id, mail.id); }); for (int i = 0; i < nextMonsterCollectionState.RewardLevel; i++) { int level = i + 1; List <MonsterCollectionRewardSheet.RewardInfo> rewardInfos = _tableSheets.MonsterCollectionRewardSheet[collectionLevel].Rewards; Assert.Contains(level, nextMonsterCollectionState.RewardMap.Keys); Assert.Equal(_avatarAddress, nextMonsterCollectionState.RewardMap[level].avatarAddress); } Assert.Equal(0 * currency, nextState.GetBalance(collectionAddress, currency)); Assert.Equal(balance, nextState.GetBalance(_signer, currency)); Assert.Equal(collectionRound, nextState.GetAgentState(_signer).MonsterCollectionRound); Assert.Equal(nextMonsterCollectionState.End, rewardLevel == 4); }
public void Execute( ItemType itemType, string guid, int itemCount, int inventoryCount, int expectedCount, bool fromPreviousAction, bool legacy ) { var avatarState = _initialState.GetAvatarState(_avatarAddress); ITradableItem tradableItem; var itemId = new Guid(guid); var orderId = Guid.NewGuid(); var updateSellOrderId = Guid.NewGuid(); ItemSubType itemSubType; const long requiredBlockIndex = Order.ExpirationInterval; switch (itemType) { case ItemType.Equipment: { var itemUsable = ItemFactory.CreateItemUsable( _tableSheets.EquipmentItemSheet.First, itemId, requiredBlockIndex); tradableItem = itemUsable; itemSubType = itemUsable.ItemSubType; break; } case ItemType.Costume: { var costume = ItemFactory.CreateCostume(_tableSheets.CostumeItemSheet.First, itemId); costume.Update(requiredBlockIndex); tradableItem = costume; itemSubType = costume.ItemSubType; break; } default: { var material = ItemFactory.CreateTradableMaterial( _tableSheets.MaterialItemSheet.OrderedList.First(r => r.ItemSubType == ItemSubType.Hourglass)); itemSubType = material.ItemSubType; material.RequiredBlockIndex = requiredBlockIndex; tradableItem = material; break; } } var shardedShopAddress = ShardedShopStateV2.DeriveAddress(itemSubType, orderId); var shopState = new ShardedShopStateV2(shardedShopAddress); var order = OrderFactory.Create( _agentAddress, _avatarAddress, orderId, new FungibleAssetValue(_goldCurrencyState.Currency, 100, 0), tradableItem.TradableId, requiredBlockIndex, itemSubType, itemCount ); var orderDigestList = new OrderDigestListState(OrderDigestListState.DeriveAddress(_avatarAddress)); var prevState = _initialState; if (inventoryCount > 1) { for (int i = 0; i < inventoryCount; i++) { // Different RequiredBlockIndex for divide inventory slot. if (tradableItem is ITradableFungibleItem tradableFungibleItem) { var tradable = (TradableMaterial)tradableFungibleItem.Clone(); tradable.RequiredBlockIndex = tradableItem.RequiredBlockIndex - i; avatarState.inventory.AddItem2(tradable, 2 - i); } } } else { avatarState.inventory.AddItem2((ItemBase)tradableItem, itemCount); } var sellItem = legacy ? order.Sell2(avatarState) : order.Sell3(avatarState); var orderDigest = legacy ? order.Digest2(avatarState, _tableSheets.CostumeStatSheet) : order.Digest(avatarState, _tableSheets.CostumeStatSheet); shopState.Add(orderDigest, requiredBlockIndex); orderDigestList.Add(orderDigest); if (legacy) { Assert.True(avatarState.inventory.TryGetTradableItems(itemId, requiredBlockIndex * 2, itemCount, out _)); } else { Assert.True(avatarState.inventory.TryGetLockedItem(new OrderLock(orderId), out _)); } Assert.Equal(inventoryCount, avatarState.inventory.Items.Count); Assert.Equal(expectedCount, avatarState.inventory.Items.Sum(i => i.count)); Assert.Single(shopState.OrderDigestList); Assert.Single(orderDigestList.OrderDigestList); Assert.Equal(requiredBlockIndex * 2, sellItem.RequiredBlockIndex); if (fromPreviousAction) { prevState = prevState.SetState(_avatarAddress, avatarState.Serialize()); } else { prevState = prevState .SetState(_avatarAddress.Derive(LegacyInventoryKey), avatarState.inventory.Serialize()) .SetState(_avatarAddress.Derive(LegacyWorldInformationKey), avatarState.worldInformation.Serialize()) .SetState(_avatarAddress.Derive(LegacyQuestListKey), avatarState.questList.Serialize()) .SetState(_avatarAddress, avatarState.SerializeV2()); } prevState = prevState .SetState(Addresses.GetItemAddress(itemId), sellItem.Serialize()) .SetState(Order.DeriveAddress(order.OrderId), order.Serialize()) .SetState(orderDigestList.Address, orderDigestList.Serialize()) .SetState(shardedShopAddress, shopState.Serialize()); var currencyState = prevState.GetGoldCurrency(); var price = new FungibleAssetValue(currencyState, ProductPrice, 0); var action = new UpdateSell0 { orderId = orderId, updateSellOrderId = updateSellOrderId, tradableId = itemId, sellerAvatarAddress = _avatarAddress, itemSubType = itemSubType, price = price, count = itemCount, }; var nextState = action.Execute(new ActionContext { BlockIndex = 101, PreviousStates = prevState, Random = new TestRandom(), Rehearsal = false, Signer = _agentAddress, }); var updateSellShopAddress = ShardedShopStateV2.DeriveAddress(itemSubType, updateSellOrderId); var nextShopState = new ShardedShopStateV2((Dictionary)nextState.GetState(updateSellShopAddress)); Assert.Equal(1, nextShopState.OrderDigestList.Count); Assert.NotEqual(orderId, nextShopState.OrderDigestList.First().OrderId); Assert.Equal(updateSellOrderId, nextShopState.OrderDigestList.First().OrderId); Assert.Equal(itemId, nextShopState.OrderDigestList.First().TradableId); Assert.Equal(requiredBlockIndex + 101, nextShopState.OrderDigestList.First().ExpiredBlockIndex); }
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; } }
public void Execute(bool backward) { var avatarState = _initialState.GetAvatarState(_avatarAddress); var row = _tableSheets.ConsumableItemRecipeSheet.Values.First(); var costActionPoint = row.RequiredActionPoint; foreach (var materialInfo in row.Materials) { var materialRow = _tableSheets.MaterialItemSheet[materialInfo.Id]; var material = ItemFactory.CreateItem(materialRow, _random); avatarState.inventory.AddItem(material, materialInfo.Count); } var previousActionPoint = avatarState.actionPoint; var previousResultConsumableCount = avatarState.inventory.Equipments.Count(e => e.Id == row.ResultConsumableItemId); var previousMailCount = avatarState.mailBox.Count; avatarState.worldInformation = new WorldInformation( 0, _tableSheets.WorldSheet, GameConfig.RequireClearedStageLevel.CombinationConsumableAction); IAccountStateDelta previousState; if (backward) { previousState = _initialState.SetState(_avatarAddress, avatarState.Serialize()); } else { previousState = _initialState .SetState(_avatarAddress.Derive(LegacyInventoryKey), avatarState.inventory.Serialize()) .SetState(_avatarAddress.Derive(LegacyWorldInformationKey), avatarState.worldInformation.Serialize()) .SetState(_avatarAddress.Derive(LegacyQuestListKey), avatarState.questList.Serialize()) .SetState(_avatarAddress, avatarState.SerializeV2()); } var action = new CombinationConsumable { avatarAddress = _avatarAddress, recipeId = row.Id, slotIndex = 0, }; var nextState = action.Execute(new ActionContext { PreviousStates = previousState, Signer = _agentAddress, BlockIndex = 1, Random = _random, }); var slotState = nextState.GetCombinationSlotState(_avatarAddress, 0); Assert.NotNull(slotState.Result); Assert.NotNull(slotState.Result.itemUsable); var consumable = (Consumable)slotState.Result.itemUsable; Assert.NotNull(consumable); var nextAvatarState = nextState.GetAvatarStateV2(_avatarAddress); Assert.Equal(previousActionPoint - costActionPoint, nextAvatarState.actionPoint); Assert.Equal(previousMailCount + 1, nextAvatarState.mailBox.Count); Assert.IsType <CombinationMail>(nextAvatarState.mailBox.First()); Assert.Equal( previousResultConsumableCount + 1, nextAvatarState.inventory.Consumables.Count(e => e.Id == row.ResultConsumableItemId)); }
public void Execute(bool isNew, bool avatarBackward, bool enemyBackward) { var previousWeeklyState = _initialState.GetWeeklyArenaState(0); var previousAvatar1State = _initialState.GetAvatarState(_avatar1Address); previousAvatar1State.level = 10; var prevScore = previousWeeklyState[_avatar1Address].Score; if (isNew) { previousWeeklyState.Remove(_avatar1Address); } var previousState = _initialState.SetState( _avatar1Address, previousAvatar1State.Serialize()); var itemIds = _tableSheets.WeeklyArenaRewardSheet.Values .Select(r => r.Reward.ItemId) .ToList(); Assert.All(itemIds, id => Assert.False(previousAvatar1State.inventory.HasItem(id))); var row = _tableSheets.CostumeStatSheet.Values.First(r => r.StatType == StatType.ATK); var costume = (Costume)ItemFactory.CreateItem( _tableSheets.ItemSheet[row.CostumeId], new TestRandom()); costume.equipped = true; previousAvatar1State.inventory.AddItem(costume); var row2 = _tableSheets.CostumeStatSheet.Values.First(r => r.StatType == StatType.DEF); var enemyCostume = (Costume)ItemFactory.CreateItem( _tableSheets.ItemSheet[row2.CostumeId], new TestRandom()); enemyCostume.equipped = true; var enemyAvatarState = _initialState.GetAvatarState(_avatar2Address); enemyAvatarState.inventory.AddItem(enemyCostume); if (avatarBackward) { previousState = previousState.SetState(_avatar1Address, previousAvatar1State.Serialize()); } else { previousState = previousState .SetState(_avatar1Address.Derive(LegacyInventoryKey), previousAvatar1State.inventory.Serialize()) .SetState(_avatar1Address.Derive(LegacyWorldInformationKey), previousAvatar1State.worldInformation.Serialize()) .SetState(_avatar1Address.Derive(LegacyQuestListKey), previousAvatar1State.questList.Serialize()) .SetState(_avatar1Address, previousAvatar1State.SerializeV2()); } if (enemyBackward) { previousState = previousState.SetState(_avatar2Address, enemyAvatarState.Serialize()); } else { previousState = previousState .SetState(_avatar2Address.Derive(LegacyInventoryKey), enemyAvatarState.inventory.Serialize()) .SetState(_avatar2Address.Derive(LegacyWorldInformationKey), enemyAvatarState.worldInformation.Serialize()) .SetState(_avatar2Address.Derive(LegacyQuestListKey), enemyAvatarState.questList.Serialize()) .SetState(_avatar2Address, enemyAvatarState.SerializeV2()); } var action = new RankingBattle { avatarAddress = _avatar1Address, enemyAddress = _avatar2Address, weeklyArenaAddress = _weeklyArenaAddress, costumeIds = new List <Guid> { costume.ItemId }, equipmentIds = new List <Guid>(), consumableIds = new List <Guid>(), }; Assert.Null(action.Result); var nextState = action.Execute(new ActionContext() { PreviousStates = previousState, Signer = _agent1Address, Random = new TestRandom(), Rehearsal = false, }); var nextAvatar1State = nextState.GetAvatarStateV2(_avatar1Address); var nextWeeklyState = nextState.GetWeeklyArenaState(0); Assert.Contains(nextAvatar1State.inventory.Materials, i => itemIds.Contains(i.Id)); Assert.NotNull(action.Result); Assert.Contains(typeof(GetReward), action.Result.Select(e => e.GetType())); Assert.Equal(BattleLog.Result.Win, action.Result.result); Assert.True(nextWeeklyState[_avatar1Address].Score > prevScore); }
public void Execute(int avatarLevel, int worldId, int stageId, bool contains) { 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>(); 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], new TestRandom()); 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], new TestRandom()) as Equipment; equipments.Add(weapon.ItemId); previousAvatarState.inventory.AddItem(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], new TestRandom()) as Equipment; equipments.Add(armor.ItemId); previousAvatarState.inventory.AddItem(armor); } var mailEquipmentRow = _tableSheets.EquipmentItemSheet.Values.First(); var mailEquipment = ItemFactory.CreateItemUsable(mailEquipmentRow, default, 0);
public void Execute() { var previousWeeklyState = _initialState.GetWeeklyArenaState(ArenaIndex); var previousAvatar1State = _initialState.GetAvatarState(_avatar1Address); previousAvatar1State.level = 10; var prevScore = previousWeeklyState[_avatar1Address].Score; var previousState = _initialState.SetState( _avatar1Address, previousAvatar1State.Serialize()); var itemIds = _tableSheets.WeeklyArenaRewardSheet.Values .Select(r => r.Reward.ItemId) .ToList(); Assert.All(itemIds, id => Assert.False(previousAvatar1State.inventory.HasItem(id))); var row = _tableSheets.CostumeStatSheet.Values.First(r => r.StatType == StatType.ATK); var costume = (Costume)ItemFactory.CreateItem( _tableSheets.ItemSheet[row.CostumeId], new TestRandom()); costume.equipped = true; previousAvatar1State.inventory.AddItem(costume); var row2 = _tableSheets.CostumeStatSheet.Values.First(r => r.StatType == StatType.DEF); var enemyCostume = (Costume)ItemFactory.CreateItem( _tableSheets.ItemSheet[row2.CostumeId], new TestRandom()); enemyCostume.equipped = true; var enemyAvatarState = _initialState.GetAvatarState(_avatar2Address); enemyAvatarState.inventory.AddItem(enemyCostume); Address worldInformationAddress = _avatar1Address.Derive(LegacyWorldInformationKey); var weeklyArenaAddress = WeeklyArenaState.DeriveAddress(RankingBattle.UpdateTargetWeeklyArenaIndex); previousState = previousState .SetState( _avatar1Address.Derive(LegacyInventoryKey), previousAvatar1State.inventory.Serialize()) .SetState( worldInformationAddress, previousAvatar1State.worldInformation.Serialize()) .SetState( _avatar1Address.Derive(LegacyQuestListKey), previousAvatar1State.questList.Serialize()) .SetState(_avatar1Address, previousAvatar1State.SerializeV2()) .SetState( _avatar2Address.Derive(LegacyInventoryKey), enemyAvatarState.inventory.Serialize()) .SetState( _avatar2Address.Derive(LegacyWorldInformationKey), enemyAvatarState.worldInformation.Serialize()) .SetState( _avatar2Address.Derive(LegacyQuestListKey), enemyAvatarState.questList.Serialize()) .SetState(_avatar2Address, enemyAvatarState.SerializeV2()) .SetState( weeklyArenaAddress, new WeeklyArenaState(RankingBattle.UpdateTargetWeeklyArenaIndex).Serialize()); var action = new RankingBattle { avatarAddress = _avatar1Address, enemyAddress = _avatar2Address, weeklyArenaAddress = weeklyArenaAddress, costumeIds = new List <Guid> { costume.ItemId }, equipmentIds = new List <Guid>(), }; var nextState = action.Execute(new ActionContext { PreviousStates = previousState, Signer = _agent1Address, Random = new TestRandom(), Rehearsal = false, BlockIndex = RankingBattle.UpdateTargetBlockIndex, }); Assert.True(nextState.TryGetState(weeklyArenaAddress.Derive(_avatar1Address.ToByteArray()), out Dictionary rawArenaInfo)); Assert.True(nextState.TryGetState(weeklyArenaAddress.Derive(_avatar2Address.ToByteArray()), out Dictionary rawEnemyInfo)); Assert.True(nextState.TryGetState(weeklyArenaAddress.Derive("address_list"), out List rawAddressList)); var nextWeekly = nextState.GetWeeklyArenaState(weeklyArenaAddress); Assert.Empty(nextWeekly.Map); var nextAvatar1State = nextState.GetAvatarStateV2(_avatar1Address); var nextArenaInfo = new ArenaInfo(rawArenaInfo); var addressList = rawAddressList.ToList(StateExtensions.ToAddress); Assert.Contains(_avatar1Address, addressList); Assert.Contains(_avatar2Address, addressList); Assert.Contains(nextAvatar1State.inventory.Materials, i => itemIds.Contains(i.Id)); Assert.NotNull(action.ArenaInfo); Assert.NotNull(action.EnemyArenaInfo); Assert.True(nextArenaInfo.Score > prevScore); // Check simulation result equal. var player = new Player( previousAvatar1State, _tableSheets.CharacterSheet, _tableSheets.CharacterLevelSheet, _tableSheets.EquipmentItemSetEffectSheet); var simulator = new RankingSimulator( new TestRandom(), player, action.EnemyPlayerDigest, new List <Guid>(), _tableSheets.GetRankingSimulatorSheets(), RankingBattle.StageId, action.ArenaInfo, action.EnemyArenaInfo, _tableSheets.CostumeStatSheet); simulator.Simulate(); Assert.Equal(nextArenaInfo.Score, simulator.Log.score); Assert.Equal(previousAvatar1State.SerializeV2(), nextAvatar1State.SerializeV2()); Assert.Equal(previousAvatar1State.worldInformation.Serialize(), nextAvatar1State.worldInformation.Serialize()); }
public void Execute( ItemType itemType, bool orderExist, int itemCount, bool backward ) { var avatarState = _initialState.GetAvatarState(_avatarAddress); ITradableItem tradableItem; switch (itemType) { case ItemType.Consumable: tradableItem = ItemFactory.CreateItemUsable( _tableSheets.ConsumableItemSheet.First, Guid.NewGuid(), 0); break; case ItemType.Costume: tradableItem = ItemFactory.CreateCostume( _tableSheets.CostumeItemSheet.First, Guid.NewGuid()); break; case ItemType.Equipment: tradableItem = ItemFactory.CreateItemUsable( _tableSheets.EquipmentItemSheet.First, Guid.NewGuid(), 0); break; case ItemType.Material: var tradableMaterialRow = _tableSheets.MaterialItemSheet.OrderedList .First(row => row.ItemSubType == ItemSubType.Hourglass); tradableItem = ItemFactory.CreateTradableMaterial(tradableMaterialRow); break; default: throw new ArgumentOutOfRangeException(nameof(itemType), itemType, null); } Assert.Equal(0, tradableItem.RequiredBlockIndex); avatarState.inventory.AddItem2((ItemBase)tradableItem, itemCount); var previousStates = _initialState; if (backward) { previousStates = previousStates.SetState(_avatarAddress, avatarState.Serialize()); } else { previousStates = previousStates .SetState(_avatarAddress.Derive(LegacyInventoryKey), avatarState.inventory.Serialize()) .SetState(_avatarAddress.Derive(LegacyWorldInformationKey), avatarState.worldInformation.Serialize()) .SetState(_avatarAddress.Derive(LegacyQuestListKey), avatarState.questList.Serialize()) .SetState(_avatarAddress, avatarState.SerializeV2()); } var currencyState = previousStates.GetGoldCurrency(); var price = new FungibleAssetValue(currencyState, ProductPrice, 0); var orderId = new Guid("6f460c1a755d48e4ad6765d5f519dbc8"); var existOrderId = new Guid("229e5f8c-fabe-4c04-bab9-45325cfa69a4"); var orderAddress = Order.DeriveAddress(orderId); var shardedShopAddress = ShardedShopStateV2.DeriveAddress( tradableItem.ItemSubType, orderId); long blockIndex = 1; if (orderExist) { var shardedShopState = new ShardedShopStateV2(shardedShopAddress); var existOrder = OrderFactory.Create( _agentAddress, _avatarAddress, existOrderId, price, tradableItem.TradableId, 0, tradableItem.ItemSubType, 1 ); existOrder.Sell2(avatarState); blockIndex = existOrder.ExpiredBlockIndex; shardedShopState.Add(existOrder.Digest2(avatarState, _tableSheets.CostumeStatSheet), blockIndex); Assert.Single(shardedShopState.OrderDigestList); previousStates = previousStates.SetState( shardedShopAddress, shardedShopState.Serialize()); } else { Assert.Null(previousStates.GetState(shardedShopAddress)); } var sellAction = new Sell7 { sellerAvatarAddress = _avatarAddress, tradableId = tradableItem.TradableId, count = itemCount, price = price, itemSubType = tradableItem.ItemSubType, orderId = orderId, }; var nextState = sellAction.Execute(new ActionContext { BlockIndex = blockIndex, PreviousStates = previousStates, Rehearsal = false, Signer = _agentAddress, Random = new TestRandom(), }); long expiredBlockIndex = Order.ExpirationInterval + blockIndex; // Check AvatarState and Inventory var nextAvatarState = nextState.GetAvatarStateV2(_avatarAddress); Assert.Single(nextAvatarState.inventory.Items); Assert.True(nextAvatarState.inventory.TryGetTradableItems( tradableItem.TradableId, expiredBlockIndex, 1, out var inventoryItems)); Assert.Single(inventoryItems); ITradableItem nextTradableItem = (ITradableItem)inventoryItems.First().item; Assert.Equal(expiredBlockIndex, nextTradableItem.RequiredBlockIndex); // Check ShardedShopState var nextSerializedShardedShopState = nextState.GetState(shardedShopAddress); Assert.NotNull(nextSerializedShardedShopState); var nextShardedShopState = new ShardedShopStateV2((Dictionary)nextSerializedShardedShopState); var expectedCount = orderExist ? 2 : 1; Assert.Equal(expectedCount, nextShardedShopState.OrderDigestList.Count); var orderDigest = nextShardedShopState.OrderDigestList.First(o => o.OrderId.Equals(orderId)); Assert.Equal(price, orderDigest.Price); Assert.Equal(blockIndex, orderDigest.StartedBlockIndex); Assert.Equal(expiredBlockIndex, orderDigest.ExpiredBlockIndex); Assert.Equal(((ItemBase)tradableItem).Id, orderDigest.ItemId); Assert.Equal(tradableItem.TradableId, orderDigest.TradableId); var serializedOrder = nextState.GetState(orderAddress); Assert.NotNull(serializedOrder); var serializedItem = nextState.GetState(Addresses.GetItemAddress(tradableItem.TradableId)); Assert.NotNull(serializedItem); var order = OrderFactory.Deserialize((Dictionary)serializedOrder); ITradableItem orderItem = (ITradableItem)ItemFactory.Deserialize((Dictionary)serializedItem); Assert.Equal(price, order.Price); Assert.Equal(orderId, order.OrderId); Assert.Equal(tradableItem.TradableId, order.TradableId); Assert.Equal(blockIndex, order.StartedBlockIndex); Assert.Equal(expiredBlockIndex, order.ExpiredBlockIndex); Assert.Equal(_agentAddress, order.SellerAgentAddress); Assert.Equal(_avatarAddress, order.SellerAvatarAddress); Assert.Equal(expiredBlockIndex, orderItem.RequiredBlockIndex); var mailList = nextAvatarState.mailBox.OfType <OrderExpirationMail>().ToList(); Assert.Single(mailList); var mail = mailList.First(); Assert.NotNull(mail); Assert.Equal(expiredBlockIndex, mail.requiredBlockIndex); Assert.Equal(orderId, mail.OrderId); var receiptDict = nextState.GetState(OrderDigestListState.DeriveAddress(_avatarAddress)); Assert.NotNull(receiptDict); var orderDigestList = new OrderDigestListState((Dictionary)receiptDict); Assert.Single(orderDigestList.OrderDigestList); OrderDigest orderDigest2 = orderDigestList.OrderDigestList.First(); Assert.Equal(orderDigest, orderDigest2); }
public void Execute(int avatarLevel, int worldId, int stageId, bool contains) { 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)); var costumeId = _tableSheets .CostumeItemSheet .Values .First(r => r.ItemSubType == ItemSubType.FullCostume) .Id; var costume = ItemFactory.CreateItem(_tableSheets.ItemSheet[costumeId], new TestRandom()); previousAvatarState.inventory.AddItem2(costume); var state = _initialState.SetState(_avatarAddress, previousAvatarState.Serialize()); var action = new HackAndSlash0() { costumes = new List <int> { costumeId }, equipments = new List <Guid>(), foods = new List <Guid>(), worldId = worldId, stageId = stageId, avatarAddress = _avatarAddress, WeeklyArenaAddress = _weeklyArenaState.address, RankingMapAddress = _rankingMapAddress, }; Assert.Null(action.Result); var nextState = action.Execute(new ActionContext() { PreviousStates = state, Signer = _agentAddress, Random = new TestRandom(), Rehearsal = false, }); var nextAvatarState = nextState.GetAvatarState(_avatarAddress); var newWeeklyState = nextState.GetWeeklyArenaState(0); Assert.NotNull(action.Result); Assert.NotEmpty(action.Result.OfType <GetReward>()); Assert.Equal(BattleLog.Result.Win, action.Result.result); Assert.Equal(contains, newWeeklyState.ContainsKey(_avatarAddress)); Assert.True(nextAvatarState.worldInformation.IsStageCleared(stageId)); var value = nextState.GetState(_rankingMapAddress); var rankingMapState = new RankingMapState((Dictionary)value); var info = rankingMapState.GetRankingInfos(null).First(); Assert.Equal(info.AgentAddress, _agentAddress); Assert.Equal(info.AvatarAddress, _avatarAddress); }