Skip to content

Commit 831e668

Browse files
add tesla rule methods
1 parent e35d548 commit 831e668

8 files changed

Lines changed: 233 additions & 0 deletions
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using JetBrains.Annotations;
2+
using SER.Code.ArgumentSystem.Arguments;
3+
using SER.Code.ArgumentSystem.BaseArguments;
4+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
5+
using SER.Code.MethodSystem.MethodDescriptors;
6+
7+
namespace SER.Code.MethodSystem.Methods.TeslaRuleMethds;
8+
9+
[UsedImplicitly]
10+
public class IgnoredPlayersByTeslaMethod : SynchronousMethod, IAdditionalDescription
11+
{
12+
public override string Description => "Sets the players that will be ignored by a tesla.";
13+
14+
public string AdditionalDescription =>
15+
"The list of ignored players is reset for every round. " +
16+
"IMPORTANT: 'IgnoredPlayersByTesla set @all' and similar will NOT update the list of ignored players when a new player joins, " +
17+
"because when 'IgnoredPlayersByTesla' was used, the @all variable did not contain the newly joined player. " +
18+
"This has to be accounted for manually: 'IgnoredPlayersByTesla add @newlyJoinedPlayer'";
19+
20+
public override Argument[] ExpectedArguments { get; } =
21+
[
22+
new OptionsArgument(
23+
"mode",
24+
new("set", "Sets the list, overriding previous values."),
25+
new("add", "Adds new players to the list."),
26+
new("remove", "Removes players from the list, making them be triggering a tesla.")
27+
),
28+
new PlayersArgument("players")
29+
];
30+
31+
public override void Execute()
32+
{
33+
var players = Args.GetPlayers("players");
34+
var ids = players.Select(p => p.PlayerId);
35+
36+
switch (Args.GetOption("mode"))
37+
{
38+
case "set":
39+
TeslaRuleHandler.IgnoredPlayerIds = ids.ToHashSet();
40+
return;
41+
case "add":
42+
TeslaRuleHandler.IgnoredPlayerIds.UnionWith(ids);
43+
return;
44+
case "remove":
45+
TeslaRuleHandler.IgnoredPlayerIds.ExceptWith(ids);
46+
return;
47+
}
48+
}
49+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using JetBrains.Annotations;
2+
using PlayerRoles;
3+
using SER.Code.ArgumentSystem.Arguments;
4+
using SER.Code.ArgumentSystem.BaseArguments;
5+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
6+
using SER.Code.MethodSystem.MethodDescriptors;
7+
8+
namespace SER.Code.MethodSystem.Methods.TeslaRuleMethds;
9+
10+
[UsedImplicitly]
11+
public class IgnoredRolesByTeslaMethod : SynchronousMethod, IAdditionalDescription
12+
{
13+
public override string Description => "Sets the type of roles that will be ignored by a tesla.";
14+
15+
public string AdditionalDescription => "The list of ignored roles is reset for every round.";
16+
17+
public override Argument[] ExpectedArguments { get; } =
18+
[
19+
new OptionsArgument(
20+
"mode",
21+
new("set", "Sets the list, overriding previous values."),
22+
new("add", "Adds new roles to the list."),
23+
new("remove", "Removes roles from the list, making them be triggering a tesla.")
24+
),
25+
new EnumArgument<RoleTypeId>("roles")
26+
{
27+
ConsumesRemainingValues = true
28+
}
29+
];
30+
31+
public override void Execute()
32+
{
33+
var roles = Args.GetRemainingArguments<RoleTypeId, EnumArgument<RoleTypeId>>("roles");
34+
35+
switch (Args.GetOption("mode"))
36+
{
37+
case "set":
38+
TeslaRuleHandler.IgnoredRoles = roles.ToHashSet();
39+
return;
40+
case "add":
41+
TeslaRuleHandler.IgnoredRoles.UnionWith(roles);
42+
return;
43+
case "remove":
44+
TeslaRuleHandler.IgnoredRoles.ExceptWith(roles);
45+
return;
46+
}
47+
}
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using JetBrains.Annotations;
2+
using PlayerRoles;
3+
using SER.Code.ArgumentSystem.Arguments;
4+
using SER.Code.ArgumentSystem.BaseArguments;
5+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
6+
using SER.Code.MethodSystem.MethodDescriptors;
7+
8+
namespace SER.Code.MethodSystem.Methods.TeslaRuleMethds;
9+
10+
[UsedImplicitly]
11+
public class IgnoredTeamsByTeslaMethod : SynchronousMethod, IAdditionalDescription
12+
{
13+
public override string Description => "Sets the type of teams that will be ignored by a tesla.";
14+
15+
public string AdditionalDescription => "The list of ignored teams is reset for every round.";
16+
17+
public override Argument[] ExpectedArguments { get; } =
18+
[
19+
new OptionsArgument(
20+
"mode",
21+
new("set", "Sets the list, overriding previous values."),
22+
new("add", "Adds new teams to the list."),
23+
new("remove", "Removes teams from the list, making them be triggering a tesla.")
24+
),
25+
new EnumArgument<Team>("teams")
26+
{
27+
ConsumesRemainingValues = true
28+
}
29+
];
30+
31+
public override void Execute()
32+
{
33+
var teams = Args.GetRemainingArguments<Team, EnumArgument<Team>>("teams");
34+
35+
switch (Args.GetOption("mode"))
36+
{
37+
case "set":
38+
TeslaRuleHandler.IgnoredTeams = teams.ToHashSet();
39+
return;
40+
case "add":
41+
TeslaRuleHandler.IgnoredTeams.UnionWith(teams);
42+
return;
43+
case "remove":
44+
TeslaRuleHandler.IgnoredTeams.ExceptWith(teams);
45+
return;
46+
}
47+
}
48+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using JetBrains.Annotations;
2+
using SER.Code.ArgumentSystem.BaseArguments;
3+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
4+
5+
namespace SER.Code.MethodSystem.Methods.TeslaRuleMethds;
6+
7+
[UsedImplicitly]
8+
public class ResetIgnoredPlayersByTeslaMethod : SynchronousMethod
9+
{
10+
public override string Description => "Resets the list of players ignored by a tesla.";
11+
12+
public override Argument[] ExpectedArguments { get; } = [];
13+
14+
public override void Execute()
15+
{
16+
TeslaRuleHandler.IgnoredPlayerIds.Clear();
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using JetBrains.Annotations;
2+
using SER.Code.ArgumentSystem.BaseArguments;
3+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
4+
5+
namespace SER.Code.MethodSystem.Methods.TeslaRuleMethds;
6+
7+
[UsedImplicitly]
8+
public class ResetIgnoredRolesByTeslaMethod : SynchronousMethod
9+
{
10+
public override string Description => "Resets the list of roles ignored by a tesla.";
11+
12+
public override Argument[] ExpectedArguments { get; } = [];
13+
14+
public override void Execute()
15+
{
16+
TeslaRuleHandler.IgnoredRoles.Clear();
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using JetBrains.Annotations;
2+
using SER.Code.ArgumentSystem.BaseArguments;
3+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
4+
5+
namespace SER.Code.MethodSystem.Methods.TeslaRuleMethds;
6+
7+
[UsedImplicitly]
8+
public class ResetIgnoredTeamsByTeslaMethod : SynchronousMethod
9+
{
10+
public override string Description => "Resets the list of teams ignored by a tesla.";
11+
12+
public override Argument[] ExpectedArguments { get; } = [];
13+
14+
public override void Execute()
15+
{
16+
TeslaRuleHandler.IgnoredTeams.Clear();
17+
}
18+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using LabApi.Events.Arguments.PlayerEvents;
2+
using LabApi.Events.CustomHandlers;
3+
using PlayerRoles;
4+
5+
namespace SER.Code.MethodSystem.Methods.TeslaRuleMethds;
6+
7+
public class TeslaRuleHandler : CustomEventsHandler
8+
{
9+
public static HashSet<RoleTypeId> IgnoredRoles = [];
10+
public static HashSet<Team> IgnoredTeams = [];
11+
public static HashSet<int> IgnoredPlayerIds = [];
12+
13+
public static void ResetAll()
14+
{
15+
IgnoredRoles.Clear();
16+
IgnoredTeams.Clear();
17+
IgnoredPlayerIds.Clear();
18+
}
19+
20+
public override void OnPlayerTriggeringTesla(PlayerTriggeringTeslaEventArgs ev)
21+
{
22+
if (ev.Player is not {} plr) return;
23+
if (
24+
IgnoredRoles.Contains(plr.Role)
25+
|| IgnoredTeams.Contains(plr.Team)
26+
|| IgnoredPlayerIds.Contains(plr.PlayerId))
27+
{
28+
ev.IsAllowed = false;
29+
}
30+
}
31+
}

Code/Plugin/MainPlugin.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using SER.Code.Helpers;
1010
using SER.Code.MethodSystem;
1111
using SER.Code.MethodSystem.Methods.PlayerDataMethods;
12+
using SER.Code.MethodSystem.Methods.TeslaRuleMethds;
1213
using SER.Code.ScriptSystem;
1314
using SER.Code.VariableSystem;
1415
using EventHandler = SER.Code.EventSystem.EventHandler;
@@ -118,12 +119,14 @@ public override void Enable()
118119
Events.PlayerEvents.Joined += OnJoined;
119120

120121
FileSystem.FileSystem.Initialize();
122+
_ = new TeslaRuleHandler();
121123
}
122124

123125
public override void Disable()
124126
{
125127
Script.StopAll();
126128
SetPlayerDataMethod.PlayerData.Clear();
129+
TeslaRuleHandler.ResetAll();
127130
}
128131

129132
private void OnServerFullyInit(FrameworkBridge frameworkBridge)

0 commit comments

Comments
 (0)