Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Commit fe8bbb5

Browse files
authored
Merge pull request #17 from Rnen/patient-zero
Patient Zero mode
2 parents 57d9923 + 06b619f commit fe8bbb5

File tree

9 files changed

+463
-190
lines changed

9 files changed

+463
-190
lines changed

SCP008/Commands/EnableDisableCommand.cs

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ namespace SCP008PLUGIN.Command
1010
/// <summary>
1111
/// Command for enabling/disabling <see cref="SCP008"/>
1212
/// </summary>
13-
class EnableDisableCommand : ICommandHandler
13+
public class EnableDisableCommand : ICommandHandler
1414
{
1515
private readonly SCP008 plugin;
1616

1717
public EnableDisableCommand(SCP008 plugin) => this.plugin = plugin;
1818
public string GetCommandDescription() => "Enables or disables " + plugin.Details.name;
19-
public string GetUsage() => "SCP008";
19+
public string GetUsage() => "SCP008 (SUBCOMMAND)";
2020

21-
bool IsAllowed(ICommandSender sender)
21+
public string[] SubCommands = new string[] { "(bool / enable / disable)", "zero / patientzero", "help / git" };
22+
23+
private bool IsAllowed(ICommandSender sender)
2224
{
2325
//Checking if the ICommandSender is a player and setting the player variable if it is
2426
Player player = (sender is Player) ? sender as Player : null;
@@ -33,12 +35,12 @@ bool IsAllowed(ICommandSender sender)
3335

3436
//Checks if there is any entries, if empty, let anyone use it
3537
if (roleList != null && roleList.Count > 0
36-
&& (roleList.Contains(player.GetUserGroup().Name.ToUpper()) || roleList.Contains(player.GetRankName().ToUpper()) ) )
38+
&& (roleList.Contains(player.GetUserGroup().Name.ToUpper()) || roleList.Contains(player.GetRankName().ToUpper())))
3739
{
3840
//Config contained rank
3941
return true;
4042
}
41-
else if (roleList == null || roleList.Count == 0 || (roleList.Count == 1 && string.IsNullOrEmpty(roleList.First()) ) )
43+
else if (roleList == null || roleList.Count == 0 || (roleList.Count == 1 && string.IsNullOrEmpty(roleList.First())))
4244
return true; // config was empty
4345
else
4446
return false; // config was not empty and didnt contain player role
@@ -49,17 +51,46 @@ bool IsAllowed(ICommandSender sender)
4951

5052
public string[] OnCall(ICommandSender sender, string[] args)
5153
{
52-
if(args.Length > 0 && args[0] == "help")
53-
return plugin.PluginManager.CommandManager.CallCommand(sender, "008help", args);
5454
if (IsAllowed(sender))
5555
{
56-
if (args.Length > 0 && bool.TryParse(args[0], out bool value)) // If the command contains a arguement and it can be parsed as a bool
57-
plugin.SetIsEnabled(value);
58-
else
59-
plugin.SetIsEnabled(!plugin.GetIsEnabled()); //If not just toggle
56+
if (args.Length > 0)
57+
{
58+
if (Utility.TryParseCommandBool(args[0], out bool b))
59+
{
60+
plugin.IsEnabled = b;
61+
return new string[] { "SCP008 plugin set to " + plugin.IsEnabled };
62+
}
63+
64+
switch (args[0].ToUpper())
65+
{
66+
case "GIT":
67+
case "GITHUB":
68+
return plugin.PluginManager.CommandManager.CallCommand(sender, "008help", args);
69+
case "HELP":
70+
return new string[] { GetUsage(), "Subcommands: " + string.Join(" ,", SubCommands) };
71+
case "V":
72+
case "VERSION":
73+
return new string[] { "Plugin Version: " + plugin.Details.version, "SMod Version: " + Smod2.PluginManager.GetSmodVersion() };
74+
case "ZERO":
75+
case "PATIENTZERO":
76+
if(args.Length > 1 && Utility.TryParseCommandBool(args[1], out bool b2))
77+
{
78+
plugin.IsEnabledZeroOnStart = b2;
79+
return new string[] { "SCP008 PatientZero mode set to " + plugin.IsEnabledZeroOnStart};
80+
}
81+
else
82+
{
83+
plugin.IsEnabledZeroOnStart = !plugin.IsEnabledZeroOnStart;
84+
return new string[] { "SCP008 PatientZero mode set to " + plugin.IsEnabledZeroOnStart };
85+
}
86+
}
87+
return new string[] { GetUsage(), "Subcommands: " + string.Join(" ,", SubCommands) };
88+
}
89+
else
90+
plugin.IsEnabled = !plugin.IsEnabled; //If not just toggle
6091

6192
//Returning the current state of the static bool
62-
return new string[] { "SCP008 plugin set to " + plugin.GetIsEnabled() };
93+
return new string[] { "SCP008 plugin set to " + plugin.IsEnabled };
6394
}
6495
else
6596
return new string[] { "You dont have the required permission to run " + GetUsage() };

SCP008/Commands/HelpCommand.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ class HelpCommand : ICommandHandler
1919
public string[] OnCall(ICommandSender sender, string[] args)
2020
{
2121
if (sender is Player p && p != null)
22-
return new string[] { "This command is only for use in server window!" };
22+
return new string[] { "Visit https://github.com/Rnen/SCP008 for more information" };
2323
else
24-
{
2524
try
2625
{
2726
System.Diagnostics.Process.Start("https://github.com/Rnen/SCP008");
2827
return new string[] { "Opening browser..." };
2928
}
30-
catch { return new string[] { "Could not open browser!" }; }
31-
}
29+
catch
30+
{
31+
return new string[] { "Could not open browser!" };
32+
}
3233
}
3334
}
3435
}

