Skip to content

Commit 6fd7b07

Browse files
committed
Get096Targets method, moved scp173Observers to method
1 parent d45939d commit 6fd7b07

File tree

4 files changed

+81
-14
lines changed

4 files changed

+81
-14
lines changed

Code/Helpers/Extensions/PlayerExtensions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using LabApi.Features.Wrappers;
2+
using PlayerRoles.PlayableScps.Scp096;
23
using PlayerRoles.PlayableScps.Scp173;
34
using UnityEngine;
45

@@ -23,4 +24,17 @@ public static Vector3 RelativeRoomPosition(this Player player)
2324
.RemoveNulls()
2425
.ToArray();
2526
}
27+
28+
extension(Scp096Role shyGuy)
29+
{
30+
public Scp096TargetsTracker TargetsTracker =>
31+
!shyGuy.SubroutineModule.TryGetSubroutine(out Scp096TargetsTracker targetsTracker)
32+
? throw new Exception("My hatred towards Northwood's code grows stronger with each day.")
33+
: targetsTracker;
34+
35+
public Player[] Targets => shyGuy.TargetsTracker.Targets
36+
.Select(Player.Get)
37+
.RemoveNulls()
38+
.ToArray();
39+
}
2640
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using JetBrains.Annotations;
2+
using LabApi.Features.Wrappers;
3+
using PlayerRoles.PlayableScps.Scp096;
4+
using SER.Code.ArgumentSystem.Arguments;
5+
using SER.Code.ArgumentSystem.BaseArguments;
6+
using SER.Code.Helpers.Exceptions;
7+
using SER.Code.Helpers.Extensions;
8+
using SER.Code.MethodSystem.BaseMethods;
9+
using SER.Code.MethodSystem.MethodDescriptors;
10+
using SER.Code.ValueSystem;
11+
12+
namespace SER.Code.MethodSystem.Methods.ScpMethods;
13+
14+
[UsedImplicitly]
15+
public class Get096TargetsMethod : ReturningMethod<PlayerValue>, ICanError
16+
{
17+
public override string Description => "Returns the targets of the specified SCP-096";
18+
19+
public string[] ErrorReasons =>
20+
[
21+
"The specified player isn't SCP-096."
22+
];
23+
24+
public override Argument[] ExpectedArguments { get; } =
25+
[
26+
new PlayerArgument("shy guy")
27+
{
28+
DefaultValue = new(null, "Every target from every SCP-096")
29+
}
30+
];
31+
32+
public override void Execute()
33+
{
34+
var shyGuy = Args.GetPlayer("shy guy").MaybeNull();
35+
36+
if (shyGuy is null)
37+
{
38+
ReturnValue = new PlayerValue(Player.ReadyList
39+
.Select(plr => plr.RoleBase is Scp096Role paleGuy ? paleGuy.Targets : null)
40+
.RemoveNulls()
41+
.Flatten());
42+
return;
43+
}
44+
45+
if (shyGuy.RoleBase is not Scp096Role shyGuyRole)
46+
throw new ScriptRuntimeError(this, ErrorReasons[0]);
47+
48+
ReturnValue = new PlayerValue(shyGuyRole.Targets);
49+
}
50+
}

Code/MethodSystem/Methods/ScpMethods/Get173ObserversMethod.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
using Exiled.Events.Handlers;
2-
using JetBrains.Annotations;
1+
using JetBrains.Annotations;
2+
using LabApi.Features.Wrappers;
33
using PlayerRoles.PlayableScps.Scp173;
44
using SER.Code.ArgumentSystem.Arguments;
55
using SER.Code.ArgumentSystem.BaseArguments;
6-
using SER.Code.ContextSystem.Structures;
76
using SER.Code.Helpers.Exceptions;
87
using SER.Code.Helpers.Extensions;
98
using SER.Code.MethodSystem.BaseMethods;
109
using SER.Code.MethodSystem.MethodDescriptors;
1110
using SER.Code.ValueSystem;
12-
using Player = LabApi.Features.Wrappers.Player;
1311

1412
namespace SER.Code.MethodSystem.Methods.ScpMethods;
1513

@@ -26,13 +24,25 @@ public class Get173ObserversMethod : ReturningMethod<PlayerValue>, ICanError
2624
public override Argument[] ExpectedArguments { get; } =
2725
[
2826
new PlayerArgument("peanut")
27+
{
28+
DefaultValue = new(null, "Every observer from every SCP-173")
29+
}
2930
];
3031

3132
public override void Execute()
3233
{
33-
var pnut = Args.GetPlayer("peanut");
34+
var peanut = Args.GetPlayer("peanut").MaybeNull();
35+
36+
if (peanut is null)
37+
{
38+
ReturnValue = new PlayerValue(Player.ReadyList
39+
.Select(plr => plr.RoleBase is Scp173Role sculpture ? sculpture.ObservingPlayers : null)
40+
.RemoveNulls()
41+
.Flatten());
42+
return;
43+
}
3444

35-
if (pnut.RoleBase is not Scp173Role pnutRole)
45+
if (peanut.RoleBase is not Scp173Role pnutRole)
3646
throw new ScriptRuntimeError(this, ErrorReasons[0]);
3747

3848
ReturnValue = new PlayerValue(pnutRole.ObservingPlayers);

Code/VariableSystem/VariableIndex.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@ public static void Initialize()
2121
new("all", Player.ReadyList.ToList, "Other"),
2222
new("alivePlayers", () => Player.ReadyList.Where(plr => plr.IsAlive).ToList(), "Other"),
2323
new("npcPlayers", () => Player.ReadyList.Where(plr => plr.IsNpc).ToList(), "Other"),
24-
new("empty", () => [], "Other"),
25-
new("scp173Observers", () => Player.ReadyList
26-
.Select(plr => plr.RoleBase is Scp173Role peanut ? peanut.ObservingPlayers : null)
27-
.RemoveNulls()
28-
.Flatten()
29-
.ToList(),
30-
"SCP Specific")
31-
24+
new("empty", () => [], "Other")
3225
];
3326

3427
allApiVariables.AddRange(

0 commit comments

Comments
 (0)