]> git.deb.at Git - rhonda/impostor.git/commitdiff
Add IInnerPlayerControl#ExileAsync (#271)
authorMinorusama <pitilulu@gmail.com>
Tue, 23 Mar 2021 20:12:39 +0000 (21:12 +0100)
committerGitHub <noreply@github.com>
Tue, 23 Mar 2021 20:12:39 +0000 (20:12 +0000)
src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs
src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs

index c0ecf855d56eeef91144c7d13c456825202da16e..0ee065ad8edd3403f1e7c1c11769850865526ae0 100644 (file)
@@ -98,5 +98,12 @@ namespace Impostor.Api.Net.Inner.Objects
         /// <exception cref="ImpostorProtocolException">Thrown when target is dead.</exception>
         /// <returns>Task that must be awaited.</returns>
         ValueTask MurderPlayerAsync(IInnerPlayerControl target);
+
+        /// <summary>
+        ///     Exile the current player. This doesn't produce a body to be reported.
+        ///     Visible to all players.
+        /// </summary>
+        /// <returns>Task that must be awaited.</returns>
+        ValueTask ExileAsync();
     }
 }
index 07c21267cef632a4b648f4c39a6cc13d0ed19c69..e55f07920050ce696286ed39f00eabb74e80e5a1 100644 (file)
@@ -106,5 +106,24 @@ namespace Impostor.Server.Net.Inner.Objects
 
             await _eventManager.CallAsync(new PlayerMurderEvent(_game, _game.GetClientPlayer(OwnerId), this, target));
         }
+
+        public async ValueTask ExileAsync()
+        {
+            if (PlayerInfo.IsDead)
+            {
+                throw new ImpostorProtocolException("Tried to exile a player, but target was not alive.");
+            }
+
+            // Update player.
+            Die(DeathReason.Exile);
+
+            // Send RPC.
+            using var writer = _game.StartRpc(NetId, RpcCalls.Exiled);
+            Rpc04Exiled.Serialize(writer);
+            await _game.FinishRpcAsync(writer);
+
+            // Notify plugins.
+            await _eventManager.CallAsync(new PlayerExileEvent(_game, _game.GetClientPlayer(OwnerId), this));
+        }
     }
 }