SCP008/Commands/InfectCommand.cs

Lines changed: 73 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ class InfectCommand : ICommandHandler
1717

1818
public InfectCommand(SCP008 plugin) => this.plugin = plugin;
1919
public string GetCommandDescription() => "Infects / removes infection";
20-
public string GetUsage() => "INFECT (PLAYER)";
20+
public string GetUsage() => "INFECT (PLAYER) [SUBCOMMAND]";
21+
22+
public string[] SubCommands = new string[] { "+ / add", "infect+ / ++ / zero / patientzero", "cure / remove / -" };
2123

2224
bool IsAllowed(ICommandSender sender)
2325
{
@@ -52,63 +54,92 @@ public string[] OnCall(ICommandSender sender, string[] args)
5254
{
5355
if (IsAllowed(sender))
5456
{
55-
if (args.Length == 0 && sender is Player p)
56-
if (SCP008.playersToDamage.Contains(p.UserId))
57+
if (args.Length == 0 && sender is Player p && p != null)
58+
try
5759
{
58-
SCP008.playersToDamage.Remove(p.UserId);
59-
return new string[] { "Cured infected " + p.Name };
60+
if (SCP008.infected.Contains(p.UserID))
61+
{
62+
Utility.CureInfection(p, true);
63+
return new string[] { "Cured infected " + p.Name };
64+
}
65+
else
66+
{
67+
Utility.Infect(p);
68+
return new string[] { "Infected " + p.Name };
69+
}
6070
}
61-
else
71+
catch (Exception e)
6272
{
63-
SCP008.playersToDamage.Add(p.UserId);
64-
return new string[] { "Infected " + p.Name };
73+
return new string[] { "Infect command exception " + e };
6574
}
6675
else if (args.Length > 0)
6776
{
68-
if (args[0].ToLower() == "all" || args[0] == "*")
77+
string arg1 = (args.Length > 1 && !string.IsNullOrEmpty(args[1])) ? args[1].ToLower() : "";
78+
List<Player> players = new List<Player>();
79+
switch (args[0].ToLower())
6980
{
70-
int x = 0;
71-
foreach(Player pl in Server.GetPlayers()
72-
.Where(ply =>
73-
ply.TeamRole.Role != Smod2.API.RoleType.SPECTATOR &&
74-
ply.TeamRole.Role != Smod2.API.RoleType.UNASSIGNED &&
75-
ply.TeamRole.Role != Smod2.API.RoleType.ZOMBIE))
76-
{
77-
string arg = (args.Length > 1 && !string.IsNullOrEmpty(args[1])) ? args[1].ToLower() : "";
78-
if (SCP008.playersToDamage.Contains(pl.UserId) && arg != "infect")
79-
SCP008.playersToDamage.Remove(pl.UserId);
80-
else if(!SCP008.playersToDamage.Contains(pl.UserId) && arg != "infect")
81-
SCP008.playersToDamage.Add(pl.UserId);
82-
x++;
83-
}
84-
return new string[] { "Toggled infection on " + x + " players!" };
81+
case "all":
82+
case "*":
83+
players = Server.GetPlayers(i => i.PlayerRole.Team != TeamType.SPECTATOR || i.PlayerRole.Team != TeamType.NONE);
84+
break;
85+
case "list":
86+
case "infected":
87+
return new string[] { "Infected Players:", string.Join("\n", SCP008.InfectedPlayers.OrderBy(s => s.Name).Select(i => i.Name).ToList()) };
88+
case "help":
89+
case "subcommand":
90+
case "subcommands":
91+
return new string[] { GetUsage(), "Availabile subcommands:" + string.Join(" ,", SubCommands) };
92+
default:
93+
players = Server.GetPlayers(args[0]);
94+
break;
8595
}
86-
else
87-
{
88-
List<Player> players = Server.GetPlayers(args[0]);
89-
Player player;
90-
if (players == null || players.Count == 0) return new string[] { "No players on the server called " + args[0] };
91-
player = players.OrderBy(pl => pl.Name.Length).First();
9296

93-
if (!SCP008.playersToDamage.Contains(player.UserId))
94-
{
95-
SCP008.playersToDamage.Add(player.UserId);
96-
return new string[] { "Infected " + player.Name };
97-
}
98-
else if (SCP008.playersToDamage.Contains(player.UserId))
97+
if (players == null || players.Count == 0)
98+
return new string[] { "No players on the server called " + args[0] };
99+
100+
string ret = this.plugin.Details.id + " INFECT COMMAND ERROR";
101+
102+
foreach (Player player in players)
103+
switch (arg1.ToLower())
99104
{
100-
SCP008.playersToDamage.Remove(player.UserId);
101-
return new string[] { "Cured infected " + player.Name };
105+
case "+":
106+
case "add":
107+
Utility.Infect(player);
108+
break;
109+
case "++":
110+
case "add+":
111+
case "zero":
112+
case "patientzero":
113+
Utility.Infect(player, true);
114+
return new string[] { $"Made \"{player.Name}\" into Patient Zero!" };
115+
case "cure":
116+
case "remove":
117+
case "-":
118+
SCP008.patientZero = "";
119+
Utility.CureInfection(player);
120+
if (players.Count == 1)
121+
return new string[] { $"Cured \"{player.Name}\" from SCP008 infection!" };
122+
ret = $"Cured {players.Count} players from SCP008 infection!";
123+
break;
124+
case "":
125+
default:
126+
if (SCP008.infected.Contains(player.UserID))
127+
Utility.CureInfection(player);
128+
else
129+
Utility.Infect(player);
130+
break;
102131
}
103-
else
104-
return new string[] { this.plugin.Details.id + " INFECT ERROR" };
105-
}
132+
if (!string.IsNullOrEmpty(arg1))
133+
return new string[] { $"Used {arg1} on {players.Count} players!" };
134+
else
135+
return new string[] { $"Toggled infection on {players.Count} players!" };
106136
}
107137
else
108-
return new string[] { GetUsage() };
138+
return new[] { GetUsage() };
109139
}
110140
else
111141
return new string[] { "You dont have the required permission to run " + GetUsage() };
112142
}
113143
}
114144
}
145+

0 commit comments

Comments
 (0)