返回提交历史
Modified
src/services/inventoryService.ts
+7
-0
Modified
src/services/purchaseService.ts
+26
-16
XFEstudio/SpaceNinjaServer
fix: handle bundles being given to addItems (#1005)
This is needed for the Hex noggles email attachment Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1005 Co-authored-by: Sainan <sainan@calamity.inc> Co-committed-by: Sainan <sainan@calamity.inc>
f672f05d
代码差异
2 个文件
+33
-16
@@ -38,6 +38,7 @@ import { getExalted, getKeyChainItems } from "@/src/services/itemDataService";
38
38
import { IEquipmentClient, IEquipmentDatabase, IItemConfig } from "../types/inventoryTypes/commonInventoryTypes";
39
39
import {
40
40
ExportArcanes,
41
ExportBundles,
41
42
ExportCustoms,
42
43
ExportDrones,
43
44
ExportFlavour,
@@ -59,6 +60,7 @@ import { toOid } from "../helpers/inventoryHelpers";
59
60
import { generateRewardSeed } from "@/src/controllers/api/getNewRewardSeedController";
60
61
import { addStartingGear } from "@/src/controllers/api/giveStartingGearController";
61
62
import { addQuestKey, completeQuest } from "@/src/services/questService";
63
import { handleBundleAcqusition } from "./purchaseService";
62
64
63
65
export const createInventory = async (
64
66
accountOwnerId: Types.ObjectId,
@@ -157,6 +159,11 @@ export const addItem = async (
157
159
typeName: string,
158
160
quantity: number = 1
159
161
): Promise<{ InventoryChanges: IInventoryChanges }> => {
162
// Bundles are technically StoreItems but a) they don't have a normal counterpart, and b) they are used in non-StoreItem contexts, e.g. email attachments.
163
if (typeName in ExportBundles) {
164
return { InventoryChanges: await handleBundleAcqusition(typeName, inventory, quantity) };
165
}
166
160
167
// Strict typing
161
168
if (typeName in ExportRecipes) {
162
169
const recipeChanges = [
@@ -200,6 +200,31 @@ const handleItemPrices = (
200
200
}
201
201
};
202
202
203
export const handleBundleAcqusition = async (
204
storeItemName: string,
205
inventory: TInventoryDatabaseDocument,
206
quantity: number = 1,
207
inventoryChanges: IInventoryChanges = {}
208
): Promise<IInventoryChanges> => {
209
const bundle = ExportBundles[storeItemName];
210
logger.debug("acquiring bundle", bundle);
211
for (const component of bundle.components) {
212
combineInventoryChanges(
213
inventoryChanges,
214
(
215
await handleStoreItemAcquisition(
216
component.typeName,
217
inventory,
218
component.purchaseQuantity * quantity,
219
component.durability,
220
true
221
)
222
).InventoryChanges
223
);
224
}
225
return inventoryChanges;
226
};
227
203
228
export const handleStoreItemAcquisition = async (
204
229
storeItemName: string,
205
230
inventory: TInventoryDatabaseDocument,
@@ -212,22 +237,7 @@ export const handleStoreItemAcquisition = async (
212
237
};
213
238
logger.debug(`handling acquision of ${storeItemName}`);
214
239
if (storeItemName in ExportBundles) {
215
const bundle = ExportBundles[storeItemName];
216
logger.debug("acquiring bundle", bundle);
217
for (const component of bundle.components) {
218
combineInventoryChanges(
219
purchaseResponse.InventoryChanges,
220
(
221
await handleStoreItemAcquisition(
222
component.typeName,
223
inventory,
224
component.purchaseQuantity * quantity,
225
component.durability,
226
true
227
)
228
).InventoryChanges
229
);
230
}
240
await handleBundleAcqusition(storeItemName, inventory, quantity, purchaseResponse.InventoryChanges);
231
241
} else {
232
242
const storeCategory = getStoreItemCategory(storeItemName);
233
243
const internalName = storeItemName.replace("/StoreItems", "");