mirror of
https://github.com/Impostor/Impostor.git
synced 2026-10-19 15:51:42 +00:00
Add enums to set Color/Hat/Pet/Skin
This commit is contained in:
1 parent
dcc4da25de
commit
e308b7e3e6
9 files changed
+272
-13
No files matched your search
@@ -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<ExamplePlugin> 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<ExamplePlugin> _logger;
|
||||
// Add the line below!
|
||||
private readonly IEventManager _eventManager;
|
||||
// Add the line below!
|
||||
private IDisposable _unregister;
|
||||
|
||||
public ExamplePlugin(ILogger<ExamplePlugin> 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
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
/// <returns>Task that must be awaited.</returns>
|
||||
ValueTask SetColorAsync(byte colorId);
|
||||
|
||||
/// <param name="colorType">A color for the player.</param>
|
||||
/// <inheritdoc cref="SetColorAsync(byte)" />
|
||||
ValueTask SetColorAsync(ColorType colorType);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the hat of the current <see cref="IInnerPlayerControl"/>.
|
||||
/// Visible to all players.
|
||||
@@ -34,22 +39,34 @@ namespace Impostor.Api.Net.Inner.Objects
|
||||
/// <returns>Task that must be awaited.</returns>
|
||||
ValueTask SetHatAsync(uint hatId);
|
||||
|
||||
/// <param name="hatType">An hat for the player.</param>
|
||||
/// <inheritdoc cref="SetHatAsync(uint)" />
|
||||
ValueTask SetHatAsync(HatType hatType);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the pet of the current <see cref="IInnerPlayerControl"/>.
|
||||
/// Visible to all players.
|
||||
/// </summary>
|
||||
/// <param name="petId">An hat for the player.</param>
|
||||
/// <param name="petId">A pet for the player.</param>
|
||||
/// <returns>Task that must be awaited.</returns>
|
||||
ValueTask SetPetAsync(uint petId);
|
||||
|
||||
/// <param name="petType">A pet for the player.</param>
|
||||
/// <inheritdoc cref="SetPetAsync(uint)" />
|
||||
ValueTask SetPetAsync(PetType petType);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the skin of the current <see cref="IInnerPlayerControl"/>.
|
||||
/// Visible to all players.
|
||||
/// </summary>
|
||||
/// <param name="skinId">An hat for the player.</param>
|
||||
/// <param name="skinId">A skin for the player.</param>
|
||||
/// <returns>Task that must be awaited.</returns>
|
||||
ValueTask SetSkinAsync(uint skinId);
|
||||
|
||||
/// <param name="skinType">A skin for the player.</param>
|
||||
/// <inheritdoc cref="SetSkinAsync(uint)" />
|
||||
ValueTask SetSkinAsync(SkinType skinType);
|
||||
|
||||
/// <summary>
|
||||
/// Send a chat message as the current <see cref="IInnerPlayerControl"/>.
|
||||
/// Visible to all players.
|
||||
|
||||
@@ -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<ExamplePlugin> _logger;
|
||||
private readonly IEventManager _eventManager;
|
||||
private IDisposable[] _cancel;
|
||||
|
||||
public ExamplePlugin(ILogger<ExamplePlugin> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user