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:
Dev 2024-02-07 20:15:44 +00:00
parent bd2ebe6cbc
commit 424e438732
2 changed files with 26 additions and 3 deletions

View File

@ -1144,9 +1144,20 @@ export class RepeatableQuestGenerator
const rewardableItemPool = this.getRewardableItems(repeatableConfig, traderId); const rewardableItemPool = this.getRewardableItems(repeatableConfig, traderId);
const minPrice = Math.min(25000, 0.5 * roublesBudget); const minPrice = Math.min(25000, 0.5 * roublesBudget);
let rewardableItemPoolWithinBudget = rewardableItemPool.filter((x) => let rewardableItemPoolWithinBudget = rewardableItemPool.filter((item) =>
this.itemHelper.getItemPrice(x[0]) < roublesBudget && this.itemHelper.getItemPrice(x[0]) > minPrice {
).map((x) => x[1]); // 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) if (rewardableItemPoolWithinBudget.length === 0)
{ {
this.logger.warning( this.logger.warning(

View File

@ -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 * 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 * found in the handbook. If the price can't be found at all return 0