diff --git a/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.cs b/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.cs index d718334e..825747dd 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.cs @@ -303,11 +303,11 @@ public class GiveSptCommand( return _localeService.GetLocaleDb(desiredLocale); } - /** - * A "simple" function that checks if an item is supposed to be given to a player or not - * @param templateItem the template item to check - * @returns true if its obtainable, false if its not - */ + /// + /// A "simple" function that checks if an item is supposed to be given to a player or not + /// + /// Template item to check + /// true if its obtainable protected bool IsItemAllowed(TemplateItem templateItem) { return templateItem.Type != "Node" && diff --git a/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/StringSimilarity.cs b/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/StringSimilarity.cs index 5ec1970f..c1e225f7 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/StringSimilarity.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/StringSimilarity.cs @@ -2,9 +2,9 @@ namespace SPTarkov.Server.Core.Helpers.Dialogue.Commando.SptCommands.GiveCommand public static class StringSimilarity { - /** - * Converted from: https://github.com/stephenjjbrown/string-similarity-js/blob/master/src/string-similarity.ts - */ + /// + /// Converted from: https://github.com/stephenjjbrown/string-similarity-js/blob/master/src/string-similarity.ts + /// public static double Match(string str1, string str2, int substringLength = 2, bool caseSensitive = false) { if (!caseSensitive) diff --git a/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/ProfileCommand/ProfileSptCommand.cs b/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/ProfileCommand/ProfileSptCommand.cs index 943cf7f1..c6a91603 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/ProfileCommand/ProfileSptCommand.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/Dialogue/Commando/SptCommands/ProfileCommand/ProfileSptCommand.cs @@ -20,16 +20,15 @@ public class ProfileSptCommand( ProfileHelper _profileHelper ) : ISptCommand { - /** - * Regex to account for all these cases: - * spt profile level 20 - * spt profile skill metabolism 10 - */ - protected Regex _commandRegex = new( - @"^spt profile (?level|skill)((?<=.*skill) (?[\w]+))? (?(?!0+)[0-9]+)$" - ); + /// + /// Regex to account for all these cases + /// spt profile level 20 + /// spt profile skill metabolism 10 + /// + protected static readonly Regex _commandRegex = new( + @"^spt profile (?level|skill)((?<=.*skill) (?[\w]+))? (?(?!0+)[0-9]+)$"); - protected Regex _examineRegex = new(@"^spt profile (?examine)"); + protected static readonly Regex _examineRegex = new(@"^spt profile (?examine)"); public string GetCommand() { diff --git a/Libraries/SPTarkov.Server.Core/Helpers/HttpServerHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/HttpServerHelper.cs index ffba5631..a9f09294 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/HttpServerHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/HttpServerHelper.cs @@ -7,7 +7,7 @@ namespace SPTarkov.Server.Core.Helpers; [Injectable(InjectionType.Singleton)] public class HttpServerHelper(ConfigServer configServer) { - protected HttpConfig _httpConfig = configServer.GetConfig(); + protected readonly HttpConfig _httpConfig = configServer.GetConfig(); protected Dictionary mime = new() { @@ -27,27 +27,28 @@ public class HttpServerHelper(ConfigServer configServer) return mime.GetValueOrDefault(key); } - /** - * Combine ip and port into address - * @returns url - */ + /// + /// Combine ip and port into address + /// + /// URI public string BuildUrl() { return $"{_httpConfig.BackendIp}:{_httpConfig.BackendPort}"; } - /** - * Prepend http to the url:port - * @returns URI - */ + /// + /// Prepend http to the url:port + /// + /// URI public string GetBackendUrl() { return $"https://{BuildUrl()}"; } - /** - * Get websocket url + port - */ + /// + /// Get websocket url + port + /// + /// wss:// address public string GetWebsocketUrl() { return $"wss://{BuildUrl()}"; diff --git a/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs index 92571d13..d9592591 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs @@ -140,15 +140,6 @@ public class ItemHelper( return filteredPool.FirstOrDefault(poolItem => poolItem.Template.Equals(tpl, StringComparison.OrdinalIgnoreCase)); } - /** - * . - * - * @param item1 - * @param item2 - * @param compareUpdProperties - * @returns - */ - /// /// This method will compare two items (with all its children) and see if they are equivalent /// This method will NOT compare IDs on the items @@ -602,12 +593,6 @@ public class ItemHelper( return _cloner.Clone(_databaseService.GetItems().Values.ToList()); } - /** - * - * @param itemTpl items - * @returns - */ - /// /// Gets item data from items.json /// @@ -686,13 +671,13 @@ public class ItemHelper( return Math.Min(Math.Round(qualityModifier / itemsWithQualityCount, 5), 1); } - /** - * Get normalized value (0-1) based on item condition - * Will return -1 for base armor items with 0 durability - * @param item Item to check - * @param skipArmorItemsWithoutDurability return -1 for armor items that have max durability of 0 - * @returns Number between 0 and 1 - */ + /// + /// Get normalized value (0-1) based on item condition + /// Will return -1 for base armor items with 0 durability + /// + /// Item to check + /// return -1 for armor items that have max durability of 0 + /// Number between 0 and 1 public double GetItemQualityModifier(Item item, bool skipArmorItemsWithoutDurability = false) { // Default to 100% @@ -749,20 +734,18 @@ public class ItemHelper( { result = 0.01; } - - return result; } return result; } - /** - * Get a quality value based on a repairable item's current state between current and max durability - * @param itemDetails Db details for item we want quality value for - * @param repairable Repairable properties - * @param item Item quality value is for - * @returns A number between 0 and 1 - */ + /// + /// Get a quality value based on a repairable item's current state between current and max durability + /// + /// Db details for item we want quality value for + /// Repairable properties + /// Item quality value is for + /// number between 0 and 1 protected double GetRepairableItemQualityValue(TemplateItem itemDetails, UpdRepairable repairable, Item item) { // Edge case, durability above max @@ -788,12 +771,12 @@ public class ItemHelper( return Math.Sqrt(durability ?? 0); } - /** - * Recursive function that looks at every item from parameter and gets their children's Ids + includes parent item in results - * @param items List of items (item + possible children) - * @param baseItemId Parent item's id - * @returns a list of strings - */ + /// + /// Recursive function that looks at every item from parameter and gets their children's Ids + includes parent item in results + /// + /// List of items (item + possible children) + /// Parent item's id + /// list of child item ids public List FindAndReturnChildrenByItems(IEnumerable items, string baseItemId) { List list = []; @@ -811,13 +794,13 @@ public class ItemHelper( return list; } - /** - * A variant of FindAndReturnChildren where the output is list of item objects instead of their ids. - * @param items List of items (item + possible children) - * @param baseItemId Parent item's id - * @param modsOnly Include only mod items, exclude items stored inside root item - * @returns A list of Item objects - */ + /// + /// A variant of FindAndReturnChildren where the output is list of item objects instead of their ids. + /// + /// List of items (item + possible children) + /// Parent item's id + /// OPTIONAL - Include only mod items, exclude items stored inside root item + /// list of Item objects public List FindAndReturnChildrenAsItems(IEnumerable items, string baseItemId, bool modsOnly = false) { // Use dictionary to make key lookup faster, convert to list before being returned @@ -850,12 +833,12 @@ public class ItemHelper( return result.Values.ToList(); } - /** - * Find children of the item in a given assort (weapons parts for example, need recursive loop function) - * @param itemIdToFind Template id of item to check for - * @param assort List of items to check in - * @returns List of children of requested item - */ + /// + /// Find children of the item in a given assort (weapons parts for example, need recursive loop function) + /// + /// Template id of item to check for + /// List of items to check in + /// List of children of requested item public List FindAndReturnChildrenByAssort(string itemIdToFind, List assort) { List list = []; @@ -873,11 +856,11 @@ public class ItemHelper( return list; } - /** - * Check if the passed in item has buy count restrictions - * @param itemToCheck Item to check - * @returns true if it has buy restrictions - */ + /// + /// Check if the passed in item has buy count restrictions + /// + /// Item to check + /// true if it has buy restrictions public bool HasBuyRestrictions(Item itemToCheck) { return itemToCheck.Upd?.BuyRestrictionCurrent is not null && itemToCheck.Upd?.BuyRestrictionMax is not null; @@ -1056,6 +1039,11 @@ public class ItemHelper( } } + /// + /// TODO - Write + /// + /// + /// public void ReplaceProfileInventoryIds(BotBaseInventory inventory, List? insuredItems = null) { // Blacklist @@ -1407,21 +1395,20 @@ public class ItemHelper( || int.TryParse(item.SlotId, out _)); // Has int as slotId, is inside container. e.g. cartridges } - /** - * Retrieves the equipment parent item for a given item. - * - * This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the equipment - * parent item. In other words, if you pass it an item id of a suppressor, it will traverse up the muzzle brake, - * barrel, upper receiver, gun, nested backpack, and finally return the backpack Item that is equipped. - * - * It's important to note that traversal is expensive, so this method requires that you pass it a Dictionary of the items - * to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates - * some of the performance concerns, as it allows for quick lookups of items by ID. - * - * @param itemId - The unique identifier of the item for which to find the equipment parent. - * @param itemsMap - A Dictionary containing item IDs mapped to their corresponding Item objects for quick lookup. - * @returns The Item object representing the equipment parent of the given item, or `null` if no such parent exists. - */ + /// + /// Retrieves the equipment parent item for a given item. + /// + /// This method traverses up the hierarchy of items starting from a given `itemId`, until it finds the equipment + /// parent item. In other words, if you pass it an item id of a suppressor, it will traverse up the muzzle brake, + /// barrel, upper receiver, gun, nested backpack, and finally return the backpack Item that is equipped. + /// + /// It's important to note that traversal is expensive, so this method requires that you pass it a Dictionary of the items + /// to traverse, where the keys are the item IDs and the values are the corresponding Item objects. This alleviates + /// some of the performance concerns, as it allows for quick lookups of items by ID. + /// + /// The unique identifier of the item for which to find the equipment parent. + /// A Dictionary containing item IDs mapped to their corresponding Item objects for quick lookup. + /// The Item object representing the equipment parent of the given item, or `null` if no such parent exists public Item? GetEquipmentParent(string itemId, Dictionary itemsMap) { var currentItem = itemsMap.GetValueOrDefault(itemId); @@ -1438,12 +1425,12 @@ public class ItemHelper( return currentItem; } - /** - * Get the inventory size of an item - * @param items Item with children - * @param rootItemId - * @returns ItemSize object (width and height) - */ + /// + /// Get the inventory size of an item + /// + /// Item with children + /// The base items root id + /// ItemSize object (width and height) public ItemSize GetItemSize(List items, string rootItemId) { var rootTemplate = GetItem(items.Where(x => x.Id.Equals(rootItemId, StringComparison.OrdinalIgnoreCase)).ToList()[0].Template).Value; @@ -1489,15 +1476,14 @@ public class ItemHelper( }; } - /** - * Get a random cartridge from an items Filter property - * @param item Db item template to look up Cartridge filter values from - * @returns Caliber of cartridge - */ + /// + /// Get a random cartridge from an items Filter property + /// + /// Db item template to look up Cartridge filter values from + /// Valid caliber for cartridge public string? GetRandomCompatibleCaliberTemplateId(TemplateItem item) { - var cartridges = item?.Properties?.Cartridges[0]?.Props?.Filters[0]?.Filter; - + var cartridges = item?.Properties?.Cartridges?.FirstOrDefault()?.Props?.Filters?.FirstOrDefault()?.Filter; if (cartridges is null) { _logger.Warning($"Failed to find cartridge for item: {item?.Id} {item?.Name}"); @@ -1519,7 +1505,7 @@ public class ItemHelper( var cartridgeDetails = GetItem(cartridgeTpl); var cartridgeMaxStackSize = cartridgeDetails.Value.Properties.StackMaxSize; - // Exit if ammo already exists in box + // Exit early if ammo already exists in box if (ammoBox.Any(item => item.Template.Equals(cartridgeTpl, StringComparison.OrdinalIgnoreCase))) { return; @@ -1557,11 +1543,11 @@ public class ItemHelper( } } - /** - * Add a single stack of cartridges to the ammo box - * @param ammoBox Box to add cartridges to - * @param ammoBoxDetails Item template from items db - */ + /// + /// Add a single stack of cartridges to the ammo box + /// + /// Box item to add cartridges to + /// Item template from items db public void AddSingleStackCartridgesToAmmoBox(List ammoBox, TemplateItem ammoBoxDetails) { var ammoBoxMaxCartridgeCount = ammoBoxDetails.Properties?.StackSlots?[0].MaxCount ?? 0; @@ -1576,13 +1562,13 @@ public class ItemHelper( ); } - /** - * Check if item is stored inside of a container - * @param itemToCheck Item to check is inside of container - * @param desiredContainerSlotId Name of slot to check item is in e.g. SecuredContainer/Backpack - * @param items Inventory with child parent items to check - * @returns True when item is in container - */ + /// + /// Check if item is stored inside a container + /// + /// Item to check is inside of container + /// Name of slot to check item is in e.g. SecuredContainer/Backpack + /// Inventory with child parent items to check + /// True when item is in container public bool ItemIsInsideContainer(Item itemToCheck, string desiredContainerSlotId, List items) { // Get items parent @@ -1601,16 +1587,16 @@ public class ItemHelper( return ItemIsInsideContainer(parent, desiredContainerSlotId, items); } - /** - * Add child items (cartridges) to a magazine - * @param magazine Magazine to add child items to - * @param magTemplate Db template of magazine - * @param staticAmmoDist Cartridge distribution - * @param caliber Caliber of cartridge to add to magazine - * @param minSizePercent % the magazine must be filled to - * @param defaultCartridgeTpl Cartridge to use when none found - * @param weapon Weapon the magazine will be used for (if passed in uses Chamber as whitelist) - */ + /// + /// Add child items (cartridges) to a magazine + /// + /// Magazine to add child items to + /// Db template of magazine + /// Cartridge distribution + /// Caliber of cartridge to add to magazine + /// OPTIONAL - % the magazine must be filled to + /// OPTIONAL -Cartridge to use when none found + /// OPTIONAL -Weapon the magazine will be used for (if passed in uses Chamber as whitelist) public void FillMagazineWithRandomCartridge( List magazine, TemplateItem magTemplate, @@ -1622,7 +1608,7 @@ public class ItemHelper( { var chosenCaliber = caliber ?? GetRandomValidCaliber(magTemplate); - // Edge case for the Klin pp-9, it has a typo in its ammo caliber + // Edge case - Klin pp-9 has a typo in its ammo caliber if (chosenCaliber == "Caliber9x18PMM") { chosenCaliber = "Caliber9x18PM";