Adds door remotes from SS13 (#6335)
This commit is contained in:
committed by
GitHub
parent
32ada7de7a
commit
11eb591c54
93
Content.Server/Remotes/DoorRemoteSystem.cs
Normal file
93
Content.Server/Remotes/DoorRemoteSystem.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Audio;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Doors.Components;
|
||||
using Content.Shared.Doors.Systems;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Server.Doors.Systems;
|
||||
using Content.Server.Doors.Components;
|
||||
|
||||
namespace Content.Server.Remotes
|
||||
{
|
||||
public sealed class DoorRemoteSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedDoorSystem _sharedDoorSystem = default!;
|
||||
[Dependency] private readonly DoorSystem _doorSystem = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<DoorRemoteComponent, UseInHandEvent>(OnInHandActivation);
|
||||
SubscribeLocalEvent<DoorRemoteComponent, AfterInteractEvent>(OnAfterInteract);
|
||||
}
|
||||
|
||||
public void OnInHandActivation(EntityUid user, DoorRemoteComponent component, UseInHandEvent args)
|
||||
{
|
||||
switch (component.Mode)
|
||||
{
|
||||
case DoorRemoteComponent.OperatingMode.OpenClose:
|
||||
component.Mode = DoorRemoteComponent.OperatingMode.ToggleBolts;
|
||||
_popupSystem.PopupEntity(Loc.GetString("door-remote-switch-state-toggle-bolts"), args.User, Filter.Entities(args.User));
|
||||
break;
|
||||
case DoorRemoteComponent.OperatingMode.ToggleBolts:
|
||||
component.Mode = DoorRemoteComponent.OperatingMode.OpenClose; // TODO: Swítch to ToggleEmergencyAcces when EA is implemented
|
||||
_popupSystem.PopupEntity(Loc.GetString("door-remote-switch-state-open-close"), args.User, Filter.Entities(args.User)); // TODO: See the above comment
|
||||
break;
|
||||
/*
|
||||
case DoorRemoteComponent.OperatingMode.ToggleEmergencyAccess:
|
||||
component.Mode = DoorRemoteComponent.OperatingMode.OpenClose;
|
||||
_popupSystem.PopupEntity(Loc.GetString("door-remote-switch-state-open-close"), args.User, Filter.Entities(args.User));
|
||||
break;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAfterInteract(EntityUid uid, DoorRemoteComponent component, AfterInteractEvent args)
|
||||
{
|
||||
if (args.Handled
|
||||
|| args.Target == null
|
||||
|| !TryComp<DoorComponent>(args.Target, out var doorComponent) // If it isn't a door we don't use it
|
||||
|| !HasComp<AccessReaderComponent>(args.Target) // Remotes do not work on doors without access requirements
|
||||
|| !TryComp<AirlockComponent>(args.Target, out var airlockComponent) // Remotes only work on airlocks
|
||||
|| !_interactionSystem.InRangeUnobstructed(args.User, doorComponent.Owner, -1f, CollisionGroup.Opaque))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
args.Handled = true;
|
||||
|
||||
if (component.Mode == DoorRemoteComponent.OperatingMode.OpenClose)
|
||||
{
|
||||
_sharedDoorSystem.TryToggleDoor(doorComponent.Owner, user: args.Used);
|
||||
}
|
||||
|
||||
if (component.Mode == DoorRemoteComponent.OperatingMode.ToggleBolts
|
||||
&& airlockComponent.IsPowered())
|
||||
{
|
||||
if (_doorSystem.HasAccess(doorComponent.Owner, args.Used))
|
||||
{
|
||||
airlockComponent.SetBoltsWithAudio(!airlockComponent.IsBolted());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (doorComponent.State != DoorState.Open)
|
||||
{
|
||||
_sharedDoorSystem.Deny(airlockComponent.Owner, user: args.User);
|
||||
}
|
||||
else if (doorComponent.DenySound != null)
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(args.Target.Value), doorComponent.DenySound.GetSound(), args.Target.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user