Improved insurance calculation accuracy with help from Doctor

Removed `insuranceMultipler` from `insurance.json` config, no longer necessary
This commit is contained in:
Dev 2024-05-27 13:42:28 +01:00
parent cc1f51e522
commit 82c6add9ab
4 changed files with 12 additions and 31 deletions

View File

@ -1,8 +1,4 @@
{ {
"insuranceMultiplier": {
"54cb50c76803fa8b248b4571": 0.16,
"54cb57776803fa99248b456e": 0.25
},
"returnChancePercent": { "returnChancePercent": {
"54cb50c76803fa8b248b4571": 75, "54cb50c76803fa8b248b4571": 75,
"54cb57776803fa99248b456e": 85 "54cb57776803fa99248b456e": 85

View File

@ -681,7 +681,9 @@ export class InsuranceController
{ {
itemsToPay.push({ itemsToPay.push({
id: this.roubleTpl, // TODO: update to handle different currencies id: this.roubleTpl, // TODO: update to handle different currencies
count: Math.round(this.insuranceService.getPremium(pmcData, inventoryItemsHash[key], body.tid)), count: this.insuranceService.getRoublePriceToInsureItemWithTrader(
pmcData, inventoryItemsHash[key],
body.tid),
}); });
} }
@ -745,9 +747,9 @@ export class InsuranceController
this.logger.debug(`Item with id: ${itemId} missing from player inventory, skipping`); this.logger.debug(`Item with id: ${itemId} missing from player inventory, skipping`);
continue; continue;
} }
items[inventoryItemsHash[itemId]._tpl] = Math.round( items[inventoryItemsHash[itemId]._tpl] = this.insuranceService.getRoublePriceToInsureItemWithTrader(
this.insuranceService.getPremium(pmcData, inventoryItemsHash[itemId], trader), pmcData, inventoryItemsHash[itemId],
); trader);
} }
response[trader] = items; response[trader] = items;

View File

@ -3,8 +3,6 @@ import { IBaseConfig } from "@spt/models/spt/config/IBaseConfig";
export interface IInsuranceConfig extends IBaseConfig export interface IInsuranceConfig extends IBaseConfig
{ {
kind: "spt-insurance" kind: "spt-insurance"
/** Insurance price multiplier */
insuranceMultiplier: Record<string, number>
/** Chance item is returned as insurance, keyed by trader id */ /** Chance item is returned as insurance, keyed by trader id */
returnChancePercent: Record<string, number> returnChancePercent: Record<string, number>
/** Item slots that should never be returned as insurance */ /** Item slots that should never be returned as insurance */

View File

@ -517,33 +517,18 @@ export class InsuranceService
* @param traderId Trader item is insured with * @param traderId Trader item is insured with
* @returns price in roubles * @returns price in roubles
*/ */
public getPremium(pmcData: IPmcData, inventoryItem: Item, traderId: string): number public getRoublePriceToInsureItemWithTrader(pmcData: IPmcData, inventoryItem: Item, traderId: string): number
{ {
let insuranceMultiplier = this.insuranceConfig.insuranceMultiplier[traderId]; const price = this.itemHelper.getStaticItemPrice(inventoryItem._tpl)
if (!insuranceMultiplier) * (this.traderHelper.getLoyaltyLevel(traderId, pmcData).insurance_price_coef / 100);
{
insuranceMultiplier = 0.3;
this.logger.warning(
this.localisationService.getText("insurance-missing_insurance_price_multiplier", traderId),
);
}
// Multiply item handbook price by multiplier in config to get the new insurance price return Math.ceil(price);
let pricePremium = this.itemHelper.getStaticItemPrice(inventoryItem._tpl) * insuranceMultiplier;
const coef = this.traderHelper.getLoyaltyLevel(traderId, pmcData).insurance_price_coef;
if (coef > 0)
{
pricePremium *= 1 - this.traderHelper.getLoyaltyLevel(traderId, pmcData).insurance_price_coef / 100;
}
return Math.round(pricePremium);
} }
/** /**
* Returns the ID that should be used for a root-level Item's parentId property value within in the context of insurance. * Returns the ID that should be used for a root-level Item's parentId property value within in the context of insurance.
* * @param sessionID Players id
* @returns The ID. * @returns The root item Id.
*/ */
public getRootItemParentID(sessionID: string): string public getRootItemParentID(sessionID: string): string
{ {