返回提交历史
Modified
src/controllers/api/infestedFoundryController.ts
+6
-1
Modified
src/services/inventoryService.ts
+12
-16
Modified
src/types/inventoryTypes/inventoryTypes.ts
+2
-2
Modified
src/types/purchaseTypes.ts
+9
-56
Modified
src/types/shipTypes.ts
+1
-1
XFEstudio/SpaceNinjaServer
fix: improve IInventoryChanges & correct shard uninstall response (#4280)
Closes #4277 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/4280 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
b546ee53
代码差异
5 个文件
+30
-76
@@ -28,6 +28,7 @@ import {
28
28
} from "../../services/infestedFoundryService.ts";
29
29
import { sendWsBroadcastToGame, sendWsBroadcastToWebui } from "../../services/wsService.ts";
30
30
import gameToBuildVersion from "../../constants/gameToBuildVersion.ts";
31
import type { IInventoryChanges } from "../../types/purchaseTypes.ts";
31
32
32
33
export const infestedFoundryController: RequestHandler = async (req, res) => {
33
34
const account = await getAccountForRequest(req);
@@ -114,11 +115,12 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
114
115
const infestedFoundry = inventory.toJSON<IInventoryClient>().InfestedFoundry!;
115
116
applyCheatsToInfestedFoundry(inventory, infestedFoundry);
116
117
res.json({
118
...request,
117
119
InventoryChanges: {
118
120
MiscItems: miscItemChanges,
119
121
InfestedFoundry: infestedFoundry
120
122
}
121
});
123
} satisfies IShardUninstallResponse);
122
124
sendWsBroadcastToWebui({ update_inventory: true }, account._id.toString());
123
125
break;
124
126
}
@@ -431,6 +433,9 @@ interface IShardUninstallRequest {
431
433
SuitId: IOid;
432
434
Slot: number;
433
435
}
436
interface IShardUninstallResponse extends IShardUninstallRequest {
437
InventoryChanges: IInventoryChanges;
438
}
434
439
435
440
interface IHelminthNameRequest {
436
441
newName: string;
@@ -388,7 +388,8 @@ export const addStartingGear = async (
388
388
export const combineInventoryChanges = (InventoryChanges: IInventoryChanges, delta: IInventoryChanges): void => {
389
389
for (const key in delta) {
390
390
if (!(key in InventoryChanges)) {
391
InventoryChanges[key] = delta[key];
391
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
392
(InventoryChanges as Record<string, any>)[key] = (delta as Record<string, any>)[key];
392
393
} else if (key == "MiscItems") {
393
394
for (const deltaItem of delta[key]!) {
394
395
const existing = InventoryChanges[key]!.find(x => x.ItemType == deltaItem.ItemType);
@@ -398,9 +399,9 @@ export const combineInventoryChanges = (InventoryChanges: IInventoryChanges, del
398
399
InventoryChanges[key]!.push(deltaItem);
399
400
}
400
401
}
401
} else if (Array.isArray(delta[key])) {
402
const left = InventoryChanges[key] as object[];
403
const right: object[] = delta[key];
402
} else if (Array.isArray(delta[key as keyof IInventoryChanges])) {
403
const left = InventoryChanges[key as keyof IInventoryChanges] as any[];
404
const right = delta[key as keyof IInventoryChanges] as any[];
404
405
for (const item of right) {
405
406
left.push(item);
406
407
}
@@ -420,8 +421,10 @@ export const combineInventoryChanges = (InventoryChanges: IInventoryChanges, del
420
421
left.Extra ??= 0;
421
422
left.Extra += right.Extra;
422
423
}
423
} else if (typeof delta[key] === "number") {
424
(InventoryChanges[key] as number) += delta[key];
424
} else if (typeof delta[key as keyof IInventoryChanges] === "number") {
425
(InventoryChanges[key as keyof IInventoryChanges] as number) += delta[
426
key as keyof IInventoryChanges
427
] as number;
425
428
} else {
426
429
throw new Error(`inventory change not merged: unhandled type for inventory key ${key}`);
427
430
}
@@ -2058,11 +2061,8 @@ const addCustomization = (
2058
2061
): IInventoryChanges => {
2059
2062
if (!inventory.FlavourItems.some(x => x.ItemType == customizationName)) {
2060
2063
const flavourItemIndex = inventory.FlavourItems.push({ ItemType: customizationName }) - 1;
2061
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
2062
2064
inventoryChanges.FlavourItems ??= [];
2063
(inventoryChanges.FlavourItems as IFlavourItem[]).push(
2064
inventory.FlavourItems[flavourItemIndex].toJSON<IFlavourItem>()
2065
);
2065
inventoryChanges.FlavourItems.push(inventory.FlavourItems[flavourItemIndex].toJSON<IFlavourItem>());
2066
2066
}
2067
2067
return inventoryChanges;
2068
2068
};
@@ -2109,11 +2109,8 @@ export const addCrewShipWeaponSkin = (
2109
2109
): IInventoryChanges => {
2110
2110
const index =
2111
2111
inventory.CrewShipWeaponSkins.push({ ItemType: typeName, UpgradeFingerprint: upgradeFingerprint }) - 1;
2112
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
2113
2112
inventoryChanges.CrewShipWeaponSkins ??= [];
2114
(inventoryChanges.CrewShipWeaponSkins as IUpgradeClient[]).push(
2115
inventory.CrewShipWeaponSkins[index].toJSON<IUpgradeClient>()
2116
);
2113
inventoryChanges.CrewShipWeaponSkins.push(inventory.CrewShipWeaponSkins[index].toJSON<IUpgradeClient>());
2117
2114
return inventoryChanges;
2118
2115
};
2119
2116
@@ -2125,9 +2122,8 @@ export const addCrewShipSalvagedWeaponSkin = (
2125
2122
): IInventoryChanges => {
2126
2123
const index =
2127
2124
inventory.CrewShipSalvagedWeaponSkins.push({ ItemType: typeName, UpgradeFingerprint: upgradeFingerprint }) - 1;
2128
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
2129
2125
inventoryChanges.CrewShipSalvagedWeaponSkins ??= [];
2130
(inventoryChanges.CrewShipSalvagedWeaponSkins as IUpgradeClient[]).push(
2126
inventoryChanges.CrewShipSalvagedWeaponSkins.push(
2131
2127
inventory.CrewShipSalvagedWeaponSkins[index].toJSON<IUpgradeClient>()
2132
2128
);
2133
2129
return inventoryChanges;
@@ -1132,8 +1132,8 @@ export interface ISettings {
1132
1132
1133
1133
export interface IShipInventory {
1134
1134
ItemType: string;
1135
ShipExterior: IShipCustomization;
1136
AirSupportPower: string;
1135
ShipExterior?: IShipCustomization;
1136
AirSupportPower?: string;
1137
1137
ItemId: IOidWithLegacySupport;
1138
1138
}
1139
1139
@@ -1,22 +1,10 @@
1
1
import type { TFocusSchool } from "warframe-public-export-plus";
2
import type { IOid, ITypeCount } from "./commonTypes.ts";
3
import type { IEquipmentClient } from "./equipmentTypes.ts";
2
import type { IOid } from "./commonTypes.ts";
4
3
import type {
5
IDroneClient,
6
IInfestedFoundryClient,
7
IMiscItem,
8
INemesisClient,
9
4
IRecentVendorPurchaseClient,
10
TEquipmentKey,
11
ICrewMemberClient,
12
IKubrowPetPrintClient,
13
IUpgradeClient,
14
IQuestKeyClient,
15
IRawUpgrade,
16
IFocusUpgrade,
17
IFocusLoadoutClient,
18
IWeaponSkinClient,
19
TInventorySlot
5
TInventorySlot,
6
IInventoryClient,
7
INemesisClient
20
8
} from "./inventoryTypes/inventoryTypes.ts";
21
9
22
10
export const ePurchaseSource = {
@@ -77,51 +65,16 @@ export interface IPurchaseParams {
77
65
IsWeekly?: boolean; // Vendor
78
66
}
79
67
80
export type IInventoryChanges = {
68
export type IInventoryChanges = Partial<
69
Omit<IInventoryClient, TInventorySlot | "Nemesis" | "RecentVendorPurchases">
70
> & {
81
71
[_ in TInventorySlot]?: IBinChanges;
82
72
} & {
83
[_ in TEquipmentKey]?: IEquipmentClient[];
84
} & {
85
RemovedIdItems?: { ItemId: IOid }[];
86
RegularCredits?: number;
87
PremiumCredits?: number;
88
PremiumCreditsFree?: number;
89
FusionPoints?: number;
90
PrimeTokens?: number;
91
InfestedFoundry?: IInfestedFoundryClient;
92
Drones?: IDroneClient[];
93
MiscItems?: IMiscItem[];
94
ShipDecorations?: ITypeCount[];
95
EmailItems?: ITypeCount[];
96
CrewShipRawSalvage?: ITypeCount[];
97
CrewShipAmmo?: ITypeCount[];
98
73
Nemesis?: Partial<INemesisClient>;
74
RemovedIdItems?: { ItemId: IOid }[];
99
75
NewVendorPurchase?: IRecentVendorPurchaseClient; // >= 38.5.0
100
76
RecentVendorPurchases?: IRecentVendorPurchaseClient; // < 38.5.0
101
CrewMembers?: ICrewMemberClient[];
102
KubrowPetPrints?: IKubrowPetPrintClient[];
103
RawUpgrades?: IRawUpgrade[];
104
Upgrades?: IUpgradeClient[]; // TOVERIFY
105
QuestKeys?: IQuestKeyClient[];
106
OneTimePurchases?: string[];
107
FocusUpgrades?: IFocusUpgrade[];
108
FocusLoadouts?: IFocusLoadoutClient[];
109
WeaponSkins?: IWeaponSkinClient[];
110
} & Record<
111
Exclude<
112
string,
113
| TInventorySlot
114
| TEquipmentKey
115
| "RegularCredits"
116
| "PremiumCredits"
117
| "PremiumCreditsFree"
118
| "InfestedFoundry"
119
| "Drones"
120
| "MiscItems"
121
| "EmailItems"
122
>,
123
number | object[]
124
>;
77
};
125
78
126
79
export interface IAffiliationMods {
127
80
Tag: string;
@@ -5,7 +5,7 @@ export interface IShipDatabase {
5
5
ItemType: string;
6
6
ShipOwnerId: Types.ObjectId;
7
7
ShipExteriorColors?: IColor;
8
AirSupportPower: string;
8
AirSupportPower?: string;
9
9
ShipAttachments?: IShipAttachments;
10
10
SkinFlavourItem?: string;
11
11
}