mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 09:50:43 -05:00
Renamed a few things to make it easier to read. Use role instead of side to know if they are pmcs. Cant test since one of patches fail due to remapping should be ok Reviewed-on: SPT/Modules#145 Co-authored-by: Kaeno <kaeno@noreply.dev.sp-tarkov.com> Co-committed-by: Kaeno <kaeno@noreply.dev.sp-tarkov.com>
86 lines
3.0 KiB
C#
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]
|
|
private static void PatchPrefix(DamageInfo 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 == WildSpawnType.pmcBEAR || killedPlayerSettings.Role == 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;
|
|
}
|
|
}
|
|
}
|