Fix insurance costing 0 roubles

This commit is contained in:
Dev 2023-11-14 11:46:51 +00:00
parent 6cf91ad923
commit 1021a945cb
3 changed files with 19 additions and 6 deletions

View File

@ -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: "",

View File

@ -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
}

View File

@ -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