返回提交历史
Modified
src/controllers/api/missionInventoryUpdateController.ts
+25
-11
Modified
src/types/missionTypes.ts
+9
-2
XFEstudio/SpaceNinjaServer
chore: improve structuring of mission response types (#2604)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2604 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
fac3ec01
代码差异
2 个文件
+34
-13
@@ -6,7 +6,11 @@ import { addMissionInventoryUpdates, addMissionRewards } from "@/src/services/mi
6
6
import { getInventory } from "@/src/services/inventoryService";
7
7
import { getInventoryResponse } from "@/src/controllers/api/inventoryController";
8
8
import { logger } from "@/src/utils/logger";
9
import { IMissionInventoryUpdateResponse } from "@/src/types/missionTypes";
9
import {
10
IMissionInventoryUpdateResponse,
11
IMissionInventoryUpdateResponseBackToDryDock,
12
IMissionInventoryUpdateResponseRailjackInterstitial
13
} from "@/src/types/missionTypes";
10
14
import { sendWsBroadcastTo } from "@/src/services/wsService";
11
15
import { generateRewardSeed } from "@/src/services/rngService";
12
16
@@ -95,17 +99,9 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res)
95
99
inventory.RewardSeed = generateRewardSeed();
96
100
}
97
101
await inventory.save();
98
const inventoryResponse = await getInventoryResponse(inventory, true, account.BuildLabel);
99
102
100
103
//TODO: figure out when to send inventory. it is needed for many cases.
101
if (missionReport.RJ) {
102
logger.debug(`railjack interstitial request, sending only deltas`, {
103
InventoryChanges: inventoryChanges,
104
AffiliationMods
105
});
106
}
107
res.json({
108
InventoryJson: missionReport.RJ ? undefined : JSON.stringify(inventoryResponse),
104
const deltas: IMissionInventoryUpdateResponseRailjackInterstitial = {
109
105
InventoryChanges: inventoryChanges,
110
106
MissionRewards,
111
107
...credits,
@@ -114,7 +110,25 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res)
114
110
SyndicateXPItemReward,
115
111
AffiliationMods,
116
112
ConquestCompletedMissionsCount
117
} satisfies IMissionInventoryUpdateResponse);
113
};
114
if (missionReport.RJ) {
115
logger.debug(`railjack interstitial request, sending only deltas`, deltas);
116
res.json(deltas);
117
} else if (missionReport.RewardInfo) {
118
logger.debug(`classic mission completion, sending everything`);
119
const inventoryResponse = await getInventoryResponse(inventory, true, account.BuildLabel);
120
res.json({
121
InventoryJson: JSON.stringify(inventoryResponse),
122
...deltas
123
} satisfies IMissionInventoryUpdateResponse);
124
} else {
125
logger.debug(`no reward info, assuming this wasn't a mission completion and we should just sync inventory`);
126
const inventoryResponse = await getInventoryResponse(inventory, true, account.BuildLabel);
127
res.json({
128
InventoryJson: JSON.stringify(inventoryResponse)
129
} satisfies IMissionInventoryUpdateResponseBackToDryDock);
130
}
131
118
132
sendWsBroadcastTo(account._id.toString(), { update_inventory: true });
119
133
};
120
134
@@ -23,12 +23,19 @@ export interface IMissionCredits {
23
23
DailyMissionBonus?: boolean;
24
24
}
25
25
26
export interface IMissionInventoryUpdateResponse extends Partial<IMissionCredits> {
26
export interface IMissionInventoryUpdateResponseRailjackInterstitial extends Partial<IMissionCredits> {
27
27
ConquestCompletedMissionsCount?: number;
28
InventoryJson?: string;
29
28
MissionRewards?: IMissionReward[];
30
29
InventoryChanges?: IInventoryChanges;
31
30
FusionPoints?: number;
32
31
SyndicateXPItemReward?: number;
33
32
AffiliationMods?: IAffiliationMods[];
34
33
}
34
35
export interface IMissionInventoryUpdateResponse extends IMissionInventoryUpdateResponseRailjackInterstitial {
36
InventoryJson?: string;
37
}
38
39
export interface IMissionInventoryUpdateResponseBackToDryDock {
40
InventoryJson: string;
41
}