2024-05-21 19:10:17 +01:00
|
|
|
|
using SPT.Reflection.Patching;
|
2024-03-21 15:21:57 +00:00
|
|
|
|
using Comfort.Common;
|
|
|
|
|
using EFT;
|
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
2024-05-21 19:10:17 +01:00
|
|
|
|
namespace SPT.SinglePlayer.Patches.ScavMode
|
2024-03-21 15:21:57 +00:00
|
|
|
|
{
|
|
|
|
|
public class ScavRepAdjustmentPatch : ModulePatch
|
|
|
|
|
{
|
|
|
|
|
protected override MethodBase GetTargetMethod()
|
|
|
|
|
{
|
2024-05-24 07:12:44 +00:00
|
|
|
|
// Correct Gclass has sessionCounters
|
2024-07-04 14:11:11 +00:00
|
|
|
|
return AccessTools.Method(typeof(LocationStatisticsCollectorAbstractClass), nameof(LocationStatisticsCollectorAbstractClass.OnEnemyKill));
|
2024-03-21 15:21:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[PatchPrefix]
|
2024-05-24 07:12:44 +00:00
|
|
|
|
private static void PatchPrefix(DamageInfo damage, string playerProfileId, out Tuple<Player, bool> __state)
|
2024-03-21 15:21:57 +00:00
|
|
|
|
{
|
|
|
|
|
__state = new Tuple<Player, bool>(null, false);
|
2024-05-24 07:12:44 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2024-03-21 15:21:57 +00:00
|
|
|
|
|
|
|
|
|
if (player.Profile.Side != EPlayerSide.Savage)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-05 07:42:11 +00:00
|
|
|
|
if (Singleton<GameWorld>.Instance.GetEverExistedPlayerByID(playerProfileId) is Player killedBot)
|
2024-03-21 15:21:57 +00:00
|
|
|
|
{
|
2024-07-05 07:42:11 +00:00
|
|
|
|
__state = new Tuple<Player, bool>(killedBot, killedBot.AIData.IsAI);
|
|
|
|
|
var killedPlayerSettings = killedBot.Profile.Info.Settings;
|
2024-03-23 12:48:51 +00:00
|
|
|
|
// Extra check to ensure we only set playerscavs to IsAI = false
|
2024-07-05 07:42:11 +00:00
|
|
|
|
if (killedPlayerSettings.Role == WildSpawnType.assault && killedBot.Profile.Nickname.Contains("("))
|
2024-03-23 12:48:51 +00:00
|
|
|
|
{
|
2024-07-05 07:42:11 +00:00
|
|
|
|
killedBot.AIData.IsAI = false;
|
2024-03-23 12:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-04 14:25:04 +00:00
|
|
|
|
// If Victim is a PMC and has killed a Scav or Marksman.
|
2024-07-05 07:42:11 +00:00
|
|
|
|
if (killedPlayerSettings.Role == WildSpawnType.pmcBEAR || killedPlayerSettings.Role == WildSpawnType.pmcUSEC)
|
2024-07-04 14:25:04 +00:00
|
|
|
|
{
|
2024-07-05 07:42:11 +00:00
|
|
|
|
if (HasBotKilledScav(killedBot))
|
2024-07-04 14:25:04 +00:00
|
|
|
|
{
|
2024-07-05 07:42:11 +00:00
|
|
|
|
player.Profile.FenceInfo.AddStanding(killedPlayerSettings.StandingForKill, EFT.Counters.EFenceStandingSource.ScavHelp);
|
2024-07-04 14:25:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-07-05 07:42:11 +00:00
|
|
|
|
player.Loyalty.method_1(killedBot);
|
2024-07-04 14:25:04 +00:00
|
|
|
|
}
|
2024-03-21 15:21:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-04 14:25:04 +00:00
|
|
|
|
|
2024-03-21 15:21:57 +00:00
|
|
|
|
[PatchPostfix]
|
|
|
|
|
private static void PatchPostfix(Tuple<Player, bool> __state)
|
|
|
|
|
{
|
2024-07-04 14:25:04 +00:00
|
|
|
|
if (__state.Item1 != null)
|
2024-03-21 15:21:57 +00:00
|
|
|
|
{
|
|
|
|
|
__state.Item1.AIData.IsAI = __state.Item2;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-04 14:25:04 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2024-03-21 15:21:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|