Type improvements

This commit is contained in:
Chomp
2025-01-30 14:33:19 +00:00
parent f0774822c1
commit 12f989a4da
10 changed files with 24 additions and 27 deletions
@@ -375,7 +375,7 @@ public class RagfairController
var fleaPrices = _databaseService.GetPrices();
if (!fleaPrices.TryGetValue(getPriceRequest.TemplateId, out var tplPrice))
{
tplPrice = _handbookHelper.GetTemplatePrice(getPriceRequest.TemplateId) ?? 0;
tplPrice = _handbookHelper.GetTemplatePrice(getPriceRequest.TemplateId);
}
return new GetItemPriceResult { Avg = tplPrice, Min = tplPrice, Max = tplPrice };
@@ -570,7 +570,7 @@ public class BotLootGenerator(
// Stop adding items to bots pool if rolling total is over total limit
if (totalValueLimitRub > 0)
{
currentTotalRub += _handbookHelper.GetTemplatePrice(itemToAddTemplate.Id) ?? 0;
currentTotalRub += _handbookHelper.GetTemplatePrice(itemToAddTemplate.Id);
if (currentTotalRub > totalValueLimitRub)
{
break;
@@ -1,4 +1,4 @@
using Core.Helpers;
using Core.Helpers;
using SptCommon.Annotations;
using Core.Models.Eft.Common.Tables;
using Core.Models.Enums;
@@ -37,7 +37,7 @@ public class FenceBaseAssortGenerator(
var blockedSeasonalItems = seasonalEventService.GetInactiveSeasonalEventItems();
var baseFenceAssort = databaseService.GetTrader(Traders.FENCE).Assort;
foreach (var rootItemDb in itemHelper.GetItems().Where((item) => IsValidFenceItem(item)))
foreach (var rootItemDb in itemHelper.GetItems().Where(IsValidFenceItem))
{
// Skip blacklisted items
if (itemFilterService.IsItemBlacklisted(rootItemDb.Id))
@@ -407,7 +407,7 @@ public class RepeatableQuestRewardGenerator(
var singleCartridgePrice = _handbookHelper.GetTemplatePrice(itemSelected.Id);
// Get a stack size of ammo that fits rouble budget
var stackSizeThatFitsBudget = Math.Round(stackRoubleBudget / singleCartridgePrice.Value);
var stackSizeThatFitsBudget = Math.Round(stackRoubleBudget / singleCartridgePrice);
// Get itemDbs max stack size for ammo - don't go above 100 (some mods mess around with stack sizes)
var stackMaxCount = Math.Min(itemSelected.Properties.StackMaxSize.Value, 100);
+7 -6
View File
@@ -1,4 +1,4 @@
using SptCommon.Annotations;
using SptCommon.Annotations;
using Core.Models.Eft.Common.Tables;
using Core.Models.Enums;
using Core.Models.Spt.Config;
@@ -72,7 +72,7 @@ public class HandbookHelper(
/// </summary>
/// <param name="tpl">Item tpl to look up price for</param>
/// <returns>price in roubles</returns>
public double? GetTemplatePrice(string tpl)
public double GetTemplatePrice(string tpl)
{
if (!_lookupCacheGenerated)
{
@@ -102,14 +102,15 @@ public class HandbookHelper(
{
_handbookPriceCache.Items.ById[tpl] = handbookItem.Price ?? 0;
}
return handbookItem.Price;
return handbookItem.Price.Value;
}
public double GetTemplatePriceForItems(List<Item> items)
{
var total = 0D;
foreach (var item in items) {
total += GetTemplatePrice(item.Template) ?? 0;
total += GetTemplatePrice(item.Template);
}
return total;
@@ -158,7 +159,7 @@ public class HandbookHelper(
{
return (int) (currencyTypeFrom == Money.ROUBLES
? nonRoubleCurrencyCount
: Math.Round(nonRoubleCurrencyCount * (GetTemplatePrice(currencyTypeFrom) ?? 0)));
: Math.Round(nonRoubleCurrencyCount * (GetTemplatePrice(currencyTypeFrom))));
}
/// <summary>
@@ -175,7 +176,7 @@ public class HandbookHelper(
// Get price of currency from handbook
var price = GetTemplatePrice(currencyTypeTo);
return (int) (price is not null ? Math.Max(1, Math.Round((double)(roubleCurrencyCount / price))) : 0);
return (int) (price > 0 ? Math.Max(1, Math.Round(roubleCurrencyCount / price)) : 0);
}
public HandbookCategory GetCategoryById(string handbookId)
+6 -10
View File
@@ -407,7 +407,7 @@ public class ItemHelper(
var staticPrice = GetStaticItemPrice(tpl);
var dynamicPrice = GetDynamicItemPrice(tpl);
return Math.Max(staticPrice ?? 0d, dynamicPrice ?? 0d);
return Math.Max(staticPrice, dynamicPrice ?? 0d);
}
/// <summary>
@@ -415,7 +415,7 @@ public class ItemHelper(
/// </summary>
/// <param name="tpl">Items tpl id to look up price</param>
/// <returns>Price in roubles (0 if not found)</returns>
public double? GetStaticItemPrice(string tpl)
public double GetStaticItemPrice(string tpl)
{
var handbookPrice = _handbookHelper.GetTemplatePrice(tpl);
if (handbookPrice >= 1)
@@ -448,15 +448,11 @@ public class ItemHelper(
/// <returns>Fixed item</returns>
public Item FixItemStackCount(Item item)
{
if (item.Upd is null)
{
item.Upd = new() { StackObjectsCount = 1 };
}
// Ensure item has 'Upd' object
item.Upd ??= new() { StackObjectsCount = 1 };
if (item.Upd.StackObjectsCount is null)
{
item.Upd.StackObjectsCount = 1;
}
// Ensure item has 'StackObjectsCount' property
item.Upd.StackObjectsCount ??= 1;
return item;
}
+1 -1
View File
@@ -582,7 +582,7 @@ public class TraderHelper(
var traderBuyBackPricePercent = traderBase.LoyaltyLevels.FirstOrDefault().BuyPriceCoefficient;
var itemHandbookPrice = _handbookHelper.GetTemplatePrice(tpl);
var priceTraderBuysItemAt = _randomUtil.GetPercentOfValue(traderBuyBackPricePercent ?? 0, itemHandbookPrice ?? 0, 0);
var priceTraderBuysItemAt = _randomUtil.GetPercentOfValue(traderBuyBackPricePercent ?? 0, itemHandbookPrice, 0);
// Price from this trader is higher than highest found, update
if (priceTraderBuysItemAt > highestPrice)
@@ -1,4 +1,4 @@
using Core.Helpers;
using Core.Helpers;
using SptCommon.Annotations;
using Core.Models.Eft.Common;
using Core.Models.Eft.Common.Tables;
@@ -61,7 +61,7 @@ public class CircleOfCultistService(
// `cultistRecipes` just has single recipeId
var cultistCraftData = _databaseService.GetHideout().Production.CultistRecipes.FirstOrDefault();
List<Item> sacrificedItems = GetSacrificedItems(pmcData);
var sacrificedItems = GetSacrificedItems(pmcData);
var sacrificedItemCostRoubles = sacrificedItems.Aggregate(
0D,
(sum, curr) => sum + (_itemHelper.GetItemPrice(curr.Template) ?? 0)
@@ -69,7 +69,7 @@ public class CircleOfCultistService(
var rewardAmountMultiplier = GetRewardAmountMultiplier(pmcData, _hideoutConfig.CultistCircle);
// Get the rouble amount we generate rewards with from cost of sacrified items * above multipler
// Get the rouble amount we generate rewards with from cost of sacrificed items * above multiplier
var rewardAmountRoubles = Math.Round(sacrificedItemCostRoubles * rewardAmountMultiplier);
// Check if it matches any direct swap recipes
+1 -1
View File
@@ -151,7 +151,7 @@ public class PaymentService(
}
var assortItemPriceRouble = _handbookHelper.GetTemplatePrice(purchasedAssortItem.Template);
if (assortItemPriceRouble is null)
if (assortItemPriceRouble == 0)
{
_logger.Debug($"No item price found for {purchasedAssortItem.Template} on trader: {traderId} in assort: {traderAssortId}");
@@ -48,7 +48,7 @@ public class RagfairPriceService(
{
_staticPrices = new Dictionary<string, double>();
foreach (var item in _databaseService.GetItems().Values.Where(item => item.Type == "Item")) {
this._staticPrices[item.Id] = _handbookHelper.GetTemplatePrice(item.Id).Value;
_staticPrices[item.Id] = _handbookHelper.GetTemplatePrice(item.Id);
}
}