fix: save login reward was claimed on milestone days #1367
@ -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);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -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,
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user