Skip to content

Commit 216e979

Browse files
Address review comments: simplify Debug.Assert, scope V28Update to Arsene
Co-authored-by: Jay Malhotra <SapiensAnatis@users.noreply.github.com>
1 parent 9ec068a commit 216e979

2 files changed

Lines changed: 24 additions & 15 deletions

File tree

DragaliaAPI/DragaliaAPI/Features/Login/SavefileUpdate/V28Update.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
namespace DragaliaAPI.Features.Login.SavefileUpdate;
1111

1212
/// <summary>
13-
/// Fixes missing dragon stories for dragons whose default reliability level is >= 5 (e.g. Arsene).
13+
/// Fixes missing dragon stories for Arsene, whose default reliability level of 30 meant that
14+
/// stories were not unlocked on receipt (unlike level-up, which is handled by <see cref="V25Update"/>).
1415
/// </summary>
1516
public partial class V28Update(
1617
ApiContext apiContext,
@@ -22,21 +23,25 @@ ILogger<V28Update> logger
2223

2324
public async Task Apply()
2425
{
25-
var dragonsAtOrOver5Bond = await apiContext
26-
.PlayerDragonReliability.Where(x => x.Level >= 5)
27-
.Select(x => new { x.DragonId, x.Level })
26+
List<int> arseneLevels = await apiContext
27+
.PlayerDragonReliability.Where(x => x.DragonId == DragonId.Arsene && x.Level >= 5)
28+
.Select(x => x.Level)
2829
.ToListAsync();
2930

30-
List<DbPlayerStoryState> intendedStoryStates = new(dragonsAtOrOver5Bond.Count * 2);
31-
32-
foreach (var info in dragonsAtOrOver5Bond)
31+
if (
32+
arseneLevels.Count == 0
33+
|| !MasterAsset.DragonStories.TryGetValue((int)DragonId.Arsene, out StoryData? data)
34+
)
3335
{
34-
if (!MasterAsset.DragonStories.TryGetValue((int)info.DragonId, out StoryData? data))
35-
{
36-
continue;
37-
}
36+
Log.AddedNewStories(logger, 0);
37+
return;
38+
}
39+
40+
List<DbPlayerStoryState> intendedStoryStates = new(arseneLevels.Count * 2);
3841

39-
int storiesToUnlock = info.Level >= 15 ? Math.Min(2, data.StoryIds.Length) : 1;
42+
foreach (int level in arseneLevels)
43+
{
44+
int storiesToUnlock = level >= 15 ? 2 : 1;
4045

4146
for (int i = 0; i < storiesToUnlock; i++)
4247
{

DragaliaAPI/DragaliaAPI/Features/Shared/Reward/Handlers/DragonHandler.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics;
12
using DragaliaAPI.Database;
23
using DragaliaAPI.Database.Entities;
34
using DragaliaAPI.Shared.Definitions.Enums;
@@ -127,9 +128,12 @@ private void AddDefaultLevelStories(DragonId dragon, int reliabilityLevel)
127128
return;
128129
}
129130

130-
int storiesToUnlock = reliabilityLevel >= 15
131-
? Math.Min(2, storyData.StoryIds.Length)
132-
: 1;
131+
Debug.Assert(
132+
storyData.StoryIds.Length == 2,
133+
"Expected all dragons to have exactly two stories"
134+
);
135+
136+
int storiesToUnlock = reliabilityLevel >= 15 ? 2 : 1;
133137

134138
for (int i = 0; i < storiesToUnlock; i++)
135139
{

0 commit comments

Comments
 (0)