Files
Delta-v/Content.Server/_Goobstation/Factory/InteractorSystem.cs
T
AlgisAlphonse f7db03182a Port goobstation factorio (#4035)
* Initial port of goobstation factorio, missing disposals integration and faxing. Also ports impstations modification for robotic arms to have static power draw. Also adds automation slots to silos and advanced microwave.

* Ports goobstation factorio fax automation, adds to the guidebook entry info about gas canisters.

* Ported Goob Disposals. Removed part about taking
mats out of storage silo cuz it ain't implemented
yet. Seems to work.

* Adds constructor circuitboard to research cuz I
forgor
2025-07-27 13:31:36 +01:00

66 lines
2.2 KiB
C#

// SPDX-FileCopyrightText: 2025 GoobBot <uristmchands@proton.me>
// SPDX-FileCopyrightText: 2025 deltanedas <39013340+deltanedas@users.noreply.github.com>
// SPDX-FileCopyrightText: 2025 deltanedas <@deltanedas:kde.org>
// SPDX-FileCopyrightText: 2025 gluesniffler <159397573+gluesniffler@users.noreply.github.com>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
using Content.Shared._Goobstation.Factory;
using Content.Server.Construction.Components;
namespace Content.Server._Goobstation.Factory;
public sealed class InteractorSystem : SharedInteractorSystem
{
private EntityQuery<ConstructionComponent> _constructionQuery;
public override void Initialize()
{
base.Initialize();
_constructionQuery = GetEntityQuery<ConstructionComponent>();
SubscribeLocalEvent<InteractorComponent, MachineStartedEvent>(OnStarted);
}
private void OnStarted(Entity<InteractorComponent> ent, ref MachineStartedEvent args)
{
// nothing there or another doafter is already running
var count = ent.Comp.TargetEntities.Count;
if (count == 0 || HasDoAfter(ent))
{
Machine.Failed(ent.Owner);
return;
}
var i = count - 1;
var netEnt = ent.Comp.TargetEntities[i].Item1;
var target = GetEntity(netEnt);
_constructionQuery.TryComp(target, out var construction);
var originalCount = construction?.InteractionQueue?.Count ?? 0;
if (!InteractWith(ent, target))
{
// have to remove it since user's filter was bad due to unhandled interaction
RemoveTarget(ent, target);
Machine.Failed(ent.Owner);
return;
}
// construction supercode queues it instead of starting a doafter now, assume that queuing means it has started
var newCount = construction?.InteractionQueue?.Count ?? 0;
if (newCount > originalCount
|| HasDoAfter(ent))
{
Machine.Started(ent.Owner);
UpdateAppearance(ent, InteractorState.Active);
}
else
{
// no doafter, complete it immediately
TryRemoveTarget(ent, target);
Machine.Completed(ent.Owner);
UpdateAppearance(ent);
}
}
}