Skip to content

Commit

Permalink
Add option for ally bots in siege
Browse files Browse the repository at this point in the history
  • Loading branch information
TimeMaster18 committed Oct 2, 2024
1 parent 0382914 commit 9f398ff
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 56 deletions.
1 change: 1 addition & 0 deletions SingleplayerLauncher/Configuration/GameConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class GameConfig : IConfiguration
public string Battleground { get; set; }
public string SiegeBattleground { get; set; }
public bool SiegeEnemyTeamAsBots { get; set; }
public bool SiegeAllyBots { get; set; }
public string ExtraDifficulty { get; set; }
public string SiegeBotDifficulty { get; set; }
public bool GodMode { get; set; }
Expand Down
59 changes: 37 additions & 22 deletions SingleplayerLauncher/Forms/LauncherMainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 68 additions & 10 deletions SingleplayerLauncher/Forms/LauncherMainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ .. ComBoxSiegeLoadoutTrapSlots
comBoxGameMode.SelectedItem = GameConfig.Instance.GameMode;

// Siege Game settings
chkSiegeAllyBots.Visible = false;
PopulateSlots([comBoxSiegeBattleground], [.. Model.Siege.SiegeBattlegrounds.Keys], addEmptyOption: false);
comBoxSiegeBattleground.SelectedItem = comBoxSiegeBattleground.Items[0];
PopulateSlots([comBoxSiegeDifficulty], [.. BotDifficulty.BotDifficultiesByName.Keys], addEmptyOption: false, sort: false);
Expand Down Expand Up @@ -1409,8 +1410,8 @@ private void btnJoinSiegeGame_Click(object sender, EventArgs e)
private void btnSiegeLaunch_Click(object sender, EventArgs e)
{
bool isSiegeCoop = GameConfig.Instance.SiegeEnemyTeamAsBots;
bool isSiegeAllyBots = GameConfig.Instance.SiegeAllyBots;

GameLauncher.ApplyChanges(isHost: true, isSiege: true, isSiegeCoop: isSiegeCoop);
SaveSettings();

string playerName = maskedTextBoxSiegePlayerName.Text;
Expand All @@ -1430,8 +1431,10 @@ private void btnSiegeLaunch_Click(object sender, EventArgs e)
return;
}

ApplyAllSiegeLoadouts(isSiegeCoop);
ApplyAllSiegeLoadouts(isSiegeCoop, isSiegeAllyBots);
GameInfo.PlayerCount = siegeLoadouts.Count(loadout => !string.IsNullOrWhiteSpace(loadout.Text));

GameLauncher.ApplyChanges(isHost: true, isSiege: true, isSiegeCoop: isSiegeCoop, isSiegeAllyBots: isSiegeAllyBots); // Must be run after ApplyAllSiegeLoadouts due to counting and preparing the ally bots loadouts
GameLauncher.StartGame(GameInfo.SiegeLoadout.PlayerName, isHost: true, mapCode: GameInfo.SiegeBattleground.Map.UmapCode, playerCount: GameInfo.PlayerCount);
}

Expand All @@ -1441,16 +1444,20 @@ private void chkSiegeEnemyTeamAsBots_CheckedChanged(object sender, EventArgs e)

