Fix insurance costing 0 roubles
This commit is contained in:
parent
6cf91ad923
commit
1021a945cb
@ -31,6 +31,7 @@ import { TimeUtil } from "@spt-aki/utils/TimeUtil";
|
|||||||
export class InsuranceController
|
export class InsuranceController
|
||||||
{
|
{
|
||||||
protected insuranceConfig: IInsuranceConfig;
|
protected insuranceConfig: IInsuranceConfig;
|
||||||
|
protected roubleTpl = "5449016a4bdc2d6f028b456f";
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@inject("WinstonLogger") protected logger: ILogger,
|
@inject("WinstonLogger") protected logger: ILogger,
|
||||||
@ -522,17 +523,17 @@ export class InsuranceController
|
|||||||
const itemsToInsureCount = body.items.length;
|
const itemsToInsureCount = body.items.length;
|
||||||
const itemsToPay = [];
|
const itemsToPay = [];
|
||||||
const inventoryItemsHash = {};
|
const inventoryItemsHash = {};
|
||||||
|
// Create hash of player inventory items (keyed by item id)
|
||||||
for (const item of pmcData.Inventory.items)
|
for (const item of pmcData.Inventory.items)
|
||||||
{
|
{
|
||||||
inventoryItemsHash[item._id] = item;
|
inventoryItemsHash[item._id] = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the price of all items
|
// Get price of all items being insured
|
||||||
for (const key of body.items)
|
for (const key of body.items)
|
||||||
{
|
{
|
||||||
itemsToPay.push({
|
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))
|
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
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
scheme_items: itemsToPay,
|
scheme_items: itemsToPay,
|
||||||
tid: body.tid,
|
tid: body.tid,
|
||||||
Action: "",
|
Action: "SptInsure",
|
||||||
type: "",
|
type: "",
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
item_id: "",
|
item_id: "",
|
||||||
|
@ -3,7 +3,7 @@ import { IProcessBaseTradeRequestData } from "@spt-aki/models/eft/trade/IProcess
|
|||||||
|
|
||||||
export interface IProcessBuyTradeRequestData extends IProcessBaseTradeRequestData
|
export interface IProcessBuyTradeRequestData extends IProcessBaseTradeRequestData
|
||||||
{
|
{
|
||||||
Action: "buy_from_trader" | "TradingConfirm" | "RestoreHealth" | ""
|
Action: "buy_from_trader" | "TradingConfirm" | "RestoreHealth" | "" | "SptInsure"
|
||||||
type: string
|
type: string
|
||||||
tid: string
|
tid: string
|
||||||
item_id: string
|
item_id: string
|
||||||
@ -14,6 +14,7 @@ export interface IProcessBuyTradeRequestData extends IProcessBaseTradeRequestDat
|
|||||||
|
|
||||||
export interface SchemeItem
|
export interface SchemeItem
|
||||||
{
|
{
|
||||||
|
/** Id of stack to take money from, is money tpl when Action is `SptInsure` */
|
||||||
id: string
|
id: string
|
||||||
count: number
|
count: number
|
||||||
}
|
}
|
||||||
|
@ -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.
|
// Track the total amount of all currencies.
|
||||||
let totalCurrencyAmount = 0;
|
let totalCurrencyAmount = 0;
|
||||||
|
|
||||||
@ -81,6 +91,7 @@ export class PaymentService
|
|||||||
|
|
||||||
if (currencyAmount > 0)
|
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);
|
output = this.addPaymentToOutput(pmcData, currencyTpl, currencyAmount, sessionID, output);
|
||||||
|
|
||||||
// If there are warnings, exit early.
|
// 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 pmcData Player profile to find and remove currency from
|
||||||
* @param currencyTpl Type of currency to pay
|
* @param currencyTpl Type of currency to pay
|
||||||
* @param amountToPay money value to pay
|
* @param amountToPay money value to pay
|
||||||
|
Loading…
Reference in New Issue
Block a user