From e8512dd2acac9dbe0b281999d94180351ade3974 Mon Sep 17 00:00:00 2001 From: Olavi Mustanoja Date: Tue, 24 Aug 2021 04:49:46 +0300 Subject: [PATCH] fix: game end triggers --- RoundsWithFriends/RoundEndHandler.cs | 44 +++++++++++++++++--------- RoundsWithFriends/RoundsWithFriends.cs | 2 +- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/RoundsWithFriends/RoundEndHandler.cs b/RoundsWithFriends/RoundEndHandler.cs index bef325b..1304df6 100644 --- a/RoundsWithFriends/RoundEndHandler.cs +++ b/RoundsWithFriends/RoundEndHandler.cs @@ -88,47 +88,61 @@ private void OnGameOverChoose(string choice) [UnboundRPC] public static void Rematch() + { + RoundEndHandler.instance.StartCoroutine(RoundEndHandler.RematchCoroutine()); + } + + [UnboundRPC] + public static void Continue() { var gm = GameModeManager.CurrentHandler; - if (RoundEndHandler.instance.gmOriginalMaxRounds != -1) + int maxRounds = (int) gm.Settings["roundsToWinGame"]; + + if (RoundEndHandler.instance.gmOriginalMaxRounds == -1) { - gm.ChangeSetting("roundsToWinGame", RoundEndHandler.instance.gmOriginalMaxRounds); - RoundEndHandler.instance.gmOriginalMaxRounds = -1; + RoundEndHandler.instance.gmOriginalMaxRounds = maxRounds; } UIHandler.instance.DisableTexts(1f); - GameManager.instance.isPlaying = false; - gm.GameMode.StopAllCoroutines(); - gm.ResetGame(); - gm.StartGame(); + gm.ChangeSetting("roundsToWinGame", maxRounds + 2); RoundEndHandler.instance.waitingForHost = false; } [UnboundRPC] - public static void Continue() + public static void Exit() { - var gm = GameModeManager.CurrentHandler; + RoundEndHandler.instance.StartCoroutine(RoundEndHandler.ExitCoroutine()); + } - int maxRounds = (int) gm.Settings["roundsToWinGame"]; + private static IEnumerator RematchCoroutine() + { + yield return GameModeManager.TriggerHook(GameModeHooks.HookGameEnd); - if (RoundEndHandler.instance.gmOriginalMaxRounds == -1) + var gm = GameModeManager.CurrentHandler; + + if (RoundEndHandler.instance.gmOriginalMaxRounds != -1) { - RoundEndHandler.instance.gmOriginalMaxRounds = maxRounds; + gm.ChangeSetting("roundsToWinGame", RoundEndHandler.instance.gmOriginalMaxRounds); + RoundEndHandler.instance.gmOriginalMaxRounds = -1; } UIHandler.instance.DisableTexts(1f); - gm.ChangeSetting("roundsToWinGame", maxRounds + 2); + GameManager.instance.isPlaying = false; + gm.GameMode.StopAllCoroutines(); + gm.ResetGame(); + gm.StartGame(); RoundEndHandler.instance.waitingForHost = false; } - [UnboundRPC] - public static void Exit() + private static IEnumerator ExitCoroutine() { + yield return GameModeManager.TriggerHook(GameModeHooks.HookGameEnd); + var gm = GameModeManager.CurrentHandler; if (RoundEndHandler.instance.gmOriginalMaxRounds != -1) diff --git a/RoundsWithFriends/RoundsWithFriends.cs b/RoundsWithFriends/RoundsWithFriends.cs index 57b3276..07dcc18 100644 --- a/RoundsWithFriends/RoundsWithFriends.cs +++ b/RoundsWithFriends/RoundsWithFriends.cs @@ -54,7 +54,7 @@ public static DebugOptions Deserialize(byte[] data) public class RWFMod : BaseUnityPlugin { private const string ModId = "io.olavim.rounds.rwf"; - public const string Version = "1.3.7"; + public const string Version = "1.3.8"; #if DEBUG public static readonly bool DEBUG = true;