if (comBoxSiegeDifficulty.Enabled)
{
chkSiegeAllyBots.Visible = true;

siegeLoadoutsTeamAux.Clear();
foreach (MaskedTextBox siegeLoadoutMaskedBox in siegeLoadoutsTeam2)
foreach (MaskedTextBox siegeLoadoutMaskedBox in siegeLoadoutsTeam2)
{
siegeLoadoutsTeamAux.Add(siegeLoadoutMaskedBox.Text);
siegeLoadoutMaskedBox.Clear();
siegeLoadoutMaskedBox.Enabled = false;
}
}
}
else
{
chkSiegeAllyBots.Visible = false;

foreach (MaskedTextBox siegeLoadoutMaskedBox in siegeLoadoutsTeam2)
{
if (siegeLoadoutsTeamAux.Count > 0)
Expand All @@ -1467,6 +1474,14 @@ private void chkSiegeEnemyTeamAsBots_CheckedChanged(object sender, EventArgs e)
GameConfig.Instance.Save();
}



private void chkSiegeAllyBots_CheckedChanged(object sender, EventArgs e)
{
GameConfig.Instance.SiegeAllyBots = chkSiegeAllyBots.Checked;
GameConfig.Instance.Save();
}

private void comBoxSiegeDifficulty_SelectedIndexChanged(object sender, EventArgs e)
{
GameConfig.Instance.SiegeBotDifficulty = comBoxSiegeDifficulty.Text;
Expand Down Expand Up @@ -1504,19 +1519,28 @@ private List<string> ValidateAllSiegeLoadoutCodes()
return invalidLoadouts;
}

private void ApplyAllSiegeLoadouts(bool isSiegeCoop = false)
private void ApplyAllSiegeLoadouts(bool isSiegeCoop = false, bool isSiegeAllyBots = false)
{
bool randomBool = random.Next(0, 2) == 0;

int team1 = randomBool ? 1 : 2;
int team2 = randomBool ? 2 : 1;

foreach (var siegeLoadoutTextBox in siegeLoadoutsTeam1)
int team1Defenders = 0;
int team1PlayerCount = 0;

foreach (var siegeLoadoutTextBox in siegeLoadoutsTeam1)
{
if (!string.IsNullOrWhiteSpace(siegeLoadoutTextBox.Text))
{
team1PlayerCount++;
SiegeLoadout siegeLoadout = new();
GameFiles.CharacterData.ApplySiegeLoadout((SiegeLoadout)siegeLoadout.Decode(siegeLoadoutTextBox.Text), team1);
siegeLoadout = (SiegeLoadout)siegeLoadout.Decode(siegeLoadoutTextBox.Text);
if (siegeLoadout.Role == SiegeRole.Defender)
{
team1Defenders++;
}
GameFiles.CharacterData.ApplySiegeLoadout(siegeLoadout, team1);
}
}

Expand All @@ -1530,16 +1554,50 @@ private void ApplyAllSiegeLoadouts(bool isSiegeCoop = false)
GameFiles.CharacterData.ApplySiegeLoadout((SiegeLoadout)siegeLoadout.Decode(siegeLoadoutTextBox.Text), team2);
}
}
}
}
else
{
string difficultyName = comBoxSiegeDifficulty.Text;
BotDifficulty botDifficulty = BotDifficulty.BotDifficultiesByName[difficultyName];
foreach (SiegeLoadout loadout in botDifficulty.botLoadouts) {
foreach (SiegeLoadout loadout in botDifficulty.botLoadouts)
{
GameFiles.CharacterData.ApplySiegeLoadout(loadout, team2, overrideTrapLevel: botDifficulty.TrapTier);
}
}

if (isSiegeAllyBots)
{
GameInfo.AllyBotsLoadouts.Clear();
int allyBotCount = 0;
foreach (SiegeLoadout loadout in botDifficulty.botLoadouts)
{
if (allyBotCount + team1PlayerCount < 5)
{
if (loadout.Role == SiegeRole.Defender && team1Defenders >= 2)
{
continue;
}

int team1Attackers = allyBotCount + team1PlayerCount - team1Defenders;
if (loadout.Role == SiegeRole.Attacker && team1Attackers >= 3)
{
continue;
}

allyBotCount++;
if (loadout.Role == SiegeRole.Defender)
{
team1Defenders++;
}

SiegeLoadout allyBotLoadout = new();
allyBotLoadout = (SiegeLoadout)allyBotLoadout.Decode(loadout.Encode());
allyBotLoadout.PlayerName = allyBotLoadout.PlayerName + "_ALLY";
GameFiles.CharacterData.ApplySiegeLoadout(allyBotLoadout, team1, overrideTrapLevel: botDifficulty.TrapTier);
GameInfo.AllyBotsLoadouts.Add(allyBotLoadout);
}
}
}
}
}

private void btnCopySiegeLoadoutToClipboard_Click(object sender, EventArgs e)
Expand Down
24 changes: 12 additions & 12 deletions SingleplayerLauncher/Forms/LauncherMainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value>
</metadata>
<data name="label10.ToolTip" xml:space="preserve">
<value>
How it works?
- Peer to peer, LAN supported
- Online multiplayer step by step guide to setup in our Discord
- Play online using VPN software such as Radmin


Looking for group? Join our discord community!
- We have dedicated roles and channels for LFG and matchmaking
</value>
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="btnDiscord.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down Expand Up @@ -173,18 +185,6 @@ How it works?
- Play online using VPN software such as Radmin


Looking for group? Join our discord community!
- We have dedicated roles and channels for LFG and matchmaking
</value>
</data>
<data name="label10.ToolTip" xml:space="preserve">
<value>
How it works?
- Peer to peer, LAN supported
- Online multiplayer step by step guide to setup in our Discord
- Play online using VPN software such as Radmin


Looking for group? Join our discord community!
- We have dedicated roles and channels for LFG and matchmaking
</value>
Expand Down
26 changes: 17 additions & 9 deletions SingleplayerLauncher/GameFiles/Config/DefaultGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
using SingleplayerLauncher.Utils;
using System;
using System.IO;
using System.Windows.Forms;

