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/IsEnemyPatch.cs

133 lines
4.8 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.Linq;
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 IsEnemyPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(BotsGroup), nameof(BotsGroup.IsEnemy));
2023-03-03 18:52:31 +00:00
}
/// <summary>
/// IsEnemy()
/// Goal: Make bots take Side into account when deciding if another player/bot is an enemy
/// Check enemy cache list first, if not found, check side, if they differ, add to enemy list and return true
/// Needed to ensure bot checks the enemy side, not just its botType
/// </summary>
[PatchPrefix]
2024-08-20 20:25:53 +01:00
public static bool PatchPrefix(ref bool __result, BotsGroup __instance, IPlayer player)
2023-03-03 18:52:31 +00:00
{
2024-08-20 20:25:53 +01:00
if (player == null)
{
__result = false;
return false; // Skip original
}
if (__instance.InitialBotType == WildSpawnType.peacefullZryachiyEvent
|| __instance.InitialBotType == WildSpawnType.shooterBTR
|| __instance.InitialBotType == WildSpawnType.gifter
|| __instance.InitialBotType == WildSpawnType.sectantWarrior
|| __instance.InitialBotType == WildSpawnType.sectantPriest
|| __instance.InitialBotType == WildSpawnType.sectactPriestEvent
|| __instance.InitialBotType == WildSpawnType.ravangeZryachiyEvent)
{
return true; // Do original code
}
2023-03-03 18:52:31 +00:00
var isEnemy = false; // default not an enemy
2023-07-11 10:19:41 +01:00
2023-03-03 18:52:31 +00:00
// Check existing enemies list
// Could also check x.Value.Player?.Id - BSG do it this way
2024-08-20 20:25:53 +01:00
if (!__instance.Enemies.IsNullOrEmpty() && __instance.Enemies.Any(x => x.Key.Id == player.Id))
2023-03-03 18:52:31 +00:00
{
__result = true;
return false; // Skip original
2023-03-03 18:52:31 +00:00
}
2024-08-01 17:41:55 +01:00
// Weird edge case - without this you get spammed with key already in enemy list error when you move around on lighthouse
// Make zryachiy use existing isEnemy() code
if (__instance.InitialBotType == WildSpawnType.bossZryachiy)
2023-03-03 18:52:31 +00:00
{
2024-08-01 17:41:55 +01:00
return false; // Skip original
}
2024-08-01 17:41:55 +01:00
if (__instance.Side == EPlayerSide.Usec)
{
2024-08-20 20:25:53 +01:00
if (player.Side == EPlayerSide.Bear || player.Side == EPlayerSide.Savage ||
ShouldAttackUsec(player))
2023-03-03 18:52:31 +00:00
{
2024-08-01 17:41:55 +01:00
isEnemy = true;
2024-08-20 20:25:53 +01:00
__instance.AddEnemy(player, EBotEnemyCause.checkAddTODO);
2023-03-03 18:52:31 +00:00
}
2024-08-01 17:41:55 +01:00
}
else if (__instance.Side == EPlayerSide.Bear)
{
2024-08-20 20:25:53 +01:00
if (player.Side == EPlayerSide.Usec || player.Side == EPlayerSide.Savage ||
ShouldAttackBear(player))
2023-03-03 18:52:31 +00:00
{
2024-08-01 17:41:55 +01:00
isEnemy = true;
2024-08-20 20:25:53 +01:00
__instance.AddEnemy(player, EBotEnemyCause.checkAddTODO);
2023-03-03 18:52:31 +00:00
}
2024-08-01 17:41:55 +01:00
}
else if (__instance.Side == EPlayerSide.Savage)
{
2024-08-20 20:25:53 +01:00
if (player.Side != EPlayerSide.Savage)
2023-03-03 18:52:31 +00:00
{
2024-08-01 17:41:55 +01:00
//Lets exUsec warn Usecs and fire at will at Bears
if (__instance.InitialBotType == WildSpawnType.exUsec)
2023-03-03 18:52:31 +00:00
{
2024-08-01 17:41:55 +01:00
return true; // Let BSG handle things
2023-03-03 18:52:31 +00:00
}
2024-08-01 17:41:55 +01:00
// everyone else is an enemy to savage (scavs)
isEnemy = true;
2024-08-20 20:25:53 +01:00
__instance.AddEnemy(player, EBotEnemyCause.checkAddTODO);
2023-03-03 18:52:31 +00:00
}
}
__result = isEnemy;
return false; // Skip original
2023-03-03 18:52:31 +00:00
}
/// <summary>
/// Return True when usec default behavior is attack + bot is usec
/// </summary>
/// <param name="requester"></param>
/// <returns>bool</returns>
private static bool ShouldAttackUsec(IPlayer requester)
2023-03-03 18:52:31 +00:00
{
var requesterMind = requester?.AIData?.BotOwner?.Settings?.FileSettings?.Mind;
if (requesterMind == null)
{
return false;
}
2024-08-20 19:00:11 +01:00
return requester.IsAI && requesterMind.DEFAULT_USEC_BEHAVIOUR == EWarnBehaviour.AlwaysEnemies && requester.Side == EPlayerSide.Usec;
2023-03-03 18:52:31 +00:00
}
/// <summary>
/// Return True when bear default behavior is attack + bot is bear
/// </summary>
/// <param name="requester"></param>
/// <returns></returns>
private static bool ShouldAttackBear(IPlayer requester)
2023-03-03 18:52:31 +00:00
{
var requesterMind = requester.AIData?.BotOwner?.Settings?.FileSettings?.Mind;
if (requesterMind == null)
{
return false;
}
2024-08-20 19:00:11 +01:00
return requester.IsAI && requesterMind.DEFAULT_BEAR_BEHAVIOUR == EWarnBehaviour.AlwaysEnemies && requester.Side == EPlayerSide.Bear;
2023-03-03 18:52:31 +00:00
}
}
}