返回提交历史
Modified
src/controllers/api/inventoryController.ts
+28
-21
Modified
src/services/saveLoadoutService.ts
+20
-14
Modified
src/types/inventoryTypes/inventoryTypes.ts
+4
-1
XFEstudio/SpaceNinjaServer
feat: loadout saving in u14-u15 (#3584)
Re #3372. Still need to handle multi-loadout stuff in these versions, but at least it works with only 1 loadout slot now. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3584 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
d0e8f028
代码差异
3 个文件
+52
-36
@@ -29,7 +29,7 @@ import {
29
29
} from "../../services/inventoryService.ts";
30
30
import { logger } from "../../utils/logger.ts";
31
31
import { addString } from "../../helpers/stringHelpers.ts";
32
import { Types } from "mongoose";
32
import { Types, type FlattenMaps } from "mongoose";
33
33
import { getNemesisManifest } from "../../helpers/nemesisHelpers.ts";
34
34
import { getPersonalRooms } from "../../services/personalRoomsService.ts";
35
35
import type { IPersonalRoomsClient } from "../../types/personalRoomsTypes.ts";
@@ -37,6 +37,7 @@ import { Ship } from "../../models/shipModel.ts";
37
37
import {
38
38
convertIColorToLegacyColors,
39
39
convertIColorToLegacyColorsWithAtt,
40
fromOid,
40
41
toLegacyOid,
41
42
toOid,
42
43
toOid2,
@@ -693,9 +694,13 @@ export const getInventoryResponse = async (
693
694
inventoryResponse.LoadOutPresets.NORMAL.length > 0
694
695
) {
695
696
if (version_compare(buildLabel, gameToBuildVersion["14.0.0"]) >= 0) {
696
// U14-U15 expect a different response than any other version, where the client is pulling loadout data from has not been found yet
697
// As such, loading loadouts is currently unsupported for these versions
698
logger.warn("Loadouts are currently unsupported in U14-U15, loadouts will be undefined");
697
// U14-U15
698
inventoryResponse.CurrentLoadout = {
699
$id: fromOid(inventoryResponse.CurrentLoadOutIds[0])
700
};
701
inventoryResponse.LoadoutPresets = [
702
mapLegacyLoadoutConfig(inventory, inventoryResponse.LoadOutPresets, buildLabel)
703
] as unknown as FlattenMaps<ILoadoutConfigClientLegacy[]>;
699
704
} else {
700
705
// U13 and below
701
706
inventoryResponse.CurrentLoadout = mapLegacyLoadoutConfig(
@@ -706,26 +711,28 @@ export const getInventoryResponse = async (
706
711
}
707
712
}
708
713
for (const category of loadoutKeysLegacy) {
709
for (const item of inventoryResponse.LoadOutPresets[category]) {
710
toLegacyOid(item.ItemId);
711
if (item.s) {
712
if (item.s.ItemId) {
713
toLegacyOid(item.s.ItemId);
714
if (category in inventoryResponse.LoadOutPresets) {
715
for (const item of inventoryResponse.LoadOutPresets[category]) {
716
toLegacyOid(item.ItemId);
717
if (item.s) {
718
if (item.s.ItemId) {
719
toLegacyOid(item.s.ItemId);
720
}
714
721
}
715
}
716
if (item.l) {
717
if (item.l.ItemId) {
718
toLegacyOid(item.l.ItemId);
722
if (item.l) {
723
if (item.l.ItemId) {
724
toLegacyOid(item.l.ItemId);
725
}
719
726
}
720
}
721
if (item.p) {
722
if (item.p.ItemId) {
723
toLegacyOid(item.p.ItemId);
727
if (item.p) {
728
if (item.p.ItemId) {
729
toLegacyOid(item.p.ItemId);
730
}
724
731
}
725
}
726
if (item.m) {
727
if (item.m.ItemId) {
728
toLegacyOid(item.m.ItemId);
732
if (item.m) {
733
if (item.m.ItemId) {
734
toLegacyOid(item.m.ItemId);
735
}
729
736
}
730
737
}
731
738
}
@@ -77,20 +77,16 @@ export const handleInventoryItemConfigChange = async (
77
77
version_compare(buildLabel, "2015.03.19.00.00") < 0
78
78
) {
79
79
// U14-U15
80
// const configs = equipment as {
81
// [key: string]: ILoadoutConfigClientLegacy;
82
// };
80
const configs = equipment as {
81
[key: string]: ILoadoutConfigClientLegacy;
82
};
83
83
84
// logger.debug("legacy loadout received (U14-U15 format)", configs);
84
logger.debug("legacy loadout received (U14-U15 format)", configs);
85
85
86
// for (const key in configs) {
87
// const x = configs[key];
88
// await saveLegacyLoadoutPreset(inventory, x.Presets, x.Name, buildLabel);
89
// }
90
91
logger.warn("Loadouts are currently unsupported in U14-U15, only saving mod/appearance configs");
92
93
break;
86
for (const key in configs) {
87
const x = configs[key];
88
await saveLegacyLoadoutPreset(inventory, x.Presets, x.Name, buildLabel);
89
}
94
90
} else {
95
91
const loadout = await Loadout.findOne({ loadoutOwnerId: accountId });
96
92
if (!loadout) {
@@ -173,7 +169,8 @@ export const handleInventoryItemConfigChange = async (
173
169
}
174
170
case "CurrentLoadout": {
175
171
// U14-U15
176
const id = equipment as string;
172
logger.debug(`ignoring CurrentLoadout from U14-U15 for now`);
173
/*const id = equipment as string;
177
174
if (inventory.CurrentLoadOutIds[0]) {
178
175
inventory.CurrentLoadOutIds[0] = toObjectId(id);
179
176
}
@@ -182,7 +179,7 @@ export const handleInventoryItemConfigChange = async (
182
179
}
183
180
if (inventory.CurrentLoadOutIds[2]) {
184
181
inventory.CurrentLoadOutIds[2] = toObjectId(id);
185
}
182
}*/
186
183
break;
187
184
}
188
185
case "CurrentLoadOutIds": {
@@ -446,6 +443,9 @@ const saveLegacyLoadoutPreset = async (
446
443
currentLoadouts[0] = loadoutId;
447
444
}
448
445
} else {
446
if (currentLoadouts.length <= 0) {
447
currentLoadouts.push(loadout.NORMAL[0]._id);
448
}
449
449
const loadoutId = currentLoadouts[0];
450
450
const preset = loadout.NORMAL.id(loadoutId);
451
451
if (preset) {
@@ -495,6 +495,9 @@ const saveLegacyLoadoutPreset = async (
495
495
currentLoadouts[1] = loadoutId;
496
496
}
497
497
} else {
498
if (currentLoadouts.length <= 1) {
499
currentLoadouts.push(loadout.SENTINEL[0]._id);
500
}
498
501
const loadoutId = currentLoadouts[1];
499
502
const preset = loadout.SENTINEL.id(loadoutId);
500
503
if (preset) {
@@ -538,6 +541,9 @@ const saveLegacyLoadoutPreset = async (
538
541
currentLoadouts[2] = loadoutId;
539
542
}
540
543
} else {
544
if (currentLoadouts.length <= 2) {
545
currentLoadouts.push(loadout.ARCHWING[0]._id);
546
}
541
547
const loadoutId = currentLoadouts[2];
542
548
const preset = loadout.ARCHWING.id(loadoutId);
543
549
if (preset) {
@@ -356,8 +356,11 @@ export interface IInventoryClient
356
356
ActiveQuest: string;
357
357
FlavourItems: IFlavourItem[];
358
358
LoadOutPresets: ILoadOutPresets;
359
LoadoutPresets?: ILoadoutConfigClientLegacy[]; // U14-U15
359
360
CurrentLoadOutIds: IOid[];
360
CurrentLoadout?: ILoadoutConfigClientLegacy; // U8-13
361
CurrentLoadout?:
362
| ILoadoutConfigClientLegacy // U8-13
363
| { $id: string }; // U14-U15
361
364
Missions: IMission[];
362
365
RandomUpgradesIdentified?: number;
363
366
LastRegionPlayed: TSolarMapRegion;