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

feat: legacy arcane install on amp & always available skins (#4041)

Re #4038 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/4041 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>

53007d7c
AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
提交于

代码差异

3 个文件 +25 -11
Modified src/controllers/api/arcaneCommonController.ts +21 -6
@@ -1,19 +1,29 @@
1 1 import type { RequestHandler } from "express";
2 2 import { getJSONfromString } from "../../helpers/stringHelpers.ts";
3 3 import { getAccountForRequest } from "../../services/loginService.ts";
4 import { getInventory, addMods, addMiscItem } from "../../services/inventoryService.ts";
4 import { getInventory, addMods, addMiscItem, addSkin } from "../../services/inventoryService.ts";
5 5 import type { IOid } from "../../types/commonTypes.ts";
6 6 import { logger } from "../../utils/logger.ts";
7 7 import gameToBuildVersion from "../../constants/gameToBuildVersion.ts";
8 import { version_compare } from "../../helpers/inventoryHelpers.ts";
8 import { fromOid, version_compare } from "../../helpers/inventoryHelpers.ts";
9 9
10 10 export const arcaneCommonController: RequestHandler = async (req, res) => {
11 11 const account = await getAccountForRequest(req);
12 12 const inventory = await getInventory(account._id.toString());
13 13 const json = getJSONfromString<IArcaneCommonRequest | IArcaneLegacyRequest>(String(req.body));
14 14 if (!("newRank" in json) && "skinId" in json) {
15 //logger.debug(`legacy arcane request:`, json);
16 const item = inventory.WeaponSkins.id(json.skinId);
15 // logger.debug(`legacy arcane request:`, json);
16 let skinId = json.skinId;
17 if (json.giveItem && json.itemTypeName && json.modType == 6) {
18 const inventoryChanges = addSkin(inventory, json.itemTypeName);
19 skinId = fromOid(inventoryChanges.WeaponSkins![0].ItemId);
20 }
21 const item =
22 json.modType == 6
23 ? inventory.WeaponSkins.id(skinId)
24 : json.modType == 5
25 ? inventory.OperatorAmps.id(skinId)
26 : null;
17 27 if (item) {
18 28 if (json.operationType == "Install") {
19 29 const resp: IArcaneLegacyInstallResp = { newLevel: 0 };
@@ -42,6 +52,10 @@ export const arcaneCommonController: RequestHandler = async (req, res) => {
42 52 item.UpgradeFingerprint = JSON.stringify({ lvl: newLevel });
43 53 item.UpgradeType = json.arcaneType!;
44 54 addMods(inventory, [{ ItemType: json.arcaneType!, ItemCount: numConsumed * -1 }]);
55 if (json.giveItem) {
56 resp.AddedSkinId = skinId;
57 }
58 // logger.debug(`legacy arcane resp:`, resp);
45 59 res.json(resp);
46 60 } else if (json.operationType == "Distill") {
47 61 const currentLevel = (JSON.parse(item.UpgradeFingerprint!) as { lvl: number }).lvl;
@@ -60,7 +74,7 @@ export const arcaneCommonController: RequestHandler = async (req, res) => {
60 74 }
61 75 } else {
62 76 logger.debug(`data provided to ${req.path}: ${String(req.body)}`);
63 throw new Error(`Failed to find item with OID ${json.skinId}`);
77 throw new Error(`Failed to find item with OID ${json.skinId}, modType ${json.modType}`);
64 78 }
65 79 await inventory.save();
66 80 return;
@@ -137,8 +151,9 @@ interface IArcaneLegacyRequest {
137 151 arcaneType?: string;
138 152 skinId: string;
139 153 operationType: "Install" | "Distill" | "idk";
140 modType: number; // 6
154 modType: number; // 6 for WeaponSkins, 5 for Amps
141 155 giveItem?: boolean;
156 itemTypeName?: string;
142 157 }
143 158
144 159 interface IArcaneLegacyInstallResp {
Modified src/services/inventoryService.ts +1 -4
@@ -1975,11 +1975,8 @@ export const addSkin = (
1975 1975 ItemType: typeName,
1976 1976 IsNew: typeName.startsWith("/Lotus/Upgrades/Skins/RailJack/") ? undefined : true // railjack skins are incompatible with this flag
1977 1977 }) - 1;
1978 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1979 1978 inventoryChanges.WeaponSkins ??= [];
1980 (inventoryChanges.WeaponSkins as IWeaponSkinClient[]).push(
1981 inventory.WeaponSkins[index].toJSON<IWeaponSkinClient>()
1982 );
1979 inventoryChanges.WeaponSkins.push(inventory.WeaponSkins[index].toJSON<IWeaponSkinClient>());
1983 1980 }
1984 1981 return inventoryChanges;
1985 1982 };
Modified src/types/purchaseTypes.ts +3 -1
@@ -13,7 +13,8 @@ import type {
13 13 IQuestKeyClient,
14 14 IRawUpgrade,
15 15 IFocusUpgrade,
16 IFocusLoadoutClient
16 IFocusLoadoutClient,
17 IWeaponSkinClient
17 18 } from "./inventoryTypes/inventoryTypes.ts";
18 19
19 20 export enum PurchaseSource {
@@ -101,6 +102,7 @@ export type IInventoryChanges = {
101 102 OneTimePurchases?: string[];
102 103 FocusUpgrades?: IFocusUpgrade[];
103 104 FocusLoadouts?: IFocusLoadoutClient[];
105 WeaponSkins?: IWeaponSkinClient[];
104 106 } & Record<
105 107 Exclude<
106 108 string,