84 lines
3.0 KiB
C#
84 lines
3.0 KiB
C#
using EFT.InventoryLogic;
|
|
using SPT.Reflection.Utils;
|
|
using System.Text;
|
|
using KeycardTemplate = GClass2623;
|
|
using ArmorTemplate = GClass2550;
|
|
using ArmoredRigTemplate = GClass2602;
|
|
using SimpleMedClass = GClass2631;
|
|
|
|
namespace LootValueEX.Extensions
|
|
{
|
|
internal static class ItemExtensions
|
|
{
|
|
internal static bool IsExamined(this Item? item) => item != null && ClientAppUtils.GetMainApp().GetClientBackEndSession().Profile.Examined(item);
|
|
internal static float GetItemAttribute(this Item? item, EItemAttributeId attributeId)
|
|
{
|
|
if (item == null)
|
|
return -1f;
|
|
try
|
|
{
|
|
return item.Attributes.Single(att => att.Id.Equals(attributeId)).Base();
|
|
}
|
|
catch (InvalidOperationException)
|
|
{
|
|
return -1f;
|
|
}
|
|
}
|
|
internal static string CustomHash(this Item? item)
|
|
{
|
|
if (item == null)
|
|
return string.Empty;
|
|
StringBuilder prehashString = new StringBuilder();
|
|
if (item.IsContainer)
|
|
{
|
|
return "0";
|
|
}
|
|
string itemHashTemplate = string.Format("{0}|{1}|{2}|{3}", item.TemplateId, item.GetDurability(), item.GetUses(), item.StackObjectsCount);
|
|
return "0";
|
|
}
|
|
#if DEBUG
|
|
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();
|
|
}
|
|
#endif
|
|
internal static float GetDurability(this Item? item)
|
|
{
|
|
if (item == null)
|
|
return -1f;
|
|
switch (item.Template)
|
|
{
|
|
case ArmoredRigTemplate armoredRig:
|
|
case ArmorTemplate armor:
|
|
return Utils.ItemUtils.GetArmorDurability(item.GetItemComponentsInChildren<RepairableComponent>(true));
|
|
default:
|
|
return item.GetItemAttribute(EItemAttributeId.Durability);
|
|
}
|
|
}
|
|
internal static float GetUses(this Item? item)
|
|
{
|
|
if (item == null)
|
|
return -1f;
|
|
switch (item.Template)
|
|
{
|
|
case KeycardTemplate key:
|
|
KeyComponent keyComponent = item.GetItemComponent<KeyComponent>();
|
|
return keyComponent.Template.MaximumNumberOfUsage - keyComponent.NumberOfUsages;
|
|
case SimpleMedClass:
|
|
case Meds2Class:
|
|
return item.GetItemAttribute(EItemAttributeId.HpResource);
|
|
default:
|
|
return -1f;
|
|
}
|
|
}
|
|
}
|
|
}
|