XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

fix: save login reward was claimed on milestone days (#1367)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1367 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

e266f9e3
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

3 个文件 +21 -9
Modified src/controllers/api/loginRewardsController.ts +6 -2
@@ -4,7 +4,8 @@ import {
4 4 claimLoginReward,
5 5 getRandomLoginRewards,
6 6 ILoginRewardsReponse,
7 isLoginRewardAChoice
7 isLoginRewardAChoice,
8 setAccountGotLoginRewardToday
8 9 } from "@/src/services/loginRewardService";
9 10 import { getInventory } from "@/src/services/inventoryService";
10 11
@@ -44,8 +45,11 @@ export const loginRewardsController: RequestHandler = async (req, res) => {
44 45 if (!isMilestoneDay && randomRewards.length == 1) {
45 46 response.DailyTributeInfo.HasChosenReward = true;
46 47 response.DailyTributeInfo.ChosenReward = randomRewards[0];
47 response.DailyTributeInfo.NewInventory = await claimLoginReward(account, inventory, randomRewards[0]);
48 response.DailyTributeInfo.NewInventory = await claimLoginReward(inventory, randomRewards[0]);
48 49 await inventory.save();
50
51 setAccountGotLoginRewardToday(account);
52 await account.save();
49 53 }
50 54 res.json(response);
51 55 };
Modified src/controllers/api/loginRewardsSelectionController.ts +10 -2
@@ -1,5 +1,9 @@
1 1 import { getInventory } from "@/src/services/inventoryService";
2 import { claimLoginReward, getRandomLoginRewards } from "@/src/services/loginRewardService";
2 import {
3 claimLoginReward,
4 getRandomLoginRewards,
5 setAccountGotLoginRewardToday
6 } from "@/src/services/loginRewardService";
3 7 import { getAccountForRequest } from "@/src/services/loginService";
4 8 import { handleStoreItemAcquisition } from "@/src/services/purchaseService";
5 9 import { IInventoryChanges } from "@/src/types/purchaseTypes";
@@ -28,9 +32,13 @@ export const loginRewardsSelectionController: RequestHandler = async (req, res)
28 32 } else {
29 33 const randomRewards = getRandomLoginRewards(account, inventory);
30 34 chosenReward = randomRewards.find(x => x.StoreItemType == body.ChosenReward)!;
31 inventoryChanges = await claimLoginReward(account, inventory, chosenReward);
35 inventoryChanges = await claimLoginReward(inventory, chosenReward);
32 36 }
33 37 await inventory.save();
38
39 setAccountGotLoginRewardToday(account);
40 await account.save();
41
34 42 res.json({
35 43 DailyTributeInfo: {
36 44 NewInventory: inventoryChanges,
Modified src/services/loginRewardService.ts +5 -5
@@ -121,14 +121,9 @@ const getRandomLoginReward = (rng: CRng, day: number, inventory: TInventoryDatab
121 121 };
122 122
123 123 export const claimLoginReward = async (
124 account: TAccountDocument,
125 124 inventory: TInventoryDatabaseDocument,
126 125 reward: ILoginReward
127 126 ): Promise<IInventoryChanges> => {
128 account.LoginDays += 1;
129 account.LastLoginRewardDate = Math.trunc(Date.now() / 86400000) * 86400;
130 await account.save();
131
132 127 switch (reward.RewardType) {
133 128 case "RT_RESOURCE":
134 129 case "RT_STORE_ITEM":
@@ -150,3 +145,8 @@ export const claimLoginReward = async (
150 145 }
151 146 throw new Error(`unknown login reward type: ${reward.RewardType}`);
152 147 };
148
149 export const setAccountGotLoginRewardToday = (account: TAccountDocument): void => {
150 account.LoginDays += 1;
151 account.LastLoginRewardDate = Math.trunc(Date.now() / 86400000) * 86400;
152 };