Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/SAIN/v17/.suo
Binary file not shown.
70 changes: 51 additions & 19 deletions Components/SAIN Bot Component/Classes/BotSquadClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace SAIN.Classes
{
public class SquadClass : SAINBot
{
public string SquadID { get; private set; } = "None";

public SquadClass(BotOwner bot) : base(bot)
{
Logger = BepInEx.Logging.Logger.CreateLogSource(GetType().Name);
Expand All @@ -25,63 +27,93 @@ public void Update()

UpdateMembers();

if (Leader == null || !Leader.HealthController.IsAlive || GroupSize != SquadMembers.Count)
if (Leader != null || Leader.IsDead)
{
if (LeaderDieTime == 0f)
{
LeaderDieTime = Time.time;
}
if (TimeSinceLeaderDied > 30f)
{
FindSquadLeader();
}
}

if ((Leader == null || GroupSize != SquadMembers.Count) && TimeSinceLeaderDied == 0f)
{
GroupSize = SquadMembers.Count;
FindSquadLeader();
}
}

if (SquadID == "None" && LeaderComponent != null && !IAmLeader)
{
SquadID = LeaderComponent.BotSquad.SquadID;
}
}
}

public float TimeSinceLeaderDied => LeaderDieTime == 0f ? 0f : Time.time - LeaderDieTime;
public float LeaderDieTime { get; private set; } = 0f;
private int GroupSize = 0;
private float UpdateMembersTimer = 0f;

private void FindSquadLeader()
{
// If this bot is a boss type, they are the squad leader
if (SAIN.Info.IsBoss)
// Assign current bot as leader to start
float power = SAIN.Info.PowerLevel;
var leadComponent = SAIN;

if (SAIN.Info.IAmBoss)
{
IsSquadLead = true;
Leader = BotOwner;
LeaderComponent = SAIN;
AddLeader(leadComponent);
return;
}
// Assign current bot as leader to start
BotOwner newSquadLead = BotOwner;
float power = SAIN.Info.PowerLevel;

// Iterate through each bot component in friendly group to see who has the highest power level or if any are bosses
foreach (var bot in SquadMembers.Values)
{
if (bot == null || bot.IsDead) continue;

// If this bot is a boss type, they are the squad leader
if (bot.Info.IsBoss)
if (bot.Info.IAmBoss)
{
newSquadLead = bot.BotOwner;
leadComponent = bot;
break;
}
// else If this bot has a higher power level than the last one we checked, they are the squad leader
if (bot.Info.PowerLevel > power)
{
power = bot.Info.PowerLevel;
newSquadLead = bot.BotOwner;
leadComponent = bot;
}
}

// If the current bot is the result, mark the IsSquadLead value as true
IsSquadLead = newSquadLead.ProfileId == BotOwner.ProfileId;
Leader = newSquadLead;
LeaderComponent = newSquadLead.GetComponent<SAINComponent>();
AddLeader(leadComponent);
}

private void AddLeader(SAINComponent sain)
{
LeaderDieTime = 0f;
IAmLeader = sain.ProfileId == BotOwner.ProfileId;
LeaderComponent = sain;
if (IAmLeader && SquadID == "None")
{
SquadID = Guid.NewGuid().ToString("N");
}
if (DebugBotInfo.Value)
Logger.LogDebug($"For Bot: [{BotOwner.Profile.Nickname}]: [{newSquadLead.Profile.Nickname}] is Squad lead! Power Level = [{power}] Squad Power = [{SquadPowerLevel}] Members Count = [{SquadMembers.Count}]");
{
Logger.LogDebug($"For Bot: [{SAIN.BotOwner.name}]: [{sain.BotOwner.name}] is Squad lead! " +
$"Lead is Boss? {sain.Info.IAmBoss} Lead Power: [{sain.Info.PowerLevel}] My Power: [{SAIN.Info.PowerLevel}] " +
$"Squad Power = [{SquadPowerLevel}] Members Count = [{SquadMembers.Count}]");
}
}

public float SquadPowerLevel { get; private set; }

public bool IsSquadLead { get; private set; } = false;
public bool IAmLeader { get; private set; } = false;

public BotOwner Leader { get; private set; }
public BotOwner Leader => LeaderComponent.BotOwner;
public SAINComponent LeaderComponent { get; private set; }

