From b563bf1febcc81db41d443fafb812a427e72371a Mon Sep 17 00:00:00 2001 From: Chomp Date: Tue, 2 Sep 2025 11:01:16 +0100 Subject: [PATCH] Improved method comments Small type improvements --- .../Generators/LocationLootGenerator.cs | 58 +++++++++++++++---- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Generators/LocationLootGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/LocationLootGenerator.cs index 5234f964..843cc244 100644 --- a/Libraries/SPTarkov.Server.Core/Generators/LocationLootGenerator.cs +++ b/Libraries/SPTarkov.Server.Core/Generators/LocationLootGenerator.cs @@ -261,6 +261,11 @@ public class LocationLootGenerator( return result; } + /// + /// Is loot container randomisation enabled for this location + globally + /// + /// Location to check + /// true = enabled protected bool LocationRandomisationEnabled(string locationId) { return _locationConfig.ContainerRandomisationSettings.Enabled @@ -316,7 +321,7 @@ public class LocationLootGenerator( if (logger.IsLogEnabled(LogLevel.Debug)) { logger.Debug( - $"Group: {groupId} wants: {containerData.ChosenCount} containers but pool only has: {containerIds.Count}, add what's available" + $"Group: {groupId} wants: {containerData.ChosenCount} containers but pool only has: {containerIds.Count}, adding what's available" ); } @@ -325,10 +330,10 @@ public class LocationLootGenerator( // Create probability array with all possible container ids in this group and their relative probability of spawning var containerDistribution = new ProbabilityObjectArray(cloner); - foreach (var x in containerIds) + foreach (var containerId in containerIds) { - var value = containerData.ContainerIdsWithProbability[x]; - containerDistribution.Add(new ProbabilityObject(x, value, value)); + var value = containerData.ContainerIdsWithProbability[containerId]; + containerDistribution.Add(new ProbabilityObject(containerId, value, value)); } chosenContainerIds.AddRange(containerDistribution.Draw((int)containerData.ChosenCount)); @@ -377,7 +382,7 @@ public class LocationLootGenerator( ); // Iterate over all containers and add to group keyed by groupId - // Containers without a group go into a group with empty key "" + // Containers without a group go into a group with the empty key: "" foreach (var container in staticContainersOnMap) { if (!staticContainerGroupData.Containers.TryGetValue(container.Template.Id, out var groupData)) @@ -613,6 +618,11 @@ public class LocationLootGenerator( return itemDistribution; } + /// + /// Get the loose loot multiplier for this location, or the default if location not found + /// + /// Location to get value for + /// multiplier protected double GetLooseLootMultiplierForLocation(string location) { return _locationConfig.LooseLootMultiplier.TryGetValue(location, out var value) @@ -620,6 +630,11 @@ public class LocationLootGenerator( : _locationConfig.LooseLootMultiplier["default"]; } + /// + /// Get the static loot multiplier for this location, or the default if location not found + /// + /// Location to get value for + /// multiplier protected double GetStaticLootMultiplierForLocation(string location) { return _locationConfig.StaticLootMultiplier.TryGetValue(location, out var value) @@ -995,7 +1010,14 @@ public class LocationLootGenerator( }; } - // TODO: rewrite, BIG yikes + /// + /// Hydrate an item with children if necessary + /// HIGHLY BRITTLE, LEGACY CODE + /// + /// Item tpl to add children to + /// Ammo pool + /// + /// ContainerItem protected ContainerItem? CreateStaticLootItem( MongoId chosenTpl, Dictionary> staticAmmoDist, @@ -1003,7 +1025,7 @@ public class LocationLootGenerator( ) { var itemTemplate = itemHelper.GetItem(chosenTpl).Value; - if (itemTemplate.Properties is null) + if (itemTemplate?.Properties is null) { logger.Error($"Unable to process item: {chosenTpl}. it lacks _props"); @@ -1021,6 +1043,7 @@ public class LocationLootGenerator( rootItem.ParentId = parentId; } + // Money needs its stack size randomised if (itemHelper.IsOfBaseclass(chosenTpl, BaseClasses.MONEY) || itemHelper.IsOfBaseclass(chosenTpl, BaseClasses.AMMO)) { // Edge case - some ammos e.g. flares or M406 grenades shouldn't be stacked @@ -1066,7 +1089,15 @@ public class LocationLootGenerator( }; } - protected List GetArmorItems(string chosenTpl, Item? rootItem, List items, TemplateItem armorDbTemplate) + /// + /// Get an armor with its children + /// + /// Armor tpl + /// Base armor item + /// Pool of items to look for armor in + /// Db template of armor we are looking for + /// Armor + children + protected List GetArmorItems(MongoId chosenTpl, Item? rootItem, List items, TemplateItem armorDbTemplate) { var defaultPreset = presetHelper.GetDefaultPreset(chosenTpl); if (defaultPreset is not null) @@ -1099,8 +1130,8 @@ public class LocationLootGenerator( /// /// Root item + children /// Root Item - protected Item? CreateWeaponRootAndChildren( - string chosenTpl, + protected Item CreateWeaponRootAndChildren( + MongoId chosenTpl, Dictionary> cartridgePool, string? parentId, ref List items @@ -1202,6 +1233,13 @@ public class LocationLootGenerator( return rootItem; } + /// + /// Given the provided magazine root item, add cartridges to a magazine + /// + /// + /// Magazine item + /// Db item of magazine + /// Item pool with magazine protected void GenerateStaticMagazineItem( Dictionary> staticAmmoDist, Item rootItem,