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);
                    }
                }
            }

            if (component.Mode == DoorRemoteComponent.OperatingMode.ToggleEmergencyAccess &&
                airlockComponent.IsPowered())
            {
                if (_doorSystem.HasAccess(doorComponent.Owner, args.Used))
                {
                    _sharedAirlockSystem.ToggleEmergencyAccess(airlockComponent);
                }
            }
        }
Beispiel #2
0
        private void OnBeforeInteract(EntityUid uid, DoorRemoteComponent component, BeforeRangedInteractEvent args)
        {
            if (args.Handled ||
                args.Target == null ||
                !TryComp <DoorComponent>(args.Target, out var doorComp) || // If it isn't a door we don't use it
                !TryComp <AirlockComponent>(args.Target, out var airlockComp)   // Remotes only work on airlocks
                // The remote can be used anywhere the user can see the door.
                // This doesn't work that well, but I don't know of an alternative
                || !_interactionSystem.InRangeUnobstructed(args.User, args.Target.Value,
                                                           SharedInteractionSystem.MaxRaycastRange, CollisionGroup.Opaque))
            {
                return;
            }

            args.Handled = true;

            if (!this.IsPowered(args.Target.Value, EntityManager))
            {
                ShowPopupToUser("door-remote-no-power", args.User);
                return;
            }

            if (TryComp <AccessReaderComponent>(args.Target, out var accessComponent) &&
                !_doorSystem.HasAccess(doorComp.Owner, args.Used, accessComponent))
            {
                _doorSystem.Deny(airlockComp.Owner, doorComp, args.User);
                ShowPopupToUser("door-remote-denied", args.User);
                return;
            }

            switch (component.Mode)
            {
            case OperatingMode.OpenClose:
                _doorSystem.TryToggleDoor(doorComp.Owner, doorComp, args.Used);
                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}");
            }
        }