XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

fix: use addItems in purchases (#3335)

Closes #3332 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3335 Co-authored-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Co-committed-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>

7151fc2f
AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
提交于

代码差异

1 个文件 +10 -20
Modified src/services/purchaseService.ts +10 -20
@@ -2,6 +2,7 @@ import { getSubstringFromKeyword } from "../helpers/stringHelpers.ts";
2 2 import {
3 3 addBooster,
4 4 addItem,
5 addItems,
5 6 addMiscItems,
6 7 combineInventoryChanges,
7 8 updateCurrency,
@@ -165,7 +166,7 @@ export const handlePurchase = async (
165 166 }
166 167 if (!inventory.dontSubtractPurchaseItemCost) {
167 168 if (offer.ItemPrices) {
168 handleItemPrices(
169 await handleItemPrices(
169 170 inventory,
170 171 offer.ItemPrices,
171 172 purchaseRequest.PurchaseParams.Quantity,
@@ -321,7 +322,7 @@ export const handlePurchase = async (
321 322 updateCurrency(inventory, offer.platinum, true, purchaseResponse.InventoryChanges);
322 323 }
323 324 if (offer.itemPrices && !inventory.dontSubtractPurchaseItemCost) {
324 handleItemPrices(
325 await handleItemPrices(
325 326 inventory,
326 327 offer.itemPrices,
327 328 purchaseRequest.PurchaseParams.Quantity,
@@ -383,28 +384,17 @@ export const handlePurchase = async (
383 384 return purchaseResponse;
384 385 };
385 386
386 const handleItemPrices = (
387 const handleItemPrices = async (
387 388 inventory: TInventoryDatabaseDocument,
388 389 itemPrices: IMiscItem[],
389 390 purchaseQuantity: number,
390 391 inventoryChanges: IInventoryChanges
391 ): void => {
392 for (const item of itemPrices) {
393 const invItem: IMiscItem = {
394 ItemType: item.ItemType,
395 ItemCount: item.ItemCount * purchaseQuantity * -1
396 };
397
398 addMiscItems(inventory, [invItem]);
399
400 inventoryChanges.MiscItems ??= [];
401 const change = inventoryChanges.MiscItems.find(x => x.ItemType == item.ItemType);
402 if (change) {
403 change.ItemCount += invItem.ItemCount;
404 } else {
405 inventoryChanges.MiscItems.push(invItem);
406 }
407 }
392 ): Promise<void> => {
393 const items: IMiscItem[] = itemPrices.map(({ ItemType, ItemCount }) => ({
394 ItemType,
395 ItemCount: ItemCount * purchaseQuantity * -1
396 }));
397 await addItems(inventory, items, inventoryChanges);
408 398 };
409 399
410 400 export const handleDailyDealPurchase = async (