eft-lootvalueex/Plugin/Extensions/ItemExtensions.cs

46 lines
1.5 KiB
C#

using EFT.InventoryLogic;
using SPT.Reflection.Utils;
using System.Text;
namespace LootValueEX.Extensions
{
internal static class ItemExtensions
{
internal static bool IsExamined(this Item? item) => item != null && ClientAppUtils.GetMainApp().GetClientBackEndSession().Profile.Examined(item);
internal static string CustomHash(this Item? item)
{
if (item == null)
return string.Empty;
string itemHashTemplate = string.Format("{0}|{1}|{2}", item.TemplateId, item.StackMaxSize, item.StackObjectsCount);
return "0";
}
internal static string AttributesToString(this Item? item)
{
if (item == null)
return String.Empty;
if (item.Attributes.IsNullOrEmpty())
return String.Empty;
StringBuilder sb = new StringBuilder();
item.Attributes.ForEach(attr => sb.Append($"\n{attr.Id}\n\tName: {attr.Name}\n\tBase Value: {attr.Base()}\n\tString value: {attr.StringValue()}\n\tDisplay Type: {attr.DisplayType()}"));
return sb.ToString();
}
internal static float GetDurability(this Item? item)
{
if (item == null)
return -1f;
try
{
return item.Attributes.Single(att => att.Id.Equals(EItemAttributeId.Durability)).Base();
}catch(InvalidOperationException)
{
return -1f;
}
}
}
}