2024-10-13 00:38:51 +02:00
|
|
|
|
using EFT.InventoryLogic;
|
|
|
|
|
using SPT.Reflection.Utils;
|
|
|
|
|
using System.Text;
|
2024-10-23 00:08:52 +02:00
|
|
|
|
using KeycardTemplate = GClass2623;
|
|
|
|
|
using ArmorTemplate = GClass2550;
|
|
|
|
|
using ArmoredRigTemplate = GClass2602;
|
|
|
|
|
using SimpleMedClass = GClass2631;
|
2024-10-13 00:38:51 +02:00
|
|
|
|
|
|
|
|
|
namespace LootValueEX.Extensions
|
|
|
|
|
{
|
|
|
|
|
internal static class ItemExtensions
|
|
|
|
|
{
|
|
|
|
|
internal static bool IsExamined(this Item? item) => item != null && ClientAppUtils.GetMainApp().GetClientBackEndSession().Profile.Examined(item);
|
2024-10-23 00:08:52 +02:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-23 17:07:04 +02:00
|
|
|
|
internal static string GetCustomHash(this Item? item)
|
2024-10-13 00:38:51 +02:00
|
|
|
|
{
|
|
|
|
|
if (item == null)
|
|
|
|
|
return string.Empty;
|
2024-10-23 00:08:52 +02:00
|
|
|
|
StringBuilder prehashString = new StringBuilder();
|
2024-10-24 01:58:19 +02:00
|
|
|
|
item.GetAllItems().Where(prop => !prop.Equals(item)).ExecuteForEach(prop => prehashString.Append(prop.GetCustomHash()));
|
2024-10-23 17:07:04 +02:00
|
|
|
|
string itemHashTemplate = string.Format("{0}|{1}|{2}|{3}", prehashString.ToString(), item.TemplateId, item.GetDurability(), item.GetUses());
|
|
|
|
|
return Utils.HashingUtils.ConvertToSha256(itemHashTemplate);
|
2024-10-13 00:38:51 +02:00
|
|
|
|
}
|
2024-10-23 00:08:52 +02:00
|
|
|
|
#if DEBUG
|
2024-10-13 00:38:51 +02:00
|
|
|
|
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();
|
|
|
|
|
}
|
2024-10-23 00:08:52 +02:00
|
|
|
|
#endif
|
2024-10-13 00:38:51 +02:00
|
|
|
|
internal static float GetDurability(this Item? item)
|
|
|
|
|
{
|
|
|
|
|
if (item == null)
|
|
|
|
|
return -1f;
|
2024-10-23 00:08:52 +02:00
|
|
|
|
switch (item.Template)
|
2024-10-13 00:38:51 +02:00
|
|
|
|
{
|
2024-10-23 00:08:52 +02:00
|
|
|
|
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)
|
2024-10-13 00:38:51 +02:00
|
|
|
|
return -1f;
|
2024-10-23 00:08:52 +02:00
|
|
|
|
switch (item.Template)
|
|
|
|
|
{
|
2024-10-24 01:58:19 +02:00
|
|
|
|
case KeycardTemplate:
|
2024-10-23 00:08:52 +02:00
|
|
|
|
KeyComponent keyComponent = item.GetItemComponent<KeyComponent>();
|
|
|
|
|
return keyComponent.Template.MaximumNumberOfUsage - keyComponent.NumberOfUsages;
|
|
|
|
|
case Meds2Class:
|
2024-10-24 01:58:19 +02:00
|
|
|
|
if (item.TryGetItemComponent(out MedKitComponent medKitComponent))
|
|
|
|
|
return medKitComponent.HpResource;
|
|
|
|
|
return -1f;
|
2024-10-23 00:08:52 +02:00
|
|
|
|
default:
|
|
|
|
|
return -1f;
|
2024-10-13 00:38:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|