feat: added a way to get item usage count
This commit is contained in:
parent
fd6e821f3e
commit
ab8c1967b8
|
@ -1,20 +1,42 @@
|
||||||
using EFT.InventoryLogic;
|
using EFT.InventoryLogic;
|
||||||
using SPT.Reflection.Utils;
|
using SPT.Reflection.Utils;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using KeycardTemplate = GClass2623;
|
||||||
|
using ArmorTemplate = GClass2550;
|
||||||
|
using ArmoredRigTemplate = GClass2602;
|
||||||
|
using SimpleMedClass = GClass2631;
|
||||||
|
|
||||||
namespace LootValueEX.Extensions
|
namespace LootValueEX.Extensions
|
||||||
{
|
{
|
||||||
internal static class ItemExtensions
|
internal static class ItemExtensions
|
||||||
{
|
{
|
||||||
internal static bool IsExamined(this Item? item) => item != null && ClientAppUtils.GetMainApp().GetClientBackEndSession().Profile.Examined(item);
|
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)
|
internal static string CustomHash(this Item? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
|
StringBuilder prehashString = new StringBuilder();
|
||||||
string itemHashTemplate = string.Format("{0}|{1}|{2}", item.TemplateId, item.StackMaxSize, item.StackObjectsCount);
|
if (item.IsContainer)
|
||||||
|
{
|
||||||
return "0";
|
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)
|
internal static string AttributesToString(this Item? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
@ -26,18 +48,34 @@ namespace LootValueEX.Extensions
|
||||||
StringBuilder sb = new StringBuilder();
|
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()}"));
|
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();
|
return sb.ToString();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
internal static float GetDurability(this Item? item)
|
internal static float GetDurability(this Item? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
return -1f;
|
return -1f;
|
||||||
|
switch (item.Template)
|
||||||
try
|
|
||||||
{
|
{
|
||||||
return item.Attributes.Single(att => att.Id.Equals(EItemAttributeId.Durability)).Base();
|
case ArmoredRigTemplate armoredRig:
|
||||||
}catch(InvalidOperationException)
|
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;
|
return -1f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace LootValueEX.Patches
|
||||||
Plugin.Log.LogDebug("Stacktrace of tooltip call: \n" + stackTrace.ToString());
|
Plugin.Log.LogDebug("Stacktrace of tooltip call: \n" + stackTrace.ToString());
|
||||||
if (GridItemTooltipPatch.PatchTooltip)
|
if (GridItemTooltipPatch.PatchTooltip)
|
||||||
{
|
{
|
||||||
text += $"<br>TemplateID: {GridItemTooltipPatch.HoveredItem?.TemplateId}<br>Item hashsum: {GridItemTooltipPatch.HoveredItem?.GetHashSum()}<br>Item durability: {GridItemTooltipPatch.HoveredItem?.GetDurability()}<br><color=#ff0fff><b>GridItemView</b></color>";
|
text += $"<br>TemplateID: {GridItemTooltipPatch.HoveredItem?.TemplateId}<br>Template: {GridItemTooltipPatch.HoveredItem?.Template}<br>Item hashsum: {GridItemTooltipPatch.HoveredItem?.GetHashSum()}<br>Item durability: {GridItemTooltipPatch.HoveredItem?.GetDurability()}<br>Item uses: {GridItemTooltipPatch.HoveredItem?.GetUses()}<br><color=#ff0fff><b>GridItemView</b></color>";
|
||||||
Plugin.Log.LogDebug(GridItemTooltipPatch.HoveredItem?.AttributesToString());
|
Plugin.Log.LogDebug(GridItemTooltipPatch.HoveredItem?.AttributesToString());
|
||||||
}
|
}
|
||||||
if (InsuranceSlotPatch.PatchTooltip)
|
if (InsuranceSlotPatch.PatchTooltip)
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
<AppDesignerFolder>..\Properties</AppDesignerFolder>
|
<AppDesignerFolder>..\Properties</AppDesignerFolder>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="ItemComponent.Types">
|
||||||
|
<HintPath>..\References\Managed\ItemComponent.Types.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="PhysicsModule">
|
<Reference Include="PhysicsModule">
|
||||||
<HintPath>..\References\Managed\UnityEngine.PhysicsModule.dll</HintPath>
|
<HintPath>..\References\Managed\UnityEngine.PhysicsModule.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
@ -82,7 +85,7 @@
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
<Exec Command="copy "$(SolutionDir)Plugin\bin\$(ConfigurationName)\net472\LootValueEX.dll" "G:\Games\eft-dev\BepInEx\plugins\"" />
|
<Exec Command="copy "$(SolutionDir)Plugin\bin\$(ConfigurationName)\net472\LootValueEX.dll" "E:\Games\eft-dev\BepInEx\plugins\"" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
17
Plugin/Utils/ItemUtils.cs
Normal file
17
Plugin/Utils/ItemUtils.cs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
using EFT.InventoryLogic;
|
||||||
|
|
||||||
|
namespace LootValueEX.Utils
|
||||||
|
{
|
||||||
|
internal class ItemUtils
|
||||||
|
{
|
||||||
|
public static float GetArmorDurability(IEnumerable<RepairableComponent> repairableComponents)
|
||||||
|
{
|
||||||
|
float totalDurability = 0;
|
||||||
|
foreach (RepairableComponent component in repairableComponents)
|
||||||
|
{
|
||||||
|
totalDurability += component.Durability;
|
||||||
|
}
|
||||||
|
return totalDurability;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user