From bc929c1223501baa9d102c60038c5b584fefbfca Mon Sep 17 00:00:00 2001 From: Mikhail Reznichenko Date: Sat, 27 Jul 2024 11:36:17 +0300 Subject: [PATCH] Added ChaosMode + some useful extensions --- Commands/ChaosMode.cs | 124 +++++++++++++++++++++++++++++++++++++++ Commands/PluginEnable.cs | 10 ++++ Handlers/Server.cs | 3 + VeryUsualDay.cs | 54 ++++++++++++++++- VeryUsualDay.csproj | 1 + 5 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 Commands/ChaosMode.cs diff --git a/Commands/ChaosMode.cs b/Commands/ChaosMode.cs new file mode 100644 index 0000000..b36e583 --- /dev/null +++ b/Commands/ChaosMode.cs @@ -0,0 +1,124 @@ +using System; +using System.Linq; +using CommandSystem; +using Exiled.API.Enums; +using Exiled.API.Features; +using UnityEngine; + +namespace VeryUsualDay.Commands +{ + [CommandHandler(typeof(RemoteAdminCommandHandler))] + public class ChaosMode : ICommand + { + public string Command => "chaosmode"; + public string[] Aliases => new string[] { }; + public string Description => "Для FX. Включает режим хаоса для конкретной комнаты / для всего комплекса."; + public bool SanitizeResponse => false; + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + if (!VeryUsualDay.Instance.IsEnabledInRound) + { + response = "Режим FX не включён."; + return false; + } + if (arguments.Count < 1) + { + response = "Использование: chaosmode [комнаты через пробел / all]"; + return false; + } + var args = arguments.ToArray(); + if (args[0].In("list", "l")) + { + response = "Список комнат:\n"; + foreach (var door in Room.List) + { + if (door.Zone != ZoneType.Unspecified) + { + response += "\n" + door.Name; + } + } + return true; + } + + if (args[0].In("set", "s")) + { + if (arguments.Count < 2) + { + response = "Использование: chaosmode set <комнаты через пробел / all>"; + return false; + } + + foreach (var roomName in args.Skip(1)) + { + if (roomName == "all" && arguments.Count == 2) + { + foreach (var room in Room.List.Where(p => p.Zone != ZoneType.Unspecified)) + { + room.Color = Color.red; + if (!room.Type.In(VeryUsualDay.Instance.ChaosRooms.ToArray())) + { + VeryUsualDay.Instance.ChaosRooms.Add(room.Type); + } + } + } + else + { + var rooms = Room.Get(p => p.Name == roomName).ToArray(); + if (!rooms.Any()) + { + response = "Использование: chaosmode set <комнаты через пробел / all>. Список комнат - chaosmode list."; + return false; + } + rooms[0].Color = Color.red; + if (!rooms[0].Type.In(VeryUsualDay.Instance.ChaosRooms.ToArray())) + { + VeryUsualDay.Instance.ChaosRooms.Add(rooms[0].Type); + } + } + } + + response = "Комнаты успешно назначены на ChaosMode."; + return true; + } + + if (args[0].In("unset", "u")) + { + if (arguments.Count < 2) + { + response = "Использование: chaosmode unset <комнаты через пробел / all>"; + return false; + } + + foreach (var roomName in args.Skip(1)) + { + if (roomName == "all" && arguments.Count == 2) + { + foreach (var room in Room.List.Where(p => p.Zone != ZoneType.Unspecified)) + { + room.ResetColor(); + VeryUsualDay.Instance.ChaosRooms.Clear(); + } + } + else + { + var rooms = Room.Get(p => p.Name == roomName).ToArray(); + if (!rooms.Any()) + { + response = "Использование: chaosmode unset <комнаты через пробел / all>. Список комнат - chaosmode list."; + return false; + } + rooms[0].ResetColor(); + VeryUsualDay.Instance.ChaosRooms.Remove(rooms[0].Type); + } + } + + response = "Комнаты успешно убраны из ChaosMode."; + return true; + } + + response = "Использование: chaosmode [комнаты через пробел / all]"; + return false; + } + } +} \ No newline at end of file diff --git a/Commands/PluginEnable.cs b/Commands/PluginEnable.cs index 0737c7c..40af29c 100644 --- a/Commands/PluginEnable.cs +++ b/Commands/PluginEnable.cs @@ -33,9 +33,11 @@ public bool Execute(ArraySegment arguments, ICommandSender sender, out s VeryUsualDay.Instance.ScpPlayers.Clear(); VeryUsualDay.Instance.JoinedDboys.Clear(); VeryUsualDay.Instance.DBoysQueue.Clear(); + VeryUsualDay.Instance.ChaosRooms.Clear(); // Timing.KillCoroutines("_avel"); Timing.KillCoroutines("_joining"); Timing.KillCoroutines("_prisonTimer"); + Timing.KillCoroutines("_chaos"); foreach (var player in Player.List) { if (player.TryGetSessionVariable("isInPrison", out bool prisonState) && prisonState) @@ -63,6 +65,14 @@ public bool Execute(ArraySegment arguments, ICommandSender sender, out s // Timing.RunCoroutine(VeryUsualDay.Instance._avel(), "_avel"); Timing.RunCoroutine(VeryUsualDay.Instance._joining(), "_joining"); Timing.RunCoroutine(VeryUsualDay.Instance._prisonTimer(), "_prisonTimer"); + Timing.RunCoroutine(VeryUsualDay.Instance._chaos(), "_chaos"); + foreach (var room in Room.List) + { + if (room.Zone != ZoneType.Unspecified && room.Color == Color.red) + { + room.ResetColor(); + } + } Timing.CallDelayed(5f, () => { VeryUsualDay.Instance.SupplyBoxCoords = Room.Get(RoomType.EzGateB).Position + new Vector3(-6.193f, 2.243f, -5.901f); diff --git a/Handlers/Server.cs b/Handlers/Server.cs index 6389dca..94a6f19 100644 --- a/Handlers/Server.cs +++ b/Handlers/Server.cs @@ -21,8 +21,11 @@ public static void OnWaitingForPlayers() VeryUsualDay.Instance.ScpPlayers.Clear(); VeryUsualDay.Instance.JoinedDboys.Clear(); VeryUsualDay.Instance.DBoysQueue.Clear(); + VeryUsualDay.Instance.ChaosRooms.Clear(); // Timing.KillCoroutines("_avel"); Timing.KillCoroutines("_joining"); + Timing.KillCoroutines("_prisonTimer"); + Timing.KillCoroutines("_chaos"); } public static void OnRoundStarted() diff --git a/VeryUsualDay.cs b/VeryUsualDay.cs index 051a597..6fe99a1 100644 --- a/VeryUsualDay.cs +++ b/VeryUsualDay.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using Exiled.API.Enums; +using Exiled.API.Extensions; using Exiled.API.Features; using MEC; using Newtonsoft.Json; @@ -14,6 +15,7 @@ using UnityEngine; using Player = VeryUsualDay.Handlers.Player; using PlayerHandler = Exiled.Events.Handlers.Player; +using Random = UnityEngine.Random; using Server = VeryUsualDay.Handlers.Server; using ServerHandler = Exiled.Events.Handlers.Server; @@ -26,7 +28,7 @@ public class VeryUsualDay : Plugin public override string Author => "JustMarfix"; public override string Name => "VeryUsualDay (FX Version)"; - public override Version Version => new Version(4, 2, 0); + public override Version Version => new Version(4, 3, 0); public bool IsEnabledInRound { get; set; } public bool IsLunchtimeActive { get; set; } @@ -34,6 +36,7 @@ public class VeryUsualDay : Plugin public bool IsTeslaEnabled { get; set; } public List JoinedDboys { get; set; } = new List(); public List DBoysQueue { get; set; } = new List(); + public List ChaosRooms { get; set; } = new List(); public int BuoCounter { get; set; } = 1; public int SpawnedDboysCounter { get; set; } = 1; public int SpawnedWorkersCounter { get; set; } = 1; @@ -202,6 +205,40 @@ public IEnumerator _prisonTimer() } } + public IEnumerator _chaos() + { + for (;;) + { + foreach (var roomType in ChaosRooms) + { + var room = Room.Get(roomType); + foreach (var door in room.Doors.Where(p => !p.IsElevator && !p.IsGate && !p.IsCheckpoint).Shuffle()) + { + door.IsOpen = !door.IsOpen; + Timing.WaitForSeconds(0.1f); + } + + foreach (var player in room.Players) + { + if (Random.Range(0, 100) < 30) + { + player.PlayGunSound(ItemType.GunCrossvec, (byte)Random.Range(155, 256)); + } + if (Random.Range(0, 100) < 20) + { + player.PlayBeepSound(); + } + + if (Random.Range(0, 100) < 10) + { + player.PlayShieldBreakSound(); + } + } + } + yield return Timing.WaitForSeconds(1.5f); + } + } + /* public IEnumerator _avel() { @@ -455,5 +492,20 @@ public static string Description(this Enum value) { return GetCustomDescription(value); } + + public static bool In(this T val, params T[] vals) => vals.Contains(val); + + public static IEnumerable Shuffle(this IEnumerable enumerable) + { + var enumerable1 = enumerable.ToList(); + var newEnum = Enumerable.Empty(); + while (enumerable1.Count != 0) + { + var index = Random.Range(0, enumerable1.Count); + newEnum = newEnum.Append(enumerable1[index]); + enumerable1.RemoveAt(index); + } + return newEnum; + } } } diff --git a/VeryUsualDay.csproj b/VeryUsualDay.csproj index 3e2a725..292eacc 100644 --- a/VeryUsualDay.csproj +++ b/VeryUsualDay.csproj @@ -72,6 +72,7 @@ +