Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vent crawl update #73

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 6 additions & 52 deletions Content.Server/VentCraw/VentCrawTubeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed class VentCrawTubeSystem : EntitySystem
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
[Dependency] private readonly VentCrawableSystem _ventCrawableSystemSystem = default!;
[Dependency] private readonly SharedVentCrawableSystem _ventCrawableSystemSystem = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly VentCrawTubeSystem _ventCrawTubeSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
Expand Down Expand Up @@ -49,7 +49,7 @@ public override void Initialize()

private void AddClimbedVerb(EntityUid uid, VentCrawEntryComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!TryComp<VentCrawlerComponent>(args.User, out var ventCrawlerComponent))
if (!TryComp<VentCrawlerComponent>(args.User, out var ventCrawlerComponent) || HasComp<BeingVentCrawComponent>(args.User))
return;

if (TryComp<TransformComponent>(uid, out var transformComponent) && !transformComponent.Anchored)
Expand Down Expand Up @@ -170,43 +170,6 @@ private void UpdateAnchored(EntityUid uid, VentCrawTubeComponent component, bool
}
}

public EntityUid? NextTubeFor(EntityUid target, Direction nextDirection, VentCrawTubeComponent? targetTube = null)
{
if (!Resolve(target, ref targetTube))
return null;
var oppositeDirection = nextDirection.GetOpposite();

var xform = Transform(target);
if (!TryComp<MapGridComponent>(xform.GridUid, out var grid))
return null;

if (xform.GridUid == null)
return null;

var position = xform.Coordinates;
foreach (EntityUid entity in _mapSystem.GetInDir(xform.GridUid.Value, grid ,position, nextDirection))
{
if (!TryComp(entity, out VentCrawTubeComponent? tube))
{
continue;
}

if (!CanConnect(entity, tube, oppositeDirection))
{
continue;
}

if (!CanConnect(target, targetTube, nextDirection))
{
continue;
}

return entity;
}

return null;
}

private static void ConnectTube(EntityUid _, VentCrawTubeComponent tube)
{
if (tube.Connected)
Expand All @@ -231,20 +194,11 @@ private void DisconnectTube(EntityUid _, VentCrawTubeComponent tube)
foreach (var entity in tube.Contents.ContainedEntities.ToArray())
{
if (query.TryGetComponent(entity, out var holder))
_ventCrawableSystemSystem.ExitVentCraws(entity, holder);
}
}

private bool CanConnect(EntityUid tubeId, VentCrawTubeComponent tube, Direction direction)
{
if (!tube.Connected)
{
return false;
{
var Exitev = new VentCrawExitEvent();
RaiseLocalEvent(entity, ref Exitev);
}
}

var ev = new GetVentCrawsConnectableDirectionsEvent();
RaiseLocalEvent(tubeId, ref ev);
return ev.Connectable.Contains(direction);
}

private bool TryInsert(EntityUid uid, EntityUid entity, VentCrawEntryComponent? entry = null)
Expand Down
Loading
Loading