Improve how daily quests calculate the price of items when choosing a reward that's inside its price boundaries
Items with a default preset inside globals.json now use all items inside the preset for price calculation
This commit is contained in:
parent
bd2ebe6cbc
commit
424e438732
@ -1144,9 +1144,20 @@ export class RepeatableQuestGenerator
|
||||
const rewardableItemPool = this.getRewardableItems(repeatableConfig, traderId);
|
||||
const minPrice = Math.min(25000, 0.5 * roublesBudget);
|
||||
|
||||
let rewardableItemPoolWithinBudget = rewardableItemPool.filter((x) =>
|
||||
this.itemHelper.getItemPrice(x[0]) < roublesBudget && this.itemHelper.getItemPrice(x[0]) > minPrice
|
||||
).map((x) => x[1]);
|
||||
let rewardableItemPoolWithinBudget = rewardableItemPool.filter((item) =>
|
||||
{
|
||||
// Get default preset if it exists
|
||||
const defaultPreset = this.presetHelper.getDefaultPreset(item[0]);
|
||||
|
||||
// Bundle up tpls we want price for
|
||||
const tpls = defaultPreset ? defaultPreset._items.map((x) => x._tpl) : [item[0]];
|
||||
|
||||
// Get price of tpls
|
||||
const itemPrice = this.itemHelper.getItemAndChildrenPrice(tpls);
|
||||
|
||||
return itemPrice < roublesBudget && itemPrice > minPrice;
|
||||
}).map((x) => x[1]);
|
||||
|
||||
if (rewardableItemPoolWithinBudget.length === 0)
|
||||
{
|
||||
this.logger.warning(
|
||||
|
@ -159,6 +159,18 @@ export class ItemHelper
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the items total price based on the handbook or as a fallback from the prices.json if the item is not
|
||||
* found in the handbook. If the price can't be found at all return 0
|
||||
* @param tpls item tpls to look up the price of
|
||||
* @returns Total price in roubles
|
||||
*/
|
||||
public getItemAndChildrenPrice(tpls: string[]): number
|
||||
{
|
||||
// Run getItemPrice for each tpl in tpls array, return sum
|
||||
return tpls.reduce((total, tpl) => total + this.getItemPrice(tpl), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the item price based on the handbook or as a fallback from the prices.json if the item is not
|
||||
* found in the handbook. If the price can't be found at all return 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user