返回提交历史
Modified
src/controllers/api/guildTechController.ts
+2
-7
Modified
src/services/inventoryService.ts
+58
-15
Modified
src/services/missionInventoryUpdateService.ts
+2
-1
Modified
src/types/inventoryTypes/inventoryTypes.ts
+1
-1
XFEstudio/XFESpaceNinjaServer
feat: cap void traces (#4410)
Closes #4409 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/4410 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
dddb6c19
代码差异
4 个文件
+63
-24
@@ -18,6 +18,7 @@ import {
18
18
addCrewShipWeaponSkin,
19
19
addEquipment,
20
20
addItem,
21
addMiscItem,
21
22
addMiscItems,
22
23
addRecipes,
23
24
combineInventoryChanges,
@@ -460,13 +461,7 @@ export const guildTechController: RequestHandler = async (req, res) => {
460
461
"MiscItems"
461
462
);
462
463
const inventoryChanges = finishComponentRepair(inventory, data.TechProductCategory, data.CategoryItemId!);
463
inventoryChanges.MiscItems = [
464
{
465
ItemType: "/Lotus/Types/Items/MiscItems/InstantSalvageRepairItem",
466
ItemCount: -1
467
}
468
];
469
addMiscItems(inventory, inventoryChanges.MiscItems);
464
addMiscItem(inventory, "/Lotus/Types/Items/MiscItems/InstantSalvageRepairItem", -1, inventoryChanges);
470
465
await inventory.save();
471
466
res.json({
472
467
inventoryChanges: inventoryChanges
@@ -569,7 +569,7 @@ export const addItem = async (
569
569
ItemCount: quantity
570
570
} satisfies IMiscItem
571
571
];
572
addMiscItems(inventory, inventoryChanges.MiscItems);
572
addMiscItemsComplex(inventory, inventoryChanges.MiscItems);
573
573
574
574
if (
575
575
typeName == "/Lotus/Types/Game/KubrowPet/Eggs/KubrowEgg" &&
@@ -2462,8 +2462,9 @@ export const applyClientEquipmentUpdates = <K extends TEquipmentKey>(
2462
2462
});
2463
2463
};
2464
2464
2465
// May not be used for adding argon or void traces (subtracting these is fine).
2465
2466
export const addMiscItem = (
2466
inventory: Pick<TInventoryDatabaseDocument, "MiscItems" | "FoundToday">,
2467
inventory: Pick<TInventoryDatabaseDocument, "MiscItems">,
2467
2468
type: string,
2468
2469
count: number,
2469
2470
inventoryChanges: IInventoryChanges = {}
@@ -2478,8 +2479,9 @@ export const addMiscItem = (
2478
2479
combineInventoryChanges(inventoryChanges, { MiscItems: miscItemChanges });
2479
2480
};
2480
2481
2482
// May not be used for adding argon or void traces (subtracting these is fine).
2481
2483
export const addMiscItems = (
2482
inventory: Pick<TInventoryDatabaseDocument, "MiscItems" | "FoundToday">,
2484
inventory: Pick<TInventoryDatabaseDocument, "MiscItems">,
2483
2485
itemsArray: IMiscItem[]
2484
2486
): void => {
2485
2487
const { MiscItems } = inventory;
@@ -2496,18 +2498,59 @@ export const addMiscItems = (
2496
2498
2497
2499
MiscItems[itemIndex].ItemCount += ItemCount;
2498
2500
2499
if (ItemType == "/Lotus/Types/Items/MiscItems/ArgonCrystal" && ItemCount > 0) {
2500
inventory.FoundToday ??= [];
2501
let foundTodayIndex = inventory.FoundToday.findIndex(x => x.ItemType == ItemType);
2502
if (foundTodayIndex == -1) {
2503
foundTodayIndex = inventory.FoundToday.push({ ItemType, ItemCount: 0 }) - 1;
2504
}
2505
inventory.FoundToday[foundTodayIndex].ItemCount += ItemCount;
2506
if (inventory.FoundToday[foundTodayIndex].ItemCount <= 0) {
2507
inventory.FoundToday.splice(foundTodayIndex, 1);
2508
}
2509
if (inventory.FoundToday.length == 0) {
2510
inventory.FoundToday = undefined;
2501
if (MiscItems[itemIndex].ItemCount == 0) {
2502
MiscItems.splice(itemIndex, 1);
2503
} else if (MiscItems[itemIndex].ItemCount < 0) {
2504
throw new Error(
2505
`Cannot remove ${ItemCount * -1}x ${ItemType} from MiscItems, would be left with ${MiscItems[itemIndex].ItemCount}`
2506
);
2507
}
2508
});
2509
};
2510
2511
// Correctly handles acquisition of argon and void traces.
2512
export const addMiscItemsComplex = (
2513
inventory: Pick<TInventoryDatabaseDocument, "MiscItems" | "FoundToday" | "PlayerLevel" | "spoofMasteryRank">,
2514
itemsArray: IMiscItem[]
2515
): void => {
2516
const { MiscItems } = inventory;
2517
2518
itemsArray.forEach(({ ItemCount, ItemType }) => {
2519
if (ItemCount == 0) {
2520
return;
2521
}
2522
2523
let itemIndex = MiscItems.findIndex(x => x.ItemType === ItemType);
2524
if (itemIndex == -1) {
2525
itemIndex = MiscItems.push({ ItemType, ItemCount: 0 }) - 1;
2526
}
2527
2528
MiscItems[itemIndex].ItemCount += ItemCount;
2529
2530
if (ItemCount > 0) {
2531
if (ItemType == "/Lotus/Types/Items/MiscItems/ArgonCrystal") {
2532
inventory.FoundToday ??= [];
2533
let foundTodayIndex = inventory.FoundToday.findIndex(x => x.ItemType == ItemType);
2534
if (foundTodayIndex == -1) {
2535
foundTodayIndex = inventory.FoundToday.push({ ItemType, ItemCount: 0 }) - 1;
2536
}
2537
inventory.FoundToday[foundTodayIndex].ItemCount += ItemCount;
2538
if (inventory.FoundToday[foundTodayIndex].ItemCount <= 0) {
2539
inventory.FoundToday.splice(foundTodayIndex, 1);
2540
}
2541
if (inventory.FoundToday.length == 0) {
2542
inventory.FoundToday = undefined;
2543
}
2544
} else if (ItemType == "/Lotus/Types/Items/MiscItems/VoidTearDrop") {
2545
const masteryRank =
2546
inventory.spoofMasteryRank && inventory.spoofMasteryRank >= 0
2547
? inventory.spoofMasteryRank
2548
: inventory.PlayerLevel;
2549
const maxVoidTraces = 100 + masteryRank * 50;
2550
if (MiscItems[itemIndex].ItemCount > maxVoidTraces) {
2551
MiscItems[itemIndex].ItemCount = maxVoidTraces;
2552
logger.debug(`capped void traces to ${maxVoidTraces} for mastery rank ${masteryRank}`);
2553
}
2511
2554
}
2512
2555
}
2513
2556
@@ -36,6 +36,7 @@ import {
36
36
addLoreFragmentScans,
37
37
addMiscItem,
38
38
addMiscItems,
39
addMiscItemsComplex,
39
40
addMissionComplete,
40
41
addMods,
41
42
addRecipes,
@@ -428,7 +429,7 @@ export const addMissionInventoryUpdates = async (
428
429
}
429
430
}
430
431
if (miscItems.length > 0) {
431
addMiscItems(inventory, miscItems);
432
addMiscItemsComplex(inventory, miscItems);
432
433
}
433
434
if (recipes.length > 0) {
434
435
addRecipes(inventory, recipes);
@@ -516,7 +516,7 @@ export interface IInventoryClient
516
516
NemesisAbandonedRewards: string[];
517
517
LastInventorySync?: IOid;
518
518
NextRefill?: IMongoDateWithLegacySupport;
519
FoundToday?: IMiscItem[]; // for Argon Crystals
519
FoundToday: IMiscItem[] | undefined; // for Argon Crystals
520
520
CustomMarkers?: ICustomMarkers[];
521
521
//ActiveLandscapeTraps: any[];
522
522
EvolutionProgress?: IEvolutionProgress[];