diff --git a/Si_CommManagement/CommanderApplications.cs b/Si_CommManagement/CommanderApplications.cs index 9c6bb35..ca9e3c8 100644 --- a/Si_CommManagement/CommanderApplications.cs +++ b/Si_CommManagement/CommanderApplications.cs @@ -263,6 +263,19 @@ public static void Postfix(MusicJukeboxHandler __instance, GameMode __0) } } + #if NET6_0 + [HarmonyPatch(typeof(MP_TowerDefense), nameof(MP_TowerDefense.RPC_TimerUpdate))] + #else + [HarmonyPatch(typeof(MP_TowerDefense), "RPC_TimerUpdate")] + #endif + private static class CommanderManager_Patch_TowerDefense_TimerUpdate + { + private static void Postfix(MP_TowerDefense __instance) + { + Process_RPC_TimerUpdate(__instance); + } + } + #if NET6_0 [HarmonyPatch(typeof(MP_Strategy), nameof(MP_Strategy.RPC_TimerUpdate))] #else @@ -272,83 +285,152 @@ private static class CommanderManager_Patch_Strategy_TimerUpdate { private static void Postfix(MP_Strategy __instance) { - if (__instance.GameOver) + Process_RPC_TimerUpdate(__instance); + } + } + + private static float GameModeTimer + { + get + { + if (GameMode.CurrentGameMode is MP_Strategy strategyInstance) { - return; + #if NET6_0 + return strategyInstance.Timer; + #else + Type strategyType = strategyInstance.GetType(); + FieldInfo timerField = strategyType.GetField("Timer", BindingFlags.NonPublic | BindingFlags.Instance); + return (float)timerField.GetValue(strategyInstance); + #endif } + else if (GameMode.CurrentGameMode is MP_TowerDefense defenseInstance) + { + #if NET6_0 + return defenseInstance.Timer; + #else + Type defenseType = defenseInstance.GetType(); + FieldInfo timerField = defenseType.GetField("Timer", BindingFlags.NonPublic | BindingFlags.Instance); + return (float)timerField.GetValue(defenseInstance); + #endif + } + throw new ArgumentException("Cannot access gamemode timer"); + } + set + { + if (GameMode.CurrentGameMode is MP_Strategy strategyInstance) + { + #if NET6_0 + strategyInstance.Timer = value; + #else + Type strategyType = strategyInstance.GetType(); + FieldInfo timerField = strategyType.GetField("Timer", BindingFlags.NonPublic | BindingFlags.Instance); + timerField.SetValue(strategyInstance, value); + #endif + } + else if (GameMode.CurrentGameMode is MP_TowerDefense defenseInstance) + { + #if NET6_0 + defenseInstance.Timer = value; + #else + Type strategyType = defenseInstance.GetType(); + FieldInfo timerField = strategyType.GetField("Timer", BindingFlags.NonPublic | BindingFlags.Instance); + timerField.SetValue(defenseInstance, value); + #endif + } + throw new ArgumentException("Cannot set gamemode timer"); + } + } - float timerValue; - + private static void RemovePlayerFromRespawnTracker(T gameModeInstance, Player player) where T : GameModeExt + { + if (gameModeInstance is MP_Strategy strategyInstance) + { + #if NET6_0 + if (strategyInstance.PlayerRespawnTracker.ContainsKey(player)) + { + strategyInstance.PlayerRespawnTracker.Remove(player); + } + #else + FieldInfo playerRespawnTrackerField = typeof(MP_Strategy).GetField("PlayerRespawnTracker", BindingFlags.NonPublic | BindingFlags.Instance); + Dictionary localPlayerRespawnTracker = (Dictionary)playerRespawnTrackerField.GetValue(strategyInstance); + if (localPlayerRespawnTracker.ContainsKey(player)) + { + localPlayerRespawnTracker.Remove(player); + playerRespawnTrackerField.SetValue(strategyInstance, localPlayerRespawnTracker); + } + #endif + } + else if (gameModeInstance is MP_TowerDefense defenseInstance) + { #if NET6_0 - timerValue = __instance.Timer; + if (defenseInstance.PlayerRespawnTracker.ContainsKey(player)) + { + defenseInstance.PlayerRespawnTracker.Remove(player); + } #else - Type strategyType = typeof(MP_Strategy); - FieldInfo timerField = strategyType.GetField("Timer", BindingFlags.NonPublic | BindingFlags.Instance); - timerValue = (float)timerField.GetValue(__instance); + FieldInfo playerRespawnTrackerField = typeof(MP_TowerDefense).GetField("PlayerRespawnTracker", BindingFlags.NonPublic | BindingFlags.Instance); + Dictionary localPlayerRespawnTracker = (Dictionary)playerRespawnTrackerField.GetValue(defenseInstance); + if (localPlayerRespawnTracker.ContainsKey(player)) + { + localPlayerRespawnTracker.Remove(player); + playerRespawnTrackerField.SetValue(defenseInstance, localPlayerRespawnTracker); + } #endif + } + } + + private static void Process_RPC_TimerUpdate(T gameModeInstance) where T : GameModeExt + { + if (gameModeInstance.GameOver) + { + return; + } + + float timerValue = GameModeTimer; - // the last second before the round is about to start - if (timerValue <= 1f && timerValue > 0f) + // the last second before the round is about to start + if (timerValue <= 1f && timerValue > 0f) + { + // switch all applicants to freecam + for (int i = 0; i < SiConstants.MaxPlayableTeams; i++) { - // switch all applicants to freecam - for (int i = 0; i < SiConstants.MaxPlayableTeams; i++) + if (commanderApplicants[i].Count == 0) { - if (commanderApplicants[i].Count == 0) + continue; + } + + foreach (Player applicantPlayer in commanderApplicants[i]) + { + if (applicantPlayer == null) { continue; } - foreach (Player applicantPlayer in commanderApplicants[i]) - { - if (applicantPlayer == null) - { - continue; - } - - // send to role NONE - CommanderPrimitives.SendToRole(applicantPlayer, GameModeExt.ETeamRole.NONE); - MelonLogger.Msg("Player " + applicantPlayer.PlayerName + " is being sent to role NONE."); + // send to role NONE + CommanderPrimitives.SendToRole(applicantPlayer, GameModeExt.ETeamRole.NONE); + MelonLogger.Msg("Player " + applicantPlayer.PlayerName + " is being sent to role NONE."); - // force switching to role NONE - GameMode.CurrentGameMode.DestroyAllUnitsForPlayer(applicantPlayer); - #if NET6_0 - if (__instance.PlayerRespawnTracker.ContainsKey(applicantPlayer)) - { - __instance.PlayerRespawnTracker.Remove(applicantPlayer); - } - #else - FieldInfo playerRespawnTrackerField = typeof(MP_Strategy).GetField("PlayerRespawnTracker", BindingFlags.NonPublic | BindingFlags.Instance); - Dictionary localPlayerRespawnTracker = (Dictionary)playerRespawnTrackerField.GetValue(__instance); - if (localPlayerRespawnTracker.ContainsKey(applicantPlayer)) - { - localPlayerRespawnTracker.Remove(applicantPlayer); - playerRespawnTrackerField.SetValue(__instance, localPlayerRespawnTracker); - } - #endif - } + // force switching to role NONE + gameModeInstance.DestroyAllUnitsForPlayer(applicantPlayer); + RemovePlayerFromRespawnTracker(gameModeInstance, applicantPlayer); } } + } - if (!CommanderManager._BlockRoundStartUntilEnoughApplicants.Value) - { - return; - } - - if (AllTeamsHaveCommanderApplicants()) - { - return; - } + if (!CommanderManager._BlockRoundStartUntilEnoughApplicants.Value) + { + return; + } - if (timerValue <= 5f && timerValue > 4f) - { - HelperMethods.ReplyToCommand("Round cannot start because all teams don't have a commander. Chat !commander to apply."); + if (AllTeamsHaveCommanderApplicants()) + { + return; + } - #if NET6_0 - __instance.Timer = 26f; - #else - timerField.SetValue(__instance, 26f); - #endif - } + if (timerValue <= 5f && timerValue > 4f) + { + GameModeTimer = 26f; + HelperMethods.ReplyToCommand("Round cannot start because all teams don't have a commander. Chat !commander to apply."); } } } diff --git a/Si_CommManagement/CommanderBanAdminCommands.cs b/Si_CommManagement/CommanderBanAdminCommands.cs index accf5e4..d4634e2 100644 --- a/Si_CommManagement/CommanderBanAdminCommands.cs +++ b/Si_CommManagement/CommanderBanAdminCommands.cs @@ -83,7 +83,6 @@ public static void Command_CommanderDemote(Player? callerPlayer, String args) } int targetTeamIndex = -1; - MP_Strategy strategyInstance = GameObject.FindObjectOfType(); // if no team was specified then try and use current team of the admin if (argumentCount == 0) @@ -101,17 +100,7 @@ public static void Command_CommanderDemote(Player? callerPlayer, String args) { String targetTeamText = args.Split(' ')[1]; - if (String.Equals(targetTeamText, "Human", StringComparison.OrdinalIgnoreCase)) - { - // check gamemode - if Humans vs Aliens or the other ones - if (strategyInstance.TeamsVersus == MP_Strategy.ETeamsVersus.HUMANS_VS_ALIENS) - { - // if it's human vs aliens then human translates to the Human (Sol) team index - targetTeamIndex = (int)SiConstants.ETeam.Sol; - } - // otherwise, it's ambigious and we can't make a decision - } - else if (String.Equals(targetTeamText, "Alien", StringComparison.OrdinalIgnoreCase)) + if (String.Equals(targetTeamText, "Alien", StringComparison.OrdinalIgnoreCase)) { targetTeamIndex = (int)SiConstants.ETeam.Alien; } @@ -140,7 +129,7 @@ public static void Command_CommanderDemote(Player? callerPlayer, String args) } // check if they have a commander to demote - Player? targetPlayer = strategyInstance.GetCommanderForTeam(targetTeam); + Player? targetPlayer = CommanderPrimitives.GetCommander(targetTeam); // team has a commander if targetPlayer isn't null if (targetPlayer == null) @@ -155,7 +144,7 @@ public static void Command_CommanderDemote(Player? callerPlayer, String args) return; } - CommanderPrimitives.DemoteTeamsCommander(strategyInstance, targetTeam); + CommanderPrimitives.DemoteTeamsCommander(targetTeam); HelperMethods.AlertAdminActivity(callerPlayer, targetPlayer, "demoted"); } diff --git a/Si_CommManagement/CommanderBanList.cs b/Si_CommManagement/CommanderBanList.cs index 1fa740a..3c90299 100644 --- a/Si_CommManagement/CommanderBanList.cs +++ b/Si_CommManagement/CommanderBanList.cs @@ -138,9 +138,7 @@ public static void AddBan(Player playerToCmdrBan) if (playerToCmdrBan.IsCommander) { Team playerTeam = playerToCmdrBan.Team; - MP_Strategy strategyInstance = GameObject.FindObjectOfType(); - - CommanderPrimitives.DemoteTeamsCommander(strategyInstance, playerTeam); + CommanderPrimitives.DemoteTeamsCommander(playerTeam); HelperMethods.ReplyToCommand_Player(playerToCmdrBan, "was demoted"); } diff --git a/Si_CommManagement/CommanderDepartures.cs b/Si_CommManagement/CommanderDepartures.cs index da54510..ed0baf6 100644 --- a/Si_CommManagement/CommanderDepartures.cs +++ b/Si_CommManagement/CommanderDepartures.cs @@ -141,88 +141,117 @@ public static void Prefix(GameMode __instance, Player __0) } } + #if NET6_0 + [HarmonyPatch(typeof(MP_TowerDefense), nameof(MP_TowerDefense.SetCommander))] + #else + [HarmonyPatch(typeof(MP_TowerDefense), "SetCommander")] + #endif + private static class ApplyPatch_MPTowerDefense_SetCommander + { + public static bool Prefix(MP_TowerDefense __instance, Team __0, Player? __1) + { + try + { + return SetCommanderPatch(__instance, __0, __1); + } + catch (Exception error) + { + HelperMethods.PrintError(error, "Failed to run MP_TowerDefense::SetCommander"); + } + + return true; + } + } + #if NET6_0 [HarmonyPatch(typeof(MP_Strategy), nameof(MP_Strategy.SetCommander))] #else [HarmonyPatch(typeof(MP_Strategy), "SetCommander")] #endif - private static class ApplyPatchSetCommander + private static class ApplyPatch_MPStrategy_SetCommander { public static bool Prefix(MP_Strategy __instance, Team __0, Player? __1) { try { - MelonLogger.Msg("Reached SetCommander Patch for Team " + __0.TeamShortName); + return SetCommanderPatch(__instance, __0, __1); + } + catch (Exception error) + { + HelperMethods.PrintError(error, "Failed to run MP_Strategy::SetCommander"); + } + + return true; + } + } - if (__instance == null || __0 == null || CommanderBans.BanList == null || CommanderApplications.commanderApplicants == null || CommanderApplications.teamswapCommanderChecks == null || CommanderApplications.promotedCommanders == null) + private static bool SetCommanderPatch(T gameModeInstance, Team team, Player? player) where T : GameModeExt + { + MelonLogger.Msg("Reached SetCommander Patch for Team " + team.TeamShortName); + + if (gameModeInstance == null || team == null || CommanderBans.BanList == null || CommanderApplications.commanderApplicants == null || CommanderApplications.teamswapCommanderChecks == null || CommanderApplications.promotedCommanders == null) + { + return true; + } + + if (player != null) + { + // when the game is in full swing + if (GameMode.CurrentGameMode.Started && GameMode.CurrentGameMode.GameBegun) + { + // determine if promoted commander was previously commanding another team + int commanderSwappedTeamIndex = -1; + for (int i = 0; i < SiConstants.MaxPlayableTeams; i++) { - return true; + if (i == team.Index) + { + continue; + } + + if (CommanderApplications.teamswapCommanderChecks[i] == player) + { + commanderSwappedTeamIndex = i; + break; + } } - if (__1 != null) + // announce a commander swapped to command another team + if (commanderSwappedTeamIndex != -1) { - // when the game is in full swing - if (GameMode.CurrentGameMode.Started && GameMode.CurrentGameMode.GameBegun) + Team departingTeam = Team.Teams[commanderSwappedTeamIndex]; + HelperMethods.ReplyToCommand_Player(player, "has left command of " + HelperMethods.GetTeamColor(departingTeam) + departingTeam.TeamShortName + " and taken command of " + HelperMethods.GetTeamColor(team) + team.TeamShortName + ""); + CommanderApplications.teamswapCommanderChecks[commanderSwappedTeamIndex] = null; + } + else + { + // announce a new commander, if needed + if (CommanderApplications.teamswapCommanderChecks[team.Index] != player && CommanderApplications.promotedCommanders[team.Index] != player) { - // determine if promoted commander was previously commanding another team - int commanderSwappedTeamIndex = -1; - for (int i = 0; i < SiConstants.MaxPlayableTeams; i++) - { - if (i == __0.Index) - { - continue; - } - - if (CommanderApplications.teamswapCommanderChecks[i] == __1) - { - commanderSwappedTeamIndex = i; - break; - } - } - - // announce a commander swapped to command another team - if (commanderSwappedTeamIndex != -1) + CommanderApplications.promotedCommanders[team.Index] = player; + if (CommanderManager._TeamOnlyResponses.Value) { - Team departingTeam = Team.Teams[commanderSwappedTeamIndex]; - HelperMethods.ReplyToCommand_Player(__1, "has left command of " + HelperMethods.GetTeamColor(departingTeam) + departingTeam.TeamShortName + " and taken command of " + HelperMethods.GetTeamColor(__0) + __0.TeamShortName + ""); - CommanderApplications.teamswapCommanderChecks[commanderSwappedTeamIndex] = null; + HelperMethods.SendChatMessageToTeam(player.Team, HelperMethods.chatPrefix, HelperMethods.GetTeamColor(player.Team), player.PlayerName, " has taken command of " + HelperMethods.GetTeamColor(team) + team.TeamShortName + ""); } else { - // announce a new commander, if needed - if (CommanderApplications.teamswapCommanderChecks[__0.Index] != __1 && CommanderApplications.promotedCommanders[__0.Index] != __1) - { - CommanderApplications.promotedCommanders[__0.Index] = __1; - if (CommanderManager._TeamOnlyResponses.Value) - { - HelperMethods.SendChatMessageToTeam(__1.Team, HelperMethods.chatPrefix, HelperMethods.GetTeamColor(__1.Team), __1.PlayerName, " has taken command of " + HelperMethods.GetTeamColor(__0) + __0.TeamShortName + ""); - } - else - { - HelperMethods.ReplyToCommand_Player(__1, "has taken command of " + HelperMethods.GetTeamColor(__0) + __0.TeamShortName + ""); - } - } + HelperMethods.ReplyToCommand_Player(player, "has taken command of " + HelperMethods.GetTeamColor(team) + team.TeamShortName + ""); } } } - // player is null - else - { - // check if there is a current commander - Player? teamCommander = __instance.GetCommanderForTeam(__0); - if (teamCommander != null) - { - CommanderApplications.teamswapCommanderChecks[__0.Index] = teamCommander; - } - } } - catch (Exception error) + } + // player is null + else + { + // check if there is a current commander + Player? teamCommander = gameModeInstance.GetCommanderForTeam(team); + if (teamCommander != null) { - HelperMethods.PrintError(error, "Failed to run MP_Strategy::SetCommander"); + CommanderApplications.teamswapCommanderChecks[team.Index] = teamCommander; } - - return true; } + + return true; } } } \ No newline at end of file diff --git a/Si_CommManagement/CommanderPrimitives.cs b/Si_CommManagement/CommanderPrimitives.cs index 87075f4..2afbe04 100644 --- a/Si_CommManagement/CommanderPrimitives.cs +++ b/Si_CommManagement/CommanderPrimitives.cs @@ -33,21 +33,32 @@ namespace Si_CommanderManagement { public class CommanderPrimitives { - public static void DemoteTeamsCommander(MP_Strategy strategyInstance, Team TargetTeam) + public static Player? GetCommander(Team team) { - Player DemotedCommander = strategyInstance.GetCommanderForTeam(TargetTeam); + if (GameMode.CurrentGameMode) + { + if (GameMode.CurrentGameMode is MP_Strategy strategyInstance) + { + return strategyInstance.GetCommanderForTeam(team); + } + else if (GameMode.CurrentGameMode is MP_TowerDefense defenseInstance) + { + return defenseInstance.GetCommanderForTeam(team); + } + } + + return null; + } - #if NET6_0 - strategyInstance.SetCommander(TargetTeam, null); - strategyInstance.RPC_SynchCommander(TargetTeam); - #else - Type strategyType = typeof(MP_Strategy); - MethodInfo setCommanderMethod = strategyType.GetMethod("SetCommander", BindingFlags.Instance | BindingFlags.NonPublic); - setCommanderMethod.Invoke(strategyInstance, parameters: new object?[] { TargetTeam, null }); + public static void DemoteTeamsCommander(Team TargetTeam) + { + Player? DemotedCommander = GetCommander(TargetTeam); + if (DemotedCommander == null) + { + throw new ArgumentException("Team has no commander"); + } - MethodInfo synchCommanderMethod = strategyType.GetMethod("RPC_SynchCommander", BindingFlags.Instance | BindingFlags.NonPublic); - synchCommanderMethod.Invoke(strategyInstance, new object[] { TargetTeam }); - #endif + SetCommander(TargetTeam, null); // need to get the player back to Infantry and not stuck in no-clip SendToRole(DemotedCommander, GameModeExt.ETeamRole.INFANTRY); @@ -55,29 +66,46 @@ public static void DemoteTeamsCommander(MP_Strategy strategyInstance, Team Targe GameMode.CurrentGameMode.SpawnUnitForPlayer(DemotedCommander, TargetTeam); } - public static void PromoteToCommander(Player CommanderPlayer) + private static void SetCommander(Team team, Player? player) { - MP_Strategy strategyInstance = GameObject.FindObjectOfType(); - - // now mimic switching to COMMANDER role - BaseTeamSetup strategyTeamInstance = strategyInstance.GetTeamSetup(CommanderPlayer.Team); - MelonLogger.Msg("Trying to promote " + CommanderPlayer.PlayerName + " on team " + CommanderPlayer.Team.TeamShortName); - - - #if NET6_0 - strategyInstance.SetCommander(strategyTeamInstance.Team, CommanderPlayer); - strategyInstance.RPC_SynchCommander(strategyTeamInstance.Team); - #else - Type strategyType = typeof(MP_Strategy); - MethodInfo setCommanderMethod = strategyType.GetMethod("SetCommander", BindingFlags.Instance | BindingFlags.NonPublic); - setCommanderMethod.Invoke(strategyInstance, parameters: new object?[] { strategyTeamInstance.Team, CommanderPlayer }); + if (GameMode.CurrentGameMode is MP_Strategy strategyInstance) + { + #if NET6_0 + strategyInstance.SetCommander(team, player); + strategyInstance.RPC_SynchCommander(team); + #else + Type strategyModeType = strategyInstance.GetType(); + MethodInfo setCommanderMethod = strategyModeType.GetMethod("SetCommander", BindingFlags.Instance | BindingFlags.NonPublic); + setCommanderMethod.Invoke(strategyInstance, parameters: new object?[] { team, player }); + + MethodInfo synchCommanderMethod = strategyModeType.GetMethod("RPC_SynchCommander", BindingFlags.Instance | BindingFlags.NonPublic); + synchCommanderMethod.Invoke(strategyInstance, new object[] { team }); + #endif + } + else if (GameMode.CurrentGameMode is MP_TowerDefense defenseInstance) + { + #if NET6_0 + defenseInstance.SetCommander(team, player); + defenseInstance.RPC_SynchCommander(team); + #else + Type defenseModeType = defenseInstance.GetType(); + MethodInfo setCommanderMethod = defenseModeType.GetMethod("SetCommander", BindingFlags.Instance | BindingFlags.NonPublic); + setCommanderMethod.Invoke(defenseInstance, parameters: new object?[] { team, player }); + + MethodInfo synchCommanderMethod = defenseModeType.GetMethod("RPC_SynchCommander", BindingFlags.Instance | BindingFlags.NonPublic); + synchCommanderMethod.Invoke(defenseInstance, new object[] { team }); + #endif + } + } - MethodInfo synchCommanderMethod = strategyType.GetMethod("RPC_SynchCommander", BindingFlags.Instance | BindingFlags.NonPublic); - synchCommanderMethod.Invoke(strategyInstance, new object[] { strategyTeamInstance.Team }); - #endif + // mimic switching to COMMANDER role + public static void PromoteToCommander(Player commander) + { + MelonLogger.Msg("Trying to promote " + commander.PlayerName + " on team " + commander.Team.TeamShortName); + SetCommander(commander.Team, commander); // make a log entry of this role change - Event_Roles.FireOnRoleChangedEvent(CommanderPlayer, GameModeExt.ETeamRole.COMMANDER); + Event_Roles.FireOnRoleChangedEvent(commander, GameModeExt.ETeamRole.COMMANDER); } public static void SendToRole(Player FormerCommander, GameModeExt.ETeamRole role) diff --git a/Si_CommManagement/Mutineer.cs b/Si_CommManagement/Mutineer.cs index 47cc851..ac4d4a0 100644 --- a/Si_CommManagement/Mutineer.cs +++ b/Si_CommManagement/Mutineer.cs @@ -63,7 +63,7 @@ public static void Command_Mutiny(Player? callerPlayer, String args) return; } - if (!GameMode.CurrentGameMode.GameOngoing) + if (!GameMode.CurrentGameMode || !GameMode.CurrentGameMode.GameOngoing) { HelperMethods.SendChatMessageToPlayer(callerPlayer, HelperMethods.chatPrefix, " Cannot mutiny at this time."); return; @@ -75,14 +75,14 @@ public static void Command_Mutiny(Player? callerPlayer, String args) return; } - MP_Strategy strategyInstance = GameObject.FindObjectOfType(); - if (strategyInstance.GetCommanderForTeam(callerPlayer.Team) == null) + // is there no commander at all? + if (CommanderPrimitives.GetCommander(callerPlayer.Team) == null) { HelperMethods.SendChatMessageToPlayer(callerPlayer, HelperMethods.chatPrefix, " Cannot mutiny when no one is commander."); return; } - // did the player already vote for surrender? + // did the player already vote for a mutiny? if (CommanderManager.mutineerPlayers[callerPlayer.Team.Index].Contains(callerPlayer)) { HelperMethods.SendChatMessageToPlayer(callerPlayer, HelperMethods.chatPrefix, " Already voted to mutiny. ", MoreMutinyVotesNeeded(callerPlayer.Team).ToString(), " more players needed."); @@ -98,15 +98,14 @@ public static void Command_Mutiny(Player? callerPlayer, String args) return; } - Mutiny(strategyInstance, callerPlayer.Team); + Mutiny(callerPlayer.Team); } public static int TeammatesNeededForMutiny(Team team) { int playerCount = team.GetNumPlayers(); // don't count the commander as a player here - MP_Strategy strategyInstance = GameObject.FindObjectOfType(); - playerCount -= (strategyInstance.GetCommanderForTeam(team) != null ? 1 : 0); + playerCount -= (CommanderPrimitives.GetCommander(team) != null ? 1 : 0); int teammatesNeeded = (int)Math.Ceiling(playerCount * 0.54f); if (teammatesNeeded < 1) @@ -129,12 +128,12 @@ public static int MoreMutinyVotesNeeded(Team team) return moreNeeded; } - public static void Mutiny(MP_Strategy strategyInstance, Team team) + public static void Mutiny(Team team) { // notify all players HelperMethods.ReplyToCommand(HelperMethods.GetTeamColor(team) + team.TeamShortName + " had a mutiny against the current commander."); - CommanderPrimitives.DemoteTeamsCommander(strategyInstance, team); + CommanderPrimitives.DemoteTeamsCommander(team); // clear all people who voted for a mutiny ClearMutineerList(); diff --git a/Si_CommManagement/Si_CommanderManager.cs b/Si_CommManagement/Si_CommanderManager.cs index 11610a2..711dd94 100644 --- a/Si_CommManagement/Si_CommanderManager.cs +++ b/Si_CommManagement/Si_CommanderManager.cs @@ -34,7 +34,7 @@ You should have received a copy of the GNU General Public License using System.Linq; using System.Collections.Generic; -[assembly: MelonInfo(typeof(CommanderManager), "Commander Management", "1.8.3", "databomb", "https://github.com/data-bomb/Silica")] +[assembly: MelonInfo(typeof(CommanderManager), "Commander Management", "1.9.0", "databomb", "https://github.com/data-bomb/Silica")] [assembly: MelonGame("Bohemia Interactive", "Silica")] [assembly: MelonOptionalDependencies("Admin Mod")]