From e3a5520f41dbdba0cae422daf5011b4ab86256ea Mon Sep 17 00:00:00 2001 From: Mikhail Reznichenko Date: Sun, 21 Jul 2024 00:45:43 +0300 Subject: [PATCH] prison final version --- Commands/PluginEnable.cs | 23 ++++++++++++++++++++++- Handlers/Player.cs | 18 ++++++++++++++---- VeryUsualDay.cs | 37 ++++++++++++++++++++++++++++++------- 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/Commands/PluginEnable.cs b/Commands/PluginEnable.cs index 97b1847..0737c7c 100644 --- a/Commands/PluginEnable.cs +++ b/Commands/PluginEnable.cs @@ -4,6 +4,7 @@ using Exiled.API.Enums; using Exiled.API.Features; using MEC; +using PlayerRoles; using UnityEngine; namespace VeryUsualDay.Commands @@ -35,6 +36,25 @@ public bool Execute(ArraySegment arguments, ICommandSender sender, out s // Timing.KillCoroutines("_avel"); Timing.KillCoroutines("_joining"); Timing.KillCoroutines("_prisonTimer"); + foreach (var player in Player.List) + { + if (player.TryGetSessionVariable("isInPrison", out bool prisonState) && prisonState) + { + player.TryGetSessionVariable("prisonReason", out string reason); + player.TryGetSessionVariable("prisonTime", out Int32 time); + VeryUsualDay.SendToPrison(player, time, reason); + // Log.Info($"Игроку {player.UserId} осталось в тюрьме {time} секунд. СОД закончен."); + Timing.CallDelayed(3f, () => + { + player.UnMute(); + player.DisableEffect(EffectType.SilentWalk); + player.Role.Set(RoleTypeId.Tutorial); + player.SessionVariables.Remove("isInPrison"); + player.SessionVariables.Remove("prisonTime"); + player.SessionVariables.Remove("prisonReason"); + }); + } + } response = "Режим FX выключен."; } else @@ -56,8 +76,9 @@ public bool Execute(ArraySegment arguments, ICommandSender sender, out s player.EnableEffect(EffectType.SilentWalk, 255); player.Teleport(VeryUsualDay.PrisonPosition); player.SessionVariables.Add("isInPrison", true); - player.SessionVariables.Add("prisonTime", (int)userData[1]); + player.SessionVariables.Add("prisonTime", (Int32)userData[1]); player.SessionVariables.Add("prisonReason", (string)userData[2]); + // Log.Info($"Игрок {player.UserId} будет находиться в тюрьме {(Int32)userData[1]} секунд."); } } response = "Режим FX включён."; diff --git a/Handlers/Player.cs b/Handlers/Player.cs index fcfd679..08ff77d 100644 --- a/Handlers/Player.cs +++ b/Handlers/Player.cs @@ -23,9 +23,9 @@ public static void OnTriggeringTesla(TriggeringTeslaEventArgs ev) public static void OnChangingRole(ChangingRoleEventArgs ev) { if (!VeryUsualDay.Instance.IsEnabledInRound) return; - if (ev.Player.TryGetSessionVariable("isInPrison", out bool prisonState) && prisonState) return; Timing.CallDelayed(5f, () => { + if (ev.Player.TryGetSessionVariable("isInPrison", out bool prisonState) && prisonState) return; if (ev.NewRole != RoleTypeId.Spectator || ev.Reason == SpawnReason.ForceClass) return; @@ -150,6 +150,12 @@ public static void OnDied(DiedEventArgs ev) public static void OnLeft(LeftEventArgs ev) { + if (ev.Player.TryGetSessionVariable("isInPrison", out bool prisonState) && prisonState) + { + ev.Player.TryGetSessionVariable("prisonReason", out string reason); + ev.Player.TryGetSessionVariable("prisonTime", out int time); + VeryUsualDay.SendToPrison(ev.Player, time, reason); + } if (!VeryUsualDay.Instance.IsEnabledInRound) return; if (VeryUsualDay.Instance.ScpPlayers.ContainsKey(ev.Player.Id)) { @@ -194,12 +200,16 @@ public static void OnVerified(VerifiedEventArgs ev) var userData = (ITuple)VeryUsualDay.CheckIfPlayerInPrison(ev.Player); if ((bool)userData[0]) { - ev.Player.Mute(); - ev.Player.EnableEffect(EffectType.SilentWalk, 255); - ev.Player.Teleport(VeryUsualDay.PrisonPosition); ev.Player.SessionVariables.Add("isInPrison", true); ev.Player.SessionVariables.Add("prisonTime", (int)userData[1]); ev.Player.SessionVariables.Add("prisonReason", (string)userData[2]); + ev.Player.Role.Set(RoleTypeId.Tutorial); + Timing.CallDelayed(1f, () => + { + ev.Player.Mute(); + ev.Player.EnableEffect(EffectType.SilentWalk, 255); + ev.Player.Teleport(VeryUsualDay.PrisonPosition); + }); } } } diff --git a/VeryUsualDay.cs b/VeryUsualDay.cs index 9d45437..53ce848 100644 --- a/VeryUsualDay.cs +++ b/VeryUsualDay.cs @@ -183,7 +183,15 @@ public IEnumerator _prisonTimer() { if (player.TryGetSessionVariable("isInPrison", out bool prisonState) && prisonState) { - player.SessionVariables["prisonTime"] = (int)player.SessionVariables["prisonTime"] - 1; + player.TryGetSessionVariable("prisonTime", out Int32 time); + // Log.Info($"Игроку {player.UserId} осталось находиться в тюрьме {time} секунд."); + time -= 1; + player.SessionVariables.Remove("prisonTime"); + player.SessionVariables.Add("prisonTime", time); + if (time == 0) + { + SendToPrison(player, 0, "Выпущен из тюрьмы."); + } } } yield return Timing.WaitForSeconds(1f); @@ -392,12 +400,27 @@ public static bool SendToPrison(Exiled.API.Features.Player player, int durationS var response = client.PostAsync($"http://justmeow.ru:9000/aban", content).Result; if (response.IsSuccessStatusCode && Instance.IsEnabledInRound) { - 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); + 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; }