diff --git a/Libraries/Core/Controllers/RagfairController.cs b/Libraries/Core/Controllers/RagfairController.cs
index ed3e35a7..c9797d88 100644
--- a/Libraries/Core/Controllers/RagfairController.cs
+++ b/Libraries/Core/Controllers/RagfairController.cs
@@ -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 };
diff --git a/Libraries/Core/Generators/BotLootGenerator.cs b/Libraries/Core/Generators/BotLootGenerator.cs
index 87b355b5..39db8a3f 100644
--- a/Libraries/Core/Generators/BotLootGenerator.cs
+++ b/Libraries/Core/Generators/BotLootGenerator.cs
@@ -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;
diff --git a/Libraries/Core/Generators/FenceBaseAssortGenerator.cs b/Libraries/Core/Generators/FenceBaseAssortGenerator.cs
index d1c9980f..7abe1934 100644
--- a/Libraries/Core/Generators/FenceBaseAssortGenerator.cs
+++ b/Libraries/Core/Generators/FenceBaseAssortGenerator.cs
@@ -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))
diff --git a/Libraries/Core/Generators/RepeatableQuestRewardGenerator.cs b/Libraries/Core/Generators/RepeatableQuestRewardGenerator.cs
index 79f96ec6..14f54cb1 100644
--- a/Libraries/Core/Generators/RepeatableQuestRewardGenerator.cs
+++ b/Libraries/Core/Generators/RepeatableQuestRewardGenerator.cs
@@ -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);
diff --git a/Libraries/Core/Helpers/HandbookHelper.cs b/Libraries/Core/Helpers/HandbookHelper.cs
index 41ee11f5..8df6fef7 100644
--- a/Libraries/Core/Helpers/HandbookHelper.cs
+++ b/Libraries/Core/Helpers/HandbookHelper.cs
@@ -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(
///
/// Item tpl to look up price for
/// price in roubles
- 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- 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))));
}
///
@@ -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)
diff --git a/Libraries/Core/Helpers/ItemHelper.cs b/Libraries/Core/Helpers/ItemHelper.cs
index 90b69d9e..d36f70c7 100644
--- a/Libraries/Core/Helpers/ItemHelper.cs
+++ b/Libraries/Core/Helpers/ItemHelper.cs
@@ -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);
}
///
@@ -415,7 +415,7 @@ public class ItemHelper(
///
/// Items tpl id to look up price
/// Price in roubles (0 if not found)
- 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(
/// Fixed item
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;
}
diff --git a/Libraries/Core/Helpers/TraderHelper.cs b/Libraries/Core/Helpers/TraderHelper.cs
index 7cff5397..692d6b03 100644
--- a/Libraries/Core/Helpers/TraderHelper.cs
+++ b/Libraries/Core/Helpers/TraderHelper.cs
@@ -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)
diff --git a/Libraries/Core/Services/CircleOfCultistService.cs b/Libraries/Core/Services/CircleOfCultistService.cs
index c8f66a1a..4ab4a3ad 100644
--- a/Libraries/Core/Services/CircleOfCultistService.cs
+++ b/Libraries/Core/Services/CircleOfCultistService.cs
@@ -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
- 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
diff --git a/Libraries/Core/Services/PaymentService.cs b/Libraries/Core/Services/PaymentService.cs
index 7622dbbd..700f9ceb 100644
--- a/Libraries/Core/Services/PaymentService.cs
+++ b/Libraries/Core/Services/PaymentService.cs
@@ -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}");
diff --git a/Libraries/Core/Services/RagfairPriceService.cs b/Libraries/Core/Services/RagfairPriceService.cs
index 677beab7..6a3eef0c 100644
--- a/Libraries/Core/Services/RagfairPriceService.cs
+++ b/Libraries/Core/Services/RagfairPriceService.cs
@@ -48,7 +48,7 @@ public class RagfairPriceService(
{
_staticPrices = new Dictionary();
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);
}
}