From 259672dd7fa6dbb265270744f2573036f257176f Mon Sep 17 00:00:00 2001 From: eugene-hong <58686228+eugene-doobu@users.noreply.github.com> Date: Mon, 16 Dec 2024 20:02:45 +0900 Subject: [PATCH 1/7] Add check slot logic --- Lib9c/Action/HackAndSlash.cs | 6 ++++++ Lib9c/Action/HackAndSlashSweep.cs | 6 ++++++ Lib9c/Action/Raid.cs | 6 ++++++ Lib9c/Model/State/AvatarState.cs | 2 +- Lib9c/Model/State/RuneSlotState.cs | 3 +-- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Lib9c/Action/HackAndSlash.cs b/Lib9c/Action/HackAndSlash.cs index e0f5b5d439..63bd06a03b 100644 --- a/Lib9c/Action/HackAndSlash.cs +++ b/Lib9c/Action/HackAndSlash.cs @@ -531,6 +531,12 @@ public IWorld Execute( states = states.SetRuneState(AvatarAddress, runeStates); } + // just validate + foreach (var runeSlotInfo in RuneInfos) + { + runeStates.GetRuneState(runeSlotInfo.RuneId); + } + slotstateActivity?.Dispose(); sw.Stop(); Log.Verbose("{AddressesHex} {Source} HAS {Process} from #{BlockIndex}: {Elapsed}", diff --git a/Lib9c/Action/HackAndSlashSweep.cs b/Lib9c/Action/HackAndSlashSweep.cs index ff49a0a35e..a5d6ad6383 100644 --- a/Lib9c/Action/HackAndSlashSweep.cs +++ b/Lib9c/Action/HackAndSlashSweep.cs @@ -236,6 +236,12 @@ public override IWorld Execute(IActionContext context) states = states.SetRuneState(avatarAddress, runeStates); } + // just validate + foreach (var runeSlotInfo in runeInfos) + { + runeStates.GetRuneState(runeSlotInfo.RuneId); + } + var equippedRune = new List(); foreach (var runeInfo in runeSlotState.GetEquippedRuneSlotInfos()) { diff --git a/Lib9c/Action/Raid.cs b/Lib9c/Action/Raid.cs index 4092627a26..3e6a335749 100644 --- a/Lib9c/Action/Raid.cs +++ b/Lib9c/Action/Raid.cs @@ -227,6 +227,12 @@ public override IWorld Execute(IActionContext context) states = states.SetRuneState(AvatarAddress, runeStates); } + // just validate + foreach (var runeSlotInfo in RuneInfos) + { + runeStates.GetRuneState(runeSlotInfo.RuneId); + } + var collectionModifiers = new List(); if (collectionExist) { diff --git a/Lib9c/Model/State/AvatarState.cs b/Lib9c/Model/State/AvatarState.cs index 68b9f1ff03..c0d9ba0c9f 100644 --- a/Lib9c/Model/State/AvatarState.cs +++ b/Lib9c/Model/State/AvatarState.cs @@ -755,7 +755,7 @@ public List ValidateEquipmentsV3(List equipmentIds, long blockI { if (!inventory.TryGetNonFungibleItem(itemId, out ItemUsable outNonFungibleItem)) { - continue; + throw new ItemDoesNotExistException($"Equipment {itemId} does not exist."); } var equipment = (Equipment)outNonFungibleItem; diff --git a/Lib9c/Model/State/RuneSlotState.cs b/Lib9c/Model/State/RuneSlotState.cs index 478ab1c7ce..123122e96c 100644 --- a/Lib9c/Model/State/RuneSlotState.cs +++ b/Lib9c/Model/State/RuneSlotState.cs @@ -6,7 +6,6 @@ using Nekoyume.Action; using Nekoyume.Model.EnumType; using Nekoyume.Model.Rune; -using Nekoyume.TableData; using Nekoyume.TableData.Rune; namespace Nekoyume.Model.State @@ -18,7 +17,7 @@ public static Address DeriveAddress(Address avatarAddress, BattleType battleType public BattleType BattleType { get; } - private readonly List _slots = new List(); + private readonly List _slots = new(); public RuneSlotState(BattleType battleType) { From 8e959cbd07977b020206cd8df08fe880ce9a03a2 Mon Sep 17 00:00:00 2001 From: eugene-hong <58686228+eugene-doobu@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:05:50 +0900 Subject: [PATCH 2/7] add item slot throw --- Lib9c/Model/State/AvatarState.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib9c/Model/State/AvatarState.cs b/Lib9c/Model/State/AvatarState.cs index c0d9ba0c9f..4afe740992 100644 --- a/Lib9c/Model/State/AvatarState.cs +++ b/Lib9c/Model/State/AvatarState.cs @@ -622,7 +622,7 @@ public void ValidateEquipments(List equipmentIds, long blockIndex) { if (!inventory.TryGetNonFungibleItem(itemId, out ItemUsable outNonFungibleItem)) { - continue; + throw new ItemDoesNotExistException($"Equipment {itemId} does not exist."); } var equipment = (Equipment) outNonFungibleItem; @@ -673,7 +673,7 @@ public List ValidateEquipmentsV2(List equipmentIds, long blockI { if (!inventory.TryGetNonFungibleItem(itemId, out ItemUsable outNonFungibleItem)) { - continue; + throw new ItemDoesNotExistException($"Equipment {itemId} does not exist."); } var equipment = (Equipment)outNonFungibleItem; From bd554bd3bc353b2deb8b983971f21f0560f34f8e Mon Sep 17 00:00:00 2001 From: eugene-hong <58686228+eugene-doobu@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:11:29 +0900 Subject: [PATCH 3/7] add rune validate for adventure boss and event dungeon --- Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs | 11 +++++++++++ Lib9c/Action/EventDungeonBattle.cs | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs b/Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs index 88d2ad2e47..906c15be5b 100644 --- a/Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs +++ b/Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs @@ -272,6 +272,17 @@ public override IWorld Execute(IActionContext context) break; } + // just validate + foreach (var runeSlotInfo in runeSlotState.GetRuneSlot()) + { + if (runeSlotInfo.RuneId is null) + { + continue; + } + + runeStates.GetRuneState(runeSlotInfo.RuneId.Value); + } + exploreBoard.UsedApPotion += exploreAp; explorer.UsedApPotion += exploreAp; diff --git a/Lib9c/Action/EventDungeonBattle.cs b/Lib9c/Action/EventDungeonBattle.cs index 4facbc1662..fd621050cd 100644 --- a/Lib9c/Action/EventDungeonBattle.cs +++ b/Lib9c/Action/EventDungeonBattle.cs @@ -346,6 +346,12 @@ is Bencodex.Types.List serializedEventDungeonInfoList states = states.SetRuneState(AvatarAddress, runeStates); } + // just validate + foreach (var runeSlotInfo in RuneInfos) + { + runeStates.GetRuneState(runeSlotInfo.RuneId); + } + var random = context.GetRandom(); var collectionModifiers = new List(); if (collectionExist) From 0144b54ed28be9972f006f10c10fd39d0ab68a11 Mon Sep 17 00:00:00 2001 From: eugene-hong <58686228+eugene-doobu@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:38:02 +0900 Subject: [PATCH 4/7] fix rune validtate --- .../AdventureBoss/ExploreAdventureBoss.cs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs b/Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs index 906c15be5b..7c10bd5328 100644 --- a/Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs +++ b/Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs @@ -210,6 +210,12 @@ public override IWorld Execute(IActionContext context) states = states.SetRuneState(AvatarAddress, runeStates); } + // just validate + foreach (var runeSlotInfo in RuneInfos) + { + runeStates.GetRuneState(runeSlotInfo.RuneId); + } + var collectionExist = states.TryGetCollectionState(AvatarAddress, out var collectionState) && collectionState.Ids.Any(); @@ -272,17 +278,6 @@ public override IWorld Execute(IActionContext context) break; } - // just validate - foreach (var runeSlotInfo in runeSlotState.GetRuneSlot()) - { - if (runeSlotInfo.RuneId is null) - { - continue; - } - - runeStates.GetRuneState(runeSlotInfo.RuneId.Value); - } - exploreBoard.UsedApPotion += exploreAp; explorer.UsedApPotion += exploreAp; 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 5/7] 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, From b2ee98a79c7ff7289061afd4d9a10d44082e8624 Mon Sep 17 00:00:00 2001 From: eugene-hong <58686228+eugene-doobu@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:40:58 +0900 Subject: [PATCH 6/7] unequippement inventory items on test adventure boss --- .../AdventureBoss/ExploreAdventureBossTest.cs | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/.Lib9c.Tests/Action/AdventureBoss/ExploreAdventureBossTest.cs b/.Lib9c.Tests/Action/AdventureBoss/ExploreAdventureBossTest.cs index 71926ca7b9..329f7d3bf8 100644 --- a/.Lib9c.Tests/Action/AdventureBoss/ExploreAdventureBossTest.cs +++ b/.Lib9c.Tests/Action/AdventureBoss/ExploreAdventureBossTest.cs @@ -218,15 +218,6 @@ Type exc : new ItemSlotState(BattleType.Adventure); Assert.True(itemSlotState.Equipments.Count == 0); - var previousAvatarState = _initialState.GetAvatarState(TesterAvatarAddress); - var equipments = Doomfist.GetAllParts(TableSheets, previousAvatarState.level); - foreach (var equipment in equipments) - { - 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; @@ -256,7 +247,7 @@ Type exc Season = 1, AvatarAddress = TesterAvatarAddress, Costumes = new List(), - Equipments = equipments.Select(e => e.NonFungibleId).ToList(), + Equipments = new List(), Foods = new List(), RuneInfos = new List(), }; @@ -337,12 +328,6 @@ out var items Assert.True( amount * currency <= state.GetBalance(TesterAvatarAddress, currency)); } - - itemSlotState = - state.TryGetLegacyState(itemSlotStateAddress, out rawItemSlotState) - ? new ItemSlotState(rawItemSlotState) - : new ItemSlotState(BattleType.Adventure); - Assert.True(itemSlotState.Equipments.Count > 0); } } From efb005884c3d63d84b47f46fb48a1b99870b3ac2 Mon Sep 17 00:00:00 2001 From: eugene-hong <58686228+eugene-doobu@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:47:51 +0900 Subject: [PATCH 7/7] remove test case for lock equipment --- .Lib9c.Tests/Action/HackAndSlashTest.cs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/.Lib9c.Tests/Action/HackAndSlashTest.cs b/.Lib9c.Tests/Action/HackAndSlashTest.cs index e5e9fb4a22..a7d1532d95 100644 --- a/.Lib9c.Tests/Action/HackAndSlashTest.cs +++ b/.Lib9c.Tests/Action/HackAndSlashTest.cs @@ -102,14 +102,12 @@ public HackAndSlashTest() } [Theory] - [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 2, false, true)] - [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 2, true, true)] - [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, false, true)] - [InlineData(200, 1, GameConfig.RequireClearedStageLevel.ActionsInRankingBoard, false, true)] - [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, false, false)] - [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, true, false)] - [InlineData(200, 1, GameConfig.RequireClearedStageLevel.ActionsInRankingBoard, false, false)] - public void Execute(int avatarLevel, int worldId, int stageId, bool isWeaponLock, bool isClearedBefore) + [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 2, true)] + [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, true)] + [InlineData(200, 1, GameConfig.RequireClearedStageLevel.ActionsInRankingBoard, true)] + [InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, false)] + [InlineData(200, 1, GameConfig.RequireClearedStageLevel.ActionsInRankingBoard, false)] + public void Execute(int avatarLevel, int worldId, int stageId, bool isClearedBefore) { Assert.True(_tableSheets.WorldSheet.TryGetValue(worldId, out var worldRow)); Assert.True(stageId >= worldRow.StageBegin); @@ -145,10 +143,7 @@ public void Execute(int avatarLevel, int worldId, int stageId, bool isWeaponLock var equipments = Doomfist.GetAllParts(_tableSheets, previousAvatarState.level); foreach (var equipment in equipments) { - var iLock = equipment.ItemSubType == ItemSubType.Weapon && isWeaponLock - ? new OrderLock(Guid.NewGuid()) - : (ILock)null; - previousAvatarState.inventory.AddItem(equipment, iLock: iLock); + previousAvatarState.inventory.AddItem(equipment, iLock: null); } var mailEquipmentRow = _tableSheets.EquipmentItemSheet.Values.First(); @@ -198,7 +193,6 @@ public void Execute(int avatarLevel, int worldId, int stageId, bool isWeaponLock Assert.True(nextAvatarState.worldInformation.IsStageCleared(stageId)); Assert.Equal(30, nextAvatarState.mailBox.Count); - Assert.Equal(!isWeaponLock, nextAvatarState.inventory.Equipments.OfType().Any(w => w.equipped)); } [Theory]