Skip to content

Commit ed1e5cc

Browse files
committed
pickup spawning remake, a few minor fixes
- joined TPRelative and TPRoom together - added IReferenceResolvingMethod to PickupInfo and added a weight option - minor fix to the if statement in AddPickupToInventory because why not
1 parent b8db82e commit ed1e5cc

File tree

12 files changed

+279
-175
lines changed

12 files changed

+279
-175
lines changed

Code/MethodSystem/Methods/PickupMethods/AddPickupToInventoryMethod.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ public override void Execute()
2525
var player = Args.GetPlayer("player");
2626
var pickup = Args.GetReference<Pickup>("pickup");
2727

28-
if (!player.IsInventoryFull)
29-
{
30-
player.AddItem(pickup);
31-
}
28+
if (player.IsInventoryFull) return;
29+
30+
player.AddItem(pickup);
3231
}
3332
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using JetBrains.Annotations;
2+
using LabApi.Features.Wrappers;
3+
using Mirror;
4+
using SER.Code.ArgumentSystem.Arguments;
5+
using SER.Code.ArgumentSystem.BaseArguments;
6+
using SER.Code.Helpers.Exceptions;
7+
using SER.Code.MethodSystem.BaseMethods;
8+
using SER.Code.MethodSystem.MethodDescriptors;
9+
10+
namespace SER.Code.MethodSystem.Methods.PickupMethods;
11+
12+
[UsedImplicitly]
13+
public class DeletePickupMethod : SynchronousMethod, ICanError
14+
{
15+
public override string Description => "Removes a pickup / grenade from the ground.";
16+
17+
public string[] ErrorReasons =>
18+
[
19+
"The pickup/projectile hasn't been spawned yet or doesn't exist anymore."
20+
];
21+
22+
public override Argument[] ExpectedArguments { get; } =
23+
[
24+
new ReferenceArgument<Pickup>("pickup/projectile reference"),
25+
];
26+
27+
public override void Execute()
28+
{
29+
var obj = Args.GetReference<Pickup>("pickup/projectile reference");
30+
31+
if (!NetworkServer.spawned.ContainsValue(obj.NetworkIdentity))
32+
throw new ScriptRuntimeError(ErrorReasons[0]);
33+
34+
obj.Destroy();
35+
}
36+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using InventorySystem;
2+
using JetBrains.Annotations;
3+
using LabApi.Features.Wrappers;
4+
using SER.Code.ArgumentSystem.Arguments;
5+
using SER.Code.ArgumentSystem.BaseArguments;
6+
using SER.Code.Helpers.Exceptions;
7+
using SER.Code.MethodSystem.BaseMethods;
8+
using SER.Code.MethodSystem.MethodDescriptors;
9+
using Object = UnityEngine.Object;
10+
using ThrowableItem = InventorySystem.Items.ThrowableProjectiles.ThrowableItem;
11+
12+
namespace SER.Code.MethodSystem.Methods.PickupMethods;
13+
14+
[UsedImplicitly]
15+
public class GrenadeMethod : ReferenceReturningMethod<Projectile>, IAdditionalDescription
16+
{
17+
public override string Description => "Creates a new grenade projectile to later spawn.";
18+
19+
public string AdditionalDescription => "To spawn SCP-018, SCP-2176 or the grenades' unactivated versions, use the Pickup method.";
20+
21+
public override Argument[] ExpectedArguments { get; } =
22+
[
23+
new OptionsArgument("grenade type",
24+
"GrenadeHE",
25+
"GrenadeFlash"),
26+
];
27+
28+
public override void Execute()
29+
{
30+
if (!Enum.TryParse(Args.GetOption("grenade type"), true, out ItemType itemType) ||
31+
!InventoryItemLoader.TryGetItem<ThrowableItem>(itemType, out var throwable))
32+
throw new TosoksFuckedUpException("Either Northwood fucked up or you're a wizard. Congratulations!");
33+
34+
var item = Object.Instantiate(throwable.Projectile) ?? throw new TosoksFuckedUpException("Somehow the prefab failed to copy??? I don't even know who to blame tbh");
35+
item.Info = new(itemType, throwable.Weight);
36+
item.PreviousOwner = new(Server.Host?.ReferenceHub);
37+
38+
ReturnValue = Projectile.Get(item);
39+
}
40+
}

Code/MethodSystem/Methods/PickupMethods/PickupInfoMethod.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
using JetBrains.Annotations;
1+
using JetBrains.Annotations;
22
using LabApi.Features.Wrappers;
33
using SER.Code.ArgumentSystem.Arguments;
44
using SER.Code.ArgumentSystem.BaseArguments;
55
using SER.Code.ArgumentSystem.Structures;
66
using SER.Code.Helpers.Exceptions;
77
using SER.Code.MethodSystem.BaseMethods;
8+
using SER.Code.MethodSystem.MethodDescriptors;
89
using SER.Code.ValueSystem;
910

1011
namespace SER.Code.MethodSystem.Methods.PickupMethods;
1112

1213
[UsedImplicitly]
13-
public class PickupInfoMethod : ReturningMethod
14+
public class PickupInfoMethod : ReturningMethod, IReferenceResolvingMethod
1415
{
1516
public override string Description => "Returns information about a pickup.";
1617

@@ -23,6 +24,8 @@ public class PickupInfoMethod : ReturningMethod
2324
typeof(NumberValue)
2425
];
2526

27+
public Type ReferenceType => typeof(Pickup);
28+
2629
public override Argument[] ExpectedArguments { get; } =
2730
[
2831
new ReferenceArgument<Pickup>("pickup"),
@@ -36,7 +39,8 @@ public class PickupInfoMethod : ReturningMethod
3639
Option.Reference<Room>("room"),
3740
"positionX",
3841
"positionY",
39-
"positionZ"
42+
"positionZ",
43+
"weight"
4044
)
4145
];
4246

