gateway changes (#20304)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
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;
|
||||
|
||||
@@ -19,6 +19,7 @@ public sealed class GatewaySystem : EntitySystem
|
||||
[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()
|
||||
@@ -31,6 +32,7 @@ public sealed class GatewaySystem : EntitySystem
|
||||
|
||||
SubscribeLocalEvent<GatewayDestinationComponent, ComponentStartup>(OnDestinationStartup);
|
||||
SubscribeLocalEvent<GatewayDestinationComponent, ComponentShutdown>(OnDestinationShutdown);
|
||||
SubscribeLocalEvent<GatewayDestinationComponent, GetVerbsEvent<AlternativeVerb>>(OnDestinationGetVerbs);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
@@ -78,7 +80,7 @@ public sealed class GatewaySystem : EntitySystem
|
||||
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);
|
||||
}
|
||||
@@ -95,7 +97,7 @@ public sealed class GatewaySystem : EntitySystem
|
||||
|
||||
// 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
|
||||
@@ -123,18 +125,21 @@ public sealed class GatewaySystem : EntitySystem
|
||||
// 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))
|
||||
@@ -143,8 +148,8 @@ public sealed class GatewaySystem : EntitySystem
|
||||
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);
|
||||
@@ -153,22 +158,6 @@ public sealed class GatewaySystem : EntitySystem
|
||||
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>();
|
||||
@@ -190,4 +179,47 @@ public sealed class GatewaySystem : EntitySystem
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user