0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00

86 lines
2.2 KiB
C#
Raw Normal View History

2024-05-21 19:10:17 +01:00
using SPT.SinglePlayer.Models.RaidFix;
using Comfort.Common;
using EFT;
using EFT.InventoryLogic;
using System.Collections.Generic;
using System.Linq;
using EFT.UI;
2024-05-21 19:10:17 +01:00
namespace SPT.SinglePlayer.Utils.Insurance
{
public class InsuredItemManager
{
private static InsuredItemManager _instance;
private List<Item> _items;
private List<string> _placedItems = new List<string>();
public static InsuredItemManager Instance
{
get
{
if (_instance == null)
{
_instance = new InsuredItemManager();
}
return _instance;
}
}
public void Init()
{
2023-08-07 19:47:22 +01:00
_items = Singleton<GameWorld>.Instance?.MainPlayer?.Profile?.Inventory?.AllRealPlayerItems?.ToList();
}
2024-05-21 19:10:17 +01:00
public List<SPTInsuredItemClass> GetTrackedItems()
{
2024-05-21 19:10:17 +01:00
var itemsToSend = new List<SPTInsuredItemClass>();
if (_items == null || !_items.Any())
{
return itemsToSend;
}
foreach (var item in _items)
{
2024-05-21 19:18:57 +01:00
var spt = new SPTInsuredItemClass
{
id = item.Id
};
if (_placedItems.Contains(item.Id))
{
spt.usedInQuest = true;
}
var dura = item.GetItemComponent<RepairableComponent>();
if (dura != null)
{
2024-05-21 19:18:57 +01:00
spt.durability = dura.Durability;
spt.maxDurability = dura.MaxDurability;
}
var faceshield = item.GetItemComponent<FaceShieldComponent>();
if (faceshield != null)
{
2024-05-21 19:18:57 +01:00
spt.hits = faceshield.Hits;
}
2024-05-21 19:18:57 +01:00
itemsToSend.Add(spt);
}
return itemsToSend;
}
public void SetPlacedItem(Item topLevelItem)
{
// Includes Parent and Children items
foreach (var item in topLevelItem.GetAllItems())
{
_placedItems.Add(item.Id);
}
}
}
}