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;
|
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 IsEnemyPatch : ModulePatch
|
|
|
|
|
{
|
|
|
|
|
protected override MethodBase GetTargetMethod()
|
|
|
|
|
{
|
2024-01-13 22:08:29 +00:00
|
|
|
|
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)
|
2024-07-04 14:11:11 +00:00
|
|
|
|
{
|
|
|
|
|
__result = false;
|
|
|
|
|
|
|
|
|
|
return false; // Skip original
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-13 19:15:54 +00:00
|
|
|
|
if (__instance.InitialBotType == WildSpawnType.peacefullZryachiyEvent
|
|
|
|
|
|| __instance.InitialBotType == WildSpawnType.shooterBTR
|
|
|
|
|
|| __instance.InitialBotType == WildSpawnType.gifter
|
|
|
|
|
|| __instance.InitialBotType == WildSpawnType.sectantWarrior
|
2024-03-17 12:47:59 +00:00
|
|
|
|
|| __instance.InitialBotType == WildSpawnType.sectantPriest
|
|
|
|
|
|| __instance.InitialBotType == WildSpawnType.sectactPriestEvent
|
|
|
|
|
|| __instance.InitialBotType == WildSpawnType.ravangeZryachiyEvent)
|
2023-11-02 15:10:44 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
2023-07-17 13:09:55 +01:00
|
|
|
|
// 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
|
|
|
|
{
|
2023-07-17 13:09:55 +01:00
|
|
|
|
__result = true;
|
2023-10-10 10:58:33 +00:00
|
|
|
|
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
|
|
|
|
|
}
|
2023-07-10 17:16:54 +01:00
|
|
|
|
|
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;
|
|
|
|
|
|
2023-10-10 10:58:33 +00:00
|
|
|
|
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>
|
2023-10-10 10:58:33 +00:00
|
|
|
|
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>
|
2023-10-10 10:58:33 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|