Skip to content

Commit

Permalink
Add new entity types to save editor (#1057)
Browse files Browse the repository at this point in the history
Add wyrmite, diamantium, and hustle hammers to the website save editor
  • Loading branch information
SapiensAnatis authored Aug 29, 2024
1 parent 9edc0d1 commit 5f86251
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,13 @@ public async Task Receive_ReceiveAllPresents_ClaimsAll()
{
ViewerId = ViewerId,
EntityType = EntityTypes.Wyrmite,
EntityQuantity = 100,
EntityQuantity = 50,
},
new()
{
ViewerId = ViewerId,
EntityType = EntityTypes.Wyrmite,
EntityQuantity = 50,
},
new()
{
Expand Down Expand Up @@ -241,7 +247,13 @@ public async Task Receive_ReceiveAllPresents_ClaimsAll()
{
ViewerId = ViewerId,
EntityType = EntityTypes.HustleHammer,
EntityQuantity = 100,
EntityQuantity = 50,
},
new()
{
ViewerId = ViewerId,
EntityType = EntityTypes.HustleHammer,
EntityQuantity = 50,
},
new()
{
Expand All @@ -256,6 +268,20 @@ public async Task Receive_ReceiveAllPresents_ClaimsAll()
EntityId = (int)Emblems.SupremeBogfish,
EntityQuantity = 1,
},
new()
{
ViewerId = ViewerId,
EntityType = EntityTypes.FreeDiamantium,
EntityId = 0,
EntityQuantity = 50,
},
new()
{
ViewerId = ViewerId,
EntityType = EntityTypes.FreeDiamantium,
EntityId = 0,
EntityQuantity = 50,
},
};

await this.AddRangeToDatabase(presents);
Expand Down Expand Up @@ -304,6 +330,10 @@ await this.Client.PostMsgpack<PresentReceiveResponse>(
.Data.UpdateDataList.PresentNotice.Should()
.BeEquivalentTo(new PresentNotice() { PresentCount = 0, PresentLimitCount = 0 });

response
.Data.UpdateDataList.DiamondData.Should()
.BeEquivalentTo(new DiamondData() { FreeDiamond = 100, PaidDiamond = 0 });

// Not sure if entity_result is correct so won't test that
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ IUserService userService
ImmutableArray.Create(
EntityTypes.Item,
EntityTypes.Dew,
EntityTypes.HustleHammer,
EntityTypes.Rupies,
EntityTypes.SkipTicket,
EntityTypes.Wyrmite,
EntityTypes.Material,
EntityTypes.Mana,
EntityTypes.FortPlant,
Expand Down Expand Up @@ -60,18 +58,12 @@ public async Task<GrantReturn> Grant(Entity entity)
case EntityTypes.Dew:
await userDataRepository.UpdateDewpoint(entity.Quantity);
break;
case EntityTypes.HustleHammer:
(await userDataRepository.UserData.SingleAsync()).BuildTimePoint += entity.Quantity;
break;
case EntityTypes.Rupies:
await userDataRepository.UpdateCoin(entity.Quantity);
break;
case EntityTypes.SkipTicket:
await userService.AddQuestSkipPoint(entity.Quantity);
break;
case EntityTypes.Wyrmite:
await userDataRepository.GiveWyrmite(entity.Quantity);
break;
case EntityTypes.Material:
(
await inventoryRepository.GetMaterial((Materials)entity.Id)
Expand Down
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 DragaliaAPI/DragaliaAPI/Features/Reward/Handlers/WyrmiteHandler.cs
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public static PresentWidgetData GetPresentWidgetData()
new() { Type = EntityTypes.DmodePoint, HasQuantity = true },
new() { Type = EntityTypes.SkipTicket, HasQuantity = true },
new() { Type = EntityTypes.DragonGift, HasQuantity = true },
new() { Type = EntityTypes.FreeDiamantium, HasQuantity = true },
new() { Type = EntityTypes.Wyrmite, HasQuantity = true },
new() { Type = EntityTypes.HustleHammer, HasQuantity = true },
];

Dictionary<EntityTypes, List<EntityTypeItem>> availableItems =
Expand All @@ -28,8 +31,11 @@ public static PresentWidgetData GetPresentWidgetData()
[EntityTypes.Dragon] = GetDragonList(),
[EntityTypes.Material] = GetMaterialList(),
[EntityTypes.DmodePoint] = GetDmodePointList(),
[EntityTypes.SkipTicket] = GetSkipTicketList(),
[EntityTypes.SkipTicket] = GetId0List(),
[EntityTypes.DragonGift] = GetDragonGiftList(),
[EntityTypes.FreeDiamantium] = GetId0List(),
[EntityTypes.Wyrmite] = GetId0List(),
[EntityTypes.HustleHammer] = GetId0List(),
};

return new() { Types = typeInfo, AvailableItems = availableItems };
Expand Down Expand Up @@ -61,7 +67,7 @@ private static List<EntityTypeItem> GetDmodePointList() =>
new EntityTypeItem { Id = (int)DmodePoint.Point2 },
];

private static List<EntityTypeItem> GetSkipTicketList() => [new EntityTypeItem { Id = 0 }];
private static List<EntityTypeItem> GetId0List() => [new EntityTypeItem { Id = 0 }];

private static List<EntityTypeItem> GetDragonGiftList() =>
Enum.GetValues<DragonGifts>().Select(x => new EntityTypeItem() { Id = (int)x }).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ private bool ValidatePresents(List<PresentFormSubmission> presents)
EntityTypes.Item => ValidateItemPresent(present),
EntityTypes.Material => ValidateMaterialPresent(present),
EntityTypes.DmodePoint => ValidateDmodePointPresent(present),
EntityTypes.SkipTicket => ValidateSkipTicketPresent(present),
EntityTypes.SkipTicket => ValidateId0Present(present),
EntityTypes.DragonGift => ValidateDragonGiftPresent(present),
EntityTypes.FreeDiamantium => ValidateId0Present(present),
EntityTypes.Wyrmite => ValidateId0Present(present),
EntityTypes.HustleHammer => ValidateId0Present(present),
_ => false,
};

