diff --git a/project/src/services/PaymentService.ts b/project/src/services/PaymentService.ts index bcbd826c..18ff2afa 100644 --- a/project/src/services/PaymentService.ts +++ b/project/src/services/PaymentService.ts @@ -46,35 +46,29 @@ export class PaymentService // Track the amounts of each type of currency involved in the trade. const currencyAmounts: { [key: string]: number } = {}; - // Delete barter items and track currencies if the action is "TradingConfirm". - if (request.Action === "TradingConfirm") + // Delete barter items and track currencies + for (const index in request.scheme_items) { - for (const index in request.scheme_items) + // Find the corresponding item in the player's inventory. + const item = pmcData.Inventory.items.find(i => i._id === request.scheme_items[index].id); + if (item !== undefined) { - // Find the corresponding item in the player's inventory. - const item = pmcData.Inventory.items.find(i => i._id === request.scheme_items[index].id); - if (item !== undefined) + if (!this.paymentHelper.isMoneyTpl(item._tpl)) { - if (!this.paymentHelper.isMoneyTpl(item._tpl)) - { - // If the item is not money, remove it from the inventory. - output = this.inventoryHelper.removeItem(pmcData, item._id, sessionID, output); - request.scheme_items[index].count = 0; - } - else - { - // If the item is money, add its count to the currencyAmounts object. - currencyAmounts[item._tpl] = (currencyAmounts[item._tpl] || 0) + request.scheme_items[index].count; - } + // If the item is not money, remove it from the inventory. + output = this.inventoryHelper.removeItem(pmcData, item._id, sessionID, output); + request.scheme_items[index].count = 0; + } + else + { + // If the item is money, add its count to the currencyAmounts object. + currencyAmounts[item._tpl] = (currencyAmounts[item._tpl] || 0) + request.scheme_items[index].count; } } - } - - // Needs specific handling, add up currency amounts for insured items - if (request.Action === "SptInsure") - { - for (const index in request.scheme_items) + else { + // Used by `SptInsure` + // Handle differently, `id` is the money type tpl const currencyTpl = request.scheme_items[index].id; currencyAmounts[currencyTpl] = (currencyAmounts[currencyTpl] || 0) + request.scheme_items[index].count; }