]> git.deb.at Git - rhonda/impostor.git/commitdiff
Implement cosmetic rpc methods
authorjs6pak <kubastaron@hotmail.com>
Wed, 15 Dec 2021 13:55:48 +0000 (14:55 +0100)
committerjs6pak <kubastaron@hotmail.com>
Wed, 15 Dec 2021 14:22:18 +0000 (15:22 +0100)
src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs
src/Impostor.Plugins.Example/Handlers/PlayerEventListener.cs
src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs

index 62beee00aad45f7b962be6a8a21951fc8e23bbc6..471eaf8ffe9350145293d312c4105a258a91f3e2 100644 (file)
@@ -45,29 +45,29 @@ namespace Impostor.Api.Net.Inner.Objects
         /// <returns>Task that must be awaited.</returns>
         ValueTask SetColorAsync(ColorType colorType);
 
-        // /// <summary>
-        // ///     Sets the hat of the current <see cref="IInnerPlayerControl" />.
-        // ///     Visible to all players.
-        // /// </summary>
-        // /// <param name="hatId">An hat for the player.</param>
-        // /// <returns>Task that must be awaited.</returns>
-        // ValueTask SetHatAsync(string hatId);
-        //
-        // /// <summary>
-        // ///     Sets the pet of the current <see cref="IInnerPlayerControl" />.
-        // ///     Visible to all players.
-        // /// </summary>
-        // /// <param name="petId">A pet for the player.</param>
-        // /// <returns>Task that must be awaited.</returns>
-        // ValueTask SetPetAsync(string petId);
-        //
-        // /// <summary>
-        // ///     Sets the skin of the current <see cref="IInnerPlayerControl" />.
-        // ///     Visible to all players.
-        // /// </summary>
-        // /// <param name="skinId">A skin for the player.</param>
-        // /// <returns>Task that must be awaited.</returns>
-        // ValueTask SetSkinAsync(string skinId);
+        /// <summary>
+        ///     Sets the hat of the current <see cref="IInnerPlayerControl" />.
+        ///     Visible to all players.
+        /// </summary>
+        /// <param name="hatId">An hat for the player.</param>
+        /// <returns>Task that must be awaited.</returns>
+        ValueTask SetHatAsync(string hatId);
+
+        /// <summary>
+        ///     Sets the pet of the current <see cref="IInnerPlayerControl" />.
+        ///     Visible to all players.
+        /// </summary>
+        /// <param name="petId">A pet for the player.</param>
+        /// <returns>Task that must be awaited.</returns>
+        ValueTask SetPetAsync(string petId);
+
+        /// <summary>
+        ///     Sets the skin of the current <see cref="IInnerPlayerControl" />.
+        ///     Visible to all players.
+        /// </summary>
+        /// <param name="skinId">A skin for the player.</param>
+        /// <returns>Task that must be awaited.</returns>
+        ValueTask SetSkinAsync(string skinId);
 
         /// <summary>
         ///     Send a chat message as the current <see cref="IInnerPlayerControl" />.
index 986b220fbf732d2e8e35697a5009000542473fda..cdadd8862c1f543147de64b6b0c8eec99df15023 100644 (file)
@@ -40,9 +40,10 @@ namespace Impostor.Plugins.Example.Handlers
                 {
                     // Modify player properties.
                     await playerControl.SetColorAsync((ColorType)_random.Next(1, 9));
-                    await playerControl.SetHatAsync((HatType)_random.Next(1, 9));
-                    await playerControl.SetSkinAsync((SkinType)_random.Next(1, 9));
-                    await playerControl.SetPetAsync((PetType)_random.Next(1, 9));
+                    // TODO Rewrite using cosmetics source generator
+                    // await playerControl.SetHatAsync((HatType)_random.Next(1, 9));
+                    // await playerControl.SetSkinAsync((SkinType)_random.Next(1, 9));
+                    // await playerControl.SetPetAsync((PetType)_random.Next(1, 9));
 
                     await Task.Delay(TimeSpan.FromMilliseconds(5000));
                 }
@@ -74,9 +75,9 @@ namespace Impostor.Plugins.Example.Handlers
             if (e.Message == "look")
             {
                 await e.PlayerControl.SetColorAsync(ColorType.Pink);
-                await e.PlayerControl.SetHatAsync(HatType.Cheese);
-                await e.PlayerControl.SetSkinAsync(SkinType.Police);
-                await e.PlayerControl.SetPetAsync(PetType.Ufo);
+                await e.PlayerControl.SetHatAsync("hat_pk05_Cheese");
+                await e.PlayerControl.SetSkinAsync("skin_Police");
+                await e.PlayerControl.SetPetAsync("pet_alien1");
             }
 
             if (e.Message == "snap")
index c2fb8cec934d0d618eeb4001392d3fe5b56397df..cb073ff2cd6f2e234a88264608d88b297ffc5d43 100644 (file)
@@ -36,6 +36,33 @@ namespace Impostor.Server.Net.Inner.Objects
             await Game.FinishRpcAsync(writer);
         }
 
+        public async ValueTask SetHatAsync(string hatId)
+        {
+            PlayerInfo.CurrentOutfit.HatId = hatId;
+
+            using var writer = Game.StartRpc(NetId, RpcCalls.SetHat);
+            Rpc39SetHat.Serialize(writer, hatId);
+            await Game.FinishRpcAsync(writer);
+        }
+
+        public async ValueTask SetPetAsync(string petId)
+        {
+            PlayerInfo.CurrentOutfit.PetId = petId;
+
+            using var writer = Game.StartRpc(NetId, RpcCalls.SetPet);
+            Rpc41SetPet.Serialize(writer, petId);
+            await Game.FinishRpcAsync(writer);
+        }
+
+        public async ValueTask SetSkinAsync(string skinId)
+        {
+            PlayerInfo.CurrentOutfit.SkinId = skinId;
+
+            using var writer = Game.StartRpc(NetId, RpcCalls.SetSkin);
+            Rpc40SetSkin.Serialize(writer, skinId);
+            await Game.FinishRpcAsync(writer);
+        }
+
         public async ValueTask SendChatAsync(string text)
         {
             using var writer = Game.StartRpc(NetId, RpcCalls.SendChat);