Cargo telepad machine linking (#7756)

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
Chris V
2022-05-12 03:24:24 -07:00
committed by GitHub
parent 06bc4c953f
commit c6483751bc
7 changed files with 62 additions and 34 deletions

View File

@@ -1,13 +1,13 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Content.Server.Access.Systems;
using Content.Server.Cargo.Components;
using Content.Server.MachineLinking.Components;
using Content.Server.MachineLinking.Events;
using Content.Server.MachineLinking.System;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Cargo;
using Content.Shared.GameTicking;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.Cargo
{
@@ -35,7 +35,7 @@ namespace Content.Server.Cargo
/// <summary>
/// Used to assign IDs to bank accounts. Incremental counter.
/// </summary>
private int _accountIndex = 0;
private int _accountIndex;
/// <summary>
/// Enumeration of all bank accounts.
/// </summary>
@@ -49,12 +49,18 @@ namespace Content.Server.Cargo
[Dependency] private readonly IdCardSystem _idCardSystem = default!;
[Dependency] private readonly AccessReaderSystem _accessReaderSystem = default!;
[Dependency] private readonly SignalLinkerSystem _linker = default!;
private void InitializeConsole()
{
SubscribeLocalEvent<CargoConsoleComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
Reset();
}
private void OnInit(EntityUid uid, CargoConsoleComponent console, ComponentInit args)
{
_linker.EnsureTransmitterPorts(uid, console.SenderPort);
}
private void Reset(RoundRestartCleanupEvent ev)
{

View File

@@ -2,7 +2,10 @@ using Content.Server.Cargo.Components;
using Content.Server.Labels.Components;
using Content.Server.Paper;
using Content.Server.Power.Components;
using Content.Server.MachineLinking.Components;
using Content.Server.MachineLinking.Events;
using Content.Shared.Cargo;
using Content.Shared.Cargo.Components;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
@@ -16,6 +19,7 @@ public sealed partial class CargoSystem
private void InitializeTelepad()
{
SubscribeLocalEvent<CargoTelepadComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<CargoTelepadComponent, PowerChangedEvent>(OnTelepadPowerChange);
// Shouldn't need re-anchored event
SubscribeLocalEvent<CargoTelepadComponent, AnchorStateChangedEvent>(OnTelepadAnchorChange);
@@ -57,6 +61,11 @@ public sealed partial class CargoSystem
}
}
private void OnInit(EntityUid uid, CargoTelepadComponent telepad, ComponentInit args)
{
_linker.EnsureReceiverPorts(uid, telepad.ReceiverPort);
}
private void SetEnabled(CargoTelepadComponent component, ApcPowerReceiverComponent? receiver = null,
TransformComponent? xform = null)
{

View File

@@ -1,27 +1,21 @@
using System.Collections.Generic;
using System.Linq;
using Content.Server.Coordinates.Helpers;
using Content.Server.Power.Components;
using Content.Server.UserInterface;
using Content.Shared.Cargo;
using Content.Shared.Cargo.Components;
using Content.Shared.Sound;
using Content.Server.MachineLinking.Components;
using Content.Shared.MachineLinking;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Player;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Cargo.Components
{
[RegisterComponent]
public sealed class CargoConsoleComponent : SharedCargoConsoleComponent
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IEntityManager _entMan = default!;
private CargoBankAccount? _bankAccount;
@@ -64,6 +58,9 @@ namespace Content.Server.Cargo.Components
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(CargoConsoleUiKey.Key);
[DataField("senderPort", customTypeSerializer: typeof(PrototypeIdSerializer<TransmitterPortPrototype>))]
public string SenderPort = "OrderSender";
protected override void Initialize()
{
base.Initialize();
@@ -160,23 +157,18 @@ namespace Content.Server.Cargo.Components
//orders.Database.ClearOrderCapacity();
// TODO replace with shuttle code
// TEMPORARY loop for spawning stuff on telepad (looks for a telepad adjacent to the console)
EntityUid? cargoTelepad = null;
var indices = _entMan.GetComponent<TransformComponent>(Owner).Coordinates.ToVector2i(_entMan, _mapManager);
var offsets = new Vector2i[] { new Vector2i(0, 1), new Vector2i(1, 1), new Vector2i(1, 0), new Vector2i(1, -1),
new Vector2i(0, -1), new Vector2i(-1, -1), new Vector2i(-1, 0), new Vector2i(-1, 1), };
var lookup = EntitySystem.Get<EntityLookupSystem>();
var gridId = _entMan.GetComponent<TransformComponent>(Owner).GridID;
// TODO: Should use anchoring.
foreach (var entity in lookup.GetEntitiesIntersecting(gridId, offsets.Select(o => o + indices)))
if (_entMan.TryGetComponent<SignalTransmitterComponent>(Owner, out var transmitter) &&
transmitter.Outputs.TryGetValue(SenderPort, out var telepad) &&
telepad.Count > 0)
{
if (_entMan.HasComponent<CargoTelepadComponent>(entity) && _entMan.TryGetComponent<ApcPowerReceiverComponent?>(entity, out var powerReceiver) && powerReceiver.Powered)
{
cargoTelepad = entity;
break;
}
// use most recent link
var pad = telepad[^1].Uid;
if (_entMan.HasComponent<CargoTelepadComponent>(pad) &&
_entMan.TryGetComponent<ApcPowerReceiverComponent?>(pad, out var powerReceiver) &&
powerReceiver.Powered)
cargoTelepad = pad;
}
if (cargoTelepad != null)

View File

@@ -1,5 +1,6 @@
using Content.Shared.Cargo;
using Content.Shared.Cargo.Components;
using Content.Shared.MachineLinking;
using Content.Shared.Sound;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
@@ -35,5 +36,8 @@ namespace Content.Server.Cargo.Components
/// </summary>
[DataField("printerOutput", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string PrinterOutput = "Paper";
[DataField("receiverPort", customTypeSerializer: typeof(PrototypeIdSerializer<ReceiverPortPrototype>))]
public string ReceiverPort = "OrderReceiver";
}
}

View File

@@ -21,3 +21,9 @@ signal-port-description-close = Closes a device.
signal-port-name-trigger = Trigger
signal-port-description-trigger = Triggers some mechanism on the device.
signal-port-name-order-sender = Order sender
signal-port-description-order-sender = Cargo console order sender
signal-port-name-order-receiver = Order receiver
signal-port-description-order-receiver = Cargo console order receiver

View File

@@ -37,3 +37,8 @@
id: Trigger
name: signal-port-name-trigger
description: signal-port-description-trigger
- type: receiverPort
id: OrderReceiver
name: signal-port-name-order-receiver
description: signal-port-description-order-receiver

View File

@@ -14,22 +14,28 @@
id: Off
name: signal-port-name-off-transmitter
description: signal-port-description-off-transmitter
defaultLinks: [ Off, Close]
defaultLinks: [ Off, Close ]
- type: transmitterPort
id: Left
name: signal-port-name-left
description: signal-port-description-left
defaultLinks: [ On, Open, Forward, Trigger]
defaultLinks: [ On, Open, Forward, Trigger ]
- type: transmitterPort
id: Right
name: signal-port-name-right
description: signal-port-description-right
defaultLinks: [ On, Open, Reverse, Trigger]
defaultLinks: [ On, Open, Reverse, Trigger ]
- type: transmitterPort
id: Middle
name: signal-port-name-middle
description: signal-port-description-middle
defaultLinks: [ Off, Close]
defaultLinks: [ Off, Close ]
- type: transmitterPort
id: OrderSender
name: signal-port-name-order-sender
description: signal-port-description-order-sender
defaultLinks: [ OrderReceiver ]