mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 05:10: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
@ -58,5 +58,29 @@ namespace SPT.Custom.CustomAI
|
|||||||
|
|
||||||
return members;
|
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,21 +32,21 @@ namespace SPT.Custom.Patches
|
|||||||
|
|
||||||
// Check existing enemies list
|
// Check existing enemies list
|
||||||
// Could also check x.Value.Player?.Id - BSG do it this way
|
// 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;
|
__result = true;
|
||||||
return false; // Skip original
|
return false; // Skip original
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not force bots to be enemies if they are allies
|
// 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;
|
__result = false;
|
||||||
return false; // Skip original
|
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).
|
// 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;
|
__result = false;
|
||||||
return false; // Skip original
|
return false; // Skip original
|
||||||
|
Loading…
x
Reference in New Issue
Block a user