-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new entity types to save editor (#1057)
Add wyrmite, diamantium, and hustle hammers to the website save editor
- Loading branch information
1 parent
9edc0d1
commit 5f86251
Showing
9 changed files
with
176 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
DragaliaAPI/DragaliaAPI/Features/Reward/Handlers/HustleHammerHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using DragaliaAPI.Database; | ||
using DragaliaAPI.Database.Entities; | ||
using DragaliaAPI.Shared.Definitions.Enums; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace DragaliaAPI.Features.Reward.Handlers; | ||
|
||
public class HustleHammerHandler(ApiContext apiContext) : IRewardHandler, IBatchRewardHandler | ||
{ | ||
// "Why would you ever need more than this...?" | ||
private const int MaxHammers = 999_999; | ||
|
||
public IReadOnlyList<EntityTypes> SupportedTypes { get; } = [EntityTypes.HustleHammer]; | ||
|
||
public async Task<IDictionary<TKey, GrantReturn>> GrantRange<TKey>( | ||
IDictionary<TKey, Entity> entities | ||
) | ||
where TKey : struct | ||
{ | ||
DbPlayerUserData userData = await apiContext.PlayerUserData.FirstAsync(); | ||
Dictionary<TKey, GrantReturn> results = new(entities.Count); | ||
|
||
foreach ((TKey key, Entity entity) in entities) | ||
{ | ||
GrantReturn result = TryIncrementBuildTimePoint(userData, entity.Quantity) | ||
? GrantReturn.Added() | ||
: GrantReturn.Limit(); | ||
|
||
results[key] = result; | ||
} | ||
|
||
return results; | ||
} | ||
|
||
public async Task<GrantReturn> Grant(Entity entity) | ||
{ | ||
DbPlayerUserData userData = await apiContext.PlayerUserData.FirstAsync(); | ||
|
||
return TryIncrementBuildTimePoint(userData, entity.Quantity) | ||
? GrantReturn.Added() | ||
: GrantReturn.Limit(); | ||
} | ||
|
||
private static bool TryIncrementBuildTimePoint(DbPlayerUserData userData, int quantity) | ||
{ | ||
if (userData.BuildTimePoint + quantity > MaxHammers) | ||
{ | ||
return false; | ||
} | ||
|
||
userData.BuildTimePoint += quantity; | ||
return true; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
DragaliaAPI/DragaliaAPI/Features/Reward/Handlers/WyrmiteHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using DragaliaAPI.Database; | ||
using DragaliaAPI.Database.Entities; | ||
using DragaliaAPI.Shared.Definitions.Enums; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace DragaliaAPI.Features.Reward.Handlers; | ||
|
||
public class WyrmiteHandler(ApiContext apiContext) : IRewardHandler, IBatchRewardHandler | ||
{ | ||
// Assumed maximum before UI bugs. True max is int.MaxValue. | ||
private const int MaxWyrmite = 999_999_999; | ||
|
||
public IReadOnlyList<EntityTypes> SupportedTypes => [EntityTypes.Wyrmite]; | ||
|
||
public async Task<IDictionary<TKey, GrantReturn>> GrantRange<TKey>( | ||
IDictionary<TKey, Entity> entities | ||
) | ||
where TKey : struct | ||
{ | ||
DbPlayerUserData userData = await apiContext.PlayerUserData.FirstAsync(); | ||
Dictionary<TKey, GrantReturn> results = new(entities.Count); | ||
|
||
foreach ((TKey key, Entity entity) in entities) | ||
{ | ||
GrantReturn result = TryIncrementCrystal(userData, entity.Quantity) | ||
? GrantReturn.Added() | ||
: GrantReturn.Limit(); | ||
|
||
results[key] = result; | ||
} | ||
|
||
return results; | ||
} | ||
|
||
public async Task<GrantReturn> Grant(Entity entity) | ||
{ | ||
DbPlayerUserData userData = await apiContext.PlayerUserData.FirstAsync(); | ||
|
||
return TryIncrementCrystal(userData, entity.Quantity) | ||
? GrantReturn.Added() | ||
: GrantReturn.Limit(); | ||
} | ||
|
||
private static bool TryIncrementCrystal(DbPlayerUserData userData, int quantity) | ||
{ | ||
if (userData.Crystal + quantity > MaxWyrmite) | ||
{ | ||
return false; | ||
} | ||
|
||
userData.Crystal += quantity; | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"sdk": { | ||
"version": "8.0.301", | ||
"version": "8.0.401", | ||
"rollForward": "latestFeature" | ||
} | ||
} |