namespace SingleplayerLauncher.GameFiles
{
public static class DefaultGame
{
// TODO: make singleton

private static readonly GameInfo GameInfo = GameInfo.Instance;

private const string RDisplayColorInfoSection = "SpitfireGame.RDisplayColorInfo";
private const string RGameReplicationInfoSection = "SpitfireGame.RGameReplicationInfo";
private const string RHUDBaseSection = "SpitfireGame.RHUDBase";
Expand All @@ -30,20 +29,20 @@ public static class DefaultGame

public static void ApplySurvival()
{
_ = GameInfo.SurvivalBattleground ?? throw new ArgumentNullException(nameof(Battleground), "Mandatory parameter");
_ = GameInfo.SurvivalBattleground.Difficulty ?? throw new ArgumentNullException(nameof(Battleground.Difficulty), "Mandatory parameter");
_ = GameInfo.Instance.SurvivalBattleground ?? throw new ArgumentNullException(nameof(Battleground), "Mandatory parameter");
_ = GameInfo.Instance.SurvivalBattleground.Difficulty ?? throw new ArgumentNullException(nameof(Battleground.Difficulty), "Mandatory parameter");
_ = Mods.Mods.ShowTrapDamageFlyoffs ?? throw new ArgumentNullException(nameof(Mods.Mods.ShowTrapDamageFlyoffs), "Mandatory parameter");
_ = Mods.Mods.AccountLevelOverride ?? throw new ArgumentNullException(nameof(Mods.Mods.AccountLevelOverride), "Mandatory parameter");

ConfigFile defaultGame = new(Path.Combine(Settings.Instance.RootGamePath, FileUtils.INI_CONFIGS_FOLDER_RELATIVE_PATH, FileUtils.INI_DEFAULT_GAME_FILENAME));
IniFile data = defaultGame.data;

data.UpdateEntry(RHUDBaseSection, RHUDBaseKeyShowFlyoffsForTrapDamage, Mods.Mods.ShowTrapDamageFlyoffs.IsEnabled.ToString());
data.UpdateEntry(RGameReplicationInfoSection, GameReplicationInfoKeyGameMode, GameInfo.SurvivalBattleground.GameMode.Id.ToString());
data.UpdateEntry(RGameReplicationInfoSection, GameReplicationInfoKeyMapLevel, GameInfo.SurvivalBattleground.Difficulty.EnemyLevel.ToString());
int accountLevel = Mods.Mods.AccountLevelOverride.IsEnabled ? Mods.Mods.AccountLevelOverride.Value : GameInfo.SurvivalBattleground.Difficulty.AccountLevel;
data.UpdateEntry(RGameReplicationInfoSection, GameReplicationInfoKeyGameMode, GameInfo.Instance.SurvivalBattleground.GameMode.Id.ToString());
data.UpdateEntry(RGameReplicationInfoSection, GameReplicationInfoKeyMapLevel, GameInfo.Instance.SurvivalBattleground.Difficulty.EnemyLevel.ToString());
int accountLevel = Mods.Mods.AccountLevelOverride.IsEnabled ? Mods.Mods.AccountLevelOverride.Value : GameInfo.Instance.SurvivalBattleground.Difficulty.AccountLevel;
data.UpdateEntry(RGameReplicationInfoSection, GameReplicationInfoKeyPlayerLevel, accountLevel.ToString());
data.UpdateEntry(RGameReplicationInfoSection, GameReplicationInfoKeyPlayerCount, GameInfo.SurvivalBattleground.Difficulty.PlayerCount.ToString());
data.UpdateEntry(RGameReplicationInfoSection, GameReplicationInfoKeyPlayerCount, GameInfo.Instance.SurvivalBattleground.Difficulty.PlayerCount.ToString());

defaultGame.Write();
}
Expand All @@ -60,7 +59,7 @@ public static void ApplySurvivalSettings()
defaultGame.Write();
}

public static void ApplySiegeBots()
public static void ApplySiegeBots(bool isSiegeAllyBots = false)
{
_ = GameConfig.Instance.SiegeEnemyTeamAsBots ? true : throw new ArgumentNullException(nameof(GameConfig.Instance.SiegeEnemyTeamAsBots), "Mandatory parameter");
_ = GameConfig.Instance.SiegeBotDifficulty ?? throw new ArgumentNullException(nameof(GameConfig.Instance.SiegeBotDifficulty), "Mandatory parameter");
Expand All @@ -82,6 +81,15 @@ public static void ApplySiegeBots()
botCount++;
}

if (isSiegeAllyBots)
{
foreach (SiegeLoadout allyBotLoadout in GameInfo.Instance.AllyBotsLoadouts)
{
data.UpdateEntry(RGameStateSection, DebugBotPlayerIDs, allyBotLoadout.PlayerName, botCount);
botCount++;
}
}

defaultGame.Write();
}

Expand Down
4 changes: 2 additions & 2 deletions SingleplayerLauncher/GameLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GameLauncher
{
private static readonly SpitfireGameUPK SpitfireGameUPK = new();

public static void ApplyChanges(bool isHost, bool isSiege = false, int parTimeSeconds = 0, bool isSiegeCoop = false)
public static void ApplyChanges(bool isHost, bool isSiege = false, int parTimeSeconds = 0, bool isSiegeCoop = false, bool isSiegeAllyBots = false)
{
if (!isSiege)
{
Expand All @@ -36,7 +36,7 @@ public static void ApplyChanges(bool isHost, bool isSiege = false, int parTimeSe
{
if (isSiegeCoop)
{
GameFiles.DefaultGame.ApplySiegeBots();
GameFiles.DefaultGame.ApplySiegeBots(isSiegeAllyBots);
}
}

Expand Down
Loading

0 comments on commit 9f398ff

Please sign in to comment.