From 95f5a49c5c30b1fa4016236d5926f90aeffe0230 Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 16 Mar 2024 22:12:03 +0000 Subject: [PATCH] Update trader refresh times to use a min and max value --- project/assets/configs/trader.json | 50 +++++++++++++++---- project/src/helpers/TraderHelper.ts | 7 ++- .../src/models/spt/config/ITraderConfig.ts | 2 +- project/src/services/FenceService.ts | 4 +- .../TraderPurchasePersisterService.ts | 5 +- 5 files changed, 53 insertions(+), 15 deletions(-) diff --git a/project/assets/configs/trader.json b/project/assets/configs/trader.json index 71bf9cd9..2b3cd4e8 100644 --- a/project/assets/configs/trader.json +++ b/project/assets/configs/trader.json @@ -3,51 +3,81 @@ { "_name": "prapor", "traderId": "54cb50c76803fa8b248b4571", - "seconds": 11100 + "seconds": { + "min": 7000, + "max": 13500 + } }, { "_name": "therapist", "traderId": "54cb57776803fa99248b456e", - "seconds": 8040 + "seconds": { + "min": 3000, + "max": 9500 + } }, { "_name": "fence", "traderId": "579dc571d53a0658a154fbec", - "seconds": 5220 + "seconds": { + "min": 3000, + "max": 9000 + } }, { "_name": "skier", "traderId": "58330581ace78e27b8b10cee", - "seconds": 6240 + "seconds": { + "min": 5000, + "max": 8500 + } }, { "_name": "peacekeeper", "traderId": "5935c25fb3acc3127c3d8cd9", - "seconds": 8580 + "seconds": { + "min": 2000, + "max": 14000 + } }, { "_name": "mechanic", "traderId": "5a7c2eca46aef81a7ca2145d", - "seconds": 8160 + "seconds": { + "min": 7000, + "max": 13500 + } }, { "_name": "ragman", "traderId": "5ac3b934156ae10c4430e83c", - "seconds": 8220 + "seconds": { + "min": 6500, + "max": 15000 + } }, { "_name": "jaeger", "traderId": "5c0647fdd443bc2504c2d371", - "seconds": 5100 + "seconds": { + "min": 2000, + "max": 5500 + } }, { "_name": "btr", "traderId": "656f0f98d80a697f855d34b1", - "seconds": 3600 + "seconds": { + "min": 3000, + "max": 7500 + } }, { "traderId": "ragfair", - "seconds": 3600 + "seconds": { + "min": 3600, + "max": 3600 + } } ], "updateTimeDefault": 3600, diff --git a/project/src/helpers/TraderHelper.ts b/project/src/helpers/TraderHelper.ts index aa16193b..3bbc14ed 100644 --- a/project/src/helpers/TraderHelper.ts +++ b/project/src/helpers/TraderHelper.ts @@ -275,12 +275,15 @@ export class TraderHelper ); this.traderConfig.updateTime.push( // create temporary entry to prevent logger spam - { traderId: traderId, seconds: this.traderConfig.updateTimeDefault }, + { + traderId: traderId, + seconds: { min: this.traderConfig.updateTimeDefault, max: this.traderConfig.updateTimeDefault }, + }, ); } else { - return traderDetails.seconds; + return this.randomUtil.getInt(traderDetails.seconds.min, traderDetails.seconds.max); } } diff --git a/project/src/models/spt/config/ITraderConfig.ts b/project/src/models/spt/config/ITraderConfig.ts index 52b92476..46b6e925 100644 --- a/project/src/models/spt/config/ITraderConfig.ts +++ b/project/src/models/spt/config/ITraderConfig.ts @@ -20,7 +20,7 @@ export interface UpdateTime { traderId: string; /** Seconds between trader resets */ - seconds: number; + seconds: MinMax; } export interface FenceConfig diff --git a/project/src/services/FenceService.ts b/project/src/services/FenceService.ts index 1e44630e..800fb71a 100644 --- a/project/src/services/FenceService.ts +++ b/project/src/services/FenceService.ts @@ -1262,7 +1262,9 @@ export class FenceService */ protected getFenceRefreshTime(): number { - return this.traderConfig.updateTime.find((x) => x.traderId === Traders.FENCE).seconds; + const fence = this.traderConfig.updateTime.find((x) => x.traderId === Traders.FENCE).seconds; + + return this.randomUtil.getInt(fence.min, fence.max); } /** diff --git a/project/src/services/TraderPurchasePersisterService.ts b/project/src/services/TraderPurchasePersisterService.ts index 5ace2017..f4ffe16f 100644 --- a/project/src/services/TraderPurchasePersisterService.ts +++ b/project/src/services/TraderPurchasePersisterService.ts @@ -7,6 +7,7 @@ import { ITraderConfig } from "@spt-aki/models/spt/config/ITraderConfig"; import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; import { ConfigServer } from "@spt-aki/servers/ConfigServer"; import { LocalisationService } from "@spt-aki/services/LocalisationService"; +import { RandomUtil } from "@spt-aki/utils/RandomUtil"; import { TimeUtil } from "@spt-aki/utils/TimeUtil"; /** @@ -20,6 +21,7 @@ export class TraderPurchasePersisterService constructor( @inject("WinstonLogger") protected logger: ILogger, @inject("TimeUtil") protected timeUtil: TimeUtil, + @inject("RandomUtil") protected randomUtil: RandomUtil, @inject("ProfileHelper") protected profileHelper: ProfileHelper, @inject("LocalisationService") protected localisationService: LocalisationService, @inject("ConfigServer") protected configServer: ConfigServer, @@ -134,7 +136,8 @@ export class TraderPurchasePersisterService } const purchaseDetails = profile.traderPurchases[traderId][purchaseKey]; - const resetTimeForItem = purchaseDetails.purchaseTimestamp + traderUpdateDetails.seconds; + const resetTimeForItem = purchaseDetails.purchaseTimestamp + + this.randomUtil.getInt(traderUpdateDetails.seconds.min, traderUpdateDetails.seconds.max); if (resetTimeForItem < this.timeUtil.getTimestamp()) { // Item was purchased far enough in past a trader refresh would have occured, remove purchase record from profile