Skip to content

Commit

Permalink
Merge pull request #2923 from planetarium/bugfix/worldboss-ranking-sheet
Browse files Browse the repository at this point in the history
fix try parse WorldBossRankingRewardSheet
  • Loading branch information
U-lis authored Oct 22, 2024
2 parents a8058b9 + 78c39e1 commit 55b6e9e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
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)]
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

0 comments on commit 55b6e9e

Please sign in to comment.