2022-08-17 02:29:54 -04:00
|
|
|
import { HandbookHelper } from "../helpers/HandbookHelper";
|
|
|
|
import { ItemHelper } from "../helpers/ItemHelper";
|
|
|
|
import { PresetHelper } from "../helpers/PresetHelper";
|
2023-01-15 00:21:11 -05:00
|
|
|
import { FenceLevel, Preset } from "../models/eft/common/IGlobals";
|
2022-08-17 02:29:54 -04:00
|
|
|
import { IPmcData } from "../models/eft/common/IPmcData";
|
2022-12-25 18:45:30 -05:00
|
|
|
import { Item } from "../models/eft/common/tables/IItem";
|
|
|
|
import { ITemplateItem } from "../models/eft/common/tables/ITemplateItem";
|
2022-08-17 02:29:54 -04:00
|
|
|
import { ITraderAssort } from "../models/eft/common/tables/ITrader";
|
|
|
|
import { ITraderConfig } from "../models/spt/config/ITraderConfig";
|
|
|
|
import { ILogger } from "../models/spt/utils/ILogger";
|
|
|
|
import { ConfigServer } from "../servers/ConfigServer";
|
|
|
|
import { DatabaseServer } from "../servers/DatabaseServer";
|
|
|
|
import { HashUtil } from "../utils/HashUtil";
|
|
|
|
import { JsonUtil } from "../utils/JsonUtil";
|
|
|
|
import { RandomUtil } from "../utils/RandomUtil";
|
|
|
|
import { TimeUtil } from "../utils/TimeUtil";
|
2022-09-01 05:19:17 -04:00
|
|
|
import { ItemFilterService } from "./ItemFilterService";
|
2022-12-25 18:45:30 -05:00
|
|
|
import { LocalisationService } from "./LocalisationService";
|
2022-09-01 05:19:17 -04:00
|
|
|
/**
|
|
|
|
* Handle actions surrounding Fence
|
|
|
|
* e.g. generating or refreshing assorts / get next refresh time
|
|
|
|
*/
|
2022-08-17 02:29:54 -04:00
|
|
|
export declare class FenceService {
|
|
|
|
protected logger: ILogger;
|
|
|
|
protected hashUtil: HashUtil;
|
|
|
|
protected jsonUtil: JsonUtil;
|
|
|
|
protected timeUtil: TimeUtil;
|
|
|
|
protected randomUtil: RandomUtil;
|
|
|
|
protected databaseServer: DatabaseServer;
|
|
|
|
protected handbookHelper: HandbookHelper;
|
|
|
|
protected itemHelper: ItemHelper;
|
|
|
|
protected presetHelper: PresetHelper;
|
2022-09-01 05:19:17 -04:00
|
|
|
protected itemFilterService: ItemFilterService;
|
2022-12-25 18:45:30 -05:00
|
|
|
protected localisationService: LocalisationService;
|
2022-08-17 02:29:54 -04:00
|
|
|
protected configServer: ConfigServer;
|
2023-02-12 23:21:22 -05:00
|
|
|
/** Main assorts you see at all rep levels */
|
2022-08-17 02:29:54 -04:00
|
|
|
protected fenceAssort: ITraderAssort;
|
2023-02-12 23:21:22 -05:00
|
|
|
/** Assorts shown on a separte tab when you max out fence rep */
|
2023-01-15 00:21:11 -05:00
|
|
|
protected fenceDiscountAssort: ITraderAssort;
|
2022-08-17 02:29:54 -04:00
|
|
|
protected traderConfig: ITraderConfig;
|
2022-09-01 05:19:17 -04:00
|
|
|
protected nextMiniRefreshTimestamp: number;
|
2022-12-25 18:45:30 -05:00
|
|
|
constructor(logger: ILogger, hashUtil: HashUtil, jsonUtil: JsonUtil, timeUtil: TimeUtil, randomUtil: RandomUtil, databaseServer: DatabaseServer, handbookHelper: HandbookHelper, itemHelper: ItemHelper, presetHelper: PresetHelper, itemFilterService: ItemFilterService, localisationService: LocalisationService, configServer: ConfigServer);
|
2023-02-12 23:21:22 -05:00
|
|
|
/**
|
|
|
|
* Replace main fence assort with new assort
|
|
|
|
* @param assort New assorts to replace old with
|
|
|
|
*/
|
2023-01-15 00:21:11 -05:00
|
|
|
protected setFenceAssort(assort: ITraderAssort): void;
|
2023-02-12 23:21:22 -05:00
|
|
|
/**
|
|
|
|
* Replace high rep level fence assort with new assort
|
|
|
|
* @param assort New assorts to replace old with
|
|
|
|
*/
|
2023-01-15 00:21:11 -05:00
|
|
|
protected setFenceDiscountAssort(assort: ITraderAssort): void;
|
2022-09-01 05:19:17 -04:00
|
|
|
/**
|
|
|
|
* Get assorts player can purchase
|
|
|
|
* Adjust prices based on fence level of player
|
|
|
|
* @param pmcProfile Player profile
|
|
|
|
* @returns ITraderAssort
|
|
|
|
*/
|
|
|
|
getFenceAssorts(pmcProfile: IPmcData): ITraderAssort;
|
2023-01-15 00:21:11 -05:00
|
|
|
/**
|
|
|
|
* Adjust all items contained inside an assort by a multiplier
|
|
|
|
* @param assort Assort that contains items with prices to adjust
|
|
|
|
* @param itemMultipler multipler to use on items
|
|
|
|
* @param presetMultiplier preset multipler to use on presets
|
|
|
|
*/
|
|
|
|
protected adjustAssortItemPrices(assort: ITraderAssort, itemMultipler: number, presetMultiplier: number): void;
|
|
|
|
/**
|
|
|
|
* Merge two trader assort files together
|
|
|
|
* @param firstAssort assort 1#
|
|
|
|
* @param secondAssort assort #2
|
|
|
|
* @returns merged assort
|
|
|
|
*/
|
|
|
|
protected mergeAssorts(firstAssort: ITraderAssort, secondAssort: ITraderAssort): ITraderAssort;
|
2022-12-25 18:45:30 -05:00
|
|
|
/**
|
|
|
|
* Adjust assorts price by a modifier
|
2023-01-15 00:21:11 -05:00
|
|
|
* @param item assort item details
|
|
|
|
* @param assort assort to be modified
|
|
|
|
* @param modifier value to multiply item price by
|
|
|
|
* @param presetModifier value to multiply preset price by
|
2022-12-25 18:45:30 -05:00
|
|
|
*/
|
2023-01-15 00:21:11 -05:00
|
|
|
protected adjustItemPriceByModifier(item: Item, assort: ITraderAssort, modifier: number, presetModifier: number): void;
|
2022-09-01 05:19:17 -04:00
|
|
|
/**
|
|
|
|
* Get fence assorts with no price adjustments based on fence rep
|
|
|
|
* @returns ITraderAssort
|
|
|
|
*/
|
|
|
|
getRawFenceAssorts(): ITraderAssort;
|
|
|
|
/**
|
|
|
|
* Does fence need to perform a partial refresh because its passed the refresh timer defined in trader.json
|
|
|
|
* @returns true if it needs a partial refresh
|
|
|
|
*/
|
|
|
|
needsPartialRefresh(): boolean;
|
|
|
|
/**
|
|
|
|
* Replace a percentage of fence assorts with freshly generated items
|
|
|
|
*/
|
|
|
|
performPartialRefresh(): void;
|
2022-09-11 21:55:55 -04:00
|
|
|
/**
|
|
|
|
* Increment fence next refresh timestamp by current timestamp + partialRefreshTimeSeconds from config
|
|
|
|
*/
|
|
|
|
protected incrementPartialRefreshTime(): void;
|
|
|
|
/**
|
|
|
|
* Compare the current fence offer count to what the config wants it to be,
|
|
|
|
* If value is lower add extra count to value to generate more items to fill gap
|
|
|
|
* @param existingItemCountToReplace count of items to generate
|
|
|
|
* @returns number of items to generate
|
|
|
|
*/
|
|
|
|
protected getCountOfItemsToGenerate(existingItemCountToReplace: number): number;
|
2022-09-01 05:19:17 -04:00
|
|
|
/**
|
|
|
|
* Choose an item (not mod) at random and remove from assorts
|
|
|
|
*/
|
2023-01-15 00:21:11 -05:00
|
|
|
protected removeRandomItemFromAssorts(assort: ITraderAssort): void;
|
2022-09-01 05:19:17 -04:00
|
|
|
/**
|
|
|
|
* Get an integer rounded count of items to replace based on percentrage from traderConfig value
|
|
|
|
* @param totalItemCount total item count
|
|
|
|
* @returns rounded int of items to replace
|
|
|
|
*/
|
|
|
|
protected getCountOfItemsToReplace(totalItemCount: number): number;
|
2022-08-17 02:29:54 -04:00
|
|
|
/**
|
|
|
|
* Get the count of items fence offers
|
|
|
|
* @returns number
|
|
|
|
*/
|
|
|
|
getOfferCount(): number;
|
2022-09-01 05:19:17 -04:00
|
|
|
/**
|
2022-12-25 18:45:30 -05:00
|
|
|
* Create trader assorts for fence and store in fenceService cache
|
2022-09-01 05:19:17 -04:00
|
|
|
*/
|
2022-12-25 18:45:30 -05:00
|
|
|
generateFenceAssorts(): void;
|
2022-09-01 05:19:17 -04:00
|
|
|
/**
|
|
|
|
* Create skeleton to hold assort items
|
|
|
|
* @returns ITraderAssort object
|
|
|
|
*/
|
|
|
|
protected createBaseTraderAssortItem(): ITraderAssort;
|
|
|
|
/**
|
2023-01-15 00:21:11 -05:00
|
|
|
* Hydrate assorts parameter object with generated assorts
|
2022-09-01 05:19:17 -04:00
|
|
|
* @param assortCount Number of assorts to generate
|
2023-01-15 00:21:11 -05:00
|
|
|
* @param assorts object to add created assorts to
|
|
|
|
*/
|
|
|
|
protected createAssorts(assortCount: number, assorts: ITraderAssort, loyaltyLevel: number): void;
|
|
|
|
protected addItemAssorts(assortCount: number, fenceAssortIds: string[], assorts: ITraderAssort, fenceAssort: ITraderAssort, itemTypeCounts: Record<string, {
|
|
|
|
current: number;
|
|
|
|
max: number;
|
|
|
|
}>, loyaltyLevel: number): void;
|
|
|
|
/**
|
|
|
|
* Add preset weapons to fence presets
|
|
|
|
* @param assortCount how many assorts to add to assorts
|
2023-02-12 23:21:22 -05:00
|
|
|
* @param defaultWeaponPresets a dictionary of default weapon presets
|
2023-01-15 00:21:11 -05:00
|
|
|
* @param assorts object to add presets to
|
2023-02-12 23:21:22 -05:00
|
|
|
* @param loyaltyLevel loyalty level to requre item at
|
2022-09-01 05:19:17 -04:00
|
|
|
*/
|
2023-01-15 00:21:11 -05:00
|
|
|
protected addPresets(desiredPresetCount: number, defaultWeaponPresets: Record<string, Preset>, assorts: ITraderAssort, loyaltyLevel: number): void;
|
2022-12-25 18:45:30 -05:00
|
|
|
/**
|
|
|
|
* Randomise items' upd properties e.g. med packs/weapons/armor
|
|
|
|
* @param itemDetails Item being randomised
|
|
|
|
* @param itemToAdjust Item being edited
|
|
|
|
*/
|
|
|
|
protected randomiseItemUpdProperties(itemDetails: ITemplateItem, itemToAdjust: Item): void;
|
|
|
|
/**
|
|
|
|
* Construct item limit record to hold max and current item count
|
|
|
|
* @param limits limits as defined in config
|
|
|
|
* @returns record, key: item tplId, value: current/max item count allowed
|
|
|
|
*/
|
|
|
|
protected initItemLimitCounter(limits: Record<string, number>): Record<string, {
|
|
|
|
current: number;
|
|
|
|
max: number;
|
|
|
|
}>;
|
2022-08-17 02:29:54 -04:00
|
|
|
/**
|
|
|
|
* Get the next update timestamp for fence
|
|
|
|
* @returns future timestamp
|
|
|
|
*/
|
|
|
|
getNextFenceUpdateTimestamp(): number;
|
|
|
|
/**
|
|
|
|
* Get fence refresh time in seconds
|
|
|
|
*/
|
|
|
|
protected getFenceRefreshTime(): number;
|
|
|
|
/**
|
2022-09-01 05:19:17 -04:00
|
|
|
* Get fence level the passed in profile has
|
2022-08-17 02:29:54 -04:00
|
|
|
* @param pmcData Player profile
|
2022-09-01 05:19:17 -04:00
|
|
|
* @returns FenceLevel object
|
2022-08-17 02:29:54 -04:00
|
|
|
*/
|
|
|
|
getFenceInfo(pmcData: IPmcData): FenceLevel;
|
2022-09-01 05:19:17 -04:00
|
|
|
/**
|
|
|
|
* Remove an assort from fence by id
|
|
|
|
* @param assortIdToRemove assort id to remove from fence assorts
|
|
|
|
*/
|
2022-08-17 02:29:54 -04:00
|
|
|
removeFenceOffer(assortIdToRemove: string): void;
|
|
|
|
}
|