Skip to content

Commit

Permalink
Fix Commander Lottery Bug
Browse files Browse the repository at this point in the history
- Fixes bug in commander lottery system where subsequent rounds (after the first) would not correctly promote commanders
  • Loading branch information
data-bomb committed Feb 13, 2024
1 parent 0211c82 commit 6902009
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Si_CommManagement/Si_CmdrMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ You should have received a copy of the GNU General Public License
using SilicaAdminMod;
using System.Linq;

[assembly: MelonInfo(typeof(CommanderManager), "Commander Management", "1.4.4", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(CommanderManager), "Commander Management", "1.4.5", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

Expand Down Expand Up @@ -319,7 +319,7 @@ public static void Postfix(MusicJukeboxHandler __instance, GameMode __0)

for (int i = 0; i < MaxTeams; i++)
{
if (commanderApplicants[i].Count == 0)
if (Team.Teams[i] == null || commanderApplicants[i].Count == 0)
{
continue;
}
Expand Down Expand Up @@ -352,6 +352,10 @@ public static void Postfix(MusicJukeboxHandler __instance, GameMode __0)
previousCommanders.Add(CommanderPlayer);
commanderApplicants[i].RemoveAt(iCommanderIndex);
}
else
{
MelonLogger.Warning("Can't find lottery winner. Not promoting for team " + Team.Teams[i].TeamName);
}

// switch remaining players to infantry
foreach (Player infantryPlayer in commanderApplicants[i])
Expand All @@ -364,6 +368,10 @@ public static void Postfix(MusicJukeboxHandler __instance, GameMode __0)
MelonLogger.Msg("Player " + infantryPlayer.PlayerName + " lost commander lottery. Spawning as infantry.");
GameMode.CurrentGameMode.SpawnUnitForPlayer(infantryPlayer, infantryPlayer.Team);
}

// everyone is promoted or moved to infantry, clear for the next round
commanderApplicants[i].Clear();
MelonLogger.Msg("Clearing commander lottery for team " + Team.Teams[i].TeamName);
}
}
catch (Exception error)
Expand Down

0 comments on commit 6902009

Please sign in to comment.