@@ -58,6 +62,7 @@ public override void Execute()
5862
"positionx" => new NumberValue((decimal)pickup.Position.x),
5963
"positiony" => new NumberValue((decimal)pickup.Position.y),
6064
"positionz" => new NumberValue((decimal)pickup.Position.z),
65+
"weight" => new NumberValue((decimal)pickup.Weight),
6166
_ => throw new AndrzejFuckedUpException("out of range")
6267
};
6368
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using InventorySystem;
2+
using JetBrains.Annotations;
3+
using LabApi.Features.Wrappers;
4+
using SER.Code.ArgumentSystem.Arguments;
5+
using SER.Code.ArgumentSystem.BaseArguments;
6+
using SER.Code.Helpers.Exceptions;
7+
using SER.Code.MethodSystem.BaseMethods;
8+
using Object = UnityEngine.Object;
9+
10+
namespace SER.Code.MethodSystem.Methods.PickupMethods;
11+
12+
[UsedImplicitly]
13+
public class PickupMethod : ReferenceReturningMethod<Pickup>
14+
{
15+
public override string Description => "Creates a new item pickup to later spawn.";
16+
17+
public override Argument[] ExpectedArguments { get; } =
18+
[
19+
new EnumArgument<ItemType>("item type"),
20+
];
21+
22+
public override void Execute()
23+
{
24+
var itemType = Args.GetEnum<ItemType>("item type");
25+
26+
if (!InventoryItemLoader.AvailableItems.TryGetValue(itemType, out var prefab))
27+
throw new TosoksFuckedUpException("Either Northwood fucked up or you're a wizard. Congratulations!");
28+
29+
var item = Object.Instantiate(prefab.PickupDropModel) ?? throw new TosoksFuckedUpException("Somehow the prefab failed to copy??? I don't even know who to blame tbh");
30+
item.Info = new(itemType, prefab.Weight);
31+
item.PreviousOwner = new(Server.Host?.ReferenceHub);
32+
33+
ReturnValue = Pickup.Get(item);
34+
}
35+
}

