返回提交历史
Modified
src/controllers/api/missionInventoryUpdateController.ts
+1
-1
Modified
src/services/inventoryService.ts
+23
-3
Modified
src/services/missionInventoryUpdateService.ts
+16
-9
Modified
src/types/purchaseTypes.ts
+9
-1
Modified
src/types/requestTypes.ts
+1
-0
XFEstudio/XFESpaceNinjaServer
feat: handle EmailItems received during mission (#1088)
Closes #1087 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1088
59fd816b
代码差异
5 个文件
+50
-14
@@ -54,7 +54,7 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res)
54
54
logger.debug("mission report:", missionReport);
55
55
56
56
const inventory = await getInventory(accountId);
57
const inventoryUpdates = addMissionInventoryUpdates(inventory, missionReport);
57
const inventoryUpdates = await addMissionInventoryUpdates(inventory, missionReport);
58
58
59
59
if (missionReport.MissionStatus !== "GS_SUCCESS") {
60
60
await inventory.save();
@@ -428,10 +428,8 @@ export const addItem = async (
428
428
};
429
429
}
430
430
if (typeName in ExportEmailItems) {
431
const emailItem = ExportEmailItems[typeName];
432
await createMessage(inventory.accountOwnerId.toString(), [convertInboxMessage(emailItem.message)]);
433
431
return {
434
InventoryChanges: {}
432
InventoryChanges: await addEmailItem(inventory, typeName)
435
433
};
436
434
}
437
435
@@ -943,6 +941,28 @@ const addDrone = (
943
941
return inventoryChanges;
944
942
};
945
943
944
export const addEmailItem = async (
945
inventory: TInventoryDatabaseDocument,
946
typeName: string,
947
inventoryChanges: IInventoryChanges = {}
948
): Promise<IInventoryChanges> => {
949
const meta = ExportEmailItems[typeName];
950
const emailItem = inventory.EmailItems.find(x => x.ItemType == typeName);
951
if (!emailItem || !meta.sendOnlyOnce) {
952
await createMessage(inventory.accountOwnerId.toString(), [convertInboxMessage(meta.message)]);
953
954
if (emailItem) {
955
emailItem.ItemCount += 1;
956
} else {
957
inventory.EmailItems.push({ ItemType: typeName, ItemCount: 1 });
958
}
959
960
inventoryChanges.EmailItems ??= [];
961
inventoryChanges.EmailItems.push({ ItemType: typeName, ItemCount: 1 });
962
}
963
return inventoryChanges;
964
};
965
946
966
//TODO: wrong id is not erroring
947
967
export const addGearExpByCategory = (
948
968
inventory: TInventoryDatabaseDocument,
@@ -14,6 +14,7 @@ import {
14
14
addConsumables,
15
15
addCrewShipAmmo,
16
16
addCrewShipRawSalvage,
17
addEmailItem,
17
18
addFocusXpIncreases,
18
19
addFusionTreasures,
19
20
addGearExpByCategory,
@@ -61,10 +62,10 @@ const getRandomRewardByChance = (pool: IReward[]): IRngResult | undefined => {
61
62
//type TignoredInventoryUpdateKeys = (typeof ignoredInventoryUpdateKeys)[number];
62
63
//const knownUnhandledKeys: readonly string[] = ["test"] as const; // for unimplemented but important keys
63
64
64
export const addMissionInventoryUpdates = (
65
export const addMissionInventoryUpdates = async (
65
66
inventory: HydratedDocument<IInventoryDatabase, InventoryDocumentProps>,
66
67
inventoryUpdates: IMissionInventoryUpdateRequest
67
): Partial<IInventoryDatabase> | undefined => {
68
): Promise<Partial<IInventoryDatabase> | undefined> => {
68
69
//TODO: type this properly
69
70
const inventoryChanges: Partial<IInventoryDatabase> = {};
70
71
if (inventoryUpdates.MissionFailed === true) {
@@ -156,6 +157,12 @@ export const addMissionInventoryUpdates = (
156
157
inventoryChanges.FusionPoints = fusionPoints;
157
158
break;
158
159
}
160
case "EmailItems": {
161
for (const tc of value) {
162
await addEmailItem(inventory, tc.ItemType);
163
}
164
break;
165
}
159
166
case "FocusXpIncreases": {
160
167
addFocusXpIncreases(inventory, value);
161
168
break;
@@ -237,32 +244,32 @@ export const addMissionInventoryUpdates = (
237
244
});
238
245
break;
239
246
case "CollectibleScans":
240
value.forEach(scan => {
247
for (const scan of value) {
241
248
const entry = inventory.CollectibleSeries?.find(x => x.CollectibleType == scan.CollectibleType);
242
249
if (entry) {
243
250
entry.Count = scan.Count;
244
251
entry.Tracking = scan.Tracking;
245
252
if (entry.CollectibleType == "/Lotus/Objects/Orokin/Props/CollectibleSeriesOne") {
246
253
const progress = entry.Count / entry.ReqScans;
247
entry.IncentiveStates.forEach(gate => {
254
for (const gate of entry.IncentiveStates) {
248
255
gate.complete = progress >= gate.threshold;
249
256
if (gate.complete && !gate.sent) {
250
257
gate.sent = true;
251
258
if (gate.threshold == 0.5) {
252
void createMessage(inventory.accountOwnerId.toString(), [kuriaMessage50]);
259
await createMessage(inventory.accountOwnerId.toString(), [kuriaMessage50]);
253
260
} else {
254
void createMessage(inventory.accountOwnerId.toString(), [kuriaMessage75]);
261
await createMessage(inventory.accountOwnerId.toString(), [kuriaMessage75]);
255
262
}
256
263
}
257
});
264
}
258
265
if (progress >= 1.0) {
259
void createMessage(inventory.accountOwnerId.toString(), [kuriaMessage100]);
266
await createMessage(inventory.accountOwnerId.toString(), [kuriaMessage100]);
260
267
}
261
268
}
262
269
} else {
263
270
logger.warn(`${scan.CollectibleType} was not found in inventory, ignoring scans`);
264
271
}
265
});
272
}
266
273
break;
267
274
case "Upgrades":
268
275
value.forEach(clientUpgrade => {
@@ -1,5 +1,11 @@
1
1
import { IEquipmentClient } from "./inventoryTypes/commonInventoryTypes";
2
import { IDroneClient, IInfestedFoundryClient, IMiscItem, TEquipmentKey } from "./inventoryTypes/inventoryTypes";
2
import {
3
IDroneClient,
4
IInfestedFoundryClient,
5
IMiscItem,
6
ITypeCount,
7
TEquipmentKey
8
} from "./inventoryTypes/inventoryTypes";
3
9
4
10
export interface IPurchaseRequest {
5
11
PurchaseParams: IPurchaseParams;
@@ -33,6 +39,7 @@ export type IInventoryChanges = {
33
39
InfestedFoundry?: IInfestedFoundryClient;
34
40
Drones?: IDroneClient[];
35
41
MiscItems?: IMiscItem[];
42
EmailItems?: ITypeCount[];
36
43
} & Record<
37
44
Exclude<
38
45
string,
@@ -44,6 +51,7 @@ export type IInventoryChanges = {
44
51
| "InfestedFoundry"
45
52
| "Drones"
46
53
| "MiscItems"
54
| "EmailItems"
47
55
>,
48
56
number | object[]
49
57
>;
@@ -46,6 +46,7 @@ export type IMissionInventoryUpdateRequest = {
46
46
CrewShipRawSalvage?: ITypeCount[];
47
47
CrewShipAmmo?: ITypeCount[];
48
48
BonusMiscItems?: ITypeCount[];
49
EmailItems?: ITypeCount[];
49
50
50
51
SyndicateId?: string;
51
52
SortieId?: string;