Files
crystall-punk-14/Content.Server/_CP14/PortalAutoLink/CP14AutoLinkSystem.cs
Ed b803496694 Procedural + z-levels refactor (#216)
* create biome tile spawner

* spawner now spawn decals and entities

* fancy spawners

* remove old decals

* randomize seed

* fix bugs

* update alchemy test map to new system

* update z-level system

* autolink tweak

* add documentation

* Update GravityComponent.cs

* Update GravityComponent.cs
2024-06-05 19:59:39 +03:00

45 lines
1.3 KiB
C#

using Content.Shared.Interaction;
using Content.Shared.Teleportation.Systems;
namespace Content.Server._CP14.PortalAutoLink;
public sealed partial class CP14AutoLinkSystem : EntitySystem
{
[Dependency] private readonly LinkedEntitySystem _link = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CP14AutoLinkComponent, MapInitEvent>(OnMapInit);
}
private void OnMapInit(Entity<CP14AutoLinkComponent> autolink, ref MapInitEvent args)
{
TryAutoLink(autolink, out var otherLink);
}
public bool TryAutoLink(Entity<CP14AutoLinkComponent> autolink, out EntityUid? linkedEnt)
{
linkedEnt = null;
var query = EntityQueryEnumerator<CP14AutoLinkComponent>();
while (query.MoveNext(out var uid, out var otherAutolink))
{
if (autolink.Comp == otherAutolink)
continue;
if (autolink.Comp.AutoLinkKey == otherAutolink.AutoLinkKey)
{
if (_link.TryLink(autolink, uid, false))
{
RemComp<CP14AutoLinkComponent>(uid);
RemComp<CP14AutoLinkComponent>(autolink);
return true;
}
}
}
return false;
}
}