From: AlexejheroYTB Date: Thu, 12 Nov 2020 03:07:20 +0000 (+0200) Subject: Add GameOverReason (#129) X-Git-Tag: v1.2.2~24 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=03b0dd4da5472e862522e39c5051a87d14e8556d;p=rhonda%2Fimpostor.git Add GameOverReason (#129) * Add GameOverReason * Remove showAd from deserialization * Update GameEventListener.cs --- diff --git a/src/Impostor.Api/Events/Game/IGameEndedEvent.cs b/src/Impostor.Api/Events/Game/IGameEndedEvent.cs index 215852c..d8ae159 100644 --- a/src/Impostor.Api/Events/Game/IGameEndedEvent.cs +++ b/src/Impostor.Api/Events/Game/IGameEndedEvent.cs @@ -1,6 +1,9 @@ -namespace Impostor.Api.Events +using Impostor.Api.Innersloth; + +namespace Impostor.Api.Events { public interface IGameEndedEvent : IGameEvent { + public GameOverReason GameOverReason { get; } } } diff --git a/src/Impostor.Api/Innersloth/GameOverReason.cs b/src/Impostor.Api/Innersloth/GameOverReason.cs new file mode 100644 index 0000000..6a95d37 --- /dev/null +++ b/src/Impostor.Api/Innersloth/GameOverReason.cs @@ -0,0 +1,15 @@ +namespace Impostor.Api.Innersloth +{ + public enum GameOverReason : byte + { + HumansByVote = 0, + HumansByTask = 1, + ImpostorByVote = 2, + ImpostorByKill = 3, + ImpostorBySabotage = 4, + + // Unused (?) + ImpostorDisconnect = 5, + HumansDisconnect = 6, + } +} \ No newline at end of file diff --git a/src/Impostor.Api/Net/Messages/C2S/Message08EndGameC2S.cs b/src/Impostor.Api/Net/Messages/C2S/Message08EndGameC2S.cs new file mode 100644 index 0000000..7ca5e3a --- /dev/null +++ b/src/Impostor.Api/Net/Messages/C2S/Message08EndGameC2S.cs @@ -0,0 +1,18 @@ +using Impostor.Api.Innersloth; + +namespace Impostor.Api.Net.Messages.C2S +{ + public class Message08EndGameC2S + { + public static void Serialize(IMessageWriter writer) + { + throw new System.NotImplementedException(); + } + + public static void Deserialize(IMessageReader reader, out GameOverReason gameOverReason) + { + gameOverReason = (GameOverReason)reader.ReadByte(); + reader.ReadBoolean(); // showAd + } + } +} \ No newline at end of file diff --git a/src/Impostor.Plugins.Example/Handlers/GameEventListener.cs b/src/Impostor.Plugins.Example/Handlers/GameEventListener.cs index fe06d51..be2d0f3 100644 --- a/src/Impostor.Plugins.Example/Handlers/GameEventListener.cs +++ b/src/Impostor.Plugins.Example/Handlers/GameEventListener.cs @@ -40,6 +40,7 @@ namespace Impostor.Plugins.Example.Handlers public void OnGameEnded(IGameEndedEvent e) { Console.WriteLine("Game > ended"); + Console.WriteLine("- Reason: " + e.GameOverReason); } [EventListener] diff --git a/src/Impostor.Server/Events/Game/GameEndedEvent.cs b/src/Impostor.Server/Events/Game/GameEndedEvent.cs index 621b581..4ec4dcf 100644 --- a/src/Impostor.Server/Events/Game/GameEndedEvent.cs +++ b/src/Impostor.Server/Events/Game/GameEndedEvent.cs @@ -1,15 +1,19 @@ using Impostor.Api.Events; using Impostor.Api.Games; +using Impostor.Api.Innersloth; namespace Impostor.Server.Events { public class GameEndedEvent : IGameEndedEvent { - public GameEndedEvent(IGame game) + public GameEndedEvent(IGame game, GameOverReason gameOverReason) { Game = game; + GameOverReason = gameOverReason; } public IGame Game { get; } + + public GameOverReason GameOverReason { get; } } } diff --git a/src/Impostor.Server/Net/Client.cs b/src/Impostor.Server/Net/Client.cs index 0036cdd..87a1bb4 100644 --- a/src/Impostor.Server/Net/Client.cs +++ b/src/Impostor.Server/Net/Client.cs @@ -193,7 +193,11 @@ namespace Impostor.Server.Net return; } - await Player.Game.HandleEndGame(reader); + Message08EndGameC2S.Deserialize( + reader, + out var gameOverReason); + + await Player.Game.HandleEndGame(reader, gameOverReason); break; } diff --git a/src/Impostor.Server/Net/State/Game.Incoming.cs b/src/Impostor.Server/Net/State/Game.Incoming.cs index 4fcc83b..4bf1c43 100644 --- a/src/Impostor.Server/Net/State/Game.Incoming.cs +++ b/src/Impostor.Server/Net/State/Game.Incoming.cs @@ -111,7 +111,7 @@ namespace Impostor.Server.Net.State return GameJoinResult.CreateSuccess(player); } - public async ValueTask HandleEndGame(IMessageReader message) + public async ValueTask HandleEndGame(IMessageReader message, GameOverReason gameOverReason) { GameState = GameStates.Ended; @@ -128,7 +128,7 @@ namespace Impostor.Server.Net.State player.Value.Limbo = LimboStates.PreSpawn; } - await _eventManager.CallAsync(new GameEndedEvent(this)); + await _eventManager.CallAsync(new GameEndedEvent(this, gameOverReason)); } public async ValueTask HandleAlterGame(IMessageReader message, IClientPlayer sender, bool isPublic)