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

Handle actions surrounding Fence e.g. generating or refreshing assorts / get next refresh time

Constructors

new
FenceService(
logger: ILogger,
jsonUtil: JsonUtil,
timeUtil: TimeUtil,
randomUtil: RandomUtil,
databaseServer: DatabaseServer,
handbookHelper: HandbookHelper,
itemHelper: ItemHelper,
presetHelper: PresetHelper,
localisationService: LocalisationService,
configServer: ConfigServer,
)

Properties

protected
configServer: ConfigServer
protected
databaseServer: DatabaseServer
protected
desiredAssortCounts: IFenceAssortGenerationValues

Desired baseline counts - Hydrated on initial assort generation as part of generateFenceAssorts()

protected
fenceAssort: ITraderAssort

Main assorts you see at all rep levels

protected
fenceDiscountAssort: ITraderAssort

Assorts shown on a separate tab when you max out fence rep

protected
fenceItemUpdCompareProperties: Set<string>
protected
handbookHelper: HandbookHelper
protected
itemHelper: ItemHelper
protected
jsonUtil: JsonUtil
protected
localisationService: LocalisationService
protected
logger: ILogger
protected
nextPartialRefreshTimestamp: number

Time when some items in assort will be replaced

protected
presetHelper: PresetHelper
protected
randomUtil: RandomUtil
protected
timeUtil: TimeUtil
protected
traderConfig: ITraderConfig

Methods

protected
addItemAssorts(
assortCount: number,
baseFenceAssortClone: ITraderAssort,
itemTypeLimits: Record<string, { current: number; max: number; }>,
loyaltyLevel: number,
): void

Add item assorts to existing assort data

protected
addPresetsToAssort(
desiredWeaponPresetsCount: number,
desiredEquipmentPresetsCount: number,
baseFenceAssort: ITraderAssort,
loyaltyLevel: number,
): void

Find presets in base fence assort and add desired number to 'assorts' parameter

protected
adjustAssortItemPricesByConfigMultiplier(
assort: ITraderAssort,
itemMultipler: number,
presetMultiplier: number,
): void

Adjust all items contained inside an assort by a multiplier

protected
adjustItemPriceByModifier(
item: Item,
assort: ITraderAssort,
modifier: number,
presetModifier: number,
): void

Adjust assorts price by a modifier

protected
adjustItemPriceByQuality(
barterSchemes: Record<string, IBarterScheme[][]>,
itemRoot: Item,
itemTemplate: ITemplateItem,
): void

Adjust price of item based on what is left to buy (resource/uses left)

Convert the intermediary assort data generated into format client can process

protected
createAssorts(itemCounts: IGenerationAssortValues, loyaltyLevel: number): ICreateFenceAssortsResult

Hydrate assorts parameter object with generated assorts

Create skeleton to hold assort items

Create object that contains calculated fence assort item values to make based on config Stored in this.desiredAssortCounts

protected
deleteOffer(assortId: string, assorts: Item[]): void
protected
deleteRandomAssorts(itemCountToReplace: number, assort: ITraderAssort): void

Delete desired number of items from assort (including children)

protected
getAmmoBoxPrice(items: Item[]): number

Calculate the overall price for an ammo box, where only one item is the ammo box itself and every other items are the bullets in that box

protected
getCountOfItemsToReplace(totalItemCount: number): number

Get an integer rounded count of items to replace based on percentrage from traderConfig value

protected
getFenceRefreshTime(): number

Get fence refresh time in seconds

Get values that will hydrate the passed in assorts back to the desired counts

protected
getMatchingItem(
rootItemBeingAdded: Item,
itemDbDetails: ITemplateItem,
itemsWithChildren: Item[][],
): Item

Find an assort item that matches the first parameter, also matches based on upd properties e.g. salewa hp resource units left

protected
getMatchingItemLimit(itemTypeLimits: Record<string, { current: number; max: number; }>, itemTpl: string): { current: number; max: number; }
protected
getRandomisedArmorDurabilityValues(itemDetails: ITemplateItem, equipmentDurabilityLimits: IItemDurabilityCurrentMax): Repairable

Generate a randomised current and max durabiltiy value for an armor item

protected
getSingleItemStackCount(itemDbDetails: ITemplateItem): number

Get stack size of a singular item (no mods)

Increment fence next refresh timestamp by current timestamp + partialRefreshTimeSeconds from config

protected
initItemLimitCounter(limits: Record<string, number>): Record<string, { current: number; max: number; }>

Construct item limit record to hold max and current item count

protected
itemInPreventDupeCategoryList(tpl: string): boolean
protected
itemShouldBeForceStacked(existingItem: Item, itemDbDetails: ITemplateItem): boolean

Should this item be forced into only 1 stack on fence

protected
mergeAssorts(firstAssort: ITraderAssort, secondAssort: ITraderAssort): ITraderAssort

Merge two trader assort files together

protected
presetModItemWillBeRemoved(weaponMod: Item, itemsBeingDeleted: string[]): boolean

Roll % chance check to see if item should be removed

protected
randomiseArmorModDurability(armor: Item[], itemDbDetails: ITemplateItem): void

Adjust plate / soft insert durability values

protected
randomiseItemUpdProperties(itemDetails: ITemplateItem, itemToAdjust: Item): void

Randomise items' upd properties e.g. med packs/weapons/armor

protected
removeRandomItemFromAssorts(assort: ITraderAssort, rootItems: Item[]): void

Choose an item at random and remove it + mods from assorts

protected
removeRandomModsOfItem(itemAndMods: Item[]): void

Remove parts of a weapon prior to being listed on flea

protected
updateFenceAssorts(newFenceAssorts: ICreateFenceAssortsResult, existingFenceAssorts: ITraderAssort): void

Handle the process of folding new assorts into existing assorts, when a new assort exists already, increment its StackObjectsCount instead

addItemsToFenceAssort(items: Item[], mainItem: Item): void

Adds to fence assort a single item (with its children)

amendOrRemoveFenceOffer(assortId: string, buyCount: number): void

Remove or lower stack size of an assort from fence by id

Create trader assorts for fence and store in fenceService cache Uses fence base cache generatedon server start as a base

Get discount fence assort

Get assorts player can purchase Adjust prices based on fence level of player

Get fence level the passed in profile has

getItemPrice(itemTpl: string, items: Item[]): number

Calculates the overall price for an item (with all its children)

Get main fence assort

Get the next update timestamp for fence

getOfferCount(): number

Get the count of items fence offers

Get fence assorts with no price adjustments based on fence rep

Does fence need to perform a partial refresh because its passed the refresh timer defined in trader.json

Replace a percentage of fence assorts with freshly generated items

Replace discount fence assort with new assort

Replace main fence assort with new assort

setFenceDiscountAssort(discountAssort: ITraderAssort): void

Replace high rep level fence assort with new assort