Converted more string comparisons to use string.equals

Optimised `CreateBarterBarterScheme`
This commit is contained in:
Chomp
2025-02-25 13:30:59 +00:00
parent 8aebbcd395
commit b67ff36631
8 changed files with 23 additions and 20 deletions
@@ -343,6 +343,6 @@ public class FenceBaseAssortGenerator(
*/
protected bool IsValidFenceItem(TemplateItem item)
{
return item.Type == "Item";
return string.Equals(item.Type, "Item", StringComparison.OrdinalIgnoreCase);
}
}
@@ -953,7 +953,7 @@ public class RagfairOfferGenerator(
false
);
// Dont make items under a designated rouble value into barter offers
// Don't make items under a designated rouble value into barter offers
if (priceOfOfferItem < barterConfig.MinRoubleCostToBecomeBarter)
{
return CreateCurrencyBarterScheme(offerItems, false);
@@ -969,25 +969,28 @@ public class RagfairOfferGenerator(
var offerCostVarianceRoubles = desiredItemCostRouble * barterConfig.PriceRangeVariancePercent / 100;
// Dict of items and their flea price (cached on first use)
var itemFleaPrices = GetFleaPricesAsArray();
List<TplWithFleaPrice> itemFleaPrices = GetFleaPricesAsArray();
// Filter possible barters to items that match the price range + not itself
var min = desiredItemCostRouble - offerCostVarianceRoubles;
var max = desiredItemCostRouble + offerCostVarianceRoubles;
var itemsInsidePriceBounds = itemFleaPrices.Where(
itemAndPrice =>
itemAndPrice.Price >= desiredItemCostRouble - offerCostVarianceRoubles &&
itemAndPrice.Price <= desiredItemCostRouble + offerCostVarianceRoubles &&
!string.Equals(itemAndPrice.Tpl, offerItems[0].Template, StringComparison.OrdinalIgnoreCase) // Don't allow the item being sold to be chosen
)
.ToList();
itemAndPrice =>
itemAndPrice.Price >= min &&
itemAndPrice.Price <= max &&
!string.Equals(itemAndPrice.Tpl, offerItems[0].Template,
StringComparison.OrdinalIgnoreCase) // Don't allow the item being sold to be chosen
);
// No items on flea have a matching price, fall back to currency
if (itemsInsidePriceBounds.Count == 0)
if (!itemsInsidePriceBounds.Any())
{
return CreateCurrencyBarterScheme(offerItems, false);
}
// Choose random item from price-filtered flea items
var randomItem = randomUtil.GetArrayValue(itemsInsidePriceBounds);
var randomItem = randomUtil.GetArrayValue(itemsInsidePriceBounds.ToList());
return
[
+1 -1
View File
@@ -350,7 +350,7 @@ public class ItemHelper(
}
return !(itemDetails.Value.Properties.QuestItem ?? false) &&
itemDetails.Value.Type == "Item" &&
string.Equals(itemDetails.Value.Type, "Item", StringComparison.OrdinalIgnoreCase) &&
baseTypes.All(x => !IsOfBaseclass(tpl, x)) &&
GetItemPrice(tpl) > 0 &&
!_itemFilterService.IsItemBlacklisted(tpl);
@@ -232,7 +232,7 @@ public class BotEquipmentModPoolService
{
var weapons = _databaseService.GetItems()
.Values.Where(
item => item.Type == "Item" && _itemHelper.IsOfBaseclass(item.Id, BaseClasses.WEAPON)
item => string.Equals(item.Type, "Item", StringComparison.OrdinalIgnoreCase) && _itemHelper.IsOfBaseclass(item.Id, BaseClasses.WEAPON)
);
GeneratePool(weapons, "weapon");
@@ -247,7 +247,7 @@ public class BotEquipmentModPoolService
{
var gear = _databaseService.GetItems()
.Values.Where(
item => item.Type == "Item" &&
item => string.Equals(item.Type, "Item", StringComparison.OrdinalIgnoreCase) &&
_itemHelper.IsOfBaseclasses(
item.Id,
[
+2 -2
View File
@@ -760,7 +760,7 @@ public class FenceService(
{
var priceLimits = traderConfig.Fence.ItemCategoryRoublePriceLimit;
var assortRootItems = baseFenceAssortClone.Items
.Where(item => item.ParentId == "hideout" && item.Upd?.SptPresetId == null)
.Where(item => string.Equals(item.ParentId, "hideout", StringComparison.OrdinalIgnoreCase) && item.Upd?.SptPresetId == null)
.ToList();
if (assortRootItems.Count == 0)
{
@@ -887,7 +887,7 @@ public class FenceService(
.Where(
itemWithChildren => itemWithChildren.FirstOrDefault(
item => item.Template == rootItemBeingAdded.Template &&
item.ParentId == "hideout"
string.Equals(item.ParentId, "hideout", StringComparison.OrdinalIgnoreCase)
) !=
null
)
+1 -1
View File
@@ -521,7 +521,7 @@ public class PostDbLoadService(
{
var dbItems = _databaseService.GetItems().Values.ToList();
foreach (var item in dbItems.Where(
item => item.Type == "Item" &&
item => string.Equals(item.Type, "Item", StringComparison.OrdinalIgnoreCase) &&
!item.Properties.CanSellOnRagfair.GetValueOrDefault(false) &&
!_ragfairConfig.Dynamic.Blacklist.Custom.Contains(item.Id)
))
@@ -276,9 +276,9 @@ public class RagfairOfferService(
// Need to regenerate Ids to ensure returned item(s) have correct parent values
var newParentId = hashUtil.Generate();
foreach (var item in unstackedItems)
// Refresh root items' parentIds
{
if (item.ParentId == "hideout")
// Refresh root items' parentIds
if (string.Equals(item.ParentId, "hideout", StringComparison.OrdinalIgnoreCase))
{
item.ParentId = newParentId;
}
@@ -48,7 +48,7 @@ public class RagfairPriceService(
public void RefreshStaticPrices()
{
_staticPrices = new Dictionary<string, double>();
foreach (var item in _databaseService.GetItems().Values.Where(item => item.Type == "Item"))
foreach (var item in _databaseService.GetItems().Values.Where(item => string.Equals(item.Type, "Item", StringComparison.OrdinalIgnoreCase)))
{
_staticPrices[item.Id] = _handbookHelper.GetTemplatePrice(item.Id);
}