From e308b7e3e67a7f983652af03afad79090433fb02 Mon Sep 17 00:00:00 2001 From: AeonLucid Date: Tue, 27 Oct 2020 01:28:28 +0100 Subject: [PATCH] Add enums to set Color/Hat/Pet/Skin --- docs/Writing-a-plugin.md | 49 ++++++++- .../Innersloth/Customization/ColorType.cs | 18 ++++ .../Innersloth/Customization/HatType.cs | 100 ++++++++++++++++++ .../Innersloth/Customization/PetType.cs | 17 +++ .../Innersloth/Customization/SkinType.cs | 22 ++++ .../Net/Inner/Objects/IInnerPlayerControl.cs | 21 +++- src/Impostor.Plugins.Example/ExamplePlugin.cs | 26 +++-- .../Handlers/PlayerEventListener.cs | 11 +- .../Inner/Objects/InnerPlayerControl.Api.cs | 21 ++++ 9 files changed, 272 insertions(+), 13 deletions(-) create mode 100644 src/Impostor.Api/Innersloth/Customization/ColorType.cs create mode 100644 src/Impostor.Api/Innersloth/Customization/HatType.cs create mode 100644 src/Impostor.Api/Innersloth/Customization/PetType.cs create mode 100644 src/Impostor.Api/Innersloth/Customization/SkinType.cs diff --git a/docs/Writing-a-plugin.md b/docs/Writing-a-plugin.md index 0cfdb26..a7ad21b 100644 --- a/docs/Writing-a-plugin.md +++ b/docs/Writing-a-plugin.md @@ -217,12 +217,53 @@ namespace Impostor.Plugins.Example.Handlers The last step to get your plugin working is to register the event listener, so the server knows about it. Go back to your plugin class and modify it as below. ```csharp -public ExamplePlugin(ILogger logger, IEventManager eventManager) +using System; +using System.Threading.Tasks; +using Impostor.Api.Events.Managers; +using Impostor.Api.Plugins; +using Impostor.Plugins.Example.Handlers; +using Microsoft.Extensions.Logging; + +namespace Impostor.Plugins.Example { - _logger = logger; - // Add this line! - eventManager.RegisterListener(new GameEventListener(logger)); + [ImpostorPlugin( + package: "gg.impostor.example", + name: "Example", + author: "AeonLucid", + version: "1.0.0")] + public class ExamplePlugin : PluginBase + { + private readonly ILogger _logger; + // Add the line below! + private readonly IEventManager _eventManager; + // Add the line below! + private IDisposable _unregister; + + public ExamplePlugin(ILogger logger, IEventManager eventManager) + { + _logger = logger; + // Add the line below! + _eventManager = eventManager; + } + + public override ValueTask EnableAsync() + { + _logger.LogInformation("Example is being enabled."); + // Add the line below! + _unregister = _eventManager.RegisterListener(new GameEventListener(_logger)); + return default; + } + + public override ValueTask DisableAsync() + { + _logger.LogInformation("Example is being disabled."); + // Add the line below! + _unregister.Dispose(); + return default; + } + } } + ``` ## 7. Build and run your plugin diff --git a/src/Impostor.Api/Innersloth/Customization/ColorType.cs b/src/Impostor.Api/Innersloth/Customization/ColorType.cs new file mode 100644 index 0000000..fc7be4c --- /dev/null +++ b/src/Impostor.Api/Innersloth/Customization/ColorType.cs @@ -0,0 +1,18 @@ +namespace Impostor.Api.Innersloth.Customization +{ + public enum ColorType : byte + { + Red = 0, + Blue = 1, + Green = 2, + Pink = 3, + Orange = 4, + Yellow = 5, + Black = 6, + White = 7, + Purple = 8, + Brown = 9, + Cyan = 10, + Lime = 11, + } +} diff --git a/src/Impostor.Api/Innersloth/Customization/HatType.cs b/src/Impostor.Api/Innersloth/Customization/HatType.cs new file mode 100644 index 0000000..5e0a3ef --- /dev/null +++ b/src/Impostor.Api/Innersloth/Customization/HatType.cs @@ -0,0 +1,100 @@ +namespace Impostor.Api.Innersloth.Customization +{ + public enum HatType + { + NoHat = 0, + Astronaut = 1, + BaseballCap = 2, + BrainSlug = 3, + BushHat = 4, + CaptainsHat = 5, + DoubleTopHat = 6, + Flowerpot = 7, + Goggles = 8, + HardHat = 9, + Military = 10, + PaperHat = 11, + PartyHat = 12, + Police = 13, + Stethescope = 14, + TopHat = 15, + TowelWizard = 16, + Ushanka = 17, + Viking = 18, + WallCap = 19, + Snowman = 20, + Reindeer = 21, + Lights = 22, + Santa = 23, + Tree = 24, + Present = 25, + Candycanes = 26, + ElfHat = 27, + NewYears2018 = 28, + WhiteHat = 29, + Crown = 30, + Eyebrows = 31, + HaloHat = 32, + HeroCap = 33, + PipCap = 34, + PlungerHat = 35, + ScubaHat = 36, + StickminHat = 37, + StrawHat = 38, + TenGallonHat = 39, + ThirdEyeHat = 40, + ToiletPaperHat = 41, + Toppat = 42, + Fedora = 43, + Goggles2 = 44, + Headphones = 45, + MaskHat = 46, + PaperMask = 47, + Security = 48, + StrapHat = 49, + Banana = 50, + Beanie = 51, + Bear = 52, + Cheese = 53, + Cherry = 54, + Egg = 55, + Fedora2 = 56, + Flamingo = 57, + FlowerPin = 58, + Helmet = 59, + Plant = 60, + BatEyes = 61, + BatWings = 62, + Horns = 63, + Mohawk = 64, + Pumpkin = 65, + ScaryBag = 66, + Witch = 67, + Wolf = 68, + Pirate = 69, + Plague = 70, + Machete = 71, + Fred = 72, + MinerCap = 73, + WinterHat = 74, + Archae = 75, + Antenna = 76, + Balloon = 77, + BirdNest = 78, + BlackBelt = 79, + Caution = 80, + Chef = 81, + CopHat = 82, + DoRag = 83, + DumSticker = 84, + Fez = 85, + GeneralHat = 86, + GreyThing = 87, + HunterCap = 88, + JungleHat = 89, + MiniCrewmate = 90, + NinjaMask = 91, + RamHorns = 92, + Snowman2 = 93, + } +} diff --git a/src/Impostor.Api/Innersloth/Customization/PetType.cs b/src/Impostor.Api/Innersloth/Customization/PetType.cs new file mode 100644 index 0000000..ec6a314 --- /dev/null +++ b/src/Impostor.Api/Innersloth/Customization/PetType.cs @@ -0,0 +1,17 @@ +namespace Impostor.Api.Innersloth.Customization +{ + public enum PetType + { + NoPet = 0, + Alien = 1, + Crewmate = 2, + Doggy = 3, + Stickmin = 4, + Hamster = 5, + Robot = 6, + Ufo = 7, + Ellie = 8, + Squig = 9, + Bedcrab = 10, + } +} diff --git a/src/Impostor.Api/Innersloth/Customization/SkinType.cs b/src/Impostor.Api/Innersloth/Customization/SkinType.cs new file mode 100644 index 0000000..35da312 --- /dev/null +++ b/src/Impostor.Api/Innersloth/Customization/SkinType.cs @@ -0,0 +1,22 @@ +namespace Impostor.Api.Innersloth.Customization +{ + public enum SkinType : byte + { + None = 0, + Astro = 1, + Capt = 2, + Mech = 3, + Military = 4, + Police = 5, + Science = 6, + SuitB = 7, + SuitW = 8, + Wall = 9, + Hazmat = 10, + Security = 11, + Tarmac = 12, + Miner = 13, + Winter = 14, + Archae = 15, + } +} diff --git a/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs b/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs index e862147..cc24b31 100644 --- a/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs +++ b/src/Impostor.Api/Net/Inner/Objects/IInnerPlayerControl.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using Impostor.Api.Innersloth.Customization; namespace Impostor.Api.Net.Inner.Objects { @@ -26,6 +27,10 @@ namespace Impostor.Api.Net.Inner.Objects /// Task that must be awaited. ValueTask SetColorAsync(byte colorId); + /// A color for the player. + /// + ValueTask SetColorAsync(ColorType colorType); + /// /// Sets the hat of the current . /// Visible to all players. @@ -34,22 +39,34 @@ namespace Impostor.Api.Net.Inner.Objects /// Task that must be awaited. ValueTask SetHatAsync(uint hatId); + /// An hat for the player. + /// + ValueTask SetHatAsync(HatType hatType); + /// /// Sets the pet of the current . /// Visible to all players. /// - /// An hat for the player. + /// A pet for the player. /// Task that must be awaited. ValueTask SetPetAsync(uint petId); + /// A pet for the player. + /// + ValueTask SetPetAsync(PetType petType); + /// /// Sets the skin of the current . /// Visible to all players. /// - /// An hat for the player. + /// A skin for the player. /// Task that must be awaited. ValueTask SetSkinAsync(uint skinId); + /// A skin for the player. + /// + ValueTask SetSkinAsync(SkinType skinType); + /// /// Send a chat message as the current . /// Visible to all players. diff --git a/src/Impostor.Plugins.Example/ExamplePlugin.cs b/src/Impostor.Plugins.Example/ExamplePlugin.cs index 1482cd3..cd6313c 100644 --- a/src/Impostor.Plugins.Example/ExamplePlugin.cs +++ b/src/Impostor.Plugins.Example/ExamplePlugin.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using Impostor.Api.Events.Managers; using Impostor.Api.Plugins; using Impostor.Plugins.Example.Handlers; @@ -14,26 +15,39 @@ namespace Impostor.Plugins.Example public class ExamplePlugin : PluginBase { private readonly ILogger _logger; + private readonly IEventManager _eventManager; + private IDisposable[] _cancel; public ExamplePlugin(ILogger logger, IEventManager eventManager) { _logger = logger; - - eventManager.RegisterListener(new GameEventListener()); - eventManager.RegisterListener(new PlayerEventListener()); - eventManager.RegisterListener(new MeetingEventListener()); + _eventManager = eventManager; } public override ValueTask EnableAsync() { _logger.LogInformation("Example is being enabled."); + + _cancel = new[] + { + _eventManager.RegisterListener(new GameEventListener()), + _eventManager.RegisterListener(new PlayerEventListener()), + _eventManager.RegisterListener(new MeetingEventListener()) + }; + return default; } public override ValueTask DisableAsync() { _logger.LogInformation("Example is being disabled."); + + foreach (var c in _cancel) + { + c.Dispose(); + } + return default; } } -} \ No newline at end of file +} diff --git a/src/Impostor.Plugins.Example/Handlers/PlayerEventListener.cs b/src/Impostor.Plugins.Example/Handlers/PlayerEventListener.cs index f3b8dfb..31a66b6 100644 --- a/src/Impostor.Plugins.Example/Handlers/PlayerEventListener.cs +++ b/src/Impostor.Plugins.Example/Handlers/PlayerEventListener.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Impostor.Api.Events; using Impostor.Api.Events.Player; +using Impostor.Api.Innersloth.Customization; namespace Impostor.Plugins.Example.Handlers { @@ -35,7 +36,7 @@ namespace Impostor.Plugins.Example.Handlers await playerControl.SetSkinAsync((uint) Random.Next(1, 9)); await playerControl.SetPetAsync((uint) Random.Next(1, 9)); - await Task.Delay(TimeSpan.FromMilliseconds(500)); + await Task.Delay(TimeSpan.FromMilliseconds(5000)); } Console.WriteLine("Stopping player task."); @@ -62,6 +63,14 @@ namespace Impostor.Plugins.Example.Handlers await e.Game.SyncSettingsAsync(); } + 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.SetNameAsync(e.Message); await e.PlayerControl.SendChatAsync(e.Message); } diff --git a/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs b/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs index d3e8d80..4431c1f 100644 --- a/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs +++ b/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.Api.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using Impostor.Api.Innersloth.Customization; using Impostor.Api.Net.Inner.Objects; namespace Impostor.Server.Net.Inner.Objects @@ -25,6 +26,11 @@ namespace Impostor.Server.Net.Inner.Objects await _game.FinishRpcAsync(writer); } + public ValueTask SetColorAsync(ColorType colorType) + { + return SetColorAsync((byte)colorType); + } + public async ValueTask SetHatAsync(uint hatId) { PlayerInfo.HatId = hatId; @@ -34,6 +40,11 @@ namespace Impostor.Server.Net.Inner.Objects await _game.FinishRpcAsync(writer); } + public ValueTask SetHatAsync(HatType hatType) + { + return SetHatAsync((uint)hatType); + } + public async ValueTask SetPetAsync(uint petId) { PlayerInfo.PetId = petId; @@ -43,6 +54,11 @@ namespace Impostor.Server.Net.Inner.Objects await _game.FinishRpcAsync(writer); } + public ValueTask SetPetAsync(PetType petType) + { + return SetPetAsync((uint)petType); + } + public async ValueTask SetSkinAsync(uint skinId) { PlayerInfo.SkinId = skinId; @@ -52,6 +68,11 @@ namespace Impostor.Server.Net.Inner.Objects await _game.FinishRpcAsync(writer); } + public ValueTask SetSkinAsync(SkinType skinType) + { + return SetSkinAsync((uint)skinType); + } + public async ValueTask SendChatAsync(string text) { using var writer = _game.StartRpc(NetId, RpcCalls.SendChat); -- 2.39.5