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;
|
2024-01-13 22:08:29 +00:00
|
|
|
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 BotEnemyTargetPatch : ModulePatch
|
|
|
|
{
|
|
|
|
protected override MethodBase GetTargetMethod()
|
|
|
|
{
|
2024-01-13 22:08:29 +00:00
|
|
|
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]
|
2023-10-10 10:58:33 +00:00
|
|
|
private static bool PatchPrefix(BotsController __instance, IPlayer aggressor, IPlayer groupOwner, IPlayer target)
|
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))
|
|
|
|
{
|
|
|
|
if (!group.Enemies.ContainsKey(aggressor) && ShouldAttack(aggressor, target, group))
|
|
|
|
{
|
2023-10-10 10:58:33 +00:00
|
|
|
group.AddEnemy(aggressor, EBotEnemyCause.AddEnemyToAllGroupsInBotZone);
|
2023-03-03 18:52:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2023-10-10 10:58:33 +00:00
|
|
|
private static bool ShouldAttack(IPlayer attacker, IPlayer victim, BotsGroup groupToCheck)
|
2023-03-03 18:52:31 +00:00
|
|
|
{
|
|
|
|
// Group should target if player attack a victim on the same side or if the group is not on the same side as the player.
|
|
|
|
bool shouldAttack = attacker.Side != groupToCheck.Side
|
|
|
|
|| attacker.Side == victim.Side;
|
|
|
|
|
|
|
|
return !groupToCheck.HaveMemberWithRole(WildSpawnType.gifter) && groupToCheck.ShallRevengeFor(victim) && shouldAttack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|