Skip to main content
The Deno 2 Release Candidate is here
Learn more
class TraderHelper
import { TraderHelper } from "https://deno.land/x/sptaki@1.2.0/helpers/TraderHelper.d.ts";

Constructors

new
TraderHelper(
logger: ILogger,
databaseServer: DatabaseServer,
saveServer: SaveServer,
profileHelper: ProfileHelper,
handbookHelper: HandbookHelper,
itemHelper: ItemHelper,
playerService: PlayerService,
localisationService: LocalisationService,
fenceService: FenceService,
timeUtil: TimeUtil,
randomUtil: RandomUtil,
configServer: ConfigServer,
)

Properties

protected
configServer: ConfigServer
protected
databaseServer: DatabaseServer
protected
fenceService: FenceService
protected
handbookHelper: HandbookHelper
protected
highestTraderBuyPriceItems: Record<string, number>

Dictionary of item tpl and the highest trader buy back rouble price

protected
highestTraderPriceItems: Record<string, number>

Dictionary of item tpl and the highest trader sell rouble price

protected
itemHelper: ItemHelper
protected
localisationService: LocalisationService
protected
logger: ILogger
protected
playerService: PlayerService
protected
profileHelper: ProfileHelper
protected
randomUtil: RandomUtil
protected
saveServer: SaveServer
protected
timeUtil: TimeUtil
protected
traderConfig: ITraderConfig

Methods

protected
addStandingValuesTogether(currentStanding: number, standingToAdd: number): number

Add standing to current standing and clamp value if it goes too low

protected
getStartingStanding(traderId: string, rawProfileTemplate: ProfileTraderTemplate): number

Get the starting standing of a trader based on the current profiles type (e.g. EoD, Standard etc)

addStandingToTrader(
sessionId: string,
traderId: string,
standingToAdd: number,
): void

Add standing to a trader and level them up if exp goes over level threshold

addTraderPurchasesToPlayerProfile(
sessionID: string,
newPurchaseDetails: { items: { itemId: string; count: number; }[]; traderId: string; },
itemPurchased: Item,
): void

Store the purchase of an assort from a trader in the player profile

getHighestSellToTraderPrice(tpl: string): number

Get the highest price item can be sold to trader for (roubles)

getHighestTraderPriceRouble(tpl: string): number

Get the highest rouble price for an item from traders UNUSED

getLoyaltyLevel(traderID: string, pmcData: IPmcData): LoyaltyLevel
getNextUpdateTimestamp(traderID: string): number

Get the next update timestamp for a trader

getTrader(traderID: string, sessionID: string): ITraderBase

Get a trader base object, update profile to reflect players current standing in profile when trader not found in profile

getTraderAssortItemByAssortId(traderId: string, assortId: string): Item

Retrieve the Item from a traders assort data by its id

Get all assort data for a particular trader

getTraderById(traderId: string): Traders

Get a trader enum key by its value

getTraderUpdateSeconds(traderId: string): number

Get the reset time between trader assort refreshes in seconds

getValidTraderIdByEnumValue(traderEnumValue: Traders): string

Validates that the provided traderEnumValue exists in the Traders enum. If the value is valid, it returns the same enum value, effectively serving as a trader ID; otherwise, it logs an error and returns an empty string. This method provides a runtime check to prevent undefined behavior when using the enum as a dictionary key.

For example, instead of this: const traderId = Traders[Traders.PRAPOR];

You can use safely use this: const traderId = this.traderHelper.getValidTraderIdByEnumValue(Traders.PRAPOR);

lvlUp(traderID: string, pmcData: IPmcData): void

Calculate traders level based on exp amount and increments level if over threshold

resetTrader(sessionID: string, traderID: string): void

Reset a profiles trader data back to its initial state as seen by a level 1 player Does NOT take into account different profile levels

setTraderUnlockedState(
traderId: string,
status: boolean,
sessionId: string,
): void

Alter a traders unlocked status

traderEnumHasKey(key: string): boolean

Does the 'Traders' enum has a value that matches the passed in parameter

traderEnumHasValue(traderId: string): boolean

Accepts a trader id