mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 07:10:44 -05:00
use data from server when choosing player scav brain
This commit is contained in:
parent
50bcd5fd3b
commit
cbd0cf5ef4
@ -13,7 +13,6 @@ namespace Aki.Custom.CustomAI
|
|||||||
private static AIBrains aiBrainsCache = null;
|
private static AIBrains aiBrainsCache = null;
|
||||||
private static DateTime aiBrainCacheDate = new DateTime();
|
private static DateTime aiBrainCacheDate = new DateTime();
|
||||||
private static readonly Random random = new Random();
|
private static readonly Random random = new Random();
|
||||||
private static readonly List<WildSpawnType> playerScavTypes = new List<WildSpawnType>() { WildSpawnType.bossKilla, WildSpawnType.pmcBot, WildSpawnType.bossGluhar };
|
|
||||||
private readonly ManualLogSource logger;
|
private readonly ManualLogSource logger;
|
||||||
|
|
||||||
public AIBrainSpawnWeightAdjustment(ManualLogSource logger)
|
public AIBrainSpawnWeightAdjustment(ManualLogSource logger)
|
||||||
@ -21,9 +20,33 @@ namespace Aki.Custom.CustomAI
|
|||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WildSpawnType GetRandomisedPlayerScavType()
|
public WildSpawnType GetRandomisedPlayerScavType(BotOwner botOwner, string currentMapName)
|
||||||
{
|
{
|
||||||
return playerScavTypes.Random();
|
// Get map brain weights from server and cache
|
||||||
|
if (aiBrainsCache == null || CacheIsStale())
|
||||||
|
{
|
||||||
|
ResetCacheDate();
|
||||||
|
HydrateCacheWithServerData();
|
||||||
|
|
||||||
|
if (!aiBrainsCache.playerScav.TryGetValue(currentMapName.ToLower(), out _))
|
||||||
|
{
|
||||||
|
throw new Exception($"Bots were refreshed from the server but the assault cache still doesnt contain data");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Choose random weighted brain
|
||||||
|
var randomType = WeightedRandom(aiBrainsCache.playerScav[currentMapName.ToLower()].Keys.ToArray(), aiBrainsCache.playerScav[currentMapName.ToLower()].Values.ToArray());
|
||||||
|
if (Enum.TryParse(randomType, out WildSpawnType newAiType))
|
||||||
|
{
|
||||||
|
logger.LogWarning($"Updated player scav bot to use: {newAiType} brain");
|
||||||
|
return newAiType;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.LogWarning($"Updated player scav bot {botOwner.Profile.Info.Nickname}: {botOwner.Profile.Info.Settings.Role} to use: {newAiType} brain");
|
||||||
|
|
||||||
|
return newAiType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WildSpawnType GetAssaultScavWildSpawnType(BotOwner botOwner, string currentMapName)
|
public WildSpawnType GetAssaultScavWildSpawnType(BotOwner botOwner, string currentMapName)
|
||||||
@ -97,6 +120,7 @@ namespace Aki.Custom.CustomAI
|
|||||||
aiBrainCacheDate = DateTime.Now;
|
aiBrainCacheDate = DateTime.Now;
|
||||||
aiBrainsCache?.pmc?.Clear();
|
aiBrainsCache?.pmc?.Clear();
|
||||||
aiBrainsCache?.assault?.Clear();
|
aiBrainsCache?.assault?.Clear();
|
||||||
|
aiBrainsCache?.playerScav?.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool CacheIsStale()
|
private static bool CacheIsStale()
|
||||||
@ -110,6 +134,7 @@ namespace Aki.Custom.CustomAI
|
|||||||
{
|
{
|
||||||
public Dictionary<WildSpawnType, Dictionary<string, Dictionary<string, int>>> pmc { get; set; }
|
public Dictionary<WildSpawnType, Dictionary<string, Dictionary<string, int>>> pmc { get; set; }
|
||||||
public Dictionary<string, Dictionary<string, int>> assault { get; set; }
|
public Dictionary<string, Dictionary<string, int>> assault { get; set; }
|
||||||
|
public Dictionary<string, Dictionary<string, int>> playerScav { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -32,13 +32,14 @@ namespace Aki.Custom.Patches
|
|||||||
__state = ___botOwner_0.Profile.Info.Settings.Role; // Store original type in state param to allow access in PatchPostFix()
|
__state = ___botOwner_0.Profile.Info.Settings.Role; // Store original type in state param to allow access in PatchPostFix()
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
string currentMapName = GetCurrentMap();
|
||||||
if (AiHelpers.BotIsPlayerScav(__state, ___botOwner_0))
|
if (AiHelpers.BotIsPlayerScav(__state, ___botOwner_0))
|
||||||
{
|
{
|
||||||
___botOwner_0.Profile.Info.Settings.Role = aIBrainSpawnWeightAdjustment.GetRandomisedPlayerScavType();
|
___botOwner_0.Profile.Info.Settings.Role = aIBrainSpawnWeightAdjustment.GetRandomisedPlayerScavType(___botOwner_0, currentMapName);
|
||||||
|
|
||||||
return true; // Do original
|
return true; // Do original
|
||||||
}
|
}
|
||||||
string currentMapName = GetCurrentMap();
|
|
||||||
if (AiHelpers.BotIsNormalAssaultScav(__state, ___botOwner_0))
|
if (AiHelpers.BotIsNormalAssaultScav(__state, ___botOwner_0))
|
||||||
{
|
{
|
||||||
___botOwner_0.Profile.Info.Settings.Role = aIBrainSpawnWeightAdjustment.GetAssaultScavWildSpawnType(___botOwner_0, currentMapName);
|
___botOwner_0.Profile.Info.Settings.Role = aIBrainSpawnWeightAdjustment.GetAssaultScavWildSpawnType(___botOwner_0, currentMapName);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user