Skip to content

Commit

Permalink
prison final version
Browse files Browse the repository at this point in the history
  • Loading branch information
JustMarfix committed Jul 20, 2024
1 parent 9b8d709 commit e3a5520
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 12 deletions.
23 changes: 22 additions & 1 deletion Commands/PluginEnable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Exiled.API.Enums;
using Exiled.API.Features;
using MEC;
using PlayerRoles;
using UnityEngine;

namespace VeryUsualDay.Commands
Expand Down Expand Up @@ -35,6 +36,25 @@ public bool Execute(ArraySegment<string> 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
Expand All @@ -56,8 +76,9 @@ public bool Execute(ArraySegment<string> 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 включён.";
Expand Down
18 changes: 14 additions & 4 deletions Handlers/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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);
});
}
}
}
Expand Down
37 changes: 30 additions & 7 deletions VeryUsualDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,15 @@ public IEnumerator<float> _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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit e3a5520

Please sign in to comment.