0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:30:46 -05:00
modules/project/SPT.SinglePlayer/Patches/ScavMode/ScavRepAdjustmentPatch.cs
2024-11-02 13:40:25 +00:00

86 lines
3.0 KiB
C#

using SPT.Reflection.Patching;
using Comfort.Common;
using EFT;
using HarmonyLib;
using System;
using System.Reflection;
namespace SPT.SinglePlayer.Patches.ScavMode
{
public class ScavRepAdjustmentPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
// Correct Gclass has sessionCounters
return AccessTools.Method(typeof(LocationStatisticsCollectorAbstractClass), nameof(LocationStatisticsCollectorAbstractClass.OnEnemyKill));
}
[PatchPrefix]
public static void PatchPrefix(DamageInfoStruct damage, string playerProfileId, out Tuple<Player, bool> __state)
{
__state = new Tuple<Player, bool>(null, false);
var player = (Player)damage.Player.iPlayer;
// Add safeguards to make sure no calculations happen from other bots
if (!player.IsYourPlayer)
{
Logger.LogError("This shouldn't be happening. Are you sure we are using the correct GClass?");
return;
}
if (player.Profile.Side != EPlayerSide.Savage)
{
return;
}
if (Singleton<GameWorld>.Instance.GetEverExistedPlayerByID(playerProfileId) is Player killedBot)
{
__state = new Tuple<Player, bool>(killedBot, killedBot.AIData.IsAI);
var killedPlayerSettings = killedBot.Profile.Info.Settings;
// Extra check to ensure we only set playerscavs to IsAI = false
if (killedPlayerSettings.Role == WildSpawnType.assault && killedBot.Profile.Nickname.Contains("("))
{
//killedBot.AIData.IsAI = false;
}
// If Victim is a PMC and has killed a Scav or Marksman.
if (killedPlayerSettings.Role is WildSpawnType.pmcBEAR or WildSpawnType.pmcUSEC)
{
if (HasBotKilledScav(killedBot))
{
player.Profile.FenceInfo.AddStanding(killedPlayerSettings.StandingForKill, EFT.Counters.EFenceStandingSource.ScavHelp);
}
}
else
{
player.Loyalty.method_1(killedBot);
}
}
}
[PatchPostfix]
private static void PatchPostfix(Tuple<Player, bool> __state)
{
if (__state.Item1 != null)
{
//__state.Item1.AIData.IsAI = __state.Item2;
}
}
private static bool HasBotKilledScav(Player killedPlayer)
{
var killedBots = killedPlayer.Profile.EftStats.Victims;
foreach (var Bot in killedBots)
{
if (Bot.Role == WildSpawnType.assault || Bot.Role == WildSpawnType.marksman || Bot.Role == WildSpawnType.assaultGroup)
{
return true;
}
}
return false;
}
}
}