Improved insurance calculation accuracy with help from Doctor
Removed `insuranceMultipler` from `insurance.json` config, no longer necessary
This commit is contained in:
parent
cc1f51e522
commit
82c6add9ab
@ -1,8 +1,4 @@
|
||||
{
|
||||
"insuranceMultiplier": {
|
||||
"54cb50c76803fa8b248b4571": 0.16,
|
||||
"54cb57776803fa99248b456e": 0.25
|
||||
},
|
||||
"returnChancePercent": {
|
||||
"54cb50c76803fa8b248b4571": 75,
|
||||
"54cb57776803fa99248b456e": 85
|
||||
|
@ -681,7 +681,9 @@ export class InsuranceController
|
||||
{
|
||||
itemsToPay.push({
|
||||
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`);
|
||||
continue;
|
||||
}
|
||||
items[inventoryItemsHash[itemId]._tpl] = Math.round(
|
||||
this.insuranceService.getPremium(pmcData, inventoryItemsHash[itemId], trader),
|
||||
);
|
||||
items[inventoryItemsHash[itemId]._tpl] = this.insuranceService.getRoublePriceToInsureItemWithTrader(
|
||||
pmcData, inventoryItemsHash[itemId],
|
||||
trader);
|
||||
}
|
||||
|
||||
response[trader] = items;
|
||||
|
@ -3,8 +3,6 @@ import { IBaseConfig } from "@spt/models/spt/config/IBaseConfig";
|
||||
export interface IInsuranceConfig extends IBaseConfig
|
||||
{
|
||||
kind: "spt-insurance"
|
||||
/** Insurance price multiplier */
|
||||
insuranceMultiplier: Record<string, number>
|
||||
/** Chance item is returned as insurance, keyed by trader id */
|
||||
returnChancePercent: Record<string, number>
|
||||
/** Item slots that should never be returned as insurance */
|
||||
|
@ -517,33 +517,18 @@ export class InsuranceService
|
||||
* @param traderId Trader item is insured with
|
||||
* @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];
|
||||
if (!insuranceMultiplier)
|
||||
{
|
||||
insuranceMultiplier = 0.3;
|
||||
this.logger.warning(
|
||||
this.localisationService.getText("insurance-missing_insurance_price_multiplier", traderId),
|
||||
);
|
||||
}
|
||||
const price = this.itemHelper.getStaticItemPrice(inventoryItem._tpl)
|
||||
* (this.traderHelper.getLoyaltyLevel(traderId, pmcData).insurance_price_coef / 100);
|
||||
|
||||
// Multiply item handbook price by multiplier in config to get the new insurance 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);
|
||||
return Math.ceil(price);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param sessionID Players id
|
||||
* @returns The root item Id.
|
||||
*/
|
||||
public getRootItemParentID(sessionID: string): string
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user