Code/MethodSystem/Methods/PickupMethods/SpawnPickupMethod.cs

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using JetBrains.Annotations;
2+
using LabApi.Features.Wrappers;
3+
using SER.Code.ArgumentSystem.Arguments;
4+
using SER.Code.ArgumentSystem.BaseArguments;
5+
using SER.Code.MethodSystem.BaseMethods;
6+
using SER.Code.MethodSystem.MethodDescriptors;
7+
8+
namespace SER.Code.MethodSystem.Methods.PickupMethods;
9+
10+
[UsedImplicitly]
11+
public class SpawnPickupPlayerMethod : SynchronousMethod, ICanError
12+
{
13+
public override string Description => "Spawns an item pickup / grenade on a player.";
14+
15+
public string[] ErrorReasons => SpawnPickupPosMethod.Singleton.ErrorReasons;
16+
17+
public override Argument[] ExpectedArguments { get; } =
18+
[
19+
new ReferenceArgument<Pickup>("pickup/projectile reference"),
20+
new PlayerArgument("player to spawn pickup on"),
21+
];
22+
23+
public override void Execute()
24+
{
25+
var obj = Args.GetReference<Pickup>("pickup/projectile reference");
26+
var plr = Args.GetPlayer("player to spawn pickup on");
27+
28+
SpawnPickupPosMethod.SpawnPickup(obj, plr.Position);
29+
}
30+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using JetBrains.Annotations;
2+
using LabApi.Features.Wrappers;
3+
using Mirror;
4+
using SER.Code.ArgumentSystem.Arguments;
5+
using SER.Code.ArgumentSystem.BaseArguments;
6+
using SER.Code.Helpers.Exceptions;
7+
using SER.Code.MethodSystem.BaseMethods;
8+
using SER.Code.MethodSystem.MethodDescriptors;
9+
using UnityEngine;
10+
11+
namespace SER.Code.MethodSystem.Methods.PickupMethods;
12+
13+
[UsedImplicitly]
14+
public class SpawnPickupPosMethod : SynchronousMethod, ICanError
15+
{
16+
public override string Description => "Spawns an item pickup / grenade at the coordinates.";
17+
18+
public string[] ErrorReasons =>
19+
[
20+
"The projectile/item has already been spawned."
21+
];
22+
23+
public override Argument[] ExpectedArguments { get; } =
24+
[
25+
new ReferenceArgument<Pickup>("pickup/projectile reference"),
26+
new FloatArgument("x position"),
27+
new FloatArgument("y position"),
28+
new FloatArgument("z position"),
29+
];
30+
31+
public override void Execute()
32+
{
33+
var obj = Args.GetReference<Pickup>("pickup/projectile reference");
34+
35+
Vector3 pos = new(
36+
Args.GetFloat("x position"),
37+
Args.GetFloat("y position"),
38+
Args.GetFloat("z position"));
39+
40+
SpawnPickup(obj, pos);
41+
}
42+
43+
// this is here just to make the ErrorReasons universal across all the pickup-spawning methods
44+
public static SpawnPickupPosMethod Singleton => field is null ? field = new SpawnPickupPosMethod() : field;
45+
46+
public static void SpawnPickup(Pickup obj, Vector3 pos)
47+
{
48+
obj.Position = pos;
49+
obj.Rotation = Quaternion.identity;
50+
obj.GameObject.SetActive(true);
51+
if (NetworkServer.spawned.ContainsValue(obj.NetworkIdentity))
52+
throw new ScriptRuntimeError(Singleton.ErrorReasons[0]);
53+
NetworkServer.Spawn(obj.GameObject);
54+
if (obj is Projectile projectile)
55+
projectile.Base.ServerActivate();
56+
}
57+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using JetBrains.Annotations;
2+
using LabApi.Features.Wrappers;
3+
using SER.Code.ArgumentSystem.Arguments;
4+
using SER.Code.ArgumentSystem.BaseArguments;
5+
using SER.Code.MethodSystem.BaseMethods;
6+
using SER.Code.MethodSystem.MethodDescriptors;
7+
8+
namespace SER.Code.MethodSystem.Methods.PickupMethods;
9+
10+
[UsedImplicitly]
11+
public class SpawnPickupRoomMethod : SynchronousMethod, ICanError
12+
{
13+
public override string Description => "Spawns an item pickup / grenade in a room.";
14+
15+
public string[] ErrorReasons => SpawnPickupPosMethod.Singleton.ErrorReasons;
16+
17+
public override Argument[] ExpectedArguments { get; } =
18+
[
19+
new ReferenceArgument<Pickup>("pickup/projectile reference"),
20+
new RoomArgument("room to spawn pickup in"),
21+
new FloatArgument("relative x")
22+
{
23+
DefaultValue = new(0, null)
24+
},
25+
new FloatArgument("relative y")
26+
{
27+
DefaultValue = new(0, null)
28+
},
29+
new FloatArgument("relative z")
30+
{
31+
DefaultValue = new(0, null)
32+
},
33+
];
34+
35+
public override void Execute()
36+
{
37+
var obj = Args.GetReference<Pickup>("pickup/projectile reference");
38+
var room = Args.GetRoom("room to teleport to");
39+
var pos = room.Transform.TransformPoint(new(
40+
Args.GetFloat("relative x"),
41+
Args.GetFloat("relative y"),
42+
Args.GetFloat("relative z")));
43+
44+
SpawnPickupPosMethod.SpawnPickup(obj, pos);
45+
}
46+
}

0 commit comments

Comments
 (0)