do a lot ig
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
using CommandSystem;
|
||||
using LabApi.Features.Permissions;
|
||||
using LabApi.Features.Wrappers;
|
||||
using UnityEngine;
|
||||
using MEC;
|
||||
|
||||
namespace VIPTreatment;
|
||||
|
||||
[CommandHandler(typeof(RemoteAdminCommandHandler))]
|
||||
[CommandHandler(typeof(ClientCommandHandler))]
|
||||
public class ColorCommand : ICommand
|
||||
{
|
||||
public string Command => "color";
|
||||
|
||||
public string[] Aliases => ["setcolor"];
|
||||
|
||||
public string Description => "Changes the color of room lights. Use 'rgbcolor' for rainbow effect";
|
||||
|
||||
private static CoroutineHandle _rgbCoroutine;
|
||||
|
||||
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
|
||||
{
|
||||
var colorArg = arguments.Count > 0 ? arguments.At(0).ToLower() : "red";
|
||||
|
||||
if (!Player.TryGet(sender, out var player))
|
||||
{
|
||||
response = "You must be a player to use this command!";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!player.HasPermissions("viptreatment.color") && player.UserId != "76561198372587687@steam")
|
||||
{
|
||||
response = "You must have the permission to use this command!";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (VIPTreatment.Instance.HasChangedColor)
|
||||
{
|
||||
response = "Die Farben wurden diese Runde bereits geändert.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (colorArg == "rgbcolor")
|
||||
{
|
||||
Timing.KillCoroutines(_rgbCoroutine);
|
||||
_rgbCoroutine = Timing.RunCoroutine(RgbColorCoroutine());
|
||||
response = "Started RGB color cycle";
|
||||
return true;
|
||||
}
|
||||
|
||||
// Stop RGB effect if it's running and another color is selected
|
||||
Timing.KillCoroutines(_rgbCoroutine);
|
||||
|
||||
var newColor = colorArg switch
|
||||
{
|
||||
"blue" => Color.blue,
|
||||
"green" => Color.green,
|
||||
"yellow" => Color.yellow,
|
||||
"white" => Color.white,
|
||||
"magenta" => Color.magenta,
|
||||
_ => Color.red,
|
||||
};
|
||||
|
||||
SetLightsColor(newColor);
|
||||
|
||||
VIPTreatment.Instance.HasChangedColor = true;
|
||||
|
||||
Timing.CallDelayed(60f, () =>
|
||||
{
|
||||
SetLightsColor(Color.clear);
|
||||
});
|
||||
|
||||
response = $"Changed lights color to {colorArg}";
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IEnumerator<float> RgbColorCoroutine()
|
||||
{
|
||||
var h = 0f;
|
||||
Timing.CallDelayed(30f, () =>
|
||||
{
|
||||
Timing.KillCoroutines(_rgbCoroutine);
|
||||
SetLightsColor(Color.clear);
|
||||
});
|
||||
while (true)
|
||||
{
|
||||
var rgbColor = Color.HSVToRGB(h, 1f, 1f);
|
||||
SetLightsColor(rgbColor);
|
||||
|
||||
h += 0.01f;
|
||||
if (h > 1f)
|
||||
h = 0f;
|
||||
|
||||
yield return Timing.WaitForSeconds(0.1f);
|
||||
}
|
||||
// ReSharper disable once IteratorNeverReturns
|
||||
}
|
||||
|
||||
private static void SetLightsColor(Color color)
|
||||
{
|
||||
foreach (var lightsController in Map.RoomLights)
|
||||
{
|
||||
lightsController.OverrideLightsColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user