public sealed partial class GatewayComponent : Component
{
/// <summary>
- /// Sound to play when opening or closing the portal.
+ /// Sound to play when opening the portal.
/// </summary>
+ /// <remarks>
+ /// Originally named PortalSound as it was used for opening and closing.
+ /// </remarks>
[DataField("portalSound")]
- public SoundSpecifier PortalSound = new SoundPathSpecifier("/Audio/Effects/Lightning/lightningbolt.ogg");
+ public SoundSpecifier OpenSound = new SoundPathSpecifier("/Audio/Effects/Lightning/lightningbolt.ogg");
+
+ /// <summary>
+ /// Sound to play when closing the portal.
+ /// </summary>
+ [DataField]
+ public SoundSpecifier CloseSound = new SoundPathSpecifier("/Audio/Effects/Lightning/lightningbolt.ogg");
+
+ /// <summary>
+ /// Sound to play when trying to open or close the portal and missing access.
+ /// </summary>
+ [DataField]
+ public SoundSpecifier AccessDeniedSound = new SoundPathSpecifier("/Audio/Machines/custom_deny.ogg");
/// <summary>
/// Every other gateway destination on the server.
/// <remarks>
/// Added on startup and when a new destination portal is created.
/// </remarks>
- [ViewVariables]
+ [DataField]
public HashSet<EntityUid> Destinations = new();
/// <summary>
/// The time at which the portal will be closed.
/// </summary>
- [ViewVariables(VVAccess.ReadWrite), DataField("nextClose", customTypeSerializer:typeof(TimeOffsetSerializer))]
+ [ViewVariables(VVAccess.ReadWrite), DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextClose;
/// <summary>
/// The time at which the portal was last opened.
/// Only used for UI.
/// </summary>
- [ViewVariables]
+ [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan LastOpen;
}
/// Whether this destination is shown in the gateway ui.
/// If you are making a gateway for an admeme set this once you are ready for players to select it.
/// </summary>
- [DataField("enabled"), ViewVariables(VVAccess.ReadWrite)]
+ [DataField, ViewVariables(VVAccess.ReadWrite)]
public bool Enabled;
/// <summary>
/// Name as it shows up on the ui of station gateways.
/// </summary>
- [DataField("name"), ViewVariables(VVAccess.ReadWrite)]
+ [DataField, ViewVariables(VVAccess.ReadWrite)]
public string Name = string.Empty;
/// <summary>
/// Time at which this destination is ready to be linked to.
/// </summary>
- [ViewVariables(VVAccess.ReadWrite), DataField("nextReady", customTypeSerializer:typeof(TimeOffsetSerializer))]
+ [ViewVariables(VVAccess.ReadWrite), DataField(customTypeSerializer:typeof(TimeOffsetSerializer))]
public TimeSpan NextReady;
/// <summary>
/// How long the portal will be open for after linking.
/// </summary>
- [DataField("openTime"), ViewVariables(VVAccess.ReadWrite)]
+ [DataField, ViewVariables(VVAccess.ReadWrite)]
public TimeSpan OpenTime = TimeSpan.FromSeconds(600);
/// <summary>
/// How long the destination is not ready for after the portal closes.
/// </summary>
- [DataField("cooldown"), ViewVariables(VVAccess.ReadWrite)]
+ [DataField, ViewVariables(VVAccess.ReadWrite)]
public TimeSpan Cooldown = TimeSpan.FromSeconds(60);
+
+ /// <summary>
+ /// If true, the portal can be closed by alt clicking it.
+ /// </summary>
+ [DataField, ViewVariables(VVAccess.ReadWrite)]
+ public bool Closeable;
}
using Content.Server.Gateway.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Gateway;
+using Content.Shared.Popups;
using Content.Shared.Teleportation.Components;
using Content.Shared.Teleportation.Systems;
+using Content.Shared.Verbs;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Timing;
-using System.Diagnostics.CodeAnalysis;
-using System.Linq;
namespace Content.Server.Gateway.Systems;
[Dependency] private readonly LinkedEntitySystem _linkedEntity = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
+ [Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
public override void Initialize()
SubscribeLocalEvent<GatewayDestinationComponent, ComponentStartup>(OnDestinationStartup);
SubscribeLocalEvent<GatewayDestinationComponent, ComponentShutdown>(OnDestinationShutdown);
+ SubscribeLocalEvent<GatewayDestinationComponent, GetVerbsEvent<AlternativeVerb>>(OnDestinationGetVerbs);
}
public override void Update(float frameTime)
destinations.Add((GetNetEntity(destUid), dest.Name, dest.NextReady, HasComp<PortalComponent>(destUid)));
}
- GetDestination(uid, out var current);
+ _linkedEntity.GetLink(uid, out var current);
var state = new GatewayBoundUserInterfaceState(destinations, GetNetEntity(current), comp.NextClose, comp.LastOpen);
_ui.TrySetUiState(uid, GatewayUiKey.Key, state);
}
// if the gateway has an access reader check it before allowing opening
var user = args.Session.AttachedEntity.Value;
- if (!_accessReader.IsAllowed(user, uid))
+ if (CheckAccess(user, uid))
return;
// can't link if portal is already open on either side, the destination is invalid or on cooldown
// close automatically after time is up
comp.NextClose = comp.LastOpen + destComp.OpenTime;
- _audio.PlayPvs(comp.PortalSound, uid);
- _audio.PlayPvs(comp.PortalSound, dest);
+ _audio.PlayPvs(comp.OpenSound, uid);
+ _audio.PlayPvs(comp.OpenSound, dest);
UpdateUserInterface(uid, comp);
UpdateAppearance(uid);
UpdateAppearance(dest);
}
- private void ClosePortal(EntityUid uid, GatewayComponent comp)
+ private void ClosePortal(EntityUid uid, GatewayComponent? comp = null)
{
+ if (!Resolve(uid, ref comp))
+ return;
+
RemComp<PortalComponent>(uid);
- if (!GetDestination(uid, out var dest))
+ if (!_linkedEntity.GetLink(uid, out var dest))
return;
if (TryComp<GatewayDestinationComponent>(dest, out var destComp))
destComp.NextReady = _timing.CurTime + destComp.Cooldown;
}
- _audio.PlayPvs(comp.PortalSound, uid);
- _audio.PlayPvs(comp.PortalSound, dest.Value);
+ _audio.PlayPvs(comp.CloseSound, uid);
+ _audio.PlayPvs(comp.CloseSound, dest.Value);
_linkedEntity.TryUnlink(uid, dest.Value);
RemComp<PortalComponent>(dest.Value);
UpdateAppearance(dest.Value);
}
- private bool GetDestination(EntityUid uid, [NotNullWhen(true)] out EntityUid? dest)
- {
- dest = null;
- if (TryComp<LinkedEntityComponent>(uid, out var linked))
- {
- var first = linked.LinkedEntities.FirstOrDefault();
- if (first != EntityUid.Invalid)
- {
- dest = first;
- return true;
- }
- }
-
- return false;
- }
-
private void OnDestinationStartup(EntityUid uid, GatewayDestinationComponent comp, ComponentStartup args)
{
var query = EntityQueryEnumerator<GatewayComponent>();
UpdateUserInterface(gatewayUid, gateway);
}
}
+
+ private void OnDestinationGetVerbs(EntityUid uid, GatewayDestinationComponent comp, GetVerbsEvent<AlternativeVerb> args)
+ {
+ if (!comp.Closeable || !args.CanInteract || !args.CanAccess)
+ return;
+
+ // a portal is open so add verb to close it
+ args.Verbs.Add(new AlternativeVerb()
+ {
+ Act = () => TryClose(uid, args.User),
+ Text = Loc.GetString("gateway-close-portal")
+ });
+ }
+
+ private void TryClose(EntityUid uid, EntityUid user)
+ {
+ // portal already closed so cant close it
+ if (!_linkedEntity.GetLink(uid, out var source))
+ return;
+
+ // not allowed to close it
+ if (CheckAccess(user, source.Value))
+ return;
+
+ ClosePortal(source.Value);
+ }
+
+ /// <summary>
+ /// Checks the user's access. Makes popup and plays sound if missing access.
+ /// Returns whether access was missing.
+ /// </summary>
+ private bool CheckAccess(EntityUid user, EntityUid uid, GatewayComponent? comp = null)
+ {
+ if (!Resolve(uid, ref comp))
+ return false;
+
+ if (_accessReader.IsAllowed(user, uid))
+ return false;
+
+ _popup.PopupEntity(Loc.GetString("gateway-access-denied"), user);
+ _audio.PlayPvs(comp.AccessDeniedSound, uid);
+ return true;
+ }
}