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

chore: improve legacy loadout stuff (#4136)

Fixes #4106 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/4136 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

4bd89e5e
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

3 个文件 +120 -131
Modified src/controllers/api/inventoryController.ts +85 -81
@@ -15,6 +15,7 @@ import type {
15 15 import {
16 16 accountCheatBooleans,
17 17 accountCheatNumbers,
18 eLoadoutIndex,
18 19 equipmentKeys,
19 20 loadoutKeysLegacy
20 21 } from "../../types/inventoryTypes/inventoryTypes.ts";
@@ -779,8 +780,8 @@ export const getInventoryResponse = async (
779 780 }
780 781 if (version_compare(buildLabel, "2015.03.19.00.00") > 0) {
781 782 for (const category of loadoutKeysLegacy) {
782 if (category in inventoryResponse.LoadOutPresets) {
783 for (const item of inventoryResponse.LoadOutPresets[category]) {
783 if (category in inventoryResponse.LoadOutPresets!) {
784 for (const item of inventoryResponse.LoadOutPresets![category]) {
784 785 toLegacyOid(item.ItemId);
785 786 if (item.s?.ItemId) {
786 787 toLegacyOid(item.s.ItemId);
@@ -857,24 +858,25 @@ export const getInventoryResponse = async (
857 858 if (version_compare(buildLabel, "2015.03.19.00.00") > 0) {
858 859 return inventoryResponse;
859 860 }
860 if (inventoryResponse.CurrentLoadOutIds.length > 0 && inventoryResponse.LoadOutPresets.NORMAL.length > 0) {
861 if (inventoryResponse.CurrentLoadOutIds.length > 0 && inventoryResponse.LoadOutPresets!.NORMAL.length > 0) {
861 862 if (version_compare(buildLabel, gameToBuildVersion["14.0.0"]) >= 0) {
862 863 // U14-U15
863 864 inventoryResponse.CurrentLoadout = {
864 865 $id: fromOid(inventoryResponse.CurrentLoadOutIds[0])
865 866 };
866 867 inventoryResponse.LoadoutPresets = [
867 mapLegacyLoadoutConfig(inventory, inventoryResponse.LoadOutPresets, buildLabel)
868 mapLegacyLoadoutConfig(inventory, inventoryResponse.LoadOutPresets!, buildLabel)
868 869 ] as unknown as FlattenMaps<ILoadoutConfigClientLegacy[]>;
869 870 } else {
870 871 // U13 and below
871 872 inventoryResponse.CurrentLoadout = mapLegacyLoadoutConfig(
872 873 inventory,
873 inventoryResponse.LoadOutPresets,
874 inventoryResponse.LoadOutPresets!,
874 875 buildLabel
875 876 );
876 877 }
877 878 }
879 delete inventoryResponse.LoadOutPresets;
878 880
879 881 // Pre-U12 builds store mods in an array called Cards, and have no concept of RawUpgrades
880 882 if (version_compare(buildLabel, "2014.02.05.00.00") >= 0) {
@@ -1012,7 +1014,9 @@ const mapLegacyLoadoutConfig = (
1012 1014 buildLabel: string
1013 1015 ): ILoadoutConfigClientLegacy | undefined => {
1014 1016 // Loadout config mapping for U15 and below
1015 const normPreset = loadoutPresets.NORMAL.find(x => inventory.CurrentLoadOutIds[0].equals(fromOid(x.ItemId)));
1017 const normPreset =
1018 inventory.CurrentLoadOutIds[eLoadoutIndex.NORMAL] &&
1019 loadoutPresets.NORMAL.find(x => inventory.CurrentLoadOutIds[eLoadoutIndex.NORMAL].equals(fromOid(x.ItemId)));
1016 1020 if (normPreset) {
1017 1021 const sId = normPreset.s?.ItemId && fromOid(normPreset.s.ItemId);
1018 1022 const pId = normPreset.p?.ItemId && fromOid(normPreset.p.ItemId);
@@ -1075,41 +1079,41 @@ const mapLegacyLoadoutConfig = (
1075 1079 };
1076 1080
1077 1081 if (version_compare(buildLabel, "2013.03.18.00.00") >= 0) {
1078 if (inventory.CurrentLoadOutIds.length > 1 && loadoutPresets.SENTINEL.length > 0) {
1079 const compPreset = loadoutPresets.SENTINEL.find(x =>
1080 inventory.CurrentLoadOutIds[1].equals(fromOid(x.ItemId))
1082 const compPreset =
1083 inventory.CurrentLoadOutIds[eLoadoutIndex.SENTINEL] &&
1084 loadoutPresets.SENTINEL.find(x =>
1085 inventory.CurrentLoadOutIds[eLoadoutIndex.SENTINEL].equals(fromOid(x.ItemId))
1081 1086 );
1082 if (compPreset) {
1083 const sId = compPreset.s?.ItemId && fromOid(compPreset.s.ItemId);
1084 const lId = compPreset.l?.ItemId && fromOid(compPreset.l.ItemId);
1085 const s = sId ? inventory.Sentinels.id(sId) : null;
1086 const l = lId ? inventory.SentinelWeapons.id(lId) : null;
1087 loadoutConfig.Presets.push(
1088 {
1089 ItemId: { $id: s?._id.toString() ?? "ffffffffffffffffffffffff" },
1090 ModSlot: version_compare(buildLabel, "2013.09.13.00.00") < 0 ? 0 : (compPreset.s?.mod ?? 0),
1091 CustSlot: compPreset.s?.cus ?? 0,
1092 Customization: {
1093 Emblem: "",
1094 Colors: convertIColorToLegacyColors(s?.Configs[compPreset.s?.cus ?? 0]?.pricol),
1095 Skins: s?.Configs[compPreset.s?.cus ?? 0]?.Skins ?? []
1096 }
1097 },
1098 {
1099 ItemId: { $id: l?._id.toString() ?? "ffffffffffffffffffffffff" },
1100 ModSlot: version_compare(buildLabel, "2013.09.13.00.00") < 0 ? 0 : (compPreset.l?.mod ?? 0),
1101 CustSlot: compPreset.l?.cus ?? 0,
1102 Customization: {
1103 Emblem: "",
1104 Colors: convertIColorToLegacyColors(l?.Configs[compPreset.l?.cus ?? 0]?.pricol),
1105 Skins: l?.Configs[compPreset.l?.cus ?? 0]?.Skins ?? []
1106 }
1087 if (compPreset) {
1088 const sId = compPreset.s?.ItemId && fromOid(compPreset.s.ItemId);
1089 const lId = compPreset.l?.ItemId && fromOid(compPreset.l.ItemId);
1090 const s = sId ? inventory.Sentinels.id(sId) : null;
1091 const l = lId ? inventory.SentinelWeapons.id(lId) : null;
1092 loadoutConfig.Presets.push(
1093 {
1094 ItemId: { $id: s?._id.toString() ?? "ffffffffffffffffffffffff" },
1095 ModSlot: version_compare(buildLabel, "2013.09.13.00.00") < 0 ? 0 : (compPreset.s?.mod ?? 0),
1096 CustSlot: compPreset.s?.cus ?? 0,
1097 Customization: {
1098 Emblem: "",
1099 Colors: convertIColorToLegacyColors(s?.Configs[compPreset.s?.cus ?? 0]?.pricol),
1100 Skins: s?.Configs[compPreset.s?.cus ?? 0]?.Skins ?? []
1107 1101 }
1108 );
1109 }
1102 },
1103 {
1104 ItemId: { $id: l?._id.toString() ?? "ffffffffffffffffffffffff" },
1105 ModSlot: version_compare(buildLabel, "2013.09.13.00.00") < 0 ? 0 : (compPreset.l?.mod ?? 0),
1106 CustSlot: compPreset.l?.cus ?? 0,
1107 Customization: {
1108 Emblem: "",
1109 Colors: convertIColorToLegacyColors(l?.Configs[compPreset.l?.cus ?? 0]?.pricol),
1110 Skins: l?.Configs[compPreset.l?.cus ?? 0]?.Skins ?? []
1111 }
1112 }
1113 );
1110 1114 } else {
1111 1115 logger.warn(
1112 `Could not find SENTINEL loadout with id ${inventory.CurrentLoadOutIds[1].toString()}, this part of the loadout will be empty`
1116 `Could not find SENTINEL loadout with id ${inventory.CurrentLoadOutIds[eLoadoutIndex.SENTINEL]?.toString()}, this part of the loadout will be empty`
1113 1117 );
1114 1118
1115 1119 loadoutConfig.Presets.push(
@@ -1138,53 +1142,53 @@ const mapLegacyLoadoutConfig = (
1138 1142 }
1139 1143
1140 1144 if (version_compare(buildLabel, gameToBuildVersion["15.0.0"]) >= 0) {
1141 if (inventory.CurrentLoadOutIds.length > 2 && loadoutPresets.ARCHWING.length > 0) {
1142 const archPreset = loadoutPresets.ARCHWING.find(x =>
1143 inventory.CurrentLoadOutIds[2].equals(fromOid(x.ItemId))
1145 const archPreset =
1146 inventory.CurrentLoadOutIds[eLoadoutIndex.ARCHWING] &&
1147 loadoutPresets.ARCHWING.find(x =>
1148 inventory.CurrentLoadOutIds[eLoadoutIndex.ARCHWING].equals(fromOid(x.ItemId))
1144 1149 );
1145 if (archPreset) {
1146 const sId = normPreset.s?.ItemId && fromOid(normPreset.s.ItemId);
1147 const pId = normPreset.p?.ItemId && fromOid(normPreset.p.ItemId);
1148 const mId = normPreset.m?.ItemId && fromOid(normPreset.m.ItemId);
1149 const s = sId ? inventory.SpaceSuits.id(sId) : null;
1150 const l = pId ? inventory.SpaceGuns.id(pId) : null;
1151 const m = mId ? inventory.SpaceMelee.id(mId) : null;
1152 loadoutConfig.Presets.push(
1153 {
1154 ItemId: { $id: s?._id.toString() ?? "ffffffffffffffffffffffff" },
1155 ModSlot: archPreset.s?.mod ?? 0,
1156 CustSlot: archPreset.s?.cus ?? 0,
1157 Customization: {
1158 Emblem: "",
1159 Colors: convertIColorToLegacyColors(s?.Configs[archPreset.s?.cus ?? 0]?.pricol),
1160 Skins: s?.Configs[0]?.Skins ?? []
1161 }
1162 },
1163 {
1164 ItemId: { $id: l?._id.toString() ?? "ffffffffffffffffffffffff" },
1165 ModSlot: archPreset.l?.mod ?? 0,
1166 CustSlot: archPreset.l?.cus ?? 0,
1167 Customization: {
1168 Emblem: "",
1169 Colors: convertIColorToLegacyColors(l?.Configs[archPreset.l?.cus ?? 0]?.pricol),
1170 Skins: l?.Configs[0]?.Skins ?? []
1171 }
1172 },
1173 {
1174 ItemId: { $id: m?._id.toString() ?? "ffffffffffffffffffffffff" },
1175 ModSlot: archPreset.m?.mod ?? 0,
1176 CustSlot: archPreset.m?.cus ?? 0,
1177 Customization: {
1178 Emblem: "",
1179 Colors: convertIColorToLegacyColors(m?.Configs[archPreset.m?.cus ?? 0]?.pricol),
1180 Skins: m?.Configs[0]?.Skins ?? []
1181 }
1150 if (archPreset) {
1151 const sId = normPreset.s?.ItemId && fromOid(normPreset.s.ItemId);
1152 const pId = normPreset.p?.ItemId && fromOid(normPreset.p.ItemId);
1153 const mId = normPreset.m?.ItemId && fromOid(normPreset.m.ItemId);
1154 const s = sId ? inventory.SpaceSuits.id(sId) : null;
1155 const l = pId ? inventory.SpaceGuns.id(pId) : null;
1156 const m = mId ? inventory.SpaceMelee.id(mId) : null;
1157 loadoutConfig.Presets.push(
1158 {
1159 ItemId: { $id: s?._id.toString() ?? "ffffffffffffffffffffffff" },
1160 ModSlot: archPreset.s?.mod ?? 0,
1161 CustSlot: archPreset.s?.cus ?? 0,
1162 Customization: {
1163 Emblem: "",
1164 Colors: convertIColorToLegacyColors(s?.Configs[archPreset.s?.cus ?? 0]?.pricol),
1165 Skins: s?.Configs[0]?.Skins ?? []
1182 1166 }
1183 );
1184 }
1167 },
1168 {
1169 ItemId: { $id: l?._id.toString() ?? "ffffffffffffffffffffffff" },
1170 ModSlot: archPreset.l?.mod ?? 0,
1171 CustSlot: archPreset.l?.cus ?? 0,
1172 Customization: {
1173 Emblem: "",
1174 Colors: convertIColorToLegacyColors(l?.Configs[archPreset.l?.cus ?? 0]?.pricol),
1175 Skins: l?.Configs[0]?.Skins ?? []
1176 }
1177 },
1178 {
1179 ItemId: { $id: m?._id.toString() ?? "ffffffffffffffffffffffff" },
1180 ModSlot: archPreset.m?.mod ?? 0,
1181 CustSlot: archPreset.m?.cus ?? 0,
1182 Customization: {
1183 Emblem: "",
1184 Colors: convertIColorToLegacyColors(m?.Configs[archPreset.m?.cus ?? 0]?.pricol),
1185 Skins: m?.Configs[0]?.Skins ?? []
1186 }
1187 }
1188 );
1185 1189 } else {
1186 1190 logger.warn(
1187 `Could not find ARCHWING loadout with id ${inventory.CurrentLoadOutIds[2].toString()}, this part of the loadout will be empty`
1191 `Could not find ARCHWING loadout with id ${inventory.CurrentLoadOutIds[eLoadoutIndex.ARCHWING]?.toString()}, this part of the loadout will be empty`
1188 1192 );
1189 1193
1190 1194 loadoutConfig.Presets.push(
@@ -1226,7 +1230,7 @@ const mapLegacyLoadoutConfig = (
1226 1230 }
1227 1231
1228 1232 logger.error(
1229 `Could not find NORMAL loadout with id ${inventory.CurrentLoadOutIds[0].toString()}, entire loadout will be undefined`
1233 `Could not find NORMAL loadout with id ${inventory.CurrentLoadOutIds[eLoadoutIndex.NORMAL]?.toString()}, entire loadout will be undefined`
1230 1234 );
1231 1235
1232 1236 return undefined;
Modified src/services/saveLoadoutService.ts +34 -49
@@ -15,7 +15,7 @@ import { isEmptyObject, isObjectEmpty } from "../helpers/general.ts";
15 15 import { convertLegacyColorsToIColor, fromOid, toObjectId, version_compare } from "../helpers/inventoryHelpers.ts";
16 16 import { logger } from "../utils/logger.ts";
17 17 import type { ISketch, TEquipmentKey } from "../types/inventoryTypes/inventoryTypes.ts";
18 import { equipmentKeys } from "../types/inventoryTypes/inventoryTypes.ts";
18 import { eLoadoutIndex, equipmentKeys } from "../types/inventoryTypes/inventoryTypes.ts";
19 19 import type { IItemConfig, IItemConfigDatabase } from "../types/inventoryTypes/commonInventoryTypes.ts";
20 20 import { importCrewShipMembers, importCrewShipWeapon, importLoadOutConfig } from "./importService.ts";
21 21 import type { IEquipmentDatabase, IEquipmentSelectionDatabase } from "../types/equipmentTypes.ts";
@@ -437,7 +437,7 @@ const saveLegacyLoadoutPreset = async (
437 437 presets[0],
438 438 buildLabel,
439 439 inventory.Suits.id(fromOid(presets[0].ItemId)),
440 loadout.NORMAL.id(currentLoadouts[0])?.s?.cus
440 loadout.NORMAL.id(currentLoadouts[eLoadoutIndex.NORMAL])?.s?.cus
441 441 )
442 442 : undefined;
443 443 const p =
@@ -446,7 +446,7 @@ const saveLegacyLoadoutPreset = async (
446 446 presets[1],
447 447 buildLabel,
448 448 inventory.Pistols.id(fromOid(presets[1].ItemId)),
449 loadout.NORMAL.id(currentLoadouts[0])?.p?.cus
449 loadout.NORMAL.id(currentLoadouts[eLoadoutIndex.NORMAL])?.p?.cus
450 450 )
451 451 : undefined;
452 452 const l =
@@ -455,7 +455,7 @@ const saveLegacyLoadoutPreset = async (
455 455 presets[2],
456 456 buildLabel,
457 457 inventory.LongGuns.id(fromOid(presets[2].ItemId)),
458 loadout.NORMAL.id(currentLoadouts[0])?.l?.cus
458 loadout.NORMAL.id(currentLoadouts[eLoadoutIndex.NORMAL])?.l?.cus
459 459 )
460 460 : undefined;
461 461 const m =
@@ -464,7 +464,7 @@ const saveLegacyLoadoutPreset = async (
464 464 presets[3],
465 465 buildLabel,
466 466 inventory.Melee.id(fromOid(presets[3].ItemId)),
467 loadout.NORMAL.id(currentLoadouts[0])?.m?.cus
467 loadout.NORMAL.id(currentLoadouts[eLoadoutIndex.NORMAL])?.m?.cus
468 468 )
469 469 : undefined;
470 470
@@ -481,25 +481,20 @@ const saveLegacyLoadoutPreset = async (
481 481 if (currentLoadouts.length == 0) {
482 482 currentLoadouts.push(loadoutId);
483 483 } else {
484 currentLoadouts[0] = loadoutId;
484 currentLoadouts[eLoadoutIndex.NORMAL] = loadoutId;
485 485 }
486 486 } else {
487 if (currentLoadouts.length <= 0) {
487 if (currentLoadouts.length <= eLoadoutIndex.NORMAL) {
488 488 currentLoadouts.push(loadout.NORMAL[0]._id);
489 } else if (!loadout.NORMAL.id(currentLoadouts[0])) {
490 currentLoadouts[eLoadoutIndex.NORMAL] = loadout.NORMAL[0]._id;
489 491 }
490 const loadoutId = currentLoadouts[0];
491 const preset = loadout.NORMAL.id(loadoutId);
492 if (preset) {
493 preset.n = name ?? preset.n;
494 preset.s = s;
495 preset.p = p;
496 preset.l = l;
497 preset.m = m;
498 } else {
499 logger.warn(
500 `Could not find NORMAL loadout with id ${loadoutId.toString()}, equipment selection will not be saved`
501 );
502 }
492 const preset = loadout.NORMAL.id(currentLoadouts[0])!;
493 preset.n = name ?? preset.n;
494 preset.s = s;
495 preset.p = p;
496 preset.l = l;
497 preset.m = m;
503 498 }
504 499
505 500 if (presets.length >= 6) {
@@ -509,7 +504,7 @@ const saveLegacyLoadoutPreset = async (
509 504 presets[4],
510 505 buildLabel,
511 506 inventory.Sentinels.id(fromOid(presets[4].ItemId)),
512 loadout.SENTINEL.id(currentLoadouts[1])?.s?.cus
507 loadout.SENTINEL.id(currentLoadouts[eLoadoutIndex.SENTINEL])?.s?.cus
513 508 )
514 509 : undefined;
515 510 const l =
@@ -518,7 +513,7 @@ const saveLegacyLoadoutPreset = async (
518 513 presets[5],
519 514 buildLabel,
520 515 inventory.SentinelWeapons.id(fromOid(presets[5].ItemId)),
521 loadout.SENTINEL.id(currentLoadouts[1])?.l?.cus
516 loadout.SENTINEL.id(currentLoadouts[eLoadoutIndex.SENTINEL])?.l?.cus
522 517 )
523 518 : undefined;
524 519
@@ -533,23 +528,18 @@ const saveLegacyLoadoutPreset = async (
533 528 if (currentLoadouts.length < 2) {
534 529 currentLoadouts.push(loadoutId);
535 530 } else {
536 currentLoadouts[1] = loadoutId;
531 currentLoadouts[eLoadoutIndex.SENTINEL] = loadoutId;
537 532 }
538 533 } else {
539 if (currentLoadouts.length <= 1) {
534 if (currentLoadouts.length <= eLoadoutIndex.SENTINEL) {
540 535 currentLoadouts.push(loadout.SENTINEL[0]._id);
536 } else if (!loadout.SENTINEL.id(currentLoadouts[eLoadoutIndex.SENTINEL])) {
537 currentLoadouts[eLoadoutIndex.SENTINEL] = loadout.SENTINEL[0]._id;
541 538 }
542 const loadoutId = currentLoadouts[1];
543 const preset = loadout.SENTINEL.id(loadoutId);
544 if (preset) {
545 preset.n = name ?? preset.n;
546 preset.s = s;
547 preset.l = l;
548 } else {
549 logger.warn(
550 `Could not find SENTINEL loadout with id ${loadoutId.toString()}, equipment selection will not be saved`
551 );
552 }
539 const preset = loadout.SENTINEL.id(currentLoadouts[eLoadoutIndex.SENTINEL])!;
540 preset.n = name ?? preset.n;
541 preset.s = s;
542 preset.l = l;
553 543 }
554 544 }
555 545
@@ -579,24 +569,19 @@ const saveLegacyLoadoutPreset = async (
579 569 if (currentLoadouts.length < 3) {
580 570 currentLoadouts.push(loadoutId);
581 571 } else {
582 currentLoadouts[2] = loadoutId;
572 currentLoadouts[eLoadoutIndex.ARCHWING] = loadoutId;
583 573 }
584 574 } else {
585 if (currentLoadouts.length <= 2) {
575 if (currentLoadouts.length <= eLoadoutIndex.ARCHWING) {
586 576 currentLoadouts.push(loadout.ARCHWING[0]._id);
577 } else if (!loadout.ARCHWING.id(currentLoadouts[eLoadoutIndex.ARCHWING])) {
578 currentLoadouts[eLoadoutIndex.ARCHWING] = loadout.ARCHWING[0]._id;
587 579 }
588 const loadoutId = currentLoadouts[2];
589 const preset = loadout.ARCHWING.id(loadoutId);
590 if (preset) {
591 preset.n = name ?? preset.n;
592 preset.s = s;
593 preset.l = l;
594 preset.m = m;
595 } else {
596 logger.warn(
597 `Could not find ARCHWING loadout with id ${loadoutId.toString()}, equipment selection will not be saved`
598 );
599 }
580 const preset = loadout.ARCHWING.id(currentLoadouts[eLoadoutIndex.ARCHWING])!;
581 preset.n = name ?? preset.n;
582 preset.s = s;
583 preset.l = l;
584 preset.m = m;
600 585 }
601 586 }
602 587
Modified src/types/inventoryTypes/inventoryTypes.ts +1 -1
@@ -409,7 +409,7 @@ export interface IInventoryClient
409 409 QuestKeys: IQuestKeyClient[];
410 410 ActiveQuest: string;
411 411 FlavourItems: IFlavourItem[];
412 LoadOutPresets: ILoadOutPresets;
412 LoadOutPresets?: ILoadOutPresets; // U16+
413 413 LoadoutPresets?: ILoadoutConfigClientLegacy[]; // U14-U15
414 414 CurrentLoadOutIds: IOid[];
415 415 CurrentLoadout?: