-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathSpawnerLinkSystem.cs
More file actions
42 lines (34 loc) · 1.54 KB
/
SpawnerLinkSystem.cs
File metadata and controls
42 lines (34 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using Content.Goobstation.Common.Spawner;
using Content.Goobstation.Shared.Spawner;
using Content.Server.Ghost.Roles.Events;
using Content.Shared.Teleportation.Components;
using Content.Shared.Teleportation.Systems;
namespace Content.Goobstation.Server.Spawner;
public sealed partial class SpawnerLinkSystem : EntitySystem
{
[Dependency] private LinkedEntitySystem _link = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SpawnerLinkComponent, SpawnerActivationEvent>(OnSpawnerActivation);
SubscribeLocalEvent<LinkedEntityTransferComponent, SpawnerActivationEvent>(OnLinkTransferActivation);
SubscribeLocalEvent<LinkedEntityTransferComponent, GhostRoleSpawnerUsedEvent>(OnGhostRoleSpawnerUsed);
}
private void OnSpawnerActivation(Entity<SpawnerLinkComponent> ent, ref SpawnerActivationEvent args)
{
_link.TryLink(ent.Owner, args.Spawned);
}
private void OnLinkTransferActivation(Entity<LinkedEntityTransferComponent> ent, ref SpawnerActivationEvent args)
=> TransferLinks(ent.Owner, args.Spawned);
private void OnGhostRoleSpawnerUsed(Entity<LinkedEntityTransferComponent> ent, ref GhostRoleSpawnerUsedEvent args)
=> TransferLinks(ent.Owner, args.Spawned);
private void TransferLinks(Entity<LinkedEntityComponent?> from, EntityUid to)
{
if (!Resolve(from.Owner, ref from.Comp))
return;
foreach (var linked in from.Comp.LinkedEntities)
{
_link.TryLink(to, linked);
}
}
}