返回提交历史
Modified
src/controllers/api/inventoryController.ts
+13
-0
Modified
src/controllers/api/upgradesController.ts
+13
-23
Modified
src/services/saveLoadoutService.ts
+38
-0
XFEstudio/SpaceNinjaServer
feat: conversion of AbilityOverride between versions (#4073)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/4073 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
bbcc4c0f
代码差异
3 个文件
+64
-23
@@ -611,6 +611,19 @@ export const getInventoryResponse = async (
611
611
inventoryResponse.Nemesis = undefined;
612
612
}
613
613
614
// U42 migrated ability paths so translate them back for older versions
615
if (version_compare(buildLabel, gameToBuildVersion["42.0.0"]) >= 0) {
616
return inventoryResponse;
617
}
618
for (const suit of inventoryResponse.Suits) {
619
for (const config of suit.Configs) {
620
if (config.AbilityOverride) {
621
config.AbilityOverride.Ability =
622
"/Lotus/Powersuits/PowersuitAbilities/" + config.AbilityOverride.Ability.split("/").pop();
623
}
624
}
625
}
626
614
627
// U40 migrated KubrowPetEggs to MiscItems so translate it back for older versions
615
628
if (version_compare(buildLabel, gameToBuildVersion["40.0.0"]) >= 0) {
616
629
return inventoryResponse;
@@ -222,32 +222,22 @@ export const upgradesController: RequestHandler = async (req, res) => {
222
222
let newAbilityOverride: IAbilityOverride | undefined;
223
223
let totalPercentagePointsConsumed = 0;
224
224
if (operation.UpgradeRequirement != "") {
225
newAbilityOverride = {
226
Ability: operation.UpgradeRequirement,
227
Index: operation.PolarizeSlot
228
};
229
230
225
const abilityName = operation.UpgradeRequirement.split("/").pop();
231
let recipeFound = false;
232
for (const recipe of Object.values(ExportRecipes)) {
233
if (recipe.resultType.endsWith(`/${abilityName}`)) {
234
recipeFound = true;
235
for (const ingredient of recipe.ingredients) {
236
totalPercentagePointsConsumed += ingredient.ItemCount / 10;
237
if (!inventory.infiniteHelminthMaterials) {
238
inventory.InfestedFoundry!.Resources!.find(
239
x => x.ItemType == ingredient.ItemType
240
)!.Count -= ingredient.ItemCount;
241
}
242
}
243
break;
244
}
226
const recipe = Object.values(ExportRecipes).find(x => x.resultType.endsWith(`/${abilityName}`));
227
if (!recipe) {
228
throw new Error(`could not find recipe for ${operation.UpgradeRequirement}`);
245
229
}
246
if (!recipeFound) {
247
console.warn(
248
`could not find recipe for ${operation.UpgradeRequirement}; helminth resources won't be charged`
249
);
230
for (const ingredient of recipe.ingredients) {
231
totalPercentagePointsConsumed += ingredient.ItemCount / 10;
232
if (!inventory.infiniteHelminthMaterials) {
233
inventory.InfestedFoundry!.Resources!.find(x => x.ItemType == ingredient.ItemType)!.Count -=
234
ingredient.ItemCount;
235
}
250
236
}
237
newAbilityOverride = {
238
Ability: recipe.resultType,
239
Index: operation.PolarizeSlot
240
};
251
241
}
252
242
253
243
for (const entry of operation.PolarityRemap) {
@@ -297,6 +297,22 @@ export const handleInventoryItemConfigChange = async (
297
297
continue;
298
298
}
299
299
300
const prevAbilityOverrides = JSON.stringify(
301
inventoryItem.Configs.map(x => x.AbilityOverride?.Ability)
302
.filter(x => x)
303
.sort()
304
);
305
306
let abilityMapping: Record<string, string> | undefined;
307
if (buildLabel && version_compare(buildLabel, gameToBuildVersion["42.0.0"]) < 0) {
308
abilityMapping = {};
309
for (const config of inventoryItem.Configs) {
310
if (config.AbilityOverride) {
311
abilityMapping[config.AbilityOverride.Ability.split("/").pop()!] =
312
config.AbilityOverride.Ability;
313
}
314
}
315
}
300
316
for (const [configId, config] of Object.entries(itemConfigEntries)) {
301
317
if (/^[0-9]+$/.test(configId)) {
302
318
const c = config as IItemConfig;
@@ -343,9 +359,31 @@ export const handleInventoryItemConfigChange = async (
343
359
}
344
360
}
345
361
}
362
if (abilityMapping && c.AbilityOverride) {
363
c.AbilityOverride.Ability =
364
abilityMapping[c.AbilityOverride.Ability.split("/").pop()!];
365
}
346
366
inventoryItem.Configs[parseInt(configId)] = c as IItemConfigDatabase;
347
367
}
348
368
}
369
370
const newAbilityOverrides = JSON.stringify(
371
inventoryItem.Configs.map(x => x.AbilityOverride?.Ability)
372
.filter(x => x)
373
.sort()
374
);
375
if (
376
JSON.stringify(
377
inventoryItem.Configs.map(x => x.AbilityOverride?.Ability)
378
.filter(x => x)
379
.sort()
380
) != prevAbilityOverrides
381
) {
382
throw new Error(
383
`refusing saveLoadout with different abilityOverrides: before=${prevAbilityOverrides}, after=${newAbilityOverrides}`
384
);
385
}
386
349
387
if ("Favorite" in itemConfigEntries) {
350
388
inventoryItem.Favorite = itemConfigEntries.Favorite;
351
389
}