From 46e9e968a7d0f78e60c6630f80b050fd46ea03bb Mon Sep 17 00:00:00 2001 From: tyrosine1153 Date: Fri, 4 Oct 2024 15:26:11 +0900 Subject: [PATCH] update test code and StageSheet to check tradable --- .Lib9c.Tests/Action/EventDungeonBattleTest.cs | 60 +++++++++++++++ .Lib9c.Tests/Action/HackAndSlashSweepTest.cs | 74 +++++++++++++++++++ .Lib9c.Tests/Action/HackAndSlashTest.cs | 14 +++- .../TableCSV/Event/EventDungeonStageSheet.csv | 2 +- Lib9c/TableCSV/WorldAndStage/StageSheet.csv | 10 +-- 5 files changed, 152 insertions(+), 8 deletions(-) diff --git a/.Lib9c.Tests/Action/EventDungeonBattleTest.cs b/.Lib9c.Tests/Action/EventDungeonBattleTest.cs index 9106b46ca2..2fec4ba2d6 100644 --- a/.Lib9c.Tests/Action/EventDungeonBattleTest.cs +++ b/.Lib9c.Tests/Action/EventDungeonBattleTest.cs @@ -13,6 +13,7 @@ namespace Lib9c.Tests.Action using Nekoyume.Exceptions; using Nekoyume.Extensions; using Nekoyume.Model.Event; + using Nekoyume.Model.Item; using Nekoyume.Model.Rune; using Nekoyume.Model.State; using Nekoyume.Module; @@ -427,6 +428,65 @@ public void Execute_V100301() eventDungeonInfo.RemainingTickets); } + [Theory] + [InlineData(1001, 10010001, 10010001)] + public void CheckRewardItems( + int eventScheduleId, + int eventDungeonId, + int eventDungeonStageId) + { + Assert.True(_tableSheets.EventScheduleSheet + .TryGetValue(eventScheduleId, out var scheduleRow)); + var contextBlockIndex = scheduleRow.StartBlockIndex; + + var avatarState = _initialStates.GetAvatarState(_avatarAddress); + var equipments = Doomfist.GetAllParts(_tableSheets, avatarState.level); + foreach (var equipment in equipments) + { + avatarState.inventory.AddItem(equipment); + } + + var state = _initialStates.SetAvatarState(_avatarAddress, avatarState); + var action = new EventDungeonBattle + { + AvatarAddress = _avatarAddress, + EventScheduleId = eventScheduleId, + EventDungeonId = eventDungeonId, + EventDungeonStageId = eventDungeonStageId, + Equipments = equipments + .Select(e => e.NonFungibleId) + .ToList(), + Costumes = new List(), + Foods = new List(), + RuneInfos = new List(), + BuyTicketIfNeeded = false, + }; + + var nextState = action.Execute(new ActionContext + { + PreviousState = state, + Signer = _agentAddress, + RandomSeed = 0, + BlockIndex = contextBlockIndex, + }); + var nextAvatar = nextState.GetAvatarState(_avatarAddress); + + var stageSheet = nextState.GetSheet(); + if (!stageSheet.TryGetValue(eventDungeonStageId, out var stageRow)) + { + throw new SheetRowNotFoundException(nameof(EventDungeonStageSheet), eventDungeonStageId); + } + + var materialItemSheet = nextState.GetSheet(); + var circleRow = materialItemSheet.Values.First(i => i.ItemSubType == ItemSubType.Circle); + var circleRewardData = stageRow.Rewards.FirstOrDefault(reward => reward.ItemId == circleRow.Id); + if (circleRewardData != null) + { + var circles = nextAvatar.inventory.Items.Where(x => x.item.Id == circleRow.Id); + Assert.All(circles, x => Assert.True(x.item is TradableMaterial)); + } + } + private IWorld Execute( IWorld previousStates, int eventScheduleId, diff --git a/.Lib9c.Tests/Action/HackAndSlashSweepTest.cs b/.Lib9c.Tests/Action/HackAndSlashSweepTest.cs index dbc7515b9e..d3d4a9d957 100644 --- a/.Lib9c.Tests/Action/HackAndSlashSweepTest.cs +++ b/.Lib9c.Tests/Action/HackAndSlashSweepTest.cs @@ -597,6 +597,80 @@ public void ExecuteWithStake(int stakingLevel) } } + [Theory] + [InlineData(1, 15)] + [InlineData(2, 55)] + [InlineData(3, 111)] + [InlineData(4, 189)] + [InlineData(4, 200)] + [InlineData(5, 250)] + [InlineData(6, 300)] + public void CheckRewardItems(int worldId, int stageId) + { + const int apStoneCount = 10; + var avatarState = AvatarState.Create( + _avatarAddress, + _agentAddress, + 0, + _initialState.GetAvatarSheets(), + _rankingMapAddress); + avatarState.level = 400; + avatarState.worldInformation = + new WorldInformation(0, _initialState.GetSheet(), stageId); + + var materialSheet = _initialState.GetSheet(); + var itemRow = materialSheet.Values.First(r => r.ItemSubType == ItemSubType.ApStone); + var apStone = ItemFactory.CreateTradableMaterial(itemRow); + avatarState.inventory.AddItem(apStone, apStoneCount); + + var equipments = Doomfist.GetAllParts(_tableSheets, avatarState.level); + foreach (var equipment in equipments) + { + avatarState.inventory.AddItem(equipment); + } + + var state = _initialState + .SetAvatarState(_avatarAddress, avatarState) + .SetLegacyState( + _avatarAddress.Derive("world_ids"), + Enumerable.Range(1, worldId).ToList().Select(i => i.Serialize()).Serialize()) + .SetActionPoint(_avatarAddress, 120); + var stageSheet = _initialState.GetSheet(); + if (!stageSheet.TryGetValue(stageId, out var stageRow)) + { + throw new SheetRowNotFoundException(nameof(StageSheet), stageId); + } + + var actionPoint = _initialState.GetActionPoint(_avatarAddress); + var action = new HackAndSlashSweep + { + costumes = new List(), + equipments = equipments.Select(e => e.NonFungibleId).ToList(), + runeInfos = new List(), + avatarAddress = _avatarAddress, + actionPoint = (int)actionPoint, + apStoneCount = apStoneCount, + worldId = worldId, + stageId = stageId, + }; + + var nextState = action.Execute(new ActionContext + { + PreviousState = state, + Signer = _agentAddress, + RandomSeed = 0, + }); + var nextAvatar = nextState.GetAvatarState(_avatarAddress); + + var circleRow = materialSheet.Values.First(i => i.ItemSubType == ItemSubType.Circle); + var circleRewardData = stageRow.Rewards.FirstOrDefault(reward => reward.ItemId == circleRow.Id); + if (circleRewardData != null) + { + var circles = nextAvatar.inventory.Items.Where(x => x.item.Id == circleRow.Id); + Assert.All(circles, x => Assert.True(x.item is TradableMaterial)); + } + } + [Theory] [InlineData(0, 30001, 1, 30001, typeof(DuplicatedRuneIdException))] [InlineData(1, 10002, 1, 30001, typeof(DuplicatedRuneSlotIndexException))] diff --git a/.Lib9c.Tests/Action/HackAndSlashTest.cs b/.Lib9c.Tests/Action/HackAndSlashTest.cs index 792495826c..9d61aab639 100644 --- a/.Lib9c.Tests/Action/HackAndSlashTest.cs +++ b/.Lib9c.Tests/Action/HackAndSlashTest.cs @@ -14,7 +14,6 @@ namespace Lib9c.Tests.Action using Nekoyume; using Nekoyume.Action; using Nekoyume.Battle; - using Nekoyume.Blockchain.Policy; using Nekoyume.Extensions; using Nekoyume.Model; using Nekoyume.Model.Item; @@ -26,7 +25,7 @@ namespace Lib9c.Tests.Action using Nekoyume.Module; using Nekoyume.TableData; using Xunit; - using static Lib9c.SerializeKeys; + using static SerializeKeys; public class HackAndSlashTest { @@ -984,6 +983,9 @@ public void ExecuteThrowNotEnoughMaterialException() [InlineData(2, 55)] [InlineData(3, 111)] [InlineData(4, 189)] + [InlineData(4, 200)] + [InlineData(5, 250)] + [InlineData(6, 300)] public void CheckRewardItems(int worldId, int stageId) { Assert.True(_tableSheets.WorldSheet.TryGetValue(worldId, out var worldRow)); @@ -1098,6 +1100,14 @@ x.item is IFungibleItem ownedFungibleItem && var totalMax = max * stageRow.DropItemMax + questSum; var totalCount = rewardItem.Sum(x => x.count); Assert.InRange(totalCount, totalMin, totalMax); + + var circleRow = materialItemSheet.Values.First(i => i.ItemSubType == ItemSubType.Circle); + var circleRewardData = stageRow.Rewards.FirstOrDefault(reward => reward.ItemId == circleRow.Id); + if (circleRewardData != null) + { + var circles = nextAvatarState.inventory.Items.Where(x => x.item.Id == circleRow.Id); + Assert.All(circles, x => Assert.True(x.item is TradableMaterial)); + } } [Theory] diff --git a/Lib9c/TableCSV/Event/EventDungeonStageSheet.csv b/Lib9c/TableCSV/Event/EventDungeonStageSheet.csv index 476085e721..e8977d575b 100644 --- a/Lib9c/TableCSV/Event/EventDungeonStageSheet.csv +++ b/Lib9c/TableCSV/Event/EventDungeonStageSheet.csv @@ -1,5 +1,5 @@ id,cost_ap,turn_limit,hp_option,atk_option,def_option,cri_option,hit_option,spd_option,background,bgm,item1,item1_ratio,item1_min,item1_max,item2,item2_ratio,item2_min,item2_max,item3,item3_ratio,item3_min,item3_max,item4,item4_ratio,item4_min,item4_max,item5,item5_ratio,item5_min,item5_max,item6,item6_ratio,item6_min,item6_max,item7,item7_ratio,item7_min,item7_max,item8,item8_ratio,item8_min,item8_max,item9,item9_ratio,item9_min,item9_max,item10,item10_ratio,item10_min,item10_max,min_drop,max_drop -10010001,5,150,60,60,60,0,60,60,EventDungeon_01_01,bgm_event_22summer_01,800101,0.2,1,1,800102,0.1,1,1,800104,0.1,1,1,400000,0.4,20,20,500000,0.1,1,1,800103,0.1,1,1,,,,,,,,,,,,,,,,,8,16 +10010001,5,150,60,60,60,0,60,60,EventDungeon_01_01,bgm_event_22summer_01,800101,0.2,1,1,800102,0.1,1,1,800104,0.1,1,1,400000,0.4,20,20,500000,0.1,1,1,800103,0.1,1,1,600402,1,1,1,,,,,,,,,,,,,8,16 10010002,5,150,60,60,60,0,60,60,EventDungeon_01_01,bgm_event_22summer_01,800101,0.2,1,1,800102,0.1,1,1,800104,0.1,1,1,400000,0.4,20,20,500000,0.1,1,1,800103,0.1,1,1,,,,,,,,,,,,,,,,,8,16 10010003,5,150,60,60,60,0,60,60,EventDungeon_01_01,bgm_event_22summer_01,800101,0.2,1,1,800102,0.1,1,1,800104,0.1,1,1,400000,0.4,20,20,500000,0.1,1,1,800103,0.1,1,1,,,,,,,,,,,,,,,,,8,16 10010004,5,150,60,60,60,0,60,60,EventDungeon_01_01,bgm_event_22summer_01,800101,0.2,1,2,800102,0.1,1,1,800104,0.1,1,2,400000,0.4,20,20,500000,0.1,1,1,800103,0.1,1,2,,,,,,,,,,,,,,,,,8,16 diff --git a/Lib9c/TableCSV/WorldAndStage/StageSheet.csv b/Lib9c/TableCSV/WorldAndStage/StageSheet.csv index 2fce781595..531150a366 100644 --- a/Lib9c/TableCSV/WorldAndStage/StageSheet.csv +++ b/Lib9c/TableCSV/WorldAndStage/StageSheet.csv @@ -198,7 +198,7 @@ id,cost_ap,turn_limit,hp_additional,atk_additional,def_additional,cri_additional 197,5,150,261,295,258,0,431,357,chapter_04_03,bgm_asgard_03,303002,0.1,1,2,303203,0.1,1,2,303402,0.1,1,2,306054,0.5,2,3,306035,0.12,1,2,306037,0.08,1,1,,,,,,,,,,,,,,,,,3,4 198,5,150,265,300,262,0,403,333,chapter_04_03,bgm_asgard_03,303203,0.1,1,2,303302,0.1,1,2,303402,0.1,1,2,306017,0.5,2,3,306035,0.12,1,2,306038,0.08,1,1,,,,,,,,,,,,,,,,,3,4 199,5,150,269,305,266,0,393,327,chapter_04_03,bgm_asgard_03,303203,0.1,1,2,303302,0.1,1,2,303402,0.1,1,2,306007,0.5,2,3,306035,0.12,1,2,306039,0.08,1,1,,,,,,,,,,,,,,,,,3,4 -200,5,150,273,310,270,0,437,364,chapter_04_03,bgm_asgard_03,600101,0.42,2,2,600102,0.41,2,2,600103,0.17,1,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,4,4 +200,5,150,273,310,270,0,437,364,chapter_04_03,bgm_asgard_03,303002,0.1,1,2,303203,0.1,1,2,303302,0.1,1,2,306029,0.5,2,3,306035,0.12,1,2,306036,0.08,1,1,,,,,,,,,,,,,,,,,3,4 201,5,150,108,198,135,0,432,360,chapter_05_01,bgm_muspelheim_01,303002,0.223,1,1,303102,0.223,1,1,303201,0.223,1,1,306017,0.3,1,2,306045,0.024,1,1,306048,0.007,1,1,,,,,,,,,,,,,,,,,1,2 202,5,150,109,198,135,0,474,395,chapter_05_01,bgm_muspelheim_01,303102,0.223,1,1,303301,0.223,1,1,303401,0.223,1,1,306015,0.3,1,2,306045,0.024,1,1,306048,0.007,1,1,,,,,,,,,,,,,,,,,1,2 203,5,150,109,194,135,0,630,382,chapter_05_02,bgm_muspelheim_02,303102,0.223,1,1,303201,0.223,1,1,303301,0.223,1,1,306055,0.3,1,2,306045,0.024,1,1,306047,0.007,1,1,,,,,,,,,,,,,,,,,1,2 @@ -248,7 +248,7 @@ id,cost_ap,turn_limit,hp_additional,atk_additional,def_additional,cri_additional 247,5,150,989,858,669,0,1164,803,chapter_05_01,bgm_muspelheim_01,303002,0.215,1,1,303102,0.215,1,1,303303,0.215,1,1,306029,0.3,1,2,306045,0.042,1,1,306046,0.013,1,1,,,,,,,,,,,,,,,,,1,2 248,5,150,1019,902,686,0,1212,805,chapter_05_02,bgm_muspelheim_02,303002,0.215,1,1,303102,0.215,1,1,303303,0.215,1,1,306031,0.3,1,2,306045,0.042,1,1,306046,0.013,1,1,,,,,,,,,,,,,,,,,1,2 249,5,150,1050,946,703,0,1177,807,chapter_05_01,bgm_muspelheim_01,303002,0.215,1,1,303203,0.215,1,1,303303,0.215,1,1,306030,0.3,1,2,306045,0.042,1,1,306046,0.013,1,1,,,,,,,,,,,,,,,,,1,2 -250,5,150,1080,990,720,0,1260,809,chapter_05_03,bgm_muspelheim_03,600101,0.4,3,3,600102,0.38,3,3,600103,0.2,1,2,600104,0.02,1,1,,,,,,,,,,,,,,,,,,,,,,,,,3,3 +250,5,150,1080,990,720,0,1260,809,chapter_05_03,bgm_muspelheim_03,303002,0.214,1,1,303102,0.214,1,1,303203,0.214,1,1,306030,0.3,1,2,306045,0.044,1,1,306046,0.014,1,1,,,,,,,,,,,,,,,,,1,2 251,5,150,446,559,381,0,1248,1248,chapter_06_01,bgm_jotunheim_01,303202,1,3,3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2,3 252,5,150,453,527,383,0,1265,1265,chapter_06_01,bgm_jotunheim_01,303003,1,3,3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,3 253,5,150,456,527,384,0,1283,1283,chapter_06_02,bgm_jotunheim_02,303003,0.43,1,2,306055,0.5,3,3,306045,0.05,1,1,306046,0.02,1,1,,,,,,,,,,,,,,,,,,,,,,,,,1,3 @@ -298,7 +298,7 @@ id,cost_ap,turn_limit,hp_additional,atk_additional,def_additional,cri_additional 297,5,150,2087,1494,1082,0,2046,2046,chapter_06_01,bgm_jotunheim_01,303403,0.43,1,2,306053,0.5,3,3,306045,0.05,1,1,306049,0.03,1,1,,,,,,,,,,,,,,,,,,,,,,,,,1,3 298,5,150,2106,1509,1086,0,1901,1901,chapter_06_02,bgm_jotunheim_02,303403,0.43,1,2,306054,0.5,3,3,306045,0.05,1,1,306048,0.03,1,1,,,,,,,,,,,,,,,,,,,,,,,,,1,3 299,5,150,2127,1524,1090,0,2028,2028,chapter_06_01,bgm_jotunheim_01,303003,0.43,1,2,306055,0.5,3,3,306045,0.05,1,1,306047,0.03,1,1,,,,,,,,,,,,,,,,,,,,,,,,,1,3 -300,5,150,2147,1539,1094,0,2046,2046,chapter_06_03,bgm_jotunheim_03,600101,0.4,3,3,600102,0.38,3,3,600103,0.2,1,2,600104,0.02,1,2,,,,,,,,,,,,,,,,,,,,,,,,,6,6 +300,5,150,2147,1539,1094,0,2046,2046,chapter_06_03,bgm_jotunheim_03,303003,0.75,3,3,306045,0.1,3,3,306046,0.05,1,1,306049,0.05,1,1,306048,0.05,1,1,600402,0.05,1,1,,,,,,,,,,,,,,,,,2,3 301,5,150,1101,875,129,0,2008,1800,chapter_07_01,bgm_niflheim_01,303004,1,4,4,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,4,4 302,5,150,1121,894,134,0,2073,1814,chapter_07_01,bgm_niflheim_01,303004,0.4,1,1,306075,0.45,2,3,306070,0.1,1,1,306071,0.05,1,1,,,,,,,,,,,,,,,,,,,,,,,,,2,3 303,5,150,1131,904,136,0,2138,1828,chapter_07_02,bgm_niflheim_02,303004,0.4,1,1,306075,0.45,2,3,306070,0.1,1,1,306071,0.05,1,1,,,,,,,,,,,,,,,,,,,,,,,,,2,3 @@ -348,7 +348,7 @@ id,cost_ap,turn_limit,hp_additional,atk_additional,def_additional,cri_additional 347,5,150,2609,2346,2210,0,9396,3110,chapter_07_01,bgm_niflheim_01,303104,0.4,2,3,306070,0.2,1,1,306071,0.1,1,1,306074,0.1,1,1,306073,0.1,1,1,306072,0.1,1,1,306072,0.1,1,1,,,,,,,,,,,,,2,3 348,5,150,2653,2482,2229,0,10044,3369,chapter_07_02,bgm_niflheim_02,303204,0.4,2,3,306070,0.2,1,1,306071,0.1,1,1,306074,0.1,1,1,306073,0.1,1,1,306072,0.1,1,1,306072,0.1,1,1,,,,,,,,,,,,,2,3 349,5,150,2697,2618,2248,0,10368,3628,chapter_07_01,bgm_niflheim_01,303304,0.4,2,3,306070,0.2,1,1,306071,0.1,1,1,306074,0.1,1,1,306073,0.1,1,1,306072,0.1,1,1,306072,0.1,1,1,,,,,,,,,,,,,2,3 -350,5,150,2741,2754,2268,0,10692,3888,chapter_07_03,bgm_niflheim_03,600101,0.39,3,3,600102,0.38,3,3,600103,0.2,2,2,600104,0.02,1,3,,,,,,,,,,,,,,,,,,,,,,,,,6,6 +350,5,150,2741,2754,2268,0,10692,3888,chapter_07_03,bgm_niflheim_03,303404,0.4,2,3,306070,0.2,1,1,306071,0.1,1,1,306074,0.1,1,1,306073,0.1,1,1,306072,0.1,1,1,306072,0.1,1,1,600402,0.1,1,1,,,,,,,,,6,6 351,5,150,1620,518,648,0,6868,2786,chapter_08_01,bgm_hel_01,303005,1,2,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2,2 352,5,150,1620,518,648,0,6868,2786,chapter_08_01,bgm_hel_01,303005,0.4,1,1,306090,0.45,2,3,306086,0.05,1,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,2 353,5,150,1620,518,648,0,6868,2786,chapter_08_02,bgm_hel_02,303005,0.4,1,1,306090,0.45,2,3,306086,0.05,1,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,2 @@ -398,7 +398,7 @@ id,cost_ap,turn_limit,hp_additional,atk_additional,def_additional,cri_additional 397,5,150,14133,18760,12338,0,85374,12506,chapter_08_01,bgm_hel_01,303105,0.4,1,2,306091,0.3,1,2,306096,0.3,1,2,306089,0.05,1,1,,,,,,,,,,,,,,,,,,,,,,,,,1,3 398,5,150,14671,19245,12804,0,90396,13089,chapter_08_02,bgm_hel_02,303105,0.4,1,2,306091,0.3,1,2,306096,0.3,1,2,306089,0.05,1,1,,,,,,,,,,,,,,,,,,,,,,,,,1,3 399,5,150,15208,19732,13271,0,95418,13672,chapter_08_01,bgm_hel_01,303005,0.4,1,2,306090,0.3,1,2,306095,0.3,1,2,306089,0.05,1,1,,,,,,,,,,,,,,,,,,,,,,,,,1,3 -400,5,150,15746,20217,13737,0,100440,14256,chapter_08_03,bgm_hel_03,303005,0.4,1,2,306090,0.3,1,2,306095,0.3,1,2,306089,0.05,1,1,,,,,,,,,,,,,,,,,,,,,,,,,1,3 +400,5,150,15746,20217,13737,0,100440,14256,chapter_08_03,bgm_hel_03,303005,0.4,1,2,306090,0.3,1,2,306095,0.3,1,2,306089,0.05,1,1,600402,0.15,1,1,,,,,,,,,,,,,,,,,,,,,6,6 10000001,10,150,184,132,132,0,184,132,chapter_99_01,bgm_hard1,303200,0.15,1,1,306064,0.25,1,2,306065,0.1,1,2,306058,0.4,1,1,306059,0.1,1,1,,,,,,,,,,,,,,,,,,,,,4,4 10000002,10,150,228,163,163,0,228,163,chapter_99_01,bgm_hard2,303200,0.15,1,1,306064,0.25,1,2,306065,0.1,1,2,306058,0.4,1,1,306059,0.1,1,1,,,,,,,,,,,,,,,,,,,,,4,4 10000003,10,150,245,175,175,0,245,175,chapter_99_01,bgm_hard1,303200,0.15,1,1,306064,0.25,1,2,306065,0.1,1,2,306058,0.4,1,1,306059,0.1,1,1,,,,,,,,,,,,,,,,,,,,,4,4