返回提交历史
Modified
src/services/saveLoadoutService.ts
+56
-56
XFEstudio/XFESpaceNinjaServer
chore: persist ability overrides when saving loadout in pre-U29 (#4240)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/4240 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
f785ea4e
代码差异
1 个文件
+56
-56
@@ -296,11 +296,7 @@ export const handleInventoryItemConfigChange = async (
296
296
continue;
297
297
}
298
298
299
const prevAbilityOverrides = JSON.stringify(
300
inventoryItem.Configs.map(x => x.AbilityOverride?.Ability)
301
.filter(x => x)
302
.sort()
303
);
299
const prevAbilityOverrides = inventoryItem.Configs.map(x => x.AbilityOverride);
304
300
305
301
let abilityMapping: Record<string, string> | undefined;
306
302
if (version_compare(buildLabel, gameToBuildVersion["42.0.0"]) < 0) {
@@ -315,71 +311,75 @@ export const handleInventoryItemConfigChange = async (
315
311
for (const [configId, config] of Object.entries(itemConfigEntries)) {
316
312
if (/^[0-9]+$/.test(configId)) {
317
313
const c = config as IItemConfig;
318
if (version_compare(buildLabel, gameToBuildVersion["16.0.2"]) <= 0) {
319
const legacyColors = c.Customization?.Colors ?? c.Colors;
320
if (legacyColors) {
321
if (legacyColors.length == 10) {
322
c.pricol = convertLegacyColorsToIColor(legacyColors.splice(0, 5));
323
c.attcol = convertLegacyColorsToIColor(legacyColors);
324
} else {
325
c.pricol = convertLegacyColorsToIColor(legacyColors);
326
}
327
}
328
const legacySkins = c.Customization?.Skins;
329
if (legacySkins) {
330
c.Skins = legacySkins;
314
if (version_compare(buildLabel, gameToBuildVersion["29.0.0"]) >= 0) {
315
if (abilityMapping && c.AbilityOverride) {
316
c.AbilityOverride.Ability =
317
abilityMapping[c.AbilityOverride.Ability.split("/").pop()!];
331
318
}
332
if (version_compare(buildLabel, gameToBuildVersion["12.1.2"]) < 0) {
333
if (c.Upgrades) {
334
// U10-U11 store mods in the item config as $id instead of a string, need to convert that here
335
const convertedUpgrades: string[] = [];
336
c.Upgrades.forEach(upgrade => {
337
const upgradeId = upgrade as { $id: string };
338
const rawUpgrade = inventory.RawUpgrades.id(upgradeId.$id);
339
if (rawUpgrade) {
340
const newId = new Types.ObjectId();
341
convertedUpgrades.push(newId.toString());
342
addMods(inventory, [
343
{
319
} else {
320
c.AbilityOverride = prevAbilityOverrides[parseInt(configId)];
321
if (version_compare(buildLabel, gameToBuildVersion["16.0.2"]) <= 0) {
322
const legacyColors = c.Customization?.Colors ?? c.Colors;
323
if (legacyColors) {
324
if (legacyColors.length == 10) {
325
c.pricol = convertLegacyColorsToIColor(legacyColors.splice(0, 5));
326
c.attcol = convertLegacyColorsToIColor(legacyColors);
327
} else {
328
c.pricol = convertLegacyColorsToIColor(legacyColors);
329
}
330
}
331
const legacySkins = c.Customization?.Skins;
332
if (legacySkins) {
333
c.Skins = legacySkins;
334
}
335
if (version_compare(buildLabel, gameToBuildVersion["12.1.2"]) < 0) {
336
if (c.Upgrades) {
337
// U10-U11 store mods in the item config as $id instead of a string, need to convert that here
338
const convertedUpgrades: string[] = [];
339
c.Upgrades.forEach(upgrade => {
340
const upgradeId = upgrade as { $id: string };
341
const rawUpgrade = inventory.RawUpgrades.id(upgradeId.$id);
342
if (rawUpgrade) {
343
const newId = new Types.ObjectId();
344
convertedUpgrades.push(newId.toString());
345
addMods(inventory, [
346
{
347
ItemType: rawUpgrade.ItemType,
348
ItemCount: -1
349
}
350
]);
351
inventory.Upgrades.push({
352
UpgradeFingerprint: `{"lvl":0}`,
344
353
ItemType: rawUpgrade.ItemType,
345
ItemCount: -1
346
}
347
]);
348
inventory.Upgrades.push({
349
UpgradeFingerprint: `{"lvl":0}`,
350
ItemType: rawUpgrade.ItemType,
351
_id: newId
352
});
353
} else {
354
convertedUpgrades.push(upgradeId.$id);
355
}
356
});
357
c.Upgrades = convertedUpgrades;
354
_id: newId
355
});
356
} else {
357
convertedUpgrades.push(upgradeId.$id);
358
}
359
});
360
c.Upgrades = convertedUpgrades;
361
}
358
362
}
359
363
}
360
364
}
361
if (abilityMapping && c.AbilityOverride) {
362
c.AbilityOverride.Ability =
363
abilityMapping[c.AbilityOverride.Ability.split("/").pop()!];
364
}
365
365
inventoryItem.Configs[parseInt(configId)] = c as IItemConfigDatabase;
366
366
}
367
367
}
368
368
369
const newAbilityOverrides = JSON.stringify(
369
const prevAbilityOverridesString = JSON.stringify(
370
prevAbilityOverrides
371
.map(x => x?.Ability)
372
.filter(x => x)
373
.sort()
374
);
375
const newAbilityOverridesString = JSON.stringify(
370
376
inventoryItem.Configs.map(x => x.AbilityOverride?.Ability)
371
377
.filter(x => x)
372
378
.sort()
373
379
);
374
if (
375
JSON.stringify(
376
inventoryItem.Configs.map(x => x.AbilityOverride?.Ability)
377
.filter(x => x)
378
.sort()
379
) != prevAbilityOverrides
380
) {
380
if (prevAbilityOverridesString != newAbilityOverridesString) {
381
381
throw new Error(
382
`refusing saveLoadout with different abilityOverrides: before=${prevAbilityOverrides}, after=${newAbilityOverrides}`
382
`refusing saveLoadout with different abilityOverrides: before=${prevAbilityOverridesString}, after=${newAbilityOverridesString}`
383
383
);
384
384
}
385
385