0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/SPT.Custom/Patches/AllScavsHostileHostileToPlayerScavPatch.cs

66 lines
2.5 KiB
C#
Raw Normal View History

2024-05-21 19:10:17 +01:00
using SPT.Reflection.Patching;
2023-03-03 18:52:31 +00:00
using EFT;
using System.Reflection;
using HarmonyLib;
2023-03-03 18:52:31 +00:00
2024-05-21 19:10:17 +01:00
namespace SPT.Custom.Patches
2023-03-03 18:52:31 +00:00
{
public class AllScavsHostileHostileToPlayerScavPatch : ModulePatch
2023-03-03 18:52:31 +00:00
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(BotsController), nameof(BotsController.AddEnemyToAllGroupsInBotZone));
2023-03-03 18:52:31 +00:00
}
/// <summary>
/// AddEnemyToAllGroupsInBotZone()
/// Goal: by default, AddEnemyToAllGroupsInBotZone doesn't check if the bot group is on the same side as the player.
/// The effect of this is that when you are a Scav and kill a Usec, every bot group in the zone will aggro you including other Scavs.
/// This should fix that.
/// </summary>
[PatchPrefix]
private static bool PatchPrefix(BotsController __instance, IPlayer aggressor, IPlayer groupOwner, IPlayer target)
2023-03-03 18:52:31 +00:00
{
if (!groupOwner.IsAI)
{
return false; // Skip original
}
// If you damage yourself exit early as we dont want to try add ourself to our own enemy list
if (aggressor.IsYourPlayer && target.IsYourPlayer)
{
return false; // Skip original
}
2023-03-03 18:52:31 +00:00
BotZone botZone = groupOwner.AIData.BotOwner.BotsGroup.BotZone;
foreach (var item in __instance.Groups())
{
if (item.Key != botZone)
{
continue;
}
foreach (var group in item.Value.GetGroups(notNull: true))
{
bool differentSide = aggressor.Side != group.Side;
bool sameSide = aggressor.Side == target.Side;
if (!group.HaveFollowTarget(aggressor)
&& !group.Enemies.ContainsKey(aggressor)
2023-03-03 18:52:31 +00:00
&& (differentSide || !sameSide)
&& !group.HaveMemberWithRole(WildSpawnType.gifter)
&& !group.HaveMemberWithRole(WildSpawnType.sectantWarrior)
&& !group.HaveMemberWithRole(WildSpawnType.sectantPriest)
&& !group.InitialFileSettings.Boss.NOT_ADD_TO_ENEMY_ON_KILLS
&& group.ShallRevengeFor(target))
2023-03-03 18:52:31 +00:00
{
group.AddEnemy(aggressor, EBotEnemyCause.AddEnemyToAllGroupsInBotZone);
2023-03-03 18:52:31 +00:00
}
}
}
return false; // Skip original
2023-03-03 18:52:31 +00:00
}
}
}