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

fix try parse WorldBossRankingRewardSheet #2923

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 10 additions & 6 deletions .Lib9c.Tests/TableData/WorldBossRankingRewardSheetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class WorldBossRankingRewardSheetTest
14,900002,11,100,0,0,10011,560,10012,150,10013,40,1500000,600201,100,500000,1000
15,900002,0,0,1,30,10011,370,10012,105,10013,25,500000,600201,50,500000,100
16,900002,0,0,31,50,10011,230,10012,60,10013,10,250000,600201,50,500000,100
17,900002,0,0,51,70,10011,75,10012,20,10013,5,125000,600201,50,500000,100
18,900002,0,0,71,100,10011,40,10012,10,0,0,100000,600201,50,500000,100
17,900002,0,0,51,70,10011,75,10012,20,10013,5,125000,600201,50,0,0
18,900002,0,0,71,100,10011,40,10012,10,0,0,100000,600201,50,,
";

[Fact]
Expand Down Expand Up @@ -68,16 +68,20 @@ public void FIndRow_Throw_ArgumentException()
Assert.Throws<ArgumentException>(() => sheet.FindRow(900003, 0, 0));
}

[Fact]
public void GetRewards()
[Theory]
[InlineData(900001, 1, 0, 6)]
[InlineData(900002, 600, 60, 5)]
[InlineData(900002, 800, 80, 4)]
U-lis marked this conversation as resolved.
Show resolved Hide resolved
public void GetRewards(int bossId, int ranking, int rate, int expected)
{
var sheet = new WorldBossRankingRewardSheet();
sheet.Set(Csv);
var row = sheet.FindRow(900001, 1, 0);
var row = sheet.FindRow(bossId, ranking, rate);
var tableSheets = new TableSheets(TableSheetsImporter.ImportSheets());
var rewards = row.GetRewards(tableSheets.RuneSheet, tableSheets.MaterialItemSheet);

Assert.Equal(6, rewards.Count);
Assert.Equal(expected, rewards.Count);
Assert.All(rewards, fav => Assert.True(fav.Sign > 0));
}
}
}
22 changes: 14 additions & 8 deletions Lib9c/TableData/WorldBossRankingRewardSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ public override void Set(IReadOnlyList<string> fields)
for (int i = 0; i < 3; i++)
{
var offset = i * 2;
Runes.Add(new RuneInfo(ParseInt(fields[6 + offset]), ParseInt(fields[7 + offset])));
var id = TryParseInt(fields[6 + offset], out var value) ? value : 0;
var quantity = TryParseInt(fields[7 + offset], out value) ? value : 0;
if (id != 0 && quantity > 0)
{
Runes.Add(new RuneInfo(id, quantity));
}
}
Crystal = ParseInt(fields[12]);

Expand All @@ -58,8 +63,12 @@ public override void Set(IReadOnlyList<string> fields)
for (int i = 0; i < 2; i++)
{
var offset = i * 2;
Materials.Add(
(ParseInt(fields[13 + offset]), ParseInt(fields[14 + offset])));
var id = TryParseInt(fields[13 + offset], out var value) ? value : 0;
var quantity = TryParseInt(fields[14 + offset], out value) ? value : 0;
if (id != 0 && quantity > 0)
{
Materials.Add((id, quantity));
}
}
}
}
Expand All @@ -72,11 +81,8 @@ public List<FungibleAssetValue> GetRewards(
{
Crystal * CrystalCalculator.CRYSTAL
};
result.AddRange(Runes
.Where(runeInfo => runeInfo.RuneQty > 0)
.Select(runeInfo =>
RuneHelper.ToFungibleAssetValue(runeSheet[runeInfo.RuneId],
runeInfo.RuneQty)));
result.AddRange(Runes.Select(runeInfo =>
RuneHelper.ToFungibleAssetValue(runeSheet[runeInfo.RuneId], runeInfo.RuneQty)));

foreach (var (itemId, quantity) in Materials)
{
Expand Down
Loading