Skip to content

Commit

Permalink
add Equipments duplicate check
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrosine1153 committed Sep 13, 2024
1 parent dfdda6b commit c9ef100
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
17 changes: 11 additions & 6 deletions .Lib9c.Tests/Action/GrindingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ public void Execute_Success(int itemLevel, int equipmentCount, bool equipped, in
.SetAgentState(_agentAddress, _agentState)
.SetActionPoint(_avatarAddress, 120);

var testRandom = new TestRandom();
var itemRow = _tableSheets.EquipmentItemSheet.Values.First(r => r.Grade == 1);
for (int i = 0; i < equipmentCount; i++)
{
var equipment = (Equipment)ItemFactory.CreateItemUsable(itemRow, default, 1, itemLevel);
var equipment = (Equipment)ItemFactory.CreateItemUsable(itemRow, testRandom.GenerateRandomGuid(), 1, itemLevel);
equipment.equipped = equipped;
_avatarState.inventory.AddItem(equipment);
}
Expand Down Expand Up @@ -126,8 +127,9 @@ public void Execute_Success_With_StakeState(
.SetAgentState(_agentAddress, _agentState)
.SetActionPoint(_avatarAddress, 120);

var testRandom = new TestRandom();
var itemRow = _tableSheets.EquipmentItemSheet.Values.First(r => r.Grade == 1);
var equipment = (Equipment)ItemFactory.CreateItemUsable(itemRow, default, 1, itemLevel);
var equipment = (Equipment)ItemFactory.CreateItemUsable(itemRow, testRandom.GenerateRandomGuid(), 1, itemLevel);
equipment.equipped = false;
_avatarState.inventory.AddItem(equipment);

Expand Down Expand Up @@ -191,8 +193,9 @@ Type exc
.SetAgentState(_agentAddress, _agentState)
.SetActionPoint(_avatarAddress, ap);

var testRandom = new TestRandom();
var itemRow = _tableSheets.EquipmentItemSheet.Values.First(r => r.Grade == 1);
var equipment = (Equipment)ItemFactory.CreateItemUsable(itemRow, default, 1);
var equipment = (Equipment)ItemFactory.CreateItemUsable(itemRow, testRandom.GenerateRandomGuid(), 1);
equipment.equipped = false;
_avatarState.inventory.AddItem(equipment);

Expand Down Expand Up @@ -281,17 +284,18 @@ public void Execute_Throw_Equipment_Exception(bool equipmentExist, long required
.SetAgentState(_agentAddress, _agentState)
.SetActionPoint(_avatarAddress, 120);

var testRandom = new TestRandom();
if (equipmentExist)
{
var itemRow = _tableSheets.EquipmentItemSheet.Values.First(r => r.Grade == 1);
var equipment = (Equipment)ItemFactory.CreateItemUsable(itemRow, default, requiredBlockIndex);
var equipment = (Equipment)ItemFactory.CreateItemUsable(itemRow, testRandom.GenerateRandomGuid(), requiredBlockIndex);
equipment.equipped = false;
_avatarState.inventory.AddItem(equipment);
}
else
{
var itemRow = _tableSheets.ConsumableItemSheet.Values.First(r => r.Grade == 1);
var consumable = (Consumable)ItemFactory.CreateItemUsable(itemRow, default, requiredBlockIndex);
var consumable = (Consumable)ItemFactory.CreateItemUsable(itemRow, testRandom.GenerateRandomGuid(), requiredBlockIndex);
_avatarState.inventory.AddItem(consumable);
}

Expand Down Expand Up @@ -346,10 +350,11 @@ private static IWorld Execute(
int rewardMaterialCount,
MaterialItemSheet materialItemSheet)
{
var testRandom = new TestRandom();
var equipmentIds = new List<Guid>();
for (int i = 0; i < equipmentCount; i++)
{
equipmentIds.Add(default);
equipmentIds.Add(testRandom.GenerateRandomGuid());
}

Assert.Equal(equipmentCount, equipmentIds.Count);
Expand Down
5 changes: 5 additions & 0 deletions Lib9c/Action/Grinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public override IWorld Execute(IActionContext context)
throw new InvalidItemCountException();
}

if (EquipmentIds.Count != EquipmentIds.Distinct().Count())
{
throw new InvalidItemCountException();
}

var agentState = states.GetAgentState(context.Signer);
if (agentState is null)
{
Expand Down

0 comments on commit c9ef100

Please sign in to comment.