do logging shit for helpers

This commit is contained in:
CWX
2025-01-28 21:09:51 +00:00
parent ac2f24c9d1
commit 05dbddcf01
12 changed files with 153 additions and 65 deletions
+7 -3
View File
@@ -9,6 +9,7 @@ using Core.Models.Utils;
using Core.Servers;
using Core.Services;
using Core.Utils;
using LogLevel = Core.Models.Spt.Logging.LogLevel;
namespace Core.Helpers;
@@ -500,9 +501,12 @@ public class BotGeneratorHelper(
if (missingContainerCount == equipmentSlots.Count)
{
// Bot doesn't have any containers we want to add item to
_logger.Debug(
$"Unable to add item: {itemWithChildren.FirstOrDefault()?.Template} to bot as it lacks the following containers: {string.Join(",", equipmentSlots)}"
);
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug(
$"Unable to add item: {itemWithChildren.FirstOrDefault()?.Template} to bot as it lacks the following containers: {string.Join(",", equipmentSlots)}"
);
}
return ItemAddedResult.NO_CONTAINERS;
}
+25 -6
View File
@@ -12,6 +12,7 @@ using Core.Servers;
using Core.Services;
using Core.Utils;
using Core.Utils.Cloners;
using LogLevel = Core.Models.Spt.Logging.LogLevel;
namespace Core.Helpers;
@@ -210,7 +211,10 @@ public class HideoutHelper(
// Add bonus to player bonuses array in profile
// EnergyRegeneration, HealthRegeneration, RagfairCommission, ScavCooldownTimer, SkillGroupLevelingBoost, ExperienceRate, QuestMoneyReward etc
_logger.Debug($"Adding bonus: {bonus.Type} to profile, value: {bonus.Value}");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Adding bonus: {bonus.Type} to profile, value: {bonus.Value}");
}
profileData.Bonuses.Add(bonus);
}
@@ -638,7 +642,10 @@ public class HideoutHelper(
// Deducted all used fuel from this container, clean up and exit loop
fuelItemInSlot.Upd = GetAreaUpdObject(1, fuelRemaining, pointsConsumed, isFuelItemFoundInRaid);
_logger.Debug($"Profile: {pmcData.Id} Generator has: {fuelRemaining} fuel left in slot {i + 1}");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Profile: {pmcData.Id} Generator has: {fuelRemaining} fuel left in slot {i + 1}");
}
hasFuelRemaining = true;
break; // Break to avoid updating all the fuel tanks
@@ -648,7 +655,10 @@ public class HideoutHelper(
// Ran out of fuel items to deduct fuel from
fuelUsedSinceLastTick = Math.Abs(fuelRemaining ?? 0);
_logger.Debug($"Profile: {pmcData.Id} Generator ran out of fuel");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Profile: {pmcData.Id} Generator ran out of fuel");
}
}
// Out of fuel, flag generator as offline
@@ -853,7 +863,10 @@ public class HideoutHelper(
pointsConsumed,
isWaterFilterFoundInRaid
);
_logger.Debug($"Water filter has: {resourceValue} units left in slot {i + 1}");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Water filter has: {resourceValue} units left in slot {i + 1}");
}
break; // Break here to avoid iterating other filters now w're done
}
@@ -1013,7 +1026,10 @@ public class HideoutHelper(
StackObjectsCount = 1,
Resource = new UpdResource { Value = resourceValue, UnitsConsumed = pointsConsumed },
};
_logger.Debug($"Air filter: {resourceValue} filter left on slot {i + 1}");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Air filter: {resourceValue} filter left on slot {i + 1}");
}
break; // Break here to avoid updating all filters
}
@@ -1459,7 +1475,10 @@ public class HideoutHelper(
bonusIdsToRemove.Add(bonus.Id);
}
_logger.Debug($"Removing: {bonusIdsToRemove.Count} bonuses from profile");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Removing: {bonusIdsToRemove.Count} bonuses from profile");
}
// Remove the wall bonuses from profile by id
pmcData.Bonuses = pmcData.Bonuses.Where((bonus) => !bonusIdsToRemove.Contains(bonus.Id)).ToList();
+26 -16
View File
@@ -15,6 +15,7 @@ using Core.Utils;
using Core.Utils.Cloners;
using SptCommon.Annotations;
using SptCommon.Extensions;
using LogLevel = Core.Models.Spt.Logging.LogLevel;
namespace Core.Helpers;
@@ -148,9 +149,12 @@ public class InventoryHelper(
.Items.NewItems.AddRange(itemWithModsToAddClone);
pmcData.Inventory.Items.AddRange(itemWithModsToAddClone);
_logger.Debug(
$"Added {itemWithModsToAddClone[0].Upd?.StackObjectsCount ?? 1} item: {itemWithModsToAddClone[0].Template} with: {itemWithModsToAddClone.Count - 1} mods to inventory"
);
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug(
$"Added {itemWithModsToAddClone[0].Upd?.StackObjectsCount ?? 1} item: {itemWithModsToAddClone[0].Template} with: {itemWithModsToAddClone.Count - 1} mods to inventory"
);
}
}
/// <summary>
@@ -444,16 +448,19 @@ public class InventoryHelper(
var itemAndChildrenToRemove = _itemHelper.FindAndReturnChildrenAsItems(profile.Inventory.Items, itemId);
if (itemAndChildrenToRemove.Count == 0)
{
_logger.Debug(
_localisationService.GetText(
"inventory-unable_to_remove_item_id_not_found",
new
{
ChildId = itemId,
ProfileId = profile.Id
}
)
);
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug(
_localisationService.GetText(
"inventory-unable_to_remove_item_id_not_found",
new
{
ChildId = itemId,
ProfileId = profile.Id
}
)
);
}
return;
}
@@ -1071,9 +1078,12 @@ public class InventoryHelper(
return false;
}
_logger.Debug(
$"{moveRequest.Action} item: ${moveRequest.Item} from slotid: {matchingInventoryItem.SlotId} to container: {moveRequest.To.Container}"
);
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug(
$"{moveRequest.Action} item: ${moveRequest.Item} from slotid: {matchingInventoryItem.SlotId} to container: {moveRequest.To.Container}"
);
}
// Don't move shells from camora to cartridges (happens when loading shells into mts-255 revolver shotgun)
if (matchingInventoryItem.SlotId?.Contains("camora_") is null && moveRequest.To.Container == "cartridges")
+21 -9
View File
@@ -8,7 +8,7 @@ using Core.Services;
using Core.Utils;
using Core.Utils.Cloners;
using Core.Utils.Collections;
using LogLevel = Core.Models.Spt.Logging.LogLevel;
namespace Core.Helpers;
@@ -1463,7 +1463,10 @@ public class ItemHelper(
);
if (cartridgeTpl is null)
{
_logger.Debug($"Unable to fill item: {magazine.FirstOrDefault().Id} {magTemplate.Name} with cartridges, none found.");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Unable to fill item: {magazine.FirstOrDefault().Id} {magTemplate.Name} with cartridges, none found.");
}
return;
}
@@ -1740,9 +1743,12 @@ public class ItemHelper(
var itemPool = slot.Props.Filters[0].Filter ?? [];
if (itemPool.Count() == 0)
{
_logger.Debug(
$"Unable to choose a mod for slot: {slot.Name} on item: {itemToAddTemplate.Id} {itemToAddTemplate.Name}, parents' 'Filter' array is empty, skipping"
);
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug(
$"Unable to choose a mod for slot: {slot.Name} on item: {itemToAddTemplate.Id} {itemToAddTemplate.Name}, parents' 'Filter' array is empty, skipping"
);
}
continue;
}
@@ -1750,9 +1756,12 @@ public class ItemHelper(
var chosenTpl = GetCompatibleTplFromArray(itemPool, incompatibleModTpls);
if (chosenTpl is null)
{
_logger.Debug(
$"Unable to choose a mod for slot: {slot.Name} on item: {itemToAddTemplate.Id} {itemToAddTemplate.Name}, no compatible tpl found in pool of {itemPool.Count()}, skipping"
);
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug(
$"Unable to choose a mod for slot: {slot.Name} on item: {itemToAddTemplate.Id} {itemToAddTemplate.Name}, no compatible tpl found in pool of {itemPool.Count()}, skipping"
);
}
continue;
}
@@ -1955,7 +1964,10 @@ public class ItemHelper(
if (warningMessageWhenMissing is not null)
{
_logger.Debug(warningMessageWhenMissing);
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug(warningMessageWhenMissing);
}
}
return true;
+3 -10
View File
@@ -9,6 +9,7 @@ namespace Core.Helpers;
public class PaymentHelper(ConfigServer _configServer)
{
protected InventoryConfig _inventoryConfig = _configServer.GetConfig<InventoryConfig>();
protected List<string> _moneyTpls = [Money.DOLLARS, Money.EUROS, Money.ROUBLES, Money.GP];
/// <summary>
/// Is the passed in tpl money (also checks custom currencies in inventoryConfig.customMoneyTpls)
@@ -17,17 +18,9 @@ public class PaymentHelper(ConfigServer _configServer)
/// <returns></returns>
public bool IsMoneyTpl(string tpl)
{
var moneyTypes = new List<string>
{
Money.DOLLARS,
Money.EUROS,
Money.ROUBLES,
Money.GP,
_moneyTpls.AddRange(_inventoryConfig.CustomMoneyTpls);
};
moneyTypes.AddRange(_inventoryConfig.CustomMoneyTpls);
return moneyTypes.Contains(tpl);
return _moneyTpls.Contains(tpl);
}
/// <summary>
+5 -1
View File
@@ -9,6 +9,7 @@ using Core.Servers;
using Core.Services;
using Core.Utils;
using Core.Utils.Cloners;
using LogLevel = Core.Models.Spt.Logging.LogLevel;
namespace Core.Helpers;
@@ -394,7 +395,10 @@ public class ProfileHelper(
var profile = GetFullProfile(playerId);
if (profile == null)
{
_logger.Debug($"Unable to gift {giftId}, Profile: {playerId} does not exist");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Unable to gift {giftId}, Profile: {playerId} does not exist");
}
return false;
}
+19 -6
View File
@@ -12,6 +12,7 @@ using Core.Services;
using Core.Utils;
using Core.Utils.Cloners;
using SptCommon.Extensions;
using LogLevel = Core.Models.Spt.Logging.LogLevel;
namespace Core.Helpers;
@@ -137,10 +138,16 @@ public class QuestHelper(
while (remainingProgress > 0 && currentLevel < 9) {
// Calculate how much progress to add, limiting it to the current level max progress
var currentLevelRemainingProgress = (currentLevel + 1) * 10 - startingLevelProgress;
_logger.Debug($"currentLevelRemainingProgress: {currentLevelRemainingProgress}");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"currentLevelRemainingProgress: {currentLevelRemainingProgress}");
}
var progressToAdd = Math.Min(remainingProgress, currentLevelRemainingProgress ?? 0);
var adjustedProgressToAdd = (10 / (currentLevel + 1)) * progressToAdd;
_logger.Debug($"Progress To Add: {progressToAdd} Adjusted for level: {adjustedProgressToAdd}");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Progress To Add: {progressToAdd} Adjusted for level: {adjustedProgressToAdd}");
}
// Add the progress amount adjusted by level
adjustedSkillProgress += (int)adjustedProgressToAdd;
@@ -822,7 +829,10 @@ public class QuestHelper(
var questInDb = allQuests.FirstOrDefault((x) => x.Id == questId);
if (questInDb is null)
{
_logger.Debug($"Unable to find quest: {questId} in db, cannot get 'FindItem' condition, skipping");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Unable to find quest: {questId} in db, cannot get 'FindItem' condition, skipping");
}
continue;
}
@@ -1061,9 +1071,12 @@ public class QuestHelper(
// Player can use trader mods then remove them, leaving quests behind
if (!profile.TradersInfo.TryGetValue(quest.TraderId, out var trader))
{
_logger.Debug(
$"Unable to show quest: {quest.QuestName} as its for a trader: {quest.TraderId} that no longer exists."
);
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug(
$"Unable to show quest: {quest.QuestName} as its for a trader: {quest.TraderId} that no longer exists."
);
}
continue;
}
+13 -3
View File
@@ -5,6 +5,7 @@ using Core.Servers;
using Core.Models.Utils;
using Core.Services;
using Core.Utils;
using LogLevel = Core.Models.Spt.Logging.LogLevel;
namespace Core.Helpers;
@@ -82,7 +83,10 @@ public class RagfairSellHelper(
_logger.Warning($"Sell chance was not a number: {sellChancePercent}, defaulting to {_ragfairConfig.Sell.Chance.Base}%");
}
_logger.Debug($"Rolling to sell: { itemSellCount}items(chance: { effectiveSellChance}%)");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Rolling to sell: { itemSellCount}items(chance: { effectiveSellChance}%)");
}
// No point rolling for a sale on a 0% chance item, exit early
if (effectiveSellChance == 0)
@@ -115,11 +119,17 @@ public class RagfairSellHelper(
sellTimestamp += (long)newSellTime;
result.Add( new SellResult{ SellTime = sellTimestamp, Amount = boughtAmount });
_logger.Debug($"Offer will sell at: { _timeUtil.GetDateTimeFromTimeStamp(sellTimestamp).ToLocalTime().ToString()}, bought: {boughtAmount}");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Offer will sell at: { _timeUtil.GetDateTimeFromTimeStamp(sellTimestamp).ToLocalTime().ToString()}, bought: {boughtAmount}");
}
}
else
{
_logger.Debug($"Offer rolled not to sell, item count: { boughtAmount}");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Offer rolled not to sell, item count: { boughtAmount}");
}
}
remainingCount -= boughtAmount;
+5 -2
View File
@@ -1,4 +1,3 @@
using Core.Models.Eft.Common;
using SptCommon.Annotations;
using Core.Models.Eft.Common.Tables;
using Core.Models.Spt.Config;
@@ -7,6 +6,7 @@ using Core.Servers;
using Core.Services;
using Core.Utils;
using Core.Utils.Cloners;
using LogLevel = Core.Models.Spt.Logging.LogLevel;
namespace Core.Helpers;
@@ -41,7 +41,10 @@ public class RepairHelper(
bool applyMaxDurabilityDegradation = true
)
{
_logger.Debug($"Adding {amountToRepair} to {itemToRepairDetails.Name} using kit: {useRepairKit}");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Adding {amountToRepair} to {itemToRepairDetails.Name} using kit: {useRepairKit}");
}
var itemMaxDurability = _cloner.Clone(itemToRepair.Upd.Repairable.MaxDurability);
var itemCurrentDurability = _cloner.Clone(itemToRepair.Upd.Repairable.Durability);
+9 -3
View File
@@ -1,5 +1,4 @@
using System.Text.RegularExpressions;
using System.Transactions;
using SptCommon.Annotations;
using Core.Models.Eft.Common;
using Core.Models.Eft.Common.Tables;
@@ -14,6 +13,7 @@ using Core.Servers;
using Core.Services;
using Core.Utils;
using Core.Utils.Cloners;
using LogLevel = Core.Models.Spt.Logging.LogLevel;
namespace Core.Helpers;
@@ -122,7 +122,10 @@ public class TradeHelper(
var rootItemIndex = fenceItems.FindIndex(item => item.Id == buyRequestData.ItemId);
if (rootItemIndex == -1)
{
_logger.Debug($"Tried to buy item {buyRequestData.ItemId} from fence that no longer exists");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Tried to buy item {buyRequestData.ItemId} from fence that no longer exists");
}
var message = _localisationService.GetText("ragfair-offer_no_longer_exists");
_httpResponseUtil.AppendErrorToOutput(output, message);
@@ -293,7 +296,10 @@ public class TradeHelper(
return;
}
_logger.Debug($"Selling: id: {matchingItemInInventory.Id} tpl: {matchingItemInInventory.Template}");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Selling: id: {matchingItemInInventory.Id} tpl: {matchingItemInInventory.Template}");
}
if (sellRequest.TransactionId == Traders.FENCE)
{
+11 -4
View File
@@ -8,6 +8,7 @@ using Core.Servers;
using Core.Services;
using Core.Utils;
using Core.Utils.Cloners;
using LogLevel = Core.Models.Spt.Logging.LogLevel;
namespace Core.Helpers;
@@ -78,16 +79,22 @@ public class TraderAssortHelper(
var assortToAdjust = traderClone.Assort.Items.FirstOrDefault(x => x.Id == assortId.Key);
if (assortToAdjust is null)
{
_logger.Debug($"Cannot find trader: {traderClone.Base.Nickname} assort: {assortId} to adjust BuyRestrictionCurrent value, skipping");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"Cannot find trader: {traderClone.Base.Nickname} assort: {assortId} to adjust BuyRestrictionCurrent value, skipping");
}
continue;
}
if (assortToAdjust.Upd is null)
{
_logger.Debug(
$"Unable to adjust assort {assortToAdjust.Id} item: {assortToAdjust.Template} BuyRestrictionCurrent value, assort has a null upd object"
);
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug(
$"Unable to adjust assort {assortToAdjust.Id} item: {assortToAdjust.Template} BuyRestrictionCurrent value, assort has a null upd object"
);
}
continue;
}
+9 -2
View File
@@ -10,6 +10,7 @@ using Core.Servers;
using Core.Services;
using Core.Utils;
using SptCommon.Extensions;
using LogLevel = Core.Models.Spt.Logging.LogLevel;
namespace Core.Helpers;
@@ -93,7 +94,10 @@ public class TraderHelper(
var traderAssorts = GetTraderAssortsByTraderId(traderId);
if (traderAssorts is null)
{
_logger.Debug($"No assorts on trader: {traderId} found");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"No assorts on trader: {traderId} found");
}
return null;
}
@@ -102,7 +106,10 @@ public class TraderHelper(
var purchasedAssort = traderAssorts.Items.FirstOrDefault(item => item.Id == assortId);
if (purchasedAssort is null)
{
_logger.Debug($"No assort {assortId} on trader: {traderId} found");
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug($"No assort {assortId} on trader: {traderId} found");
}
return null;
}