返回提交历史
Modified
src/controllers/api/descentRewardsController.ts
+4
-11
Modified
src/services/missionInventoryUpdateService.ts
+19
-37
XFEstudio/SpaceNinjaServer
chore: remove redundant version checks (#3175)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3175 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
e7e3016d
代码差异
2 个文件
+23
-48
@@ -1,24 +1,17 @@
1
1
import type { RequestHandler } from "express";
2
import { getAccountForRequest } from "../../services/loginService.ts";
2
import { getAccountIdForRequest } from "../../services/loginService.ts";
3
3
import { getJSONfromString } from "../../helpers/stringHelpers.ts";
4
4
import type { TDescentCategory } from "../../types/inventoryTypes/inventoryTypes.ts";
5
5
import { getInventory } from "../../services/inventoryService.ts";
6
6
import type { ICountedStoreItem } from "warframe-public-export-plus";
7
7
import { getRandomElement, getRandomInt } from "../../services/rngService.ts";
8
8
import { logger } from "../../utils/logger.ts";
9
import { version_compare } from "../../helpers/inventoryHelpers.ts";
10
import gameToBuildVersion from "../../constants/gameToBuildVersion.ts";
11
9
12
10
export const descentRewardsController: RequestHandler = async (req, res) => {
13
const account = await getAccountForRequest(req);
14
if (account.BuildLabel && version_compare(account.BuildLabel, gameToBuildVersion["41.0.0"]) < 0) {
15
throw new Error(
16
`account logged into ${account.BuildLabel} (< 41.0.0) but is now attempting to call a >= 41.0.0 endpoint ?!`
17
);
18
}
11
const accountId = await getAccountIdForRequest(req);
19
12
const payload = getJSONfromString<IDescentRewardsRequest>(String(req.body));
20
13
if (payload.Mode == "r") {
21
const inventory = await getInventory(account._id.toString(), "DescentRewards");
14
const inventory = await getInventory(accountId, "DescentRewards");
22
15
inventory.DescentRewards ??= [];
23
16
let entry = inventory.DescentRewards.find(x => x.Category == payload.Category);
24
17
if (!entry) {
@@ -109,7 +102,7 @@ export const descentRewardsController: RequestHandler = async (req, res) => {
109
102
SelectedUpgrades: entry.SelectedUpgrades
110
103
});
111
104
} else if (payload.Mode == "s") {
112
const inventory = await getInventory(account._id.toString(), "DescentRewards");
105
const inventory = await getInventory(accountId, "DescentRewards");
113
106
inventory.DescentRewards ??= [];
114
107
const entry = inventory.DescentRewards.find(x => x.Category == payload.Category);
115
108
if (!entry) {
@@ -1253,18 +1253,10 @@ export const addMissionRewards = async (
1253
1253
1254
1254
if (goalTag && goalTag == "12MinWarEvent") {
1255
1255
if (["SolNode250", "SolNode251", "SolNode252"].includes(rewardInfo.node)) {
1256
if (account.BuildLabel) {
1257
if (version_compare(account.BuildLabel, gameToBuildVersion["41.0.0"]) < 0) {
1258
throw new Error(
1259
`account logged into ${account.BuildLabel} (< 41.0.0) but now completes >= 41.0.0 goal ?!`
1260
);
1261
}
1262
1263
MissionRewards.push({
1264
StoreItem: "/Lotus/StoreItems/Types/Gameplay/Tau/Resources/TwelveResourceCurrencyItem",
1265
ItemCount: getRandomInt(8, 15) + (missions?.Tier ? 2 : 0)
1266
});
1267
}
1256
MissionRewards.push({
1257
StoreItem: "/Lotus/StoreItems/Types/Gameplay/Tau/Resources/TwelveResourceCurrencyItem",
1258
ItemCount: getRandomInt(8, 15) + (missions?.Tier ? 2 : 0)
1259
});
1268
1260
}
1269
1261
}
1270
1262
@@ -1575,31 +1567,21 @@ export const addMissionRewards = async (
1575
1567
}
1576
1568
1577
1569
if (rewardInfo.missionType == "MT_DESCENT") {
1578
if (account.BuildLabel) {
1579
if (version_compare(account.BuildLabel, gameToBuildVersion["41.0.0"]) < 0) {
1580
throw new Error(
1581
`account logged into ${account.BuildLabel} (< 41.0.0) but now completes >= 41.0.0 misssion ?!`
1582
);
1583
}
1584
1585
const isSteelPath = missions?.Tier;
1586
inventory.DescentRewards ??= [];
1587
const entry = inventory.DescentRewards.find(
1588
x => x.Category == (isSteelPath ? "DM_COH_HARD" : "DM_COH_NORMAL")
1589
);
1590
if (!entry) {
1591
throw new Error(`Missing DescentRewards entry`);
1592
}
1593
logger.debug(`completed ${rewardInfo.CheckpointCounter} ${entry.Category} floor`);
1594
if (rewardInfo.CheckpointCounter && rewardInfo.CheckpointCounter > entry.FloorClaimed) {
1595
entry.FloorClaimed = rewardInfo.CheckpointCounter;
1596
const reward = entry.PendingRewards.find(x => x.FloorCheckpoint == rewardInfo.CheckpointCounter);
1597
if (reward) {
1598
logger.debug(`giving ${entry.Category} floor ${rewardInfo.CheckpointCounter} reward`, {
1599
reward: reward.Rewards
1600
});
1601
MissionRewards.push(...reward.Rewards);
1602
}
1570
const isSteelPath = missions?.Tier;
1571
inventory.DescentRewards ??= [];
1572
const entry = inventory.DescentRewards.find(x => x.Category == (isSteelPath ? "DM_COH_HARD" : "DM_COH_NORMAL"));
1573
if (!entry) {
1574
throw new Error(`Missing DescentRewards entry`);
1575
}
1576
logger.debug(`completed ${rewardInfo.CheckpointCounter} ${entry.Category} floor`);
1577
if (rewardInfo.CheckpointCounter && rewardInfo.CheckpointCounter > entry.FloorClaimed) {
1578
entry.FloorClaimed = rewardInfo.CheckpointCounter;
1579
const reward = entry.PendingRewards.find(x => x.FloorCheckpoint == rewardInfo.CheckpointCounter);
1580
if (reward) {
1581
logger.debug(`giving ${entry.Category} floor ${rewardInfo.CheckpointCounter} reward`, {
1582
reward: reward.Rewards
1583
});
1584
MissionRewards.push(...reward.Rewards);
1603
1585
}
1604
1586
}
1605
1587
}