]> git.deb.at Git - rhonda/impostor.git/commitdiff
Fix set murdered (#192)
authorZiad Montaser <62536773+ZiadMontaser@users.noreply.github.com>
Mon, 30 Nov 2020 19:41:46 +0000 (23:41 +0400)
committerGitHub <noreply@github.com>
Mon, 30 Nov 2020 19:41:46 +0000 (20:41 +0100)
Co-authored-by: Ziad Montaser <ZiadMontaser@users.noreply.github.com>
Co-authored-by: AeonLucid <aeonlucid@outlook.com>
src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs
src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs

index 4109509c1ad6de67a4c516384c2402c854b705fb..04558b96e5c1e18968d6be22d8f8bdd455d1e50c 100644 (file)
@@ -106,10 +106,11 @@ namespace Impostor.Api.Net.Inner.Objects
         ValueTask SendChatToPlayerAsync(string text, IInnerPlayerControl? player = null);
 
         /// <summary>
-        ///     Sets the current to be murdered <see cref="IInnerPlayerControl"/>.
+        ///     Sets the current to be murdered by an impostor <see cref="IInnerPlayerControl"/>.
         ///     Visible to all players.
         /// </summary>
+        /// /// <param name="impostor">The Impostor who kill.</param>
         /// <returns>Task that must be awaited.</returns>
-        ValueTask SetMurderedAsync();
+        ValueTask SetMurderedByAsync(IClientPlayer impostor);
     }
 }
index 49076bfc3d9ec9bc997f2ad7cb46aadf886d1ee5..0a7997d5c7149e8035015e0f50b874c1a3db8c43 100644 (file)
@@ -1,7 +1,11 @@
 using System.Threading.Tasks;
+using Impostor.Api;
+using Impostor.Api.Innersloth;
 using Impostor.Api.Innersloth.Customization;
+using Impostor.Api.Net;
 using Impostor.Api.Net.Inner.Objects;
 using Impostor.Api.Net.Inner.Objects.Components;
+using Impostor.Server.Events.Player;
 
 namespace Impostor.Server.Net.Inner.Objects
 {
@@ -97,11 +101,38 @@ namespace Impostor.Server.Net.Inner.Objects
             await _game.FinishRpcAsync(writer, player.OwnerId);
         }
 
-        public async ValueTask SetMurderedAsync()
+        public async ValueTask SetMurderedByAsync(IClientPlayer impostor)
         {
-            using var writer = _game.StartRpc(NetId, RpcCalls.MurderPlayer);
-            writer.Write((byte)NetId);
+            if (impostor.Character == null)
+            {
+                throw new ImpostorException("Character is null.");
+            }
+
+            if (!impostor.Character.PlayerInfo.IsImpostor)
+            {
+                throw new ImpostorProtocolException("Plugin tried to murder a player while the impostor specified was not an impostor.");
+            }
+
+            if (impostor.Character.PlayerInfo.IsDead)
+            {
+                throw new ImpostorProtocolException("Plugin tried to murder a player while the impostor specified was dead.");
+            }
+
+            if (PlayerInfo.IsDead)
+            {
+                return;
+            }
+
+            // Update player.
+            Die(DeathReason.Kill);
+
+            // Send RPC.
+            using var writer = _game.StartRpc(impostor.Character.NetId, RpcCalls.MurderPlayer);
+            writer.WritePacked(NetId);
             await _game.FinishRpcAsync(writer);
+
+            // Notify plugins.
+            await _eventManager.CallAsync(new PlayerMurderEvent(_game, impostor, impostor.Character, this));
         }
     }
 }