mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 01:30:45 -05:00
IsEnemyPatch Improvements (Part 2) (!157)
Made the following changes to !156: * Replaced `IsNullOrEmpty()` EFT checks with basic null checks * Replaced `Any()` with new helper method to check if bots exist in collections Reviewed-on: SPT/Modules#157 Co-authored-by: dwesterwick <dwesterwick@yahoo.com> Co-committed-by: dwesterwick <dwesterwick@yahoo.com>
This commit is contained in:
parent
af96c37815
commit
ebac61e0a4
@ -47,7 +47,7 @@ namespace SPT.Custom.CustomAI
|
||||
public static List<BotOwner> GetAllMembers(this BotsGroup group)
|
||||
{
|
||||
List<BotOwner> members = new List<BotOwner>();
|
||||
|
||||
|
||||
if (group != null)
|
||||
{
|
||||
for (int m = 0; m < group.MembersCount; m++)
|
||||
@ -58,5 +58,29 @@ namespace SPT.Custom.CustomAI
|
||||
|
||||
return members;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the player is found in the collection by searching for matching player Id's
|
||||
/// </summary>
|
||||
/// <param name="players"></param>
|
||||
/// <param name="playerToCheck"></param>
|
||||
/// <returns></returns>
|
||||
public static bool ContainsPlayer(this IEnumerable<IPlayer> players, IPlayer playerToCheck)
|
||||
{
|
||||
if (playerToCheck == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (IPlayer player in players)
|
||||
{
|
||||
if (player.Id == playerToCheck.Id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,33 +32,33 @@ namespace SPT.Custom.Patches
|
||||
|
||||
// Check existing enemies list
|
||||
// Could also check x.Value.Player?.Id - BSG do it this way
|
||||
if (!__instance.Enemies.IsNullOrEmpty() && __instance.Enemies.Any(x => x.Key?.Id == requester.Id))
|
||||
if (__instance.Enemies != null && __instance.Enemies.Keys.ContainsPlayer(requester))
|
||||
{
|
||||
__result = true;
|
||||
return false; // Skip original
|
||||
}
|
||||
|
||||
// Do not force bots to be enemies if they are allies
|
||||
if (!__instance.Allies.IsNullOrEmpty() && __instance.Allies.Any(x => x?.Id == requester.Id))
|
||||
if (__instance.Allies != null && __instance.Allies.ContainsPlayer(requester))
|
||||
{
|
||||
__result = false;
|
||||
return false; // Skip original
|
||||
}
|
||||
|
||||
// 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).
|
||||
if (__instance.GetAllMembers().Any(i => i?.Id == requester.Id))
|
||||
if (__instance.GetAllMembers().ContainsPlayer(requester))
|
||||
{
|
||||
__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
|
||||
|| __instance.InitialBotType == WildSpawnType.shooterBTR
|
||||
|| __instance.InitialBotType == WildSpawnType.gifter
|
||||
|| __instance.InitialBotType == WildSpawnType.sectantWarrior
|
||||
|| __instance.InitialBotType == WildSpawnType.sectantPriest
|
||||
|| __instance.InitialBotType == WildSpawnType.sectactPriestEvent
|
||||
|| __instance.InitialBotType == WildSpawnType.ravangeZryachiyEvent
|
||||
|| __instance.InitialBotType == WildSpawnType.bossZryachiy
|
||||
|| __instance.InitialBotType == WildSpawnType.followerZryachiy)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user