返回提交历史
Modified
src/controllers/api/arcaneCommonController.ts
+75
-1
Modified
src/models/inventoryModels/inventoryModel.ts
+3
-1
Modified
src/types/inventoryTypes/inventoryTypes.ts
+2
-0
XFEstudio/XFESpaceNinjaServer
feat: install arcane on skins (#3588)
Closes #3311 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3588 Reviewed-by: Sainan <63328889+sainan@users.noreply.github.com> Co-authored-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Co-committed-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
d767ce12
代码差异
3 个文件
+80
-2
@@ -3,11 +3,65 @@ import { getJSONfromString } from "../../helpers/stringHelpers.ts";
3
3
import { getAccountIdForRequest } from "../../services/loginService.ts";
4
4
import { getInventory, addMods } from "../../services/inventoryService.ts";
5
5
import type { IOid } from "../../types/commonTypes.ts";
6
import { logger } from "../../utils/logger.ts";
7
import { JSONParse } from "json-with-bigint";
6
8
7
9
export const arcaneCommonController: RequestHandler = async (req, res) => {
8
10
const accountId = await getAccountIdForRequest(req);
9
const json = getJSONfromString<IArcaneCommonRequest>(String(req.body));
10
11
const inventory = await getInventory(accountId);
12
const body = String(req.body);
13
14
const parsed: unknown = JSONParse(body.substring(0, body.lastIndexOf("}") + 1));
15
if (typeof parsed === "object" && parsed !== null && !("newRank" in parsed) && "skinId" in parsed) {
16
const json = getJSONfromString<IArcaneLegacyRequest>(body);
17
const item = inventory.WeaponSkins.id(json.skinId);
18
const legacyArcaneLevelCounts = [1, 3, 6, 10];
19
if (item) {
20
if (json.operationType == "Install") {
21
const resp: IArcaneLegacyInstallResp = { newLevel: 0 };
22
let currentLevel = item.UpgradeFingerprint
23
? (JSON.parse(item.UpgradeFingerprint) as { lvl: number }).lvl
24
: -1;
25
26
// Return different arcane
27
if (item.UpgradeType && item.UpgradeType != json.arcaneType && currentLevel >= 0) {
28
const numToRefund = legacyArcaneLevelCounts[currentLevel];
29
resp.numToRefund = numToRefund;
30
resp.typeToRefund = item.UpgradeType;
31
addMods(inventory, [{ ItemType: item.UpgradeType, ItemCount: numToRefund }]);
32
33
item.UpgradeFingerprint = undefined;
34
item.UpgradeType = undefined;
35
currentLevel = -1;
36
}
37
38
const newLevel = currentLevel + 1;
39
resp.newLevel = newLevel;
40
let numConsumed = legacyArcaneLevelCounts[newLevel];
41
if (currentLevel >= 0) {
42
numConsumed -= legacyArcaneLevelCounts[currentLevel];
43
}
44
item.UpgradeFingerprint = JSON.stringify({ lvl: newLevel });
45
item.UpgradeType = json.arcaneType!;
46
addMods(inventory, [{ ItemType: json.arcaneType!, ItemCount: numConsumed * -1 }]);
47
res.json(resp);
48
} else if (json.operationType == "Distill") {
49
const currentLevel = (JSON.parse(item.UpgradeFingerprint!) as { lvl: number }).lvl;
50
const arcaneType = item.UpgradeType!;
51
const numToRefund = legacyArcaneLevelCounts[currentLevel];
52
item.UpgradeFingerprint = undefined;
53
item.UpgradeType = undefined;
54
addMods(inventory, [{ ItemType: arcaneType, ItemCount: numToRefund }]);
55
res.json({ arcaneType, numToRefund });
56
} else {
57
logger.debug(`data provided to ${req.path}: ${String(req.body)}`);
58
throw new Error(`unknown legacy arcaneCommon operationType: ${json.operationType}`);
59
}
60
}
61
await inventory.save();
62
return;
63
}
64
const json = getJSONfromString<IArcaneCommonRequest>(body);
11
65
const upgrade = inventory.Upgrades.id(json.arcane.ItemId.$oid);
12
66
if (json.newRank == -1) {
13
67
// Break down request?
@@ -74,3 +128,23 @@ interface IArcaneCommonRequest {
74
128
};
75
129
newRank: number;
76
130
}
131
132
interface IArcaneLegacyRequest {
133
arcaneType?: string;
134
skinId: string;
135
operationType: "Install" | "Distill" | "idk";
136
modType: number; // 6
137
giveItem?: boolean;
138
}
139
140
interface IArcaneLegacyInstallResp {
141
newLevel: number;
142
typeToRefund?: string;
143
numToRefund?: number;
144
AddedSkinId?: string;
145
}
146
147
// interface IArcaneLegacyDistillResp {
148
// arcaneType: string;
149
// numToRefund: number;
150
// }
@@ -760,7 +760,9 @@ const weaponSkinsSchema = new Schema<IWeaponSkinDatabase>(
760
760
{
761
761
ItemType: String,
762
762
Favorite: Boolean,
763
IsNew: Boolean
763
IsNew: Boolean,
764
UpgradeType: String,
765
UpgradeFingerprint: String
764
766
},
765
767
{ id: false }
766
768
);
@@ -1129,6 +1129,8 @@ export interface IWeaponSkinDatabase {
1129
1129
ItemType: string;
1130
1130
Favorite?: boolean;
1131
1131
IsNew?: boolean;
1132
UpgradeType?: string;
1133
UpgradeFingerprint?: string;
1132
1134
_id: Types.ObjectId;
1133
1135
}
1134
1136