fix: save login reward was claimed on milestone days
All checks were successful
Build / build (18) (push) Successful in 49s
Build / build (20) (push) Successful in 1m16s
Build / build (22) (push) Successful in 1m18s
Build / build (18) (pull_request) Successful in 50s
Build / build (20) (pull_request) Successful in 1m15s
Build / build (22) (pull_request) Successful in 1m20s

This commit is contained in:
Sainan 2025-03-29 14:29:34 +01:00
parent 3a904753f2
commit f708890411
3 changed files with 21 additions and 9 deletions

View File

@ -4,7 +4,8 @@ import {
claimLoginReward,
getRandomLoginRewards,
ILoginRewardsReponse,
isLoginRewardAChoice
isLoginRewardAChoice,
setAccountGotLoginRewardToday
} from "@/src/services/loginRewardService";
import { getInventory } from "@/src/services/inventoryService";
@ -44,8 +45,11 @@ export const loginRewardsController: RequestHandler = async (req, res) => {
if (!isMilestoneDay && randomRewards.length == 1) {
response.DailyTributeInfo.HasChosenReward = true;
response.DailyTributeInfo.ChosenReward = randomRewards[0];
response.DailyTributeInfo.NewInventory = await claimLoginReward(account, inventory, randomRewards[0]);
response.DailyTributeInfo.NewInventory = await claimLoginReward(inventory, randomRewards[0]);
await inventory.save();
setAccountGotLoginRewardToday(account);
await account.save();
}
res.json(response);
};

View File

@ -1,5 +1,9 @@
import { getInventory } from "@/src/services/inventoryService";
import { claimLoginReward, getRandomLoginRewards } from "@/src/services/loginRewardService";
import {
claimLoginReward,
getRandomLoginRewards,
setAccountGotLoginRewardToday
} from "@/src/services/loginRewardService";
import { getAccountForRequest } from "@/src/services/loginService";
import { handleStoreItemAcquisition } from "@/src/services/purchaseService";
import { IInventoryChanges } from "@/src/types/purchaseTypes";
@ -28,9 +32,13 @@ export const loginRewardsSelectionController: RequestHandler = async (req, res)
} else {
const randomRewards = getRandomLoginRewards(account, inventory);
chosenReward = randomRewards.find(x => x.StoreItemType == body.ChosenReward)!;
inventoryChanges = await claimLoginReward(account, inventory, chosenReward);
inventoryChanges = await claimLoginReward(inventory, chosenReward);
}
await inventory.save();
setAccountGotLoginRewardToday(account);
await account.save();
res.json({
DailyTributeInfo: {
NewInventory: inventoryChanges,

View File

@ -121,14 +121,9 @@ const getRandomLoginReward = (rng: CRng, day: number, inventory: TInventoryDatab
};
export const claimLoginReward = async (
account: TAccountDocument,
inventory: TInventoryDatabaseDocument,
reward: ILoginReward
): Promise<IInventoryChanges> => {
account.LoginDays += 1;
account.LastLoginRewardDate = Math.trunc(Date.now() / 86400000) * 86400;
await account.save();
switch (reward.RewardType) {
case "RT_RESOURCE":
case "RT_STORE_ITEM":
@ -150,3 +145,8 @@ export const claimLoginReward = async (
}
throw new Error(`unknown login reward type: ${reward.RewardType}`);
};
export const setAccountGotLoginRewardToday = (account: TAccountDocument): void => {
account.LoginDays += 1;
account.LastLoginRewardDate = Math.trunc(Date.now() / 86400000) * 86400;
};