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

58 lines
2.0 KiB
C#
Raw Normal View History

2023-03-03 18:52:31 +00:00
using Aki.Reflection.Patching;
using EFT;
using System.Reflection;
using HarmonyLib;
2023-03-03 18:52:31 +00:00
namespace Aki.Custom.Patches
{
public class AddEnemyToAllGroupsInBotZonePatch : ModulePatch
{
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 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;
}
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.Enemies.ContainsKey(aggressor)
&& (differentSide || !sameSide)
&& !group.HaveMemberWithRole(WildSpawnType.gifter)
&& group.ShallRevengeFor(target)
)
{
group.AddEnemy(aggressor, EBotEnemyCause.AddEnemyToAllGroupsInBotZone);
2023-03-03 18:52:31 +00:00
}
}
}
return false;
}
}
}