2025-06-05 01:12:55 +02:00

82 lines
2.0 KiB
C#

using CommandSystem;
using LabApi.Features.Wrappers;
using PlayerRoles;
namespace ScpSwap;
[CommandHandler(typeof(ClientCommandHandler))]
public class SwapCommand : ICommand
{
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if (arguments.Count != 1)
{
response = "Usage: .scpswap <SCP_NUMBER>";
return false;
}
if (!Player.TryGet(sender, out var player))
{
response = "You must be a player to use this command!";
return false;
}
if (Round.Duration.TotalSeconds > 120)
{
response = "You can't swap SCPs during a round!";
return false;
}
if (!player.IsSCP)
{
response = "You must be an SCP to use this command!";
return false;
}
List<string> validScp =
[
"049",
"079",
"096",
"106",
"173",
"939"
];
var arg = arguments.First();
if (!validScp.Contains(arg))
{
response = "Invalid SCP number.";
return false;
}
if (Player.List.Where(x => x.IsSCP).Select(x => x.RoleBase)
.Any(playerRole => playerRole.RoleName == "SCP-" + arg))
{
response = "Already exists";
return false;
}
var role = arg switch
{
"049" => RoleTypeId.Scp049,
"079" => RoleTypeId.Scp079,
"096" => RoleTypeId.Scp096,
"106" => RoleTypeId.Scp106,
"173" => RoleTypeId.Scp173,
"939" => RoleTypeId.Scp939,
_ => throw new ArgumentOutOfRangeException()
};
player.SetRole(role);
response = "Swapping...";
return true;
}
public string Command { get; } = "scpswap";
public string[] Aliases { get; } = ["ss"];
public string Description { get; } = "Swaps SCPs";
}