docs: added documentation on ItemExtensions.cs

This commit is contained in:
Yui 2024-10-29 19:32:48 -03:00
parent 313763cfc4
commit ac5140ce24
Signed by: yui
GPG Key ID: F368D23A0ABA04B4

View File

@ -10,7 +10,19 @@ namespace LootValueEX.Extensions
{
internal static class ItemExtensions
{
/// <summary>
/// Checks if an item has been examined by the player.
/// </summary>
/// <param name="item">The item to check.</param>
/// <returns>True if the item has been examined, false otherwise.</returns>
internal static bool IsExamined(this Item? item) => item != null && ClientAppUtils.GetMainApp().GetClientBackEndSession().Profile.Examined(item);
/// <summary>
/// Retrieves the value of a specific attribute from an item.
/// </summary>
/// <param name="item">The item to retrieve the attribute from.</param>
/// <param name="attributeId">The ID of the attribute to retrieve.</param>
/// <returns>The value of the attribute, or -1f if the item is null or the attribute is not found.</returns>
internal static float GetItemAttribute(this Item? item, EItemAttributeId attributeId)
{
if (item == null)
@ -24,13 +36,24 @@ namespace LootValueEX.Extensions
return -1f;
}
}
/// <summary>
/// Generates a custom hash for the given item.
///
/// This function takes an optional Item as a parameter and returns its custom hash.
/// If the item is null, it returns an empty string. The custom hash is determined by the item's template, durability, and uses.
/// </summary>
/// <param name="item">The item to retrieve the custom hash for.</param>
/// <returns>The custom hash of the item, or an empty string if the item is null.</returns>
internal static string GetCustomHash(this Item? item)
{
if (item == null)
return string.Empty;
StringBuilder prehashString = new StringBuilder();
item.GetAllItems().Where(prop => !prop.Equals(item)).ExecuteForEach(prop => prehashString.Append(prop.GetCustomHash()));
if (item.Template.Equals(typeof(MagazineTemplate))){
if (item.Template.Equals(typeof(MagazineTemplate)))
{
MagazineTemplate magTemplate = (MagazineTemplate)item.Template;
magTemplate.Cartridges.ExecuteForEach(prop => prop.Items.ExecuteForEach(ammo => prehashString.Append(ammo.GetCustomHash())));
}
@ -43,7 +66,7 @@ namespace LootValueEX.Extensions
if (item == null)
return String.Empty;
if (item.Attributes.IsNullOrEmpty())
if (item.Attributes.IsNullOrEmpty())
return String.Empty;
StringBuilder sb = new StringBuilder();
@ -51,10 +74,21 @@ namespace LootValueEX.Extensions
return sb.ToString();
}
#endif
/// <summary>
/// Retrieves the durability of a given item.
///
/// This function takes an optional Item as a parameter and returns its durability.
/// If the item is null, it returns -1f. The durability is determined by the item's template.
/// </summary>
/// <param name="item">The item to retrieve the durability for.</param>
/// <returns>The durability of the item, or -1f if the item is null.</returns>
internal static float GetDurability(this Item? item)
{
if (item == null)
return -1f;
switch (item.Template)
{
case ArmoredRigTemplate armoredRig:
@ -64,10 +98,21 @@ namespace LootValueEX.Extensions
return item.GetItemAttribute(EItemAttributeId.Durability);
}
}
/// <summary>
/// Retrieves the number of uses remaining for a given item.
///
/// This function takes an optional Item as a parameter and returns the number of uses remaining.
/// If the item is null, it returns -1f. The number of uses is determined by the item's template.
/// </summary>
/// <param name="item">The item to retrieve the number of uses for.</param>
/// <returns>The number of uses remaining for the item, or -1f if the item is null.</returns>
internal static float GetUses(this Item? item)
{
if (item == null)
return -1f;
switch (item.Template)
{
case KeycardTemplate:
@ -79,10 +124,10 @@ namespace LootValueEX.Extensions
return -1f;
case MagazineTemplate:
MagazineClass? magazineClass = item as MagazineClass;
return magazineClass != null ? magazineClass.Count : -1f;
return magazineClass?.Count ?? -1f;
case AmmoBoxTemplate:
AmmoBox? ammoBox = item as AmmoBox;
return ammoBox != null ? ammoBox.Count : -1f;
return ammoBox?.Count ?? -1f;
default:
return -1f;
}