Skip to content

Commit

Permalink
Added ChaosMode + some useful extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
JustMarfix committed Jul 27, 2024
1 parent 237c71c commit bc929c1
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 1 deletion.
124 changes: 124 additions & 0 deletions Commands/ChaosMode.cs
Original file line number Diff line number Diff line change
@@ -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<string> arguments, ICommandSender sender, out string response)
{
if (!VeryUsualDay.Instance.IsEnabledInRound)
{
response = "Режим FX не включён.";
return false;
}
if (arguments.Count < 1)
{
response = "Использование: chaosmode <list(l)/set(s)/unset(u)> [комнаты через пробел / 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 <list(l)/set(s)/unset(u)> [комнаты через пробел / all]";
return false;
}
}
}
10 changes: 10 additions & 0 deletions Commands/PluginEnable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ public bool Execute(ArraySegment<string> 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)
Expand Down Expand Up @@ -63,6 +65,14 @@ public bool Execute(ArraySegment<string> 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);
Expand Down
3 changes: 3 additions & 0 deletions Handlers/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
54 changes: 53 additions & 1 deletion VeryUsualDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
using System.Text;
using System.Threading.Tasks;
using Exiled.API.Enums;
using Exiled.API.Extensions;
using Exiled.API.Features;
using MEC;
using Newtonsoft.Json;
using PlayerRoles;
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;

Expand All @@ -26,14 +28,15 @@ public class VeryUsualDay : Plugin<Config>
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; }
public bool IsDboysSpawnAllowed { get; set; }
public bool IsTeslaEnabled { get; set; }
public List<int> JoinedDboys { get; set; } = new List<int>();
public List<int> DBoysQueue { get; set; } = new List<int>();
public List<RoomType> ChaosRooms { get; set; } = new List<RoomType>();
public int BuoCounter { get; set; } = 1;
public int SpawnedDboysCounter { get; set; } = 1;
public int SpawnedWorkersCounter { get; set; } = 1;
Expand Down Expand Up @@ -202,6 +205,40 @@ public IEnumerator<float> _prisonTimer()
}
}

public IEnumerator<float> _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<float> _avel()
{
Expand Down Expand Up @@ -455,5 +492,20 @@ public static string Description(this Enum value)
{
return GetCustomDescription(value);
}

public static bool In<T>(this T val, params T[] vals) => vals.Contains(val);

public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> enumerable)
{
var enumerable1 = enumerable.ToList();
var newEnum = Enumerable.Empty<T>();
while (enumerable1.Count != 0)
{
var index = Random.Range(0, enumerable1.Count);
newEnum = newEnum.Append(enumerable1[index]);
enumerable1.RemoveAt(index);
}
return newEnum;
}
}
}
1 change: 1 addition & 0 deletions VeryUsualDay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<Compile Include="Commands\Aban.cs" />
<Compile Include="Commands\allowspawn.cs" />
<Compile Include="Commands\breach244.cs" />
<Compile Include="Commands\ChaosMode.cs" />
<Compile Include="Commands\checkcode.cs" />
<Compile Include="Commands\checkcode_player.cs" />
<Compile Include="Commands\classd.cs" />
Expand Down

0 comments on commit bc929c1

Please sign in to comment.