Expand Down Expand Up @@ -88,8 +91,7 @@ private static bool ValidateMaterialPresent(PresentFormSubmission present) =>
private static bool ValidateDmodePointPresent(PresentFormSubmission present) =>
(DmodePoint)present.Item is DmodePoint.Point1 or DmodePoint.Point2;

private static bool ValidateSkipTicketPresent(PresentFormSubmission present) =>
present.Item == 0;
private static bool ValidateId0Present(PresentFormSubmission present) => present.Item == 0;

private static bool ValidateDragonGiftPresent(PresentFormSubmission present) =>
Enum.IsDefined((DragonGifts)present.Item);
Expand Down
18 changes: 18 additions & 0 deletions Website/src/lib/translations/en/save-editor.json
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,24 @@
"30003": "Valentine's Card",
"40001": "Pup Grub"
}
},
"FreeDiamantium": {
"label": "Diamantium",
"item": {
"0": "Diamantium"
}
},
"Wyrmite": {
"label": "Wyrmite",
"item": {
"0": "Wyrmite"
}
},
"HustleHammer": {
"label": "Hustle Hammer",
"item": {
"0": "Hustle Hammer"
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export const EntityType = z.enum([
'Material',
'DmodePoint',
'SkipTicket',
'DragonGift'
'DragonGift',
'FreeDiamantium',
'Wyrmite',
'HustleHammer'
]);

export type EntityType = z.infer<typeof EntityType>;
Expand Down
2 changes: 1 addition & 1 deletion global.json
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"
}
}

0 comments on commit 5f86251

Please sign in to comment.