From 7a5a98db87a76c87245031ad7b8ca76e26779104 Mon Sep 17 00:00:00 2001 From: Platinum Date: Tue, 6 Feb 2024 17:59:20 +1100 Subject: [PATCH] Move a lot of functions to helpers --- src/helpers.ts | 51 ++++++++++++++++++++++++++++++++++++++++++ src/mod.ts | 60 ++++++-------------------------------------------- 2 files changed, 58 insertions(+), 53 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index b8ea7f4..00c3df1 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -16,6 +16,10 @@ // along with spt-the-blacklist. If not, see . import { Category } from "@spt-aki/models/eft/common/tables/IHandbookBase"; +import { ITemplateItem } from "@spt-aki/models/eft/common/tables/ITemplateItem"; + +import config from "../config.json"; +import advancedConfig from "../advancedConfig.json"; // There are so many child categories of attachments, this will return all categories using recursion so I don't have to type each ID. export function getAttachmentCategoryIds(handbookCategories: Category[]): string[] { @@ -35,4 +39,51 @@ function getChildCategoriesRecursively(handbookCategories: Category[], parentId: ); return childCategories.concat(grandChildrenCategories); +} + +export function isBulletOrShotgunShell(item: ITemplateItem): boolean { + const props = item._props; + + return props.ammoType === "bullet" || props.ammoType === "buckshot"; +} + +// Some blacklisted guns are very cheap because they don't have a flea price, just a handbook price. The ones listed below will get a much higher default price. +export function isGun(item: ITemplateItem): boolean { + const marksmanRiflesItemCategoryId = "5447b6194bdc2d67278b4567"; + const assaultRiflesItemCategoryId = "5447b5f14bdc2d61278b4567"; + const sniperRiflesItemCategoryId = "5447b6254bdc2dc3278b4568"; + const smgsItemCategoryId = "5447b5e04bdc2d62278b4567"; + const carbinesItemCategoryId = "5447b5fc4bdc2d87278b4567"; + const gunCategories = [marksmanRiflesItemCategoryId, assaultRiflesItemCategoryId, sniperRiflesItemCategoryId, smgsItemCategoryId, carbinesItemCategoryId]; + + return gunCategories.includes(item._parent); +} + +export function getUpdatedAmmoPrice(item: ITemplateItem): number { + const baselinePen = this.baselineBullet._props.PenetrationPower; + const baselineDamage = this.baselineBullet._props.Damage; + + const basePenetrationMultiplier = item._props.PenetrationPower / baselinePen; + const baseDamageMultiplier = item._props.Damage / baselineDamage; + + let penetrationMultiplier: number; + if (basePenetrationMultiplier > 1) { + // A good gradient to make higher power rounds more expensive + penetrationMultiplier = 7 * basePenetrationMultiplier - 6; + } else { + // Due to maths above, its really easy to go < 1. The baseline ammo is mid tier with a reasonable 1000 rouble each. Ammo weaker than this tend to be pretty crap so we'll make it much cheaper + const newMultiplier = basePenetrationMultiplier * 0.7; + penetrationMultiplier = newMultiplier < 0.1 ? 0.1 : newMultiplier; + } + + // Reduces the effect of the damage multiplier so high DMG rounds aren't super expensive. + // Eg. let baseDamageMultiplier = 2 & bulletDamageMultiplierRedutionFactor = 0.7. Instead of a 2x price when a bullet is 2x damage, we instead get: + // 2 + (1 - 2) * 0.7 = 2 - 0.7 = 1.3x the price. + const damageMultiplier = baseDamageMultiplier + (1 - baseDamageMultiplier) * advancedConfig.bulletDamageMultiplierRedutionFactor; + + return advancedConfig.baselineBulletPrice * penetrationMultiplier * damageMultiplier * config.blacklistedAmmoAdditionalPriceMultiplier; +} + +export function getFallbackGunPrice(): number { + return advancedConfig.gunPriceFallback || 100000; } \ No newline at end of file diff --git a/src/mod.ts b/src/mod.ts index 2c447db..f130408 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -28,7 +28,7 @@ import { Category, HandbookItem } from "@spt-aki/models/eft/common/tables/IHandb import config from "../config.json"; import advancedConfig from "../advancedConfig.json"; -import { getAttachmentCategoryIds } from "./helpers"; +import { getAttachmentCategoryIds, getFallbackGunPrice, getUpdatedAmmoPrice, isBulletOrShotgunShell, isGun } from "./helpers"; class TheBlacklistMod implements IPostDBLoadModAsync { private logger: ILogger; @@ -84,8 +84,8 @@ class TheBlacklistMod implements IPostDBLoadModAsync { const itemProps = item._props; - if (config.useBalancedPricingForAllAmmo && this.isBulletOrShotgunShell(item)) { - const newPrice = this.getUpdatedAmmoPrice(item); + if (config.useBalancedPricingForAllAmmo && isBulletOrShotgunShell(item)) { + const newPrice = getUpdatedAmmoPrice(item); prices[item._id] = newPrice; if (!itemProps.CanSellOnRagfair) { @@ -183,10 +183,10 @@ class TheBlacklistMod implements IPostDBLoadModAsync { const currentFleaPrice = prices[item._id]; let newPrice: number; - if (this.isBulletOrShotgunShell(item)) { - newPrice = this.getUpdatedAmmoPrice(item); - } else if (this.isGun(item) && currentFleaPrice == null) { - newPrice = this.getFallbackGunPrice(); + if (isBulletOrShotgunShell(item)) { + newPrice = getUpdatedAmmoPrice(item); + } else if (isGun(item) && currentFleaPrice == null) { + newPrice = getFallbackGunPrice(); } // Avoids NaN. Also we shouldn't have any prices of 0. @@ -194,52 +194,6 @@ class TheBlacklistMod implements IPostDBLoadModAsync { return price && price * config.blacklistedItemPriceMultiplier; } - private isBulletOrShotgunShell(item: ITemplateItem): boolean { - const props = item._props; - return props.ammoType === "bullet" || props.ammoType === "buckshot"; - } - - // Some blacklisted guns are very cheap because they don't have a flea price, just a handbook price. The ones listed below will get a much higher default price. - private isGun(item: ITemplateItem): boolean { - const marksmanRiflesItemCategoryId = "5447b6194bdc2d67278b4567"; - const assaultRiflesItemCategoryId = "5447b5f14bdc2d61278b4567"; - const sniperRiflesItemCategoryId = "5447b6254bdc2dc3278b4568"; - const smgsItemCategoryId = "5447b5e04bdc2d62278b4567"; - const carbinesItemCategoryId = "5447b5fc4bdc2d87278b4567"; - const gunCategories = [marksmanRiflesItemCategoryId, assaultRiflesItemCategoryId, sniperRiflesItemCategoryId, smgsItemCategoryId, carbinesItemCategoryId]; - - return gunCategories.includes(item._parent); - } - - private getUpdatedAmmoPrice(item: ITemplateItem) { - const baselinePen = this.baselineBullet._props.PenetrationPower; - const baselineDamage = this.baselineBullet._props.Damage; - - const basePenetrationMultiplier = item._props.PenetrationPower / baselinePen; - const baseDamageMultiplier = item._props.Damage / baselineDamage; - - let penetrationMultiplier: number; - if (basePenetrationMultiplier > 1) { - // A good gradient to make higher power rounds more expensive - penetrationMultiplier = 7 * basePenetrationMultiplier - 6; - } else { - // Due to maths above, its really easy to go < 1. The baseline ammo is mid tier with a reasonable 1000 rouble each. Ammo weaker than this tend to be pretty crap so we'll make it much cheaper - const newMultiplier = basePenetrationMultiplier * 0.7; - penetrationMultiplier = newMultiplier < 0.1 ? 0.1 : newMultiplier; - } - - // Reduces the effect of the damage multiplier so high DMG rounds aren't super expensive. - // Eg. let baseDamageMultiplier = 2 & bulletDamageMultiplierRedutionFactor = 0.7. Instead of a 2x price when a bullet is 2x damage, we instead get: - // 2 + (1 - 2) * 0.7 = 2 - 0.7 = 1.3x the price. - const damageMultiplier = baseDamageMultiplier + (1 - baseDamageMultiplier) * advancedConfig.bulletDamageMultiplierRedutionFactor; - - return advancedConfig.baselineBulletPrice * penetrationMultiplier * damageMultiplier * config.blacklistedAmmoAdditionalPriceMultiplier; - } - - private getFallbackGunPrice() { - return advancedConfig.gunPriceFallback || 100000; - } - private debug(message: string) { if (advancedConfig.enableDebug) { this.logger.debug(`${this.modName}: ${message}`);