Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/synthesize item #3001

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 114 additions & 20 deletions .Lib9c.Tests/Action/SynthesizeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,30 @@ public IWorld Init(out Address agentAddress, out Address avatarAddress, out long
}

[Theory]
[InlineData((Grade)3, new[] { ItemSubType.FullCostume, ItemSubType.FullCostume, ItemSubType.FullCostume, })]
[InlineData((Grade)4, new[] { ItemSubType.FullCostume, ItemSubType.FullCostume, ItemSubType.FullCostume, })]
[InlineData((Grade)5, new[] { ItemSubType.FullCostume, ItemSubType.FullCostume, ItemSubType.FullCostume, })]
[InlineData((Grade)3, new[] { ItemSubType.Title, ItemSubType.Title, ItemSubType.Title, })]
[InlineData((Grade)4, new[] { ItemSubType.Title, ItemSubType.Title, ItemSubType.Title, })]
[InlineData((Grade)5, new[] { ItemSubType.Title, ItemSubType.Title, ItemSubType.Title, })]
[InlineData((Grade)3, new[] { ItemSubType.Grimoire, ItemSubType.Grimoire, ItemSubType.Grimoire, })]
[InlineData((Grade)4, new[] { ItemSubType.Grimoire, ItemSubType.Grimoire, ItemSubType.Grimoire, })]
[InlineData((Grade)5, new[] { ItemSubType.Grimoire, ItemSubType.Grimoire, ItemSubType.Grimoire, })]
[InlineData((Grade)6, new[] { ItemSubType.Grimoire, ItemSubType.Grimoire, ItemSubType.Grimoire, })]
[InlineData((Grade)1, new[] { ItemSubType.Aura, ItemSubType.Aura, ItemSubType.Aura, })]
[InlineData((Grade)2, new[] { ItemSubType.Aura, ItemSubType.Aura, ItemSubType.Aura, })]
[InlineData((Grade)3, new[] { ItemSubType.Aura, ItemSubType.Aura, ItemSubType.Aura, })]
[InlineData((Grade)4, new[] { ItemSubType.Aura, ItemSubType.Aura, ItemSubType.Aura, })]
[InlineData((Grade)5, new[] { ItemSubType.Aura, ItemSubType.Aura, ItemSubType.Aura, })]
[InlineData((Grade)6, new[] { ItemSubType.Aura, ItemSubType.Aura, ItemSubType.Aura, })]
public void Execute(Grade grade, ItemSubType[] itemSubTypes)
[InlineData((Grade)3, ItemSubType.FullCostume)]
[InlineData((Grade)4, ItemSubType.FullCostume)]
[InlineData((Grade)5, ItemSubType.FullCostume)]
[InlineData((Grade)3, ItemSubType.Title)]
[InlineData((Grade)4, ItemSubType.Title)]
[InlineData((Grade)5, ItemSubType.Title)]
[InlineData((Grade)3, ItemSubType.Grimoire)]
[InlineData((Grade)4, ItemSubType.Grimoire)]
[InlineData((Grade)5, ItemSubType.Grimoire)]
[InlineData((Grade)6, ItemSubType.Grimoire)]
[InlineData((Grade)1, ItemSubType.Aura)]
[InlineData((Grade)2, ItemSubType.Aura)]
[InlineData((Grade)3, ItemSubType.Aura)]
[InlineData((Grade)4, ItemSubType.Aura)]
[InlineData((Grade)5, ItemSubType.Aura)]
[InlineData((Grade)6, ItemSubType.Aura)]
public void ExecuteSingle(Grade grade, ItemSubType itemSubType)
{
var context = new ActionContext();
var itemSubTypes = GetSubTypeArray(itemSubType, GetSucceededMaterialCount(grade));

var state = Init(out var agentAddress, out var avatarAddress, out var blockIndex);
(state, var items) = UpdateItemsFromSubType(grade, itemSubTypes, state, avatarAddress);
state = state.SetActionPoint(avatarAddress, 120);

var action = new Synthesize()
{
Expand All @@ -101,8 +104,7 @@ public void Execute(Grade grade, ItemSubType[] itemSubTypes)
state = action.Execute(ctx);
var inventory = state.GetInventoryV2(avatarAddress);

// Tests
// 현재 아이템 3개를 넣어 1개가 나오는 구조라 이런 형태로 체크, 추후 변경될 수 있음
// Tests - result inventory should have only one item in this case.
Assert.Single(inventory.Items);
var firstItem = inventory.Items.First().item;
Assert.True(firstItem.ItemSubType == itemSubTypes[0]);
Expand Down Expand Up @@ -139,16 +141,90 @@ public void Execute(Grade grade, ItemSubType[] itemSubTypes)
Assert.True(expectedGrade == resultGrade || resultGrade == grade);
}

[Fact]
public void ExecuteNotEnoughActionPoint()
{
var grade = Grade.Rare;
var itemSubType = ItemSubType.FullCostume;
var context = new ActionContext();
var itemSubTypes = GetSubTypeArray(itemSubType, GetSucceededMaterialCount(grade));

var state = Init(out var agentAddress, out var avatarAddress, out var blockIndex);
(state, var items) = UpdateItemsFromSubType(grade, itemSubTypes, state, avatarAddress);

var action = new Synthesize()
{
AvatarAddress = avatarAddress,
MaterialIds = Synthesize.GetItemGuids(items),
};

var ctx = new ActionContext
{
BlockIndex = blockIndex,
PreviousState = state,
RandomSeed = 0,
Signer = agentAddress,
};

Assert.Throws<NotEnoughActionPointException>(() => action.Execute(ctx));
}

[Theory]
[InlineData(2)]
[InlineData(3)]
[InlineData(12)]
public void ExecuteMultipleSameType(int testCount)
{
var grade = Grade.Rare;
var itemSubType = ItemSubType.FullCostume;
var materialCount = GetSucceededMaterialCount(grade) * testCount;
var itemSubTypes = GetSubTypeArray(itemSubType, materialCount);

var state = Init(out var agentAddress, out var avatarAddress, out var blockIndex);
(state, var items) = UpdateItemsFromSubType(grade, itemSubTypes, state, avatarAddress);
state = state.SetActionPoint(avatarAddress, 120);

var action = new Synthesize()
{
AvatarAddress = avatarAddress,
MaterialIds = Synthesize.GetItemGuids(items),
};

var ctx = new ActionContext
{
BlockIndex = blockIndex,
PreviousState = state,
RandomSeed = 0,
Signer = agentAddress,
};

state = action.Execute(ctx);
var inventory = state.GetInventoryV2(avatarAddress);

// Assert
Assert.Equal(testCount, inventory.Items.Count);
foreach (var item in inventory.Items.Select(i => i.item))
{
Assert.Equal(itemSubType, item.ItemSubType);
var expectedGrade = Synthesize.GetTargetGrade((int)grade);
Assert.True(item.Grade == expectedGrade || item.Grade == (int)grade);
}
}

// TODO: Add Simulator for test and client
// TODO: Exception Tests
// TODO: ExecuteMultiple
[Theory]
[InlineData((Grade)3, new[] { ItemSubType.Aura, ItemSubType.FullCostume, ItemSubType.FullCostume })]
[InlineData((Grade)3, new[] { ItemSubType.Title, ItemSubType.Grimoire, ItemSubType.Title })]
[InlineData((Grade)3, new[] { ItemSubType.Grimoire, ItemSubType.Title, ItemSubType.Grimoire })]
[InlineData((Grade)3, new[] { ItemSubType.Aura, ItemSubType.Aura, ItemSubType.Grimoire })]
public void ExecuteMixedSubTypes(Grade grade, ItemSubType[] itemSubTypes)
public void ExecuteInvalidMaterial(Grade grade, ItemSubType[] itemSubTypes)
{
var context = new ActionContext();
var state = Init(out var agentAddress, out var avatarAddress, out var blockIndex);
(state, var items) = UpdateItemsFromSubType(grade, itemSubTypes, state, avatarAddress);
state = state.SetActionPoint(avatarAddress, 120);

var action = new Synthesize()
{
Expand Down Expand Up @@ -252,4 +328,22 @@ private static ItemBase GetFirstGrimoire(Grade grade)

return ItemFactory.CreateItem(row, new TestRandom(_randomSeed++));
}

private static ItemSubType[] GetSubTypeArray(ItemSubType subtype, int count)
{
var subTypes = new ItemSubType[count];
for (var i = 0; i < count; i++)
{
subTypes[i] = subtype;
}

return subTypes;
}

private static int GetSucceededMaterialCount(Grade grade)
{
var synthesizeSheet = TableSheets.SynthesizeSheet;
var row = synthesizeSheet.Values.First(r => (Grade)r.GradeId == grade);
return row.RequiredCount;
}
}
4 changes: 4 additions & 0 deletions .Lib9c.Tests/TableSheets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ public TableSheets(Dictionary<string, string> sheets, bool ignoreFailedGetProper

public ClaimableGiftsSheet ClaimableGiftsSheet { get; private set; }

public SynthesizeSheet SynthesizeSheet { get; private set; }

public SynthesizeWeightSheet SynthesizeWeightSheet { get; private set; }

public void ItemSheetInitialize()
{
ItemSheet ??= new ItemSheet();
Expand Down
Loading
Loading