diff --git a/.Lib9c.Tests/Model/State/CollectionStateTest.cs b/.Lib9c.Tests/Model/State/CollectionStateTest.cs index b02dc0cf4b..53c62cbd9a 100644 --- a/.Lib9c.Tests/Model/State/CollectionStateTest.cs +++ b/.Lib9c.Tests/Model/State/CollectionStateTest.cs @@ -2,8 +2,6 @@ namespace Lib9c.Tests.Model.State { using System.Collections.Generic; using Bencodex.Types; - using Libplanet.Crypto; - using Nekoyume.Action; using Nekoyume.Model.State; using Xunit; @@ -14,20 +12,23 @@ public void Bencoded() { var state = new CollectionState { - Ids = new List + Ids = new SortedSet { 1, + 3, + 1, + 2, 2, }, }; var serialized = state.Bencoded; var expected = List.Empty - .Add(List.Empty.Add(1).Add(2)); + .Add(List.Empty.Add(1).Add(2).Add(3)); Assert.Equal(expected, serialized); var deserialized = new CollectionState(serialized); - Assert.Equal(state.Ids, deserialized.Ids); + Assert.Equal(new SortedSet { 1, 2, 3, }, deserialized.Ids); } } } diff --git a/.Lib9c.Tests/Module/CollectionModuleTest.cs b/.Lib9c.Tests/Module/CollectionModuleTest.cs index a996886239..fe3e7c5cc5 100644 --- a/.Lib9c.Tests/Module/CollectionModuleTest.cs +++ b/.Lib9c.Tests/Module/CollectionModuleTest.cs @@ -22,7 +22,7 @@ public void CollectionState() var state = new CollectionState { - Ids = new List + Ids = new SortedSet { 1, }, @@ -47,7 +47,7 @@ public void CollectionStates() var state = new CollectionState { - Ids = new List + Ids = new SortedSet { 1, }, diff --git a/Lib9c/Action/BattleArena.cs b/Lib9c/Action/BattleArena.cs index b7f958979f..79f00cf2cc 100644 --- a/Lib9c/Action/BattleArena.cs +++ b/Lib9c/Action/BattleArena.cs @@ -397,11 +397,7 @@ public override IWorld Execute(IActionContext context) foreach (var (address, state) in collectionStates) #pragma warning restore LAA1002 { - var modifier = modifiers[address]; - foreach (var collectionId in state.Ids) - { - modifier.AddRange(collectionSheet[collectionId].StatModifiers); - } + modifiers[address] = state.GetModifiers(collectionSheet); } } for (var i = 0; i < ticket; i++) diff --git a/Lib9c/Action/EventDungeonBattle.cs b/Lib9c/Action/EventDungeonBattle.cs index 8e75818e83..f2be6660e6 100644 --- a/Lib9c/Action/EventDungeonBattle.cs +++ b/Lib9c/Action/EventDungeonBattle.cs @@ -341,10 +341,7 @@ is Bencodex.Types.List serializedEventDungeonInfoList if (collectionExist) { var collectionSheet = sheets.GetSheet(); - foreach (var collectionId in collectionState.Ids) - { - collectionModifiers.AddRange(collectionSheet[collectionId].StatModifiers); - } + collectionModifiers = collectionState.GetModifiers(collectionSheet); } var deBuffLimitSheet = sheets.GetSheet(); diff --git a/Lib9c/Action/HackAndSlash.cs b/Lib9c/Action/HackAndSlash.cs index b91cecc313..ea621a7809 100644 --- a/Lib9c/Action/HackAndSlash.cs +++ b/Lib9c/Action/HackAndSlash.cs @@ -473,10 +473,7 @@ public IWorld Execute( if (collectionExist) { var collectionSheet = sheets.GetSheet(); - foreach (var collectionId in collectionState.Ids) - { - collectionModifiers.AddRange(collectionSheet[collectionId].StatModifiers); - } + collectionModifiers = collectionState.GetModifiers(collectionSheet); } var deBuffLimitSheet = sheets.GetSheet(); diff --git a/Lib9c/Action/HackAndSlashSweep.cs b/Lib9c/Action/HackAndSlashSweep.cs index 17e9e8a638..6d5707f46b 100644 --- a/Lib9c/Action/HackAndSlashSweep.cs +++ b/Lib9c/Action/HackAndSlashSweep.cs @@ -256,10 +256,7 @@ public override IWorld Execute(IActionContext context) if (collectionExist) { var collectionSheet = sheets.GetSheet(); - foreach (var collectionId in collectionState.Ids) - { - collectionModifiers.AddRange(collectionSheet[collectionId].StatModifiers); - } + collectionModifiers = collectionState.GetModifiers(collectionSheet); } var costumeStatSheet = sheets.GetSheet(); diff --git a/Lib9c/Action/Raid.cs b/Lib9c/Action/Raid.cs index 8c742a96bd..a86a6201ad 100644 --- a/Lib9c/Action/Raid.cs +++ b/Lib9c/Action/Raid.cs @@ -217,10 +217,7 @@ public override IWorld Execute(IActionContext context) if (collectionExist) { var collectionSheet = sheets.GetSheet(); - foreach (var collectionId in collectionState.Ids) - { - collectionModifiers.AddRange(collectionSheet[collectionId].StatModifiers); - } + collectionModifiers = collectionState.GetModifiers(collectionSheet); } // Simulate. var random = context.GetRandom(); diff --git a/Lib9c/Model/State/CollectionState.cs b/Lib9c/Model/State/CollectionState.cs index b62af1ab83..1458e83bc4 100644 --- a/Lib9c/Model/State/CollectionState.cs +++ b/Lib9c/Model/State/CollectionState.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using Bencodex; using Bencodex.Types; +using Nekoyume.Model.Stat; +using Nekoyume.TableData; namespace Nekoyume.Model.State { @@ -9,7 +11,7 @@ namespace Nekoyume.Model.State /// public class CollectionState : IBencodable { - public List Ids = new(); + public SortedSet Ids = new(); public CollectionState() { @@ -29,5 +31,16 @@ public CollectionState(IValue bencoded) : this((List)bencoded) } public IValue Bencoded => List.Empty.Add(new List(Ids)); + + public List GetModifiers(CollectionSheet collectionSheet) + { + var collectionModifiers = new List(); + foreach (var collectionId in Ids) + { + collectionModifiers.AddRange(collectionSheet[collectionId].StatModifiers); + } + + return collectionModifiers; + } } }