From e15ac51dcf3af6514b7f1663148e5745c3e7c2c0 Mon Sep 17 00:00:00 2001 From: js6pak Date: Wed, 15 Dec 2021 14:55:48 +0100 Subject: [PATCH] Implement cosmetic rpc methods --- .../Net/Inner/Objects/IInnerPlayerControl.cs | 46 +++++++++---------- .../Handlers/PlayerEventListener.cs | 13 +++--- .../Inner/Objects/InnerPlayerControl.Api.cs | 27 +++++++++++ 3 files changed, 57 insertions(+), 29 deletions(-) diff --git a/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs b/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs index 62beee0..471eaf8 100644 --- a/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs +++ b/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs @@ -45,29 +45,29 @@ namespace Impostor.Api.Net.Inner.Objects /// Task that must be awaited. ValueTask SetColorAsync(ColorType colorType); - // /// - // /// Sets the hat of the current . - // /// Visible to all players. - // /// - // /// An hat for the player. - // /// Task that must be awaited. - // ValueTask SetHatAsync(string hatId); - // - // /// - // /// Sets the pet of the current . - // /// Visible to all players. - // /// - // /// A pet for the player. - // /// Task that must be awaited. - // ValueTask SetPetAsync(string petId); - // - // /// - // /// Sets the skin of the current . - // /// Visible to all players. - // /// - // /// A skin for the player. - // /// Task that must be awaited. - // ValueTask SetSkinAsync(string skinId); + /// + /// Sets the hat of the current . + /// Visible to all players. + /// + /// An hat for the player. + /// Task that must be awaited. + ValueTask SetHatAsync(string hatId); + + /// + /// Sets the pet of the current . + /// Visible to all players. + /// + /// A pet for the player. + /// Task that must be awaited. + ValueTask SetPetAsync(string petId); + + /// + /// Sets the skin of the current . + /// Visible to all players. + /// + /// A skin for the player. + /// Task that must be awaited. + ValueTask SetSkinAsync(string skinId); /// /// Send a chat message as the current . diff --git a/src/Impostor.Plugins.Example/Handlers/PlayerEventListener.cs b/src/Impostor.Plugins.Example/Handlers/PlayerEventListener.cs index 986b220..cdadd88 100644 --- a/src/Impostor.Plugins.Example/Handlers/PlayerEventListener.cs +++ b/src/Impostor.Plugins.Example/Handlers/PlayerEventListener.cs @@ -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") diff --git a/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs b/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs index c2fb8ce..cb073ff 100644 --- a/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs +++ b/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs @@ -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); -- 2.39.5