Skip to content

Commit

Permalink
Merge branch 'development' into feature/rune-level-bonus
Browse files Browse the repository at this point in the history
  • Loading branch information
U-lis authored Apr 4, 2024
2 parents c1b8f2c + 7a3d932 commit af3f3aa
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 29 deletions.
11 changes: 6 additions & 5 deletions .Lib9c.Tests/Model/State/CollectionStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -14,20 +12,23 @@ public void Bencoded()
{
var state = new CollectionState
{
Ids = new List<int>
Ids = new SortedSet<int>
{
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<int> { 1, 2, 3, }, deserialized.Ids);
}
}
}
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Module/CollectionModuleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void CollectionState()

var state = new CollectionState
{
Ids = new List<int>
Ids = new SortedSet<int>
{
1,
},
Expand All @@ -47,7 +47,7 @@ public void CollectionStates()

var state = new CollectionState
{
Ids = new List<int>
Ids = new SortedSet<int>
{
1,
},
Expand Down
6 changes: 1 addition & 5 deletions Lib9c/Action/BattleArena.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
5 changes: 1 addition & 4 deletions Lib9c/Action/EventDungeonBattle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,7 @@ is Bencodex.Types.List serializedEventDungeonInfoList
if (collectionExist)
{
var collectionSheet = sheets.GetSheet<CollectionSheet>();
foreach (var collectionId in collectionState.Ids)
{
collectionModifiers.AddRange(collectionSheet[collectionId].StatModifiers);
}
collectionModifiers = collectionState.GetModifiers(collectionSheet);
}

var deBuffLimitSheet = sheets.GetSheet<DeBuffLimitSheet>();
Expand Down
5 changes: 1 addition & 4 deletions Lib9c/Action/HackAndSlash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,7 @@ public IWorld Execute(
if (collectionExist)
{
var collectionSheet = sheets.GetSheet<CollectionSheet>();
foreach (var collectionId in collectionState.Ids)
{
collectionModifiers.AddRange(collectionSheet[collectionId].StatModifiers);
}
collectionModifiers = collectionState.GetModifiers(collectionSheet);
}

var deBuffLimitSheet = sheets.GetSheet<DeBuffLimitSheet>();
Expand Down
5 changes: 1 addition & 4 deletions Lib9c/Action/HackAndSlashSweep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,7 @@ public override IWorld Execute(IActionContext context)
if (collectionExist)
{
var collectionSheet = sheets.GetSheet<CollectionSheet>();
foreach (var collectionId in collectionState.Ids)
{
collectionModifiers.AddRange(collectionSheet[collectionId].StatModifiers);
}
collectionModifiers = collectionState.GetModifiers(collectionSheet);
}

var costumeStatSheet = sheets.GetSheet<CostumeStatSheet>();
Expand Down
5 changes: 1 addition & 4 deletions Lib9c/Action/Raid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,7 @@ public override IWorld Execute(IActionContext context)
if (collectionExist)
{
var collectionSheet = sheets.GetSheet<CollectionSheet>();
foreach (var collectionId in collectionState.Ids)
{
collectionModifiers.AddRange(collectionSheet[collectionId].StatModifiers);
}
collectionModifiers = collectionState.GetModifiers(collectionSheet);
}
// Simulate.
var random = context.GetRandom();
Expand Down
15 changes: 14 additions & 1 deletion Lib9c/Model/State/CollectionState.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using Bencodex;
using Bencodex.Types;
using Nekoyume.Model.Stat;
using Nekoyume.TableData;

namespace Nekoyume.Model.State
{
Expand All @@ -9,7 +11,7 @@ namespace Nekoyume.Model.State
/// </summary>
public class CollectionState : IBencodable
{
public List<int> Ids = new();
public SortedSet<int> Ids = new();

public CollectionState()
{
Expand All @@ -29,5 +31,16 @@ public CollectionState(IValue bencoded) : this((List)bencoded)
}

public IValue Bencoded => List.Empty.Add(new List(Ids));

public List<StatModifier> GetModifiers(CollectionSheet collectionSheet)
{
var collectionModifiers = new List<StatModifier>();
foreach (var collectionId in Ids)
{
collectionModifiers.AddRange(collectionSheet[collectionId].StatModifiers);
}

return collectionModifiers;
}
}
}

0 comments on commit af3f3aa

Please sign in to comment.