0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-12 22:50:44 -05:00

Track insured item values to be used post-raid by server (!16)

Co-authored-by: CWX <CWX@noreply.dev.sp-tarkov.com>
Co-authored-by: Dev <dev@dev.sp-tarkov.com>
Reviewed-on: SPT-AKI/Modules#16
This commit is contained in:
chomp 2023-08-05 17:26:09 +00:00
parent 37e356c430
commit 49acd11765
6 changed files with 108 additions and 6 deletions

View File

@ -51,6 +51,7 @@ namespace Aki.SinglePlayer
new PlayerToggleSoundFixPatch().Enable();
new PluginErrorNotifierPatch().Enable();
new SpawnProcessNegativeValuePatch().Enable();
new InsuredItemManagerStartPatch().Enable();
}
catch (Exception ex)
{

View File

@ -1,6 +1,8 @@
using Aki.SinglePlayer.Models.Healing;
using Newtonsoft.Json;
using Newtonsoft.Json;
using EFT;
using System.Collections.Generic;
using Aki.SinglePlayer.Models.Healing;
using Aki.SinglePlayer.Models.RaidFix;
namespace Aki.SinglePlayer.Models.Progression
{
@ -18,6 +20,9 @@ namespace Aki.SinglePlayer.Models.Progression
[JsonProperty("health")]
public PlayerHealth Health;
[JsonProperty("insurance")]
public List<AkiInsuredItemClass> Insurance;
public SaveProfileRequest()
{
Exit = "left";

View File

@ -0,0 +1,10 @@
namespace Aki.SinglePlayer.Models.RaidFix
{
public class AkiInsuredItemClass
{
public string id;
public float? durability = null;
public float? maxDurability = null;
public byte? hits = null;
}
}

View File

@ -59,10 +59,11 @@ namespace Aki.SinglePlayer.Patches.Progression
: PatchConstants.BackEndSession.Profile;
SaveProfileRequest request = new SaveProfileRequest
{
Exit = result.Value0.ToString().ToLowerInvariant(),
Profile = profile,
Health = Utils.Healing.HealthListener.Instance.CurrentHealth,
{
Exit = result.Value0.ToString().ToLowerInvariant(),
Profile = profile,
Health = Utils.Healing.HealthListener.Instance.CurrentHealth,
Insurance = Utils.Insurance.InsuredItemManager.Instance.GetTrackedItems(),
IsPlayerScav = ____raidSettings.IsScav
};

View File

@ -0,0 +1,21 @@
using Aki.Reflection.Patching;
using EFT;
using System.Reflection;
using Aki.SinglePlayer.Utils.Insurance;
namespace Aki.SinglePlayer.Patches.RaidFix
{
public class InsuredItemManagerStartPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(GameWorld).GetMethod(nameof(GameWorld.OnGameStarted));
}
[PatchPostfix]
public static void PatchPostFix()
{
InsuredItemManager.Instance.Init();
}
}
}

View File

@ -0,0 +1,64 @@
using Aki.SinglePlayer.Models.RaidFix;
using Comfort.Common;
using EFT;
using EFT.InventoryLogic;
using System.Collections.Generic;
using System.Linq;
namespace Aki.SinglePlayer.Utils.Insurance
{
public class InsuredItemManager
{
private static InsuredItemManager _instance;
private List<Item> items;
public static InsuredItemManager Instance
{
get
{
if (_instance == null)
{
_instance = new InsuredItemManager();
}
return _instance;
}
}
public void Init()
{
items = Singleton<GameWorld>.Instance?.MainPlayer?.Profile?.Inventory?.AllRealPlayerItems.ToList();
}
public List<AkiInsuredItemClass> GetTrackedItems()
{
var itemsToSend = new List<AkiInsuredItemClass>();
foreach (var item in items)
{
var aki = new AkiInsuredItemClass
{
id = item.Id
};
var dura = item.GetItemComponent<RepairableComponent>();
if (dura != null)
{
aki.durability = dura.Durability;
aki.maxDurability = dura.MaxDurability;
}
var faceshield = item.GetItemComponent<FaceShieldComponent>();
if (faceshield != null)
{
aki.hits = faceshield.Hits;
}
itemsToSend.Add(aki);
}
return itemsToSend;
}
}
}