diff --git a/.Lib9c.Tests/Action/RapidCombinationTest.cs b/.Lib9c.Tests/Action/RapidCombinationTest.cs index 1af5e83f0..b929f4ffc 100644 --- a/.Lib9c.Tests/Action/RapidCombinationTest.cs +++ b/.Lib9c.Tests/Action/RapidCombinationTest.cs @@ -129,12 +129,8 @@ public void Execute() result.id = mail.id; avatarState.Update2(mail); - var slotAddress = _avatarAddress.Derive(string.Format( - CultureInfo.InvariantCulture, - CombinationSlotState.DeriveFormat, - 0)); var allSlotState = new AllCombinationSlotState(); - allSlotState.AddSlot(slotAddress); + allSlotState.AddSlot(_avatarAddress); var slotState = allSlotState.GetSlot(0); slotState.Update(result, 0, requiredBlockIndex); @@ -163,6 +159,90 @@ public void Execute() Assert.Equal(51, item.RequiredBlockIndex); } + [Fact] + public void Execute_Many() + { + const int slotStateUnlockStage = 1; + + var avatarState = _initialState.GetAvatarState(_avatarAddress); + avatarState.worldInformation = new WorldInformation( + 0, + _initialState.GetSheet(), + slotStateUnlockStage); + + var row = _tableSheets.MaterialItemSheet.Values.First(r => + r.ItemSubType == ItemSubType.Hourglass); + + var numOfHourglass = 83 * AvatarState.DefaultCombinationSlotCount; + avatarState.inventory.AddItem(ItemFactory.CreateMaterial(row), numOfHourglass); + + var numOfTradableHourglass = 100 * AvatarState.DefaultCombinationSlotCount; + avatarState.inventory.AddItem(ItemFactory.CreateTradableMaterial(row), numOfTradableHourglass); + + Assert.True(avatarState.inventory.HasFungibleItem(row.ItemId, 0, numOfHourglass + numOfTradableHourglass)); + + 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 targetState = _initialState; + var allSlotState = new AllCombinationSlotState(); + for (var i = 0; i < AvatarState.DefaultCombinationSlotCount; ++i) + { + var result = new CombinationConsumable5.ResultModel + { + actionPoint = 0, + gold = 0, + materials = new Dictionary(), + itemUsable = equipment, + recipeId = 0, + itemType = ItemType.Equipment, + }; + + var mail = new CombinationMail(result, 0, default, requiredBlockIndex); + result.id = mail.id; + avatarState.Update2(mail); + + targetState = targetState + .SetAvatarState(_avatarAddress, avatarState); + + allSlotState.AddSlot(_avatarAddress, i); + var slotState = allSlotState.GetSlot(i); + slotState.Update(result, 0, requiredBlockIndex); + } + + targetState = targetState + .SetCombinationSlotState(_avatarAddress, allSlotState); + + var slotIndexList = Enumerable.Range(0, AvatarState.DefaultCombinationSlotCount).ToList(); + var action = new RapidCombination + { + avatarAddress = _avatarAddress, + slotIndexList = slotIndexList, + }; + + var nextState = action.Execute(new ActionContext + { + PreviousState = targetState, + Signer = _agentAddress, + BlockIndex = 51, + }); + + var nextAvatarState = nextState.GetAvatarState(_avatarAddress); + var item = nextAvatarState.inventory.Equipments.First(); + + Assert.Empty(nextAvatarState.inventory.Materials.Select(r => r.ItemSubType == ItemSubType.Hourglass)); + Assert.Equal(equipment.ItemId, item.ItemId); + Assert.Equal(51, item.RequiredBlockIndex); + } + [Fact] public void Execute_Throw_CombinationSlotResultNullException() { diff --git a/Lib9c/Model/State/AllCombinationSlotState.cs b/Lib9c/Model/State/AllCombinationSlotState.cs index a4387cf69..39367ba42 100644 --- a/Lib9c/Model/State/AllCombinationSlotState.cs +++ b/Lib9c/Model/State/AllCombinationSlotState.cs @@ -64,7 +64,7 @@ public CombinationSlotState GetSlot(int slotStateIndex) { return CombinationSlots.TryGetValue(slotStateIndex, out var combinationSlotState) ? combinationSlotState - : throw new CombinationSlotNotFoundException($"Rune {slotStateIndex} not found in AllCombinationSlotState"); + : throw new CombinationSlotNotFoundException($"CombinationSlot {slotStateIndex} not found in AllCombinationSlotState"); } public void AddSlot(Address address, int index = 0)