diff --git a/project/src/controllers/InsuranceController.ts b/project/src/controllers/InsuranceController.ts index a2593187..9ba20416 100644 --- a/project/src/controllers/InsuranceController.ts +++ b/project/src/controllers/InsuranceController.ts @@ -31,6 +31,7 @@ import { TimeUtil } from "@spt-aki/utils/TimeUtil"; export class InsuranceController { protected insuranceConfig: IInsuranceConfig; + protected roubleTpl = "5449016a4bdc2d6f028b456f"; constructor( @inject("WinstonLogger") protected logger: ILogger, @@ -522,17 +523,17 @@ export class InsuranceController const itemsToInsureCount = body.items.length; const itemsToPay = []; const inventoryItemsHash = {}; - + // Create hash of player inventory items (keyed by item id) for (const item of pmcData.Inventory.items) { inventoryItemsHash[item._id] = item; } - // get the price of all items + // Get price of all items being insured for (const key of body.items) { itemsToPay.push({ - id: inventoryItemsHash[key]._id, + id: this.roubleTpl, // TODO: update to handle difference currencies count: Math.round(this.insuranceService.getPremium(pmcData, inventoryItemsHash[key], body.tid)) }); } @@ -541,7 +542,7 @@ export class InsuranceController // eslint-disable-next-line @typescript-eslint/naming-convention scheme_items: itemsToPay, tid: body.tid, - Action: "", + Action: "SptInsure", type: "", // eslint-disable-next-line @typescript-eslint/naming-convention item_id: "", diff --git a/project/src/models/eft/trade/IProcessBuyTradeRequestData.ts b/project/src/models/eft/trade/IProcessBuyTradeRequestData.ts index 5fc93bbb..54b4f8b7 100644 --- a/project/src/models/eft/trade/IProcessBuyTradeRequestData.ts +++ b/project/src/models/eft/trade/IProcessBuyTradeRequestData.ts @@ -3,7 +3,7 @@ import { IProcessBaseTradeRequestData } from "@spt-aki/models/eft/trade/IProcess export interface IProcessBuyTradeRequestData extends IProcessBaseTradeRequestData { - Action: "buy_from_trader" | "TradingConfirm" | "RestoreHealth" | "" + Action: "buy_from_trader" | "TradingConfirm" | "RestoreHealth" | "" | "SptInsure" type: string tid: string item_id: string @@ -14,6 +14,7 @@ export interface IProcessBuyTradeRequestData extends IProcessBaseTradeRequestDat export interface SchemeItem { + /** Id of stack to take money from, is money tpl when Action is `SptInsure` */ id: string count: number } diff --git a/project/src/services/PaymentService.ts b/project/src/services/PaymentService.ts index 09e022c6..bcbd826c 100644 --- a/project/src/services/PaymentService.ts +++ b/project/src/services/PaymentService.ts @@ -70,6 +70,16 @@ export class PaymentService } } + // Needs specific handling, add up currency amounts for insured items + if (request.Action === "SptInsure") + { + for (const index in request.scheme_items) + { + const currencyTpl = request.scheme_items[index].id; + currencyAmounts[currencyTpl] = (currencyAmounts[currencyTpl] || 0) + request.scheme_items[index].count; + } + } + // Track the total amount of all currencies. let totalCurrencyAmount = 0; @@ -81,6 +91,7 @@ export class PaymentService if (currencyAmount > 0) { + // Find money stacks in inventory and remove amount needed + update output object to inform client of changes output = this.addPaymentToOutput(pmcData, currencyTpl, currencyAmount, sessionID, output); // If there are warnings, exit early. @@ -240,7 +251,7 @@ export class PaymentService } /** - * Remove currency from player stash/inventory + * Remove currency from player stash/inventory and update client object with changes * @param pmcData Player profile to find and remove currency from * @param currencyTpl Type of currency to pay * @param amountToPay money value to pay