Skip to content

Commit

Permalink
Fixed price discrepancy between trader and flea price for trader items,
Browse files Browse the repository at this point in the history
resolves #968
  • Loading branch information
Chomp committed Dec 3, 2024
1 parent b48c115 commit e5fb672
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
13 changes: 13 additions & 0 deletions project/src/generators/RagfairOfferGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
IDynamic,
IRagfairConfig,
} from "@spt/models/spt/config/IRagfairConfig";
import { ITraderConfig } from "@spt/models/spt/config/ITraderConfig";
import { ITplWithFleaPrice } from "@spt/models/spt/ragfair/ITplWithFleaPrice";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
Expand All @@ -40,6 +41,7 @@ import { inject, injectable } from "tsyringe";
@injectable()
export class RagfairOfferGenerator {
protected ragfairConfig: IRagfairConfig;
protected traderConfig: ITraderConfig;
protected botConfig: IBotConfig;
protected allowedFleaPriceItemsForBarter: { tpl: string; price: number }[];

Expand Down Expand Up @@ -69,6 +71,7 @@ export class RagfairOfferGenerator {
@inject("PrimaryCloner") protected cloner: ICloner,
) {
this.ragfairConfig = this.configServer.getConfig(ConfigTypes.RAGFAIR);
this.traderConfig = this.configServer.getConfig(ConfigTypes.TRADER);
this.botConfig = this.configServer.getConfig(ConfigTypes.BOT);
}

Expand Down Expand Up @@ -589,6 +592,16 @@ export class RagfairOfferGenerator {
}

const barterSchemeItems = assorts.barter_scheme[item._id][0];

// Adjust price by traderPriceMultipler config property
if (this.traderConfig.traderPriceMultipler > 0) {
if (barterSchemeItems.length === 1 && this.paymentHelper.isMoneyTpl(barterSchemeItems[0]._tpl)) {
barterSchemeItems[0].count = Math.ceil(
barterSchemeItems[0].count * this.traderConfig.traderPriceMultipler,
);
}
}

const loyalLevel = assorts.loyal_level_items[item._id];

const offer = this.createAndAddFleaOffer(traderID, time, items, barterSchemeItems, loyalLevel, false);
Expand Down
23 changes: 0 additions & 23 deletions project/src/helpers/TraderAssortHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ export class TraderAssortHelper {
this.removeItemsFromAssort(traderClone.assort, fullProfile.spt.blacklistedItemTpls);
}

// Multiply price if multiplier is other than 1
if (this.traderConfig.traderPriceMultipler !== 1) {
this.multiplyItemPricesByConfigMultiplier(traderClone.assort);
}

return traderClone.assort;
}

Expand Down Expand Up @@ -218,24 +213,6 @@ export class TraderAssortHelper {
return trader.base.nextResupply <= time;
}

/**
* Iterate over all assorts barter_scheme values, find barters selling for money and multiply by multipler in config
* @param traderAssort Assorts to multiple price of
*/
protected multiplyItemPricesByConfigMultiplier(traderAssort: ITraderAssort): void {
if (!this.traderConfig.traderPriceMultipler || this.traderConfig.traderPriceMultipler <= 0) {
this.traderConfig.traderPriceMultipler = 0.01;
this.logger.warning(this.localisationService.getText("trader-price_multipler_is_zero_use_default"));
}

for (const assortId in traderAssort.barter_scheme) {
const schemeDetails = traderAssort.barter_scheme[assortId][0];
if (schemeDetails.length === 1 && this.paymentHelper.isMoneyTpl(schemeDetails[0]._tpl)) {
schemeDetails[0].count = Math.ceil(schemeDetails[0].count * this.traderConfig.traderPriceMultipler);
}
}
}

/**
* Get an array of pristine trader items prior to any alteration by player (as they were on server start)
* @param traderId trader id
Expand Down
2 changes: 1 addition & 1 deletion project/src/models/spt/config/ITraderConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { ILootRequest } from "@spt/models/spt/services/ILootRequest";
export interface ITraderConfig extends IBaseConfig {
kind: "spt-trader";
updateTime: IUpdateTime[];
updateTimeDefault: number;
purchasesAreFoundInRaid: boolean;
/** Should trader reset times be set based on server start time (false = bsg time - on the hour) */
tradersResetFromServerStart: boolean;
updateTimeDefault: number;
traderPriceMultipler: number;
fence: IFenceConfig;
moddedTraders: IModdedTraders;
Expand Down

0 comments on commit e5fb672

Please sign in to comment.