Clean up door remote (#8829)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Audio;
|
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Popups;
|
using Content.Shared.Popups;
|
||||||
using Content.Shared.Doors.Components;
|
using Content.Shared.Doors.Components;
|
||||||
@@ -8,7 +7,9 @@ using Content.Shared.Physics;
|
|||||||
using Content.Shared.Access.Components;
|
using Content.Shared.Access.Components;
|
||||||
using Content.Server.Doors.Systems;
|
using Content.Server.Doors.Systems;
|
||||||
using Content.Server.Doors.Components;
|
using Content.Server.Doors.Components;
|
||||||
|
using Content.Server.Power.EntitySystems;
|
||||||
using Content.Shared.Interaction.Events;
|
using Content.Shared.Interaction.Events;
|
||||||
|
using static Content.Server.Remotes.DoorRemoteComponent;
|
||||||
|
|
||||||
namespace Content.Server.Remotes
|
namespace Content.Server.Remotes
|
||||||
{
|
{
|
||||||
@@ -21,80 +22,81 @@ namespace Content.Server.Remotes
|
|||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
|
||||||
|
|
||||||
SubscribeLocalEvent<DoorRemoteComponent, UseInHandEvent>(OnInHandActivation);
|
SubscribeLocalEvent<DoorRemoteComponent, UseInHandEvent>(OnInHandActivation);
|
||||||
SubscribeLocalEvent<DoorRemoteComponent, BeforeRangedInteractEvent>(OnBeforeInteract);
|
SubscribeLocalEvent<DoorRemoteComponent, BeforeRangedInteractEvent>(OnBeforeInteract);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnInHandActivation(EntityUid user, DoorRemoteComponent component, UseInHandEvent args)
|
public void OnInHandActivation(EntityUid user, DoorRemoteComponent component, UseInHandEvent args)
|
||||||
{
|
{
|
||||||
|
string switchMessageId;
|
||||||
switch (component.Mode)
|
switch (component.Mode)
|
||||||
{
|
{
|
||||||
case DoorRemoteComponent.OperatingMode.OpenClose:
|
case OperatingMode.OpenClose:
|
||||||
component.Mode = DoorRemoteComponent.OperatingMode.ToggleBolts;
|
component.Mode = OperatingMode.ToggleBolts;
|
||||||
_popupSystem.PopupEntity(Loc.GetString("door-remote-switch-state-toggle-bolts"), args.User, Filter.Entities(args.User));
|
switchMessageId = "door-remote-switch-state-toggle-bolts";
|
||||||
break;
|
break;
|
||||||
case DoorRemoteComponent.OperatingMode.ToggleBolts:
|
case OperatingMode.ToggleBolts:
|
||||||
component.Mode = DoorRemoteComponent.OperatingMode.ToggleEmergencyAccess;
|
component.Mode = OperatingMode.ToggleEmergencyAccess;
|
||||||
_popupSystem.PopupEntity(Loc.GetString("door-remote-switch-state-toggle-emergency-access"), args.User, Filter.Entities(args.User));
|
switchMessageId = "door-remote-switch-state-toggle-emergency-access";
|
||||||
break;
|
break;
|
||||||
case DoorRemoteComponent.OperatingMode.ToggleEmergencyAccess:
|
case OperatingMode.ToggleEmergencyAccess:
|
||||||
component.Mode = DoorRemoteComponent.OperatingMode.OpenClose;
|
component.Mode = OperatingMode.OpenClose;
|
||||||
_popupSystem.PopupEntity(Loc.GetString("door-remote-switch-state-open-close"), args.User, Filter.Entities(args.User));
|
switchMessageId = "door-remote-switch-state-open-close";
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
$"{nameof(DoorRemoteComponent)} had invalid mode {component.Mode}");
|
||||||
}
|
}
|
||||||
|
ShowPopupToUser(switchMessageId, args.User);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBeforeInteract(EntityUid uid, DoorRemoteComponent component, BeforeRangedInteractEvent args)
|
private void OnBeforeInteract(EntityUid uid, DoorRemoteComponent component, BeforeRangedInteractEvent args)
|
||||||
{
|
{
|
||||||
if (!args.CanReach ||
|
if (args.Handled
|
||||||
args.Handled
|
|
||||||
|| args.Target == null
|
|| args.Target == null
|
||||||
|| !TryComp<DoorComponent>(args.Target, out var doorComponent) // If it isn't a door we don't use it
|
|| !TryComp<DoorComponent>(args.Target, out var doorComp) // 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 airlockComp) // Remotes only work on airlocks
|
||||||
|| !TryComp<AirlockComponent>(args.Target, out var airlockComponent) // Remotes only work on airlocks
|
// The remote can be used anywhere the user can see the door.
|
||||||
// TODO: Why the fuck is this -1f
|
// This doesn't work that well, but I don't know of an alternative
|
||||||
|| !_interactionSystem.InRangeUnobstructed(args.User, doorComponent.Owner, -1f, CollisionGroup.Opaque))
|
|| !_interactionSystem.InRangeUnobstructed(args.User, args.Target.Value,
|
||||||
{
|
SharedInteractionSystem.MaxRaycastRange, CollisionGroup.Opaque))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
|
|
||||||
if (component.Mode == DoorRemoteComponent.OperatingMode.OpenClose)
|
if (!this.IsPowered(args.Target.Value, EntityManager))
|
||||||
{
|
{
|
||||||
_doorSystem.TryToggleDoor(doorComponent.Owner, user: args.Used);
|
ShowPopupToUser("door-remote-no-power", args.User);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (component.Mode == DoorRemoteComponent.OperatingMode.ToggleBolts
|
if (TryComp<AccessReaderComponent>(args.Target, out var accessComponent) &&
|
||||||
&& airlockComponent.IsPowered())
|
!_doorSystem.HasAccess(doorComp.Owner, args.Used, accessComponent))
|
||||||
{
|
{
|
||||||
if (_doorSystem.HasAccess(doorComponent.Owner, args.Used))
|
_doorSystem.Deny(airlockComp.Owner, doorComp, args.User);
|
||||||
{
|
ShowPopupToUser("door-remote-denied", args.User);
|
||||||
airlockComponent.SetBoltsWithAudio(!airlockComponent.IsBolted());
|
return;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (doorComponent.State != DoorState.Open)
|
|
||||||
{
|
|
||||||
_doorSystem.Deny(airlockComponent.Owner, user: args.User);
|
|
||||||
}
|
|
||||||
else if (doorComponent.DenySound != null)
|
|
||||||
{
|
|
||||||
SoundSystem.Play(doorComponent.DenySound.GetSound(), Filter.Pvs(args.Target.Value, entityManager: EntityManager), args.Target.Value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (component.Mode == DoorRemoteComponent.OperatingMode.ToggleEmergencyAccess
|
switch (component.Mode)
|
||||||
&& airlockComponent.IsPowered())
|
|
||||||
{
|
{
|
||||||
if (_doorSystem.HasAccess(doorComponent.Owner, args.Used))
|
case OperatingMode.OpenClose:
|
||||||
{
|
_doorSystem.TryToggleDoor(doorComp.Owner, doorComp, args.Used);
|
||||||
_sharedAirlockSystem.ToggleEmergencyAccess(airlockComponent);
|
break;
|
||||||
}
|
case OperatingMode.ToggleBolts:
|
||||||
|
//TODO: What about cut wires...?
|
||||||
|
airlockComp.SetBoltsWithAudio(!airlockComp.IsBolted());
|
||||||
|
break;
|
||||||
|
case OperatingMode.ToggleEmergencyAccess:
|
||||||
|
_sharedAirlockSystem.ToggleEmergencyAccess(airlockComp);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
$"{nameof(DoorRemoteComponent)} had invalid mode {component.Mode}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ShowPopupToUser(string messageId, EntityUid user) =>
|
||||||
|
_popupSystem.PopupEntity(Loc.GetString(messageId), user, Filter.Entities(user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,10 +52,10 @@ namespace Content.Shared.Interaction
|
|||||||
private const CollisionGroup InRangeUnobstructedMask
|
private const CollisionGroup InRangeUnobstructedMask
|
||||||
= CollisionGroup.Impassable | CollisionGroup.InteractImpassable;
|
= CollisionGroup.Impassable | CollisionGroup.InteractImpassable;
|
||||||
|
|
||||||
public const float InteractionRange = 2;
|
public const float InteractionRange = 2f;
|
||||||
public const float InteractionRangeSquared = InteractionRange * InteractionRange;
|
public const float InteractionRangeSquared = InteractionRange * InteractionRange;
|
||||||
|
|
||||||
public const float MaxRaycastRange = 100;
|
public const float MaxRaycastRange = 100f;
|
||||||
|
|
||||||
public delegate bool Ignored(EntityUid entity);
|
public delegate bool Ignored(EntityUid entity);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
door-remote-switch-state-open-close = You switch the remote to open and close doors
|
door-remote-switch-state-open-close = You switch the remote to open and close doors
|
||||||
door-remote-switch-state-toggle-bolts = You switch the remote to toggle bolts
|
door-remote-switch-state-toggle-bolts = You switch the remote to toggle bolts
|
||||||
door-remote-switch-state-toggle-emergency-access = You switch the remote to toggle emergency access
|
door-remote-switch-state-toggle-emergency-access = You switch the remote to toggle emergency access
|
||||||
|
door-remote-no-power = The door is not powered
|
||||||
|
door-remote-denied = Access denied
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user