2024-08-15 08:45:47 +00:00
|
|
|
|
using EFT;
|
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using SPT.Custom.CustomAI;
|
|
|
|
|
using SPT.Reflection.Patching;
|
|
|
|
|
using System.Collections.Generic;
|
2023-03-03 18:52:31 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
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]
|
2023-10-10 10:58:33 +00:00
|
|
|
|
private static bool PatchPrefix(ref bool __result, BotsGroup __instance, IPlayer requester)
|
2023-03-03 18:52:31 +00:00
|
|
|
|
{
|
2024-07-04 14:11:11 +00:00
|
|
|
|
if (requester == null)
|
|
|
|
|
{
|
|
|
|
|
__result = false;
|
2024-08-15 08:45:47 +00:00
|
|
|
|
return false; // Skip original
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check existing enemies list
|
|
|
|
|
// Could also check x.Value.Player?.Id - BSG do it this way
|
2024-08-16 17:35:35 +00:00
|
|
|
|
if (__instance.Enemies != null && __instance.Enemies.Keys.ContainsPlayer(requester))
|
2024-08-15 08:45:47 +00:00
|
|
|
|
{
|
|
|
|
|
__result = true;
|
|
|
|
|
return false; // Skip original
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Do not force bots to be enemies if they are allies
|
2024-08-16 17:35:35 +00:00
|
|
|
|
if (__instance.Allies != null && __instance.Allies.ContainsPlayer(requester))
|
2024-08-15 08:45:47 +00:00
|
|
|
|
{
|
|
|
|
|
__result = false;
|
|
|
|
|
return false; // Skip original
|
|
|
|
|
}
|
2024-07-04 14:11:11 +00:00
|
|
|
|
|
2024-08-15 08:45:47 +00:00
|
|
|
|
// Bots should not become hostile with their group members here. This is needed in case mods add mixed groups (i.e. BEAR's and USEC's).
|
2024-08-16 17:35:35 +00:00
|
|
|
|
if (__instance.GetAllMembers().ContainsPlayer(requester))
|
2024-08-15 08:45:47 +00:00
|
|
|
|
{
|
|
|
|
|
__result = false;
|
2024-07-04 14:11:11 +00:00
|
|
|
|
return false; // Skip original
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-13 19:15:54 +00:00
|
|
|
|
if (__instance.InitialBotType == WildSpawnType.peacefullZryachiyEvent
|
2024-08-16 17:35:35 +00:00
|
|
|
|
|| __instance.InitialBotType == WildSpawnType.shooterBTR
|
|
|
|
|
|| __instance.InitialBotType == WildSpawnType.gifter
|
|
|
|
|
|| __instance.InitialBotType == WildSpawnType.sectantWarrior
|
|
|
|
|
|| __instance.InitialBotType == WildSpawnType.sectantPriest
|
|
|
|
|
|| __instance.InitialBotType == WildSpawnType.sectactPriestEvent
|
|
|
|
|
|| __instance.InitialBotType == WildSpawnType.ravangeZryachiyEvent
|
2024-08-15 08:45:47 +00:00
|
|
|
|
|| __instance.InitialBotType == WildSpawnType.bossZryachiy
|
|
|
|
|
|| __instance.InitialBotType == WildSpawnType.followerZryachiy)
|
2023-11-02 15:10:44 +00:00
|
|
|
|
{
|
|
|
|
|
return true; // Do original code
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-15 08:45:47 +00:00
|
|
|
|
// Let EFT manage Rogue behavior toward PMC's
|
|
|
|
|
if (__instance.InitialBotType == WildSpawnType.exUsec
|
|
|
|
|
&& __instance.Side == EPlayerSide.Savage
|
|
|
|
|
&& requester.Side != EPlayerSide.Savage)
|
2023-03-03 18:52:31 +00:00
|
|
|
|
{
|
2024-08-15 08:45:47 +00:00
|
|
|
|
return true; // Do original code
|
2023-03-03 18:52:31 +00:00
|
|
|
|
}
|
2023-07-10 17:16:54 +01:00
|
|
|
|
|
2024-08-15 08:45:47 +00:00
|
|
|
|
// In all other cases, requester needs to be added to the enemies collection of the bot group if it should be treated as hostile
|
|
|
|
|
// NOTE: Manually adding enemies is needed as a result of EFT's implementation of PMC's because they are not hostile toward
|
|
|
|
|
// Scavs (any probably other bot types too)
|
|
|
|
|
__result = CheckIfPlayerShouldBeEnemy(__instance, requester);
|
|
|
|
|
if (__result)
|
|
|
|
|
{
|
|
|
|
|
__instance.AddEnemy(requester, EBotEnemyCause.checkAddTODO);
|
2023-03-03 18:52:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-10 10:58:33 +00:00
|
|
|
|
return false; // Skip original
|
2023-03-03 18:52:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-15 08:45:47 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns true if requester should be an enemy of the bot group
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="__instance"></param>
|
|
|
|
|
/// <param name="requester"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private static bool CheckIfPlayerShouldBeEnemy(BotsGroup __instance, IPlayer requester)
|
|
|
|
|
{
|
|
|
|
|
switch (__instance.Side)
|
|
|
|
|
{
|
|
|
|
|
case EPlayerSide.Usec:
|
|
|
|
|
return requester.Side != EPlayerSide.Usec || ShouldAttackUsec(requester);
|
|
|
|
|
case EPlayerSide.Bear:
|
|
|
|
|
return requester.Side != EPlayerSide.Bear || ShouldAttackBear(requester);
|
|
|
|
|
case EPlayerSide.Savage:
|
|
|
|
|
return requester.Side != EPlayerSide.Savage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
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>
|
2024-08-15 08:45:47 +00:00
|
|
|
|
/// <returns></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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return requester.IsAI && requesterMind.DEFAULT_USEC_BEHAVIOUR == EWarnBehaviour.Attack && requester.Side == EPlayerSide.Usec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return requester.IsAI && requesterMind.DEFAULT_BEAR_BEHAVIOUR == EWarnBehaviour.Attack && requester.Side == EPlayerSide.Bear;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|