public bool BotInGroup => BotOwner.BotsGroup.MembersCount > 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public SquadDecisionClass(BotOwner bot) : base(bot) { }
public bool GetDecision(out SAINSquadDecision Decision)
{
Decision = SAINSquadDecision.None;
if (!SAIN.BotSquad.BotInGroup || SAIN.BotSquad.SquadMembers == null)
if (!SAIN.BotSquad.BotInGroup || SAIN.BotSquad.SquadMembers == null || SAIN.BotSquad.Leader?.IsDead == true)
{
return false;
}
if (SAIN.Enemy?.IsVisible == true)
if (SAIN.Enemy?.IsVisible == true || BotOwner.Memory.GoalEnemy?.PersonalLastShootTime < 3f)
{
return false;
}
Expand Down Expand Up @@ -132,7 +132,7 @@ private bool EndHelp(SAINComponent member, float distance)
public bool StartRegroup()
{
var squad = SAIN.BotSquad;
if (squad.IsSquadLead)
if (squad.IAmLeader)
{
return false;
}
Expand Down
34 changes: 18 additions & 16 deletions Components/SAIN Bot Component/Classes/Decision/DecisionClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ public void Update()
{
MainDecision = SAINSoloDecision.None;
CurrentSquadDecision = SAINSquadDecision.None;
CurrentSelfDecision = SAINSelfDecision.None;
return;
}

if (DecisionTimer < Time.time)
{
DecisionTimer = Time.time + 0.03f;
DecisionTimer = Time.time + 0.05f;

if (UpdateEnemyTimer < Time.time)
{
Expand All @@ -63,23 +64,24 @@ public void Update()

private void GetDecision()
{
SAINSquadDecision squadDecision = SAINSquadDecision.None;
SAINSelfDecision selfDecision = SAINSelfDecision.None;
var soloDecision = SAINSoloDecision.None;
var squadDecision = SAINSquadDecision.None;
var selfDecision = SAINSelfDecision.None;

if (!CheckStuckDecision(out SAINSoloDecision soloDecision))
if (SelfActionDecisions.GetDecision(out selfDecision))
{
}
else if (CheckStuckDecision(out soloDecision))
{
}
else if (SquadDecisions.GetDecision(out squadDecision))
{
}
else if (EnemyDecisions.GetDecision(out soloDecision))
{
}
else if (GoalTargetDecisions.GetDecision(out soloDecision))
{
if (!SelfActionDecisions.GetDecision(out selfDecision))
{
if (!SquadDecisions.GetDecision(out squadDecision))
{
if (!EnemyDecisions.GetDecision(out soloDecision))
{
if (!GoalTargetDecisions.GetDecision(out soloDecision))
{
}
}
}
}
}

UpdateDecisionProperties(soloDecision, squadDecision, selfDecision);
Expand Down
12 changes: 6 additions & 6 deletions Components/SAIN Bot Component/Classes/InfoClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public BotInfoClass(BotOwner bot) : base(bot)

private void Init()
{
IsBoss = CheckIsBoss(BotType);
IAmBoss = CheckIsBoss(BotType);
IsFollower = CheckIsFollower(BotType);
IsScav = BotType == WildSpawnType.assault || BotType == WildSpawnType.cursedAssault || BotType == WildSpawnType.marksman;
string botTypeString = BotType.ToString();
Expand Down Expand Up @@ -54,7 +54,7 @@ public bool CanBotTalk
{
if (BotOwner.Settings.FileSettings.Mind.CAN_TALK && TalkGlobal.Value)
{
if (IsBoss)
if (IAmBoss)
{
return BossTalk.Value;
}
Expand All @@ -81,7 +81,7 @@ private float CalculateDifficulty(BotOwner bot)

if (settings != null)
{
return GetDifficultyMod(settings.Role, settings.BotDifficulty, IsBoss, IsFollower);
return GetDifficultyMod(settings.Role, settings.BotDifficulty, IAmBoss, IsFollower);
}

return 1f;
Expand Down Expand Up @@ -131,7 +131,7 @@ public void GetTimeBeforeSearch()
{
searchTime = 3f;
}
else if (IsBoss && group.BotInGroup)
else if (IAmBoss && group.BotInGroup)
{
searchTime = 20f;
}
Expand Down Expand Up @@ -169,7 +169,7 @@ public void GetTimeBeforeSearch()

if (DebugBotInfo.Value)
{
Logger.LogDebug($"Search Time = [{searchTime}] because: IsBoss? [{IsBoss}] IsFollower? [{IsFollower}] Personality [{BotPersonality}] SquadLead? [{group.IsSquadLead}] Squad Members: [{group.SquadMembers.Count}]");
Logger.LogDebug($"Search Time = [{searchTime}] because: IsBoss? [{IAmBoss}] IsFollower? [{IsFollower}] Personality [{BotPersonality}] SquadLead? [{group.IAmLeader}] Squad Members: [{group.SquadMembers.Count}]");
}

TimeBeforeSearch = searchTime;
Expand Down Expand Up @@ -330,7 +330,7 @@ private bool CanBeRat

public EPlayerSide Faction => BotOwner.Profile.Side;

public bool IsBoss { get; private set; }
public bool IAmBoss { get; private set; }

public bool IsFollower { get; private set; }

Expand Down
Loading