more fixes

This commit is contained in:
Alex
2025-01-27 21:21:04 +00:00
parent b7b5b7da34
commit efe9f81b31
8 changed files with 165 additions and 104 deletions
+17 -14
View File
@@ -11,6 +11,7 @@ using Core.Servers;
using Core.Services;
using Core.Utils;
using Core.Utils.Cloners;
using LogLevel = Core.Models.Spt.Logging.LogLevel;
namespace Core.Generators;
@@ -529,9 +530,10 @@ public class BotWeaponGenerator(
}
var defaultMagTplId = _botWeaponGeneratorHelper.GetWeaponsDefaultMagazineTpl(weaponTemplate);
_logger.Debug(
$"[{botRole}] Unable to find magazine for weapon: {weaponTemplate.Id} {weaponTemplate.Name}, using mag template default: {defaultMagTplId}."
);
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug(
$"[{botRole}] Unable to find magazine for weapon: {weaponTemplate.Id} {weaponTemplate.Name}, using mag template default: {defaultMagTplId}."
);
return defaultMagTplId;
}
@@ -550,17 +552,18 @@ public class BotWeaponGenerator(
var desiredCaliber = GetWeaponCaliber(weaponTemplate);
if (!cartridgePool.TryGetValue(desiredCaliber, out var cartridgePoolForWeapon) || cartridgePoolForWeapon?.Keys.Count == 0)
{
_logger.Debug(
_localisationService.GetText(
"bot-no_caliber_data_for_weapon_falling_back_to_default",
new
{
weaponId = weaponTemplate.Id,
weaponName = weaponTemplate.Name,
defaultAmmo = weaponTemplate.Properties.DefAmmo,
}
)
);
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug(
_localisationService.GetText(
"bot-no_caliber_data_for_weapon_falling_back_to_default",
new
{
weaponId = weaponTemplate.Id,
weaponName = weaponTemplate.Name,
defaultAmmo = weaponTemplate.Properties.DefAmmo,
}
)
);
// Immediately returns, default ammo is guaranteed to be compatible
return weaponTemplate.Properties.DefAmmo;
@@ -11,6 +11,7 @@ using Core.Utils;
using Core.Utils.Cloners;
using Core.Utils.Collections;
using SptCommon.Annotations;
using LogLevel = Core.Models.Spt.Logging.LogLevel;
namespace Core.Generators;
@@ -113,7 +114,8 @@ public class LocationLootGenerator(
staticLootItemCount += containerWithLoot.Template.Items.Count;
}
_logger.Debug($"Added {guaranteedContainers.Count} guaranteed containers");
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug($"Added {guaranteedContainers.Count} guaranteed containers");
// Randomisation is turned off globally or just turned off for this map
if (
@@ -123,9 +125,10 @@ public class LocationLootGenerator(
)
)
{
_logger.Debug(
$"Container randomisation disabled, Adding {staticRandomisableContainersOnMap.Count} containers to {locationBase.Name}"
);
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug(
$"Container randomisation disabled, Adding {staticRandomisableContainersOnMap.Count} containers to {locationBase.Name}"
);
foreach (var container in staticRandomisableContainersOnMap)
{
var containerWithLoot = AddLootToContainer(
@@ -166,7 +169,8 @@ public class LocationLootGenerator(
if (data.ContainerIdsWithProbability.Count == 0)
{
_logger.Debug($"`Group: {key} has no containers with< 100 % spawn chance to choose from, skipping");
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug($"`Group: {key} has no containers with< 100 % spawn chance to choose from, skipping");
continue;
}
@@ -203,9 +207,10 @@ public class LocationLootGenerator(
);
if (containerObject is null)
{
_logger.Debug(
$"Container: {chosenContainerId} not found in staticRandomisableContainersOnMap, this is bad"
);
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug(
$"Container: {chosenContainerId} not found in staticRandomisableContainersOnMap, this is bad"
);
continue;
}
@@ -283,9 +288,10 @@ public class LocationLootGenerator(
var containerIds = containerData.ContainerIdsWithProbability.Keys.ToList();
if (containerData.ChosenCount > containerIds.Count)
{
_logger.Debug(
$"Group: {groupId} wants {containerData.ChosenCount} containers but pool only has {containerIds.Count}, add what's available"
);
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug(
$"Group: {groupId} wants {containerData.ChosenCount} containers but pool only has {containerIds.Count}, add what's available"
);
return containerIds;
}
@@ -357,9 +363,10 @@ public class LocationLootGenerator(
if (container.Probability >= 1)
{
_logger.Debug(
$"Container {container.Template.Id} with group ${groupData.GroupId} had 100 % chance to spawn was picked as random container, skipping"
);
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug(
$"Container {container.Template.Id} with group ${groupData.GroupId} had 100 % chance to spawn was picked as random container, skipping"
);
continue;
}
@@ -677,7 +684,8 @@ public class LocationLootGenerator(
// Point is blacklsited, skip
if (blacklistedSpawnpoints?.Contains(spawnpoint.Template.Id) ?? false)
{
_logger.Debug($"Ignoring loose loot location: {spawnpoint.Template.Id}");
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug($"Ignoring loose loot location: {spawnpoint.Template.Id}");
continue;
}
@@ -720,17 +728,18 @@ public class LocationLootGenerator(
var tooManySpawnPointsRequested = desiredSpawnpointCount - chosenSpawnpoints.Count > 0;
if (tooManySpawnPointsRequested)
{
_logger.Debug(
_localisationService.GetText(
"location-spawn_point_count_requested_vs_found",
new
{
requested = desiredSpawnpointCount + guaranteedLoosePoints.Count,
found = chosenSpawnpoints.Count,
mapName = locationName,
}
)
);
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug(
_localisationService.GetText(
"location-spawn_point_count_requested_vs_found",
new
{
requested = desiredSpawnpointCount + guaranteedLoosePoints.Count,
found = chosenSpawnpoints.Count,
mapName = locationName,
}
)
);
}
// Iterate over spawnpoints
@@ -839,7 +848,8 @@ public class LocationLootGenerator(
);
if (items is null || !items.Any())
{
_logger.Debug($"Unable to adjust loot item {itemTpl} as it does not exist inside {locationName} forced loot.");
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug($"Unable to adjust loot item {itemTpl} as it does not exist inside {locationName} forced loot.");
continue;
}
@@ -917,9 +927,10 @@ public class LocationLootGenerator(
}
else
{
_logger.Debug(
$"Attempted to add a forced loot location with Id: {locationTemplateToAdd.Id} to map {locationName} that already has that id in use, skipping"
);
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug(
$"Attempted to add a forced loot location with Id: {locationTemplateToAdd.Id} to map {locationName} that already has that id in use, skipping"
);
}
}
}
@@ -1076,7 +1087,8 @@ public class LocationLootGenerator(
else
{
// RSP30 (62178be9d0050232da3485d9/624c0b3340357b5f566e8766/6217726288ed9f0845317459) doesn't have any default presets and kills this code below as it has no chidren to reparent
_logger.Debug($"createStaticLootItem() No preset found for weapon: {chosenTpl}");
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug($"createStaticLootItem() No preset found for weapon: {chosenTpl}");
}
rootItem = items[0];
+13 -7
View File
@@ -11,6 +11,7 @@ using Core.Models.Utils;
using Core.Services;
using Core.Utils;
using Core.Utils.Cloners;
using LogLevel = Core.Models.Spt.Logging.LogLevel;
namespace Core.Generators;
@@ -360,7 +361,8 @@ public class LootGenerator(
// No `_encyclopedia` property, not possible to reliably get root item tpl
if (chosenPreset.Encyclopedia is null) {
_logger.Debug("$Preset with id: {chosenPreset?.Id} lacks encyclopedia property, skipping");
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug("$Preset with id: {chosenPreset?.Id} lacks encyclopedia property, skipping");
return false;
}
@@ -368,7 +370,8 @@ public class LootGenerator(
// Get preset root item db details via its `_encyclopedia` property
var itemDbDetails = _itemHelper.GetItem(chosenPreset.Encyclopedia);
if (!itemDbDetails.Key) {
_logger.Debug($"$Unable to find preset with tpl: {chosenPreset.Encyclopedia}, skipping");
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug($"$Unable to find preset with tpl: {chosenPreset.Encyclopedia}, skipping");
return false;
}
@@ -493,7 +496,8 @@ public class LootGenerator(
var ammoBoxesMatchingCaliber = ammoBoxesDetails.Where((x) =>
x.Properties.AmmoCaliber == weaponCaliber);
if (!ammoBoxesMatchingCaliber.Any()) {
_logger.Debug($"No ammo box with caliber {weaponCaliber} found, skipping");
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug($"No ammo box with caliber {weaponCaliber} found, skipping");
continue;
}
@@ -519,7 +523,8 @@ public class LootGenerator(
);
if (rewardItemPool.Count() == 0) {
_logger.Debug($"No items with base type of {rewardKey} found, skipping");
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug($"No items with base type of {rewardKey} found, skipping");
continue;
}
@@ -561,9 +566,10 @@ public class LootGenerator(
(item) => item?.Parent == rewardKey && !_itemFilterService.IsItemBlacklisted(item.Id)
);
if (relatedItems is null || relatedItems.Count() == 0) {
_logger.Debug(
$"No items found to fulfil reward type: {rewardKey} for weapon: {chosenWeaponPreset.Name}, skipping type"
);
if(_logger.IsLogEnabled(LogLevel.Debug))
_logger.Debug(
$"No items found to fulfil reward type: {rewardKey} for weapon: {chosenWeaponPreset.Name}, skipping type"
);
continue;
}