Generate weapon/armor price based on the child item price total

This commit is contained in:
Chomp
2025-10-30 22:13:53 +00:00
parent 1b07ce530d
commit ab882617d7
4 changed files with 37 additions and 3 deletions
@@ -346,6 +346,7 @@
"useTraderPriceForOffersIfHigher": true,
"generateBaseFleaPrices": {
"useHandbookPrice": true,
"generatePresetPriceByChildren": true,
"priceMultiplier": 1.5,
"itemTplMultiplierOverride": {
"5780cf7f2459777de4559322": 1.8
@@ -473,7 +473,7 @@ public class RagfairOfferGenerator(
// Not barter or pack offer
// Apply randomised properties
RandomiseOfferItemUpdProperties(sellerId, itemWithChildren, itemToSellDetails, offerCreator);
barterScheme = CreateCurrencyBarterScheme(itemWithChildren, isPackOffer);
barterScheme = CreateCurrencyBarterScheme(itemWithChildren, false);
}
var createOfferDetails = new CreateFleaOfferDetails
@@ -487,6 +487,7 @@ public class RagfairOfferGenerator(
Creator = offerCreator,
SellInOnePiece = isPackOffer, // sellAsOnePiece - pack offer
};
CreateAndAddFleaOffer(createOfferDetails);
}
@@ -269,6 +269,12 @@ public record GenerateFleaPrices
[JsonPropertyName("hideoutCraftMultiplier")]
public double HideoutCraftMultiplier { get; set; }
/// <summary>
/// Should weapons/armors have their price generated by totalling its child items
/// </summary>
[JsonPropertyName("generatePresetPriceByChildren")]
public bool GeneratePresetPriceByChildren { get; set; }
}
public record PriceRanges
@@ -272,7 +272,7 @@ public class RagfairPriceService(
continue;
}
price += GetDynamicItemPrice(item.Template, desiredCurrency, item, offerItems, isPackOffer).Value;
price += GetDynamicItemPrice(item.Template, desiredCurrency, item, offerItems, isPackOffer) ?? 0;
// Check if the item is a weapon preset.
if (item?.Upd?.SptPresetId is not null && presetHelper.IsPresetBaseClass(item.Upd.SptPresetId.Value, BaseClasses.WEAPON))
@@ -329,7 +329,11 @@ public class RagfairPriceService(
&& presetHelper.IsPresetBaseClass(item.Upd.SptPresetId.Value, BaseClasses.WEAPON)
)
{
price = GetWeaponPresetPrice(item, offerItems, price);
price =
RagfairConfig.Dynamic.GenerateBaseFleaPrices.UseHandbookPrice
&& RagfairConfig.Dynamic.GenerateBaseFleaPrices.GeneratePresetPriceByChildren
? GetPresetPriceByChildren(offerItems)
: GetWeaponPresetPrice(item, offerItems, price);
isPreset = true;
}
@@ -522,6 +526,28 @@ public class RagfairPriceService(
return existingPrice + extraModsPrice;
}
/// <summary>
/// Calculate the cost of a weapon preset by adding together the price of its mods
/// </summary>
/// <param name="weaponWithChildren">weapon plus mods</param>
/// <returns>price of weapon in roubles</returns>
protected double GetPresetPriceByChildren(IEnumerable<Item> weaponWithChildren)
{
var priceTotal = 0d;
foreach (var item in weaponWithChildren)
{
// Root item uses static price
if (item.ParentId == null)
{
priceTotal += GetStaticPriceForItem(item.Template) ?? 0;
}
priceTotal += GetFleaPriceForItem(item.Template);
}
return priceTotal;
}
/// <summary>
/// Get the highest price for an item that is stored in handbook or trader assorts
/// </summary>