From b59c01db1ed95d99e045b72b13ece14fe3d29ec0 Mon Sep 17 00:00:00 2001 From: Mikhail Reznichenko Date: Sun, 6 Oct 2024 15:06:12 +0300 Subject: [PATCH] RoleDistr & 019 fixes RoleDistr doesn't affect users in azkaban 019 now spawns in right place + added commands for its breach/recontain --- Commands/Aban.cs | 4 +- Commands/Breach019.cs | 30 +++++++++++++++ Commands/PluginEnable.cs | 13 ++++--- Commands/Recontain019.cs | 25 +++++++++++++ Config.cs | 5 ++- Handlers/Player.cs | 4 +- Helpers.cs | 16 ++++++++ PrisonController.cs | 68 ++++++++++++++++++++++++++++++++++ VeryUsualDay.cs | 79 +++------------------------------------- VeryUsualDay.csproj | 3 ++ 10 files changed, 162 insertions(+), 85 deletions(-) create mode 100644 Commands/Breach019.cs create mode 100644 Commands/Recontain019.cs create mode 100644 PrisonController.cs diff --git a/Commands/Aban.cs b/Commands/Aban.cs index 82e2fb6..7c9e3dc 100644 --- a/Commands/Aban.cs +++ b/Commands/Aban.cs @@ -34,8 +34,8 @@ public bool Execute(ArraySegment arguments, ICommandSender sender, out s response = "Время введено в неправильном формате."; return false; } - var timeToPrison = VeryUsualDay.ConvertToTimeSpan(args[1]); - if (VeryUsualDay.SendToPrison(target, Convert.ToInt32(timeToPrison.TotalSeconds), string.Join(" ", args.Skip(2)))) + var timeToPrison = Helpers.ConvertToTimeSpan(args[1]); + if (PrisonController.SendToPrison(target, Convert.ToInt32(timeToPrison.TotalSeconds), string.Join(" ", args.Skip(2)))) { response = $"Игрок {target.Nickname} был отправлен в тюрьму."; return true; diff --git a/Commands/Breach019.cs b/Commands/Breach019.cs new file mode 100644 index 0000000..0ffb94c --- /dev/null +++ b/Commands/Breach019.cs @@ -0,0 +1,30 @@ +using System; +using CommandSystem; +using Exiled.API.Enums; +using Exiled.API.Features.Doors; +using Exiled.API.Features.Pickups; +using InventorySystem.Items.Usables.Scp244; +using MEC; + +namespace VeryUsualDay.Commands +{ + [CommandHandler(typeof(RemoteAdminCommandHandler))] + public class Breach019 : ICommand + { + public string Command => "breach019"; + public string[] Aliases => null; + public string Description => "Открывает SCP-019 без дыма."; + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + Door.Get(DoorType.Scp173Armory).Lock(float.PositiveInfinity, DoorLockType.AdminCommand); + VeryUsualDay.Instance.Vase.As().State = Scp244State.Active; + Timing.CallDelayed(1f, () => + { + VeryUsualDay.Instance.Vase.As().State = Scp244State.Idle; + }); + response = "SCP-019 открыт."; + return true; + } + } +} \ No newline at end of file diff --git a/Commands/PluginEnable.cs b/Commands/PluginEnable.cs index 0eca0a7..626a7cb 100644 --- a/Commands/PluginEnable.cs +++ b/Commands/PluginEnable.cs @@ -5,7 +5,6 @@ using Exiled.API.Features; using MEC; using PlayerRoles; -using PluginAPI.Core.Items; using UnityEngine; using Item = Exiled.API.Features.Items.Item; @@ -51,7 +50,7 @@ public bool Execute(ArraySegment arguments, ICommandSender sender, out s { player.TryGetSessionVariable("prisonReason", out string reason); player.TryGetSessionVariable("prisonTime", out Int32 time); - VeryUsualDay.SendToPrison(player, time, reason); + PrisonController.SendToPrison(player, time, reason); Timing.CallDelayed(3f, () => { player.UnMute(); @@ -64,6 +63,8 @@ public bool Execute(ArraySegment arguments, ICommandSender sender, out s } } } + + VeryUsualDay.Instance.Vase.Destroy(); response = "Режим FX выключен."; } else @@ -86,7 +87,7 @@ public bool Execute(ArraySegment arguments, ICommandSender sender, out s { foreach (var player in Player.List) { - var userData = (ITuple)VeryUsualDay.CheckIfPlayerInPrison(player); + var userData = (ITuple)PrisonController.CheckIfPlayerInPrison(player); if ((bool)userData[0]) { player.Mute(); @@ -116,15 +117,15 @@ public bool Execute(ArraySegment arguments, ICommandSender sender, out s } else if (Room.Get(RoomType.Lcz173).Rotation == new Quaternion(0, 0.70711f, 0, -0.70711f)) { - VeryUsualDay.Instance.VaseCoords = Room.Get(RoomType.Lcz173).Position + new Vector3(8f, 13.6f, 20.193f); + VeryUsualDay.Instance.VaseCoords = Room.Get(RoomType.Lcz173).Position + new Vector3(-8f, 13.6f, 20.193f); } else { - VeryUsualDay.Instance.VaseCoords = Room.Get(RoomType.Lcz173).Position + new Vector3(-8f, 13.6f, 20.193f); + Log.Error("SCP-019 не появился! Поворот комнаты: " + Room.Get(RoomType.Lcz173).Rotation); } var vase = Item.Create(ItemType.SCP244a); vase.Scale = new Vector3(8f, 8f, 8f); - vase.CreatePickup(VeryUsualDay.Instance.VaseCoords); + VeryUsualDay.Instance.Vase = vase.CreatePickup(VeryUsualDay.Instance.VaseCoords); response = "Режим FX включён."; } diff --git a/Commands/Recontain019.cs b/Commands/Recontain019.cs new file mode 100644 index 0000000..4d8f702 --- /dev/null +++ b/Commands/Recontain019.cs @@ -0,0 +1,25 @@ +using System; +using CommandSystem; +using Exiled.API.Features.Items; +using UnityEngine; + +namespace VeryUsualDay.Commands +{ + [CommandHandler(typeof(RemoteAdminCommandHandler))] + public class Recontain019 : ICommand + { + public string Command => "recontain019"; + public string[] Aliases => null; + public string Description => "Восстанавливает ОУС SCP-019."; + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + VeryUsualDay.Instance.Vase.Destroy(); + var vase = Item.Create(ItemType.SCP244a); + vase.Scale = new Vector3(8f, 8f, 8f); + VeryUsualDay.Instance.Vase = vase.CreatePickup(VeryUsualDay.Instance.VaseCoords); + response = "SCP-019 закрыт."; + return true; + } + } +} \ No newline at end of file diff --git a/Config.cs b/Config.cs index d4d006c..f876022 100644 --- a/Config.cs +++ b/Config.cs @@ -841,7 +841,7 @@ public class Config : IConfig ItemType.ArmorHeavy }; - [Description("Список ролей, на которые не распростроняется инфекиция SCP-008 (List)")] + [Description("Список ролей, на которые не распростроняется инфекция SCP-008 (List)")] public List DoNotPoisonRoles { get; set; } = new List { RoleTypeId.ChaosConscript, @@ -886,7 +886,8 @@ public class Config : IConfig ItemType.SCP500, ItemType.SCP1853, ItemType.SCP244a, - ItemType.SCP244b + ItemType.SCP244b, + ItemType.SCP207 }; [Description("Список DamageType, которые взрывают пояс шахида (List)")] diff --git a/Handlers/Player.cs b/Handlers/Player.cs index 04af64f..92c4201 100644 --- a/Handlers/Player.cs +++ b/Handlers/Player.cs @@ -205,7 +205,7 @@ public static void OnLeft(LeftEventArgs ev) { ev.Player.TryGetSessionVariable("prisonReason", out string reason); ev.Player.TryGetSessionVariable("prisonTime", out int time); - VeryUsualDay.SendToPrison(ev.Player, time, reason); + PrisonController.SendToPrison(ev.Player, time, reason); } if (VeryUsualDay.Instance.Zombies.Contains(ev.Player.Id)) { @@ -255,7 +255,7 @@ public static void OnVerified(VerifiedEventArgs ev) { if (VeryUsualDay.Instance.IsEnabledInRound && VeryUsualDay.Instance.Config.AuthToken != "") { - var userData = (ITuple)VeryUsualDay.CheckIfPlayerInPrison(ev.Player); + var userData = (ITuple)PrisonController.CheckIfPlayerInPrison(ev.Player); if ((bool)userData[0]) { ev.Player.SessionVariables.Add("isInPrison", true); diff --git a/Helpers.cs b/Helpers.cs index f6b8c03..0d9b4a1 100644 --- a/Helpers.cs +++ b/Helpers.cs @@ -8,6 +8,22 @@ namespace VeryUsualDay { public static class Helpers { + public static TimeSpan ConvertToTimeSpan(string timeSpan) + { + var l = timeSpan.Length - 1; + var value = timeSpan.Substring(0, l); + var type = timeSpan.Substring(l, 1); + + switch (type) + { + case "d": return TimeSpan.FromDays(double.Parse(value)); + case "h": return TimeSpan.FromHours(double.Parse(value)); + case "m": return TimeSpan.FromMinutes(double.Parse(value)); + case "s": return TimeSpan.FromSeconds(double.Parse(value)); + default: return TimeSpan.FromSeconds(double.Parse(value)); + } + } + private static string GetCustomDescription(object objEnum) { var fi = objEnum.GetType().GetField(objEnum.ToString()); diff --git a/PrisonController.cs b/PrisonController.cs new file mode 100644 index 0000000..5999de6 --- /dev/null +++ b/PrisonController.cs @@ -0,0 +1,68 @@ +using System.Collections.Generic; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using Exiled.API.Enums; +using MEC; +using Newtonsoft.Json; +using PlayerRoles; + +namespace VeryUsualDay +{ + public static class PrisonController + { + public static bool SendToPrison(Exiled.API.Features.Player player, int durationSeconds, string reason) + { + using (var client = new HttpClient()) + { + var data = new Dictionary + { + { "steamId", player.UserId }, + { "time", durationSeconds.ToString() }, + { "reason", reason } + }; + var json = JsonConvert.SerializeObject(data); + HttpContent content = new StringContent(json, Encoding.UTF8, "application/json"); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", VeryUsualDay.Instance.Config.AuthToken); + var response = client.PostAsync($"http://justmeow.ru:9000/aban", content).Result; + if (response.IsSuccessStatusCode && VeryUsualDay.Instance.IsEnabledInRound) + { + player.Role.Set(RoleTypeId.Tutorial); + Timing.CallDelayed(0.5f, () => + { + if (durationSeconds == 0) + { + player.UnMute(); + player.DisableEffect(EffectType.SilentWalk); + player.SessionVariables.Remove("isInPrison"); + player.SessionVariables.Remove("prisonTime"); + player.SessionVariables.Remove("prisonReason"); + } + else + { + player.Mute(); + player.EnableEffect(EffectType.SilentWalk, 255); + player.Teleport(VeryUsualDay.PrisonPosition); + player.SessionVariables.Add("isInPrison", true); + player.SessionVariables.Add("prisonTime", durationSeconds); + player.SessionVariables.Add("prisonReason", reason); + } + }); + } + return response.IsSuccessStatusCode; + } + } + + public static (bool, int, string) CheckIfPlayerInPrison(Exiled.API.Features.Player player) + { + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", VeryUsualDay.Instance.Config.AuthToken); + var response = client.GetAsync($"http://justmeow.ru:9000/aban?steamId={player.UserId}").Result; + var content = response.Content.ReadAsStringAsync().Result; + var json = JsonConvert.DeserializeObject>(content); + return (response.IsSuccessStatusCode, int.Parse(json[0]), json[1]); + } + } + } +} \ No newline at end of file diff --git a/VeryUsualDay.cs b/VeryUsualDay.cs index 560bae4..8a50b7e 100644 --- a/VeryUsualDay.cs +++ b/VeryUsualDay.cs @@ -9,6 +9,7 @@ using Exiled.API.Enums; using Exiled.API.Extensions; using Exiled.API.Features; +using Exiled.API.Features.Pickups; using MEC; using Newtonsoft.Json; using PlayerRoles; @@ -28,7 +29,7 @@ public class VeryUsualDay : Plugin public override string Author => "JustMarfix"; public override string Name => "VeryUsualDay (FX Version)"; - public override Version Version => new Version(5, 1, 1); + public override Version Version => new Version(5, 2, 0); public bool IsEnabledInRound { get; set; } public bool IsLunchtimeActive { get; set; } @@ -53,6 +54,8 @@ public class VeryUsualDay : Plugin public Vector3 SupplyBoxCoords = new Vector3(); public Vector3 VaseCoords = new Vector3(); + public Pickup Vase; + public readonly List EmfSupplyCoords = new List { new Vector3(-10.682f, 1003f, -32.115f), @@ -231,7 +234,7 @@ public IEnumerator _prisonTimer() player.SessionVariables.Add("prisonTime", time); if (time == 0) { - SendToPrison(player, 0, "Выпущен из тюрьмы."); + PrisonController.SendToPrison(player, 0, "Выпущен из тюрьмы."); } } } @@ -464,81 +467,11 @@ public void RoleDistribution() { foreach (var player in Exiled.API.Features.Player.Get(RoleTypeId.Tutorial)) { - if (player.CustomInfo == "Человек" || player.CustomInfo is null) + if (player.TryGetSessionVariable("isInPrison", out bool prisonState) && prisonState && (player.CustomInfo == "Человек" || player.CustomInfo is null)) { SetUserRole(player); } } } - - public static TimeSpan ConvertToTimeSpan(string timeSpan) - { - var l = timeSpan.Length - 1; - var value = timeSpan.Substring(0, l); - var type = timeSpan.Substring(l, 1); - - switch (type) - { - case "d": return TimeSpan.FromDays(double.Parse(value)); - case "h": return TimeSpan.FromHours(double.Parse(value)); - case "m": return TimeSpan.FromMinutes(double.Parse(value)); - case "s": return TimeSpan.FromSeconds(double.Parse(value)); - default: return TimeSpan.FromSeconds(double.Parse(value)); - } - } - - public static bool SendToPrison(Exiled.API.Features.Player player, int durationSeconds, string reason) - { - using (var client = new HttpClient()) - { - var data = new Dictionary - { - { "steamId", player.UserId }, - { "time", durationSeconds.ToString() }, - { "reason", reason } - }; - var json = JsonConvert.SerializeObject(data); - HttpContent content = new StringContent(json, Encoding.UTF8, "application/json"); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Instance.Config.AuthToken); - var response = client.PostAsync($"http://justmeow.ru:9000/aban", content).Result; - if (response.IsSuccessStatusCode && Instance.IsEnabledInRound) - { - player.Role.Set(RoleTypeId.Tutorial); - Timing.CallDelayed(0.5f, () => - { - if (durationSeconds == 0) - { - player.UnMute(); - player.DisableEffect(EffectType.SilentWalk); - player.SessionVariables.Remove("isInPrison"); - player.SessionVariables.Remove("prisonTime"); - player.SessionVariables.Remove("prisonReason"); - } - else - { - player.Mute(); - player.EnableEffect(EffectType.SilentWalk, 255); - player.Teleport(PrisonPosition); - player.SessionVariables.Add("isInPrison", true); - player.SessionVariables.Add("prisonTime", durationSeconds); - player.SessionVariables.Add("prisonReason", reason); - } - }); - } - return response.IsSuccessStatusCode; - } - } - - public static (bool, int, string) CheckIfPlayerInPrison(Exiled.API.Features.Player player) - { - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Instance.Config.AuthToken); - var response = client.GetAsync($"http://justmeow.ru:9000/aban?steamId={player.UserId}").Result; - var content = response.Content.ReadAsStringAsync().Result; - var json = JsonConvert.DeserializeObject>(content); - return (response.IsSuccessStatusCode, int.Parse(json[0]), json[1]); - } - } } } diff --git a/VeryUsualDay.csproj b/VeryUsualDay.csproj index fcac166..ff3f13a 100644 --- a/VeryUsualDay.csproj +++ b/VeryUsualDay.csproj @@ -71,6 +71,7 @@ + @@ -86,6 +87,7 @@ + @@ -117,6 +119,7 @@ +