From 8317149f11fecd6ee6c85961db65ee3e259acf50 Mon Sep 17 00:00:00 2001 From: eugene-hong <58686228+eugene-doobu@users.noreply.github.com> Date: Tue, 17 Dec 2024 18:53:36 +0900 Subject: [PATCH] fix inventory state --- .../AdventureBoss/ExploreAdventureBossTest.cs | 2 ++ .Lib9c.Tests/Action/EventDungeonBattleTest.cs | 15 +++++++++++++++ .Lib9c.Tests/Action/HackAndSlashSweepTest.cs | 15 ++++++++++++--- .Lib9c.Tests/Action/HackAndSlashTest.cs | 13 +++++++++++++ .Lib9c.Tests/Action/RaidTest.cs | 13 +++++++++++++ .Lib9c.Tests/Action/Scenario/RuneScenarioTest.cs | 7 +++++++ 6 files changed, 62 insertions(+), 3 deletions(-) diff --git a/.Lib9c.Tests/Action/AdventureBoss/ExploreAdventureBossTest.cs b/.Lib9c.Tests/Action/AdventureBoss/ExploreAdventureBossTest.cs index c742acc4fd..71926ca7b9 100644 --- a/.Lib9c.Tests/Action/AdventureBoss/ExploreAdventureBossTest.cs +++ b/.Lib9c.Tests/Action/AdventureBoss/ExploreAdventureBossTest.cs @@ -225,6 +225,8 @@ Type exc previousAvatarState.inventory.AddItem(equipment); } + state = state.SetAvatarState(TesterAvatarAddress, previousAvatarState); + var expectedItemRewards = new List<(int, int)>(); var expectedFavRewards = new List<(int, int)>(); var firstRewardSheet = TableSheets.AdventureBossFloorFirstRewardSheet; diff --git a/.Lib9c.Tests/Action/EventDungeonBattleTest.cs b/.Lib9c.Tests/Action/EventDungeonBattleTest.cs index 4aaec59d70..487611b71e 100644 --- a/.Lib9c.Tests/Action/EventDungeonBattleTest.cs +++ b/.Lib9c.Tests/Action/EventDungeonBattleTest.cs @@ -533,6 +533,21 @@ private IWorld Execute( previousAvatarState.inventory.AddItem(equipment, iLock: null); } + previousStates = previousStates.SetAvatarState(_avatarAddress, previousAvatarState); + + var allRuneState = previousStates.GetRuneState(_avatarAddress, out _); + if (!allRuneState.TryGetRuneState(runeId, out _)) + { + allRuneState.AddRuneState(new RuneState(runeId, 1)); + } + + if (!allRuneState.TryGetRuneState(runeId2, out _)) + { + allRuneState.AddRuneState(new RuneState(runeId2, 1)); + } + + previousStates = previousStates.SetRuneState(_avatarAddress, allRuneState); + var action = new EventDungeonBattle { AvatarAddress = _avatarAddress, diff --git a/.Lib9c.Tests/Action/HackAndSlashSweepTest.cs b/.Lib9c.Tests/Action/HackAndSlashSweepTest.cs index 061bab0219..a2ad9b1920 100644 --- a/.Lib9c.Tests/Action/HackAndSlashSweepTest.cs +++ b/.Lib9c.Tests/Action/HackAndSlashSweepTest.cs @@ -92,8 +92,13 @@ public HackAndSlashSweepTest() public (List Equipments, List Costumes) GetDummyItems(AvatarState avatarState) { - var equipments = Doomfist.GetAllParts(_tableSheets, avatarState.level) - .Select(e => e.NonFungibleId).ToList(); + var equipments = Doomfist.GetAllParts(_tableSheets, avatarState.level).ToList(); + foreach (var equipment in equipments) + { + avatarState.inventory.AddItem(equipment, iLock: null); + } + + var equipmentGuids = equipments.Select(e => e.NonFungibleId).ToList(); var random = new TestRandom(); var costumes = new List(); if (avatarState.level >= GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot) @@ -111,7 +116,7 @@ public HackAndSlashSweepTest() costumes.Add(costume.ItemId); } - return (equipments, costumes); + return (equipmentGuids, costumes); } [Fact] @@ -349,6 +354,7 @@ public void Execute_NotEnoughMaterialException(int useApStoneCount, int holdingA (int)playCount); var (equipments, costumes) = GetDummyItems(avatarState); + state = state.SetAvatarState(_avatarAddress, avatarState); var action = new HackAndSlashSweep { @@ -405,6 +411,8 @@ public void Execute_NotEnoughActionPointException() (int)playCount); var (equipments, costumes) = GetDummyItems(avatarState); + state = state.SetAvatarState(_avatarAddress, avatarState); + var action = new HackAndSlashSweep { runeInfos = new List(), @@ -461,6 +469,7 @@ public void Execute_PlayCountIsZeroException() (int)playCount); var (equipments, costumes) = GetDummyItems(avatarState); + state = state.SetAvatarState(_avatarAddress, avatarState); var action = new HackAndSlashSweep { costumes = costumes, diff --git a/.Lib9c.Tests/Action/HackAndSlashTest.cs b/.Lib9c.Tests/Action/HackAndSlashTest.cs index bbacbfee05..e5e9fb4a22 100644 --- a/.Lib9c.Tests/Action/HackAndSlashTest.cs +++ b/.Lib9c.Tests/Action/HackAndSlashTest.cs @@ -1571,6 +1571,19 @@ public void ExecuteTwoRepetitions() _avatarAddress.Derive("world_ids"), List.Empty.Add(worldId.Serialize())); + var allRuneState = state.GetRuneState(_avatarAddress, out _); + if (!allRuneState.TryGetRuneState(30001, out _)) + { + allRuneState.AddRuneState(new RuneState(30001)); + } + + if (!allRuneState.TryGetRuneState(10002, out _)) + { + allRuneState.AddRuneState(new RuneState(10002)); + } + + state = state.SetRuneState(_avatarAddress, allRuneState); + var action = new HackAndSlash { Costumes = costumes, diff --git a/.Lib9c.Tests/Action/RaidTest.cs b/.Lib9c.Tests/Action/RaidTest.cs index 6ca01079dc..30475ca487 100644 --- a/.Lib9c.Tests/Action/RaidTest.cs +++ b/.Lib9c.Tests/Action/RaidTest.cs @@ -149,6 +149,19 @@ int runeId2 state = state.SetLegacyState(Addresses.TableSheet.Derive(key), value.Serialize()); } + var allRuneState = state.GetRuneState(_avatarAddress, out _); + if (!allRuneState.TryGetRuneState(runeId, out _)) + { + allRuneState.AddRuneState(new RuneState(runeId, 1)); + } + + if (!allRuneState.TryGetRuneState(runeId2, out _)) + { + allRuneState.AddRuneState(new RuneState(runeId2, 1)); + } + + state = state.SetRuneState(_avatarAddress, allRuneState); + var gameConfigState = new GameConfigState(_sheets[nameof(GameConfigSheet)]); var avatarState = AvatarState.Create( _avatarAddress, diff --git a/.Lib9c.Tests/Action/Scenario/RuneScenarioTest.cs b/.Lib9c.Tests/Action/Scenario/RuneScenarioTest.cs index e83d66f729..0405507229 100644 --- a/.Lib9c.Tests/Action/Scenario/RuneScenarioTest.cs +++ b/.Lib9c.Tests/Action/Scenario/RuneScenarioTest.cs @@ -199,6 +199,13 @@ public void MigrateToRuneStateModule() avatarState.inventory.AddItem(equipment, iLock: iLock); } + foreach (var equipment in equipments) + { + avatarState.inventory.AddItem(equipment, iLock: null); + } + + initialState = initialState.SetAvatarState(avatarAddress, avatarState); + var action = new HackAndSlash { Costumes = costumes,