Skip to content

Commit

Permalink
RoleDistr & 019 fixes
Browse files Browse the repository at this point in the history
RoleDistr doesn't affect users in azkaban
019 now spawns in right place + added commands for its breach/recontain
  • Loading branch information
JustMarfix committed Oct 6, 2024
1 parent 1674dae commit b59c01d
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 85 deletions.
4 changes: 2 additions & 2 deletions Commands/Aban.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public bool Execute(ArraySegment<string> 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;
Expand Down
30 changes: 30 additions & 0 deletions Commands/Breach019.cs
Original file line number Diff line number Diff line change
@@ -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<string> arguments, ICommandSender sender, out string response)
{
Door.Get(DoorType.Scp173Armory).Lock(float.PositiveInfinity, DoorLockType.AdminCommand);
VeryUsualDay.Instance.Vase.As<Scp244Pickup>().State = Scp244State.Active;
Timing.CallDelayed(1f, () =>
{
VeryUsualDay.Instance.Vase.As<Scp244Pickup>().State = Scp244State.Idle;
});
response = "SCP-019 открыт.";
return true;
}
}
}
13 changes: 7 additions & 6 deletions Commands/PluginEnable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -51,7 +50,7 @@ public bool Execute(ArraySegment<string> 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();
Expand All @@ -64,6 +63,8 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
}
}
}

VeryUsualDay.Instance.Vase.Destroy();
response = "Режим FX выключен.";
}
else
Expand All @@ -86,7 +87,7 @@ public bool Execute(ArraySegment<string> 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();
Expand Down Expand Up @@ -116,15 +117,15 @@ public bool Execute(ArraySegment<string> 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 включён.";
}
Expand Down
25 changes: 25 additions & 0 deletions Commands/Recontain019.cs
Original file line number Diff line number Diff line change
@@ -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<string> 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;
}
}
}
5 changes: 3 additions & 2 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ public class Config : IConfig
ItemType.ArmorHeavy
};

[Description("Список ролей, на которые не распростроняется инфекиция SCP-008 (List<RoleTypeId>)")]
[Description("Список ролей, на которые не распростроняется инфекция SCP-008 (List<RoleTypeId>)")]
public List<RoleTypeId> DoNotPoisonRoles { get; set; } = new List<RoleTypeId>
{
RoleTypeId.ChaosConscript,
Expand Down Expand Up @@ -886,7 +886,8 @@ public class Config : IConfig
ItemType.SCP500,
ItemType.SCP1853,
ItemType.SCP244a,
ItemType.SCP244b
ItemType.SCP244b,
ItemType.SCP207
};

[Description("Список DamageType, которые взрывают пояс шахида (List<DamageType>)")]
Expand Down
4 changes: 2 additions & 2 deletions Handlers/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
68 changes: 68 additions & 0 deletions PrisonController.cs
Original file line number Diff line number Diff line change
@@ -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<string, string>
{
{ "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<List<string>>(content);
return (response.IsSuccessStatusCode, int.Parse(json[0]), json[1]);
}
}
}
}
79 changes: 6 additions & 73 deletions VeryUsualDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +29,7 @@ public class VeryUsualDay : Plugin<Config>
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; }
Expand All @@ -53,6 +54,8 @@ public class VeryUsualDay : Plugin<Config>
public Vector3 SupplyBoxCoords = new Vector3();
public Vector3 VaseCoords = new Vector3();

public Pickup Vase;

public readonly List<Vector3> EmfSupplyCoords = new List<Vector3>
{
new Vector3(-10.682f, 1003f, -32.115f),
Expand Down Expand Up @@ -231,7 +234,7 @@ public IEnumerator<float> _prisonTimer()
player.SessionVariables.Add("prisonTime", time);
if (time == 0)
{
SendToPrison(player, 0, "Выпущен из тюрьмы.");
PrisonController.SendToPrison(player, 0, "Выпущен из тюрьмы.");
}
}
}
Expand Down Expand Up @@ -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<string, string>
{
{ "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<List<string>>(content);
return (response.IsSuccessStatusCode, int.Parse(json[0]), json[1]);
}
}
}
}
3 changes: 3 additions & 0 deletions VeryUsualDay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<ItemGroup>
<Compile Include="Commands\Aban.cs" />
<Compile Include="Commands\AllowSpawn.cs" />
<Compile Include="Commands\Breach019.cs" />
<Compile Include="Commands\Breach244.cs" />
<Compile Include="Commands\ChaosMode.cs" />
<Compile Include="Commands\CheckCode.cs" />
Expand All @@ -86,6 +87,7 @@
<Compile Include="Commands\Patogen008.cs" />
<Compile Include="Commands\PluginEnable.cs" />
<Compile Include="Commands\Recontain008.cs" />
<Compile Include="Commands\Recontain019.cs" />
<Compile Include="Commands\Recontain244.cs" />
<Compile Include="Commands\ReDoors.cs" />
<Compile Include="Commands\RoleDistribution.cs" />
Expand Down Expand Up @@ -117,6 +119,7 @@
<Compile Include="Handlers\Player.cs" />
<Compile Include="Handlers\Server.cs" />
<Compile Include="Helpers.cs" />
<Compile Include="PrisonController.cs" />
<Compile Include="Utils\ClassD.cs" />
<Compile Include="Utils\Guard.cs" />
<Compile Include="Utils\MtfMedic.cs" />
Expand Down

0 comments on commit b59c01d

Please sign in to comment.