private void OnInteractUsing(EntityUid uid, PaperComponent paperComp, InteractUsingEvent args)
        {
            if (_tagSystem.HasTag(args.Used, "Write"))
            {
                if (!TryComp <ActorComponent>(args.User, out var actor))
                {
                    return;
                }

                paperComp.Mode = PaperAction.Write;
                UpdateUserInterface(uid, paperComp);
                _uiSystem.GetUiOrNull(uid, PaperUiKey.Key)?.Open(actor.PlayerSession);
                return;
            }

            // If a stamp, attempt to stamp paper
            if (TryComp <StampComponent>(args.Used, out var stampComp) && TryStamp(uid, stampComp.StampedName, stampComp.StampState, paperComp))
            {
                // successfully stamped, play popup
                var stampPaperOtherMessage = Loc.GetString("paper-component-action-stamp-paper-other", ("user", args.User), ("target", args.Target), ("stamp", args.Used));
                _popupSystem.PopupEntity(stampPaperOtherMessage, args.User, Filter.Pvs(args.User, entityManager: EntityManager).RemoveWhereAttachedEntity(puid => puid == args.User));
                var stampPaperSelfMessage = Loc.GetString("paper-component-action-stamp-paper-self", ("target", args.Target), ("stamp", args.Used));
                _popupSystem.PopupEntity(stampPaperSelfMessage, args.User, Filter.Entities(args.User));
            }
        }
        private void OnCanisterActivate(EntityUid uid, GasCanisterComponent component, ActivateInWorldEvent args)
        {
            if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
            {
                return;
            }

            _userInterfaceSystem.GetUiOrNull(uid, GasCanisterUiKey.Key)?.Open(actor.PlayerSession);
            args.Handled = true;
        }
        private void OnInteract(EntityUid uid, AirAlarmComponent component, InteractHandEvent args)
        {
            if (!_interactionSystem.InRangeUnobstructed(args.User, args.Target))
            {
                return;
            }

            if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
            {
                return;
            }

            if (EntityManager.TryGetComponent(uid, out WiresComponent wire) && wire.IsPanelOpen)
            {
                args.Handled = false;
                return;
            }

            if (EntityManager.TryGetComponent(uid, out ApcPowerReceiverComponent recv) && !recv.Powered)
            {
                return;
            }

            _uiSystem.GetUiOrNull(component.Owner, SharedAirAlarmInterfaceKey.Key)?.Open(actor.PlayerSession);
            component.ActivePlayers.Add(actor.PlayerSession.UserId);
            AddActiveInterface(uid);
            SendAddress(uid);
            SendAlarmMode(uid);
            SendThresholds(uid);
            SyncAllDevices(uid);
            SendAirData(uid);
        }
Beispiel #4
0
    protected override void UpdateState(RadarConsoleComponent component)
    {
        var xform  = Transform(component.Owner);
        var onGrid = xform.ParentUid == xform.GridUid;
        EntityCoordinates?coordinates = onGrid ? xform.Coordinates : null;
        Angle?            angle       = onGrid ? xform.LocalRotation : null;

        // Use ourself I guess.
        if (TryComp <IntrinsicUIComponent>(component.Owner, out var intrinsic))
        {
            foreach (var uiKey in intrinsic.UIs)
            {
                if (uiKey.Key?.Equals(RadarConsoleUiKey.Key) == true)
                {
                    coordinates = new EntityCoordinates(component.Owner, Vector2.Zero);
                    angle       = Angle.Zero;
                    break;
                }
            }
        }

        var radarState = new RadarConsoleBoundInterfaceState(
            component.MaxRange,
            coordinates,
            angle,
            new List <DockingInterfaceState>());

        _uiSystem.GetUiOrNull(component.Owner, RadarConsoleUiKey.Key)?.SetState(radarState);
    }
    public override void Update(float frameTime)
    {
        base.Update(frameTime);

        foreach (var component in EntityManager.EntityQuery <NetworkConfiguratorComponent>())
        {
            if (component.ActiveDeviceList != null && EntityManager.EntityExists(component.ActiveDeviceList.Value) &&
                _interactionSystem.InRangeUnobstructed(component.Owner, component.ActiveDeviceList.Value))
            {
                return;
            }

            //The network configurator is a handheld device. There can only ever be an ui session open for the player holding the device.
            _uiSystem.GetUiOrNull(component.Owner, NetworkConfiguratorUiKey.Configure)?.CloseAll();
        }
    }
Beispiel #6
0
        private void UpdateState(ShuttleConsoleComponent component, List <DockingInterfaceState>?docks = null)
        {
            EntityUid?entity = component.Owner;

            var getShuttleEv = new ConsoleShuttleEvent
            {
                Console = entity,
            };

            RaiseLocalEvent(entity.Value, ref getShuttleEv, false);
            entity = getShuttleEv.Console;

            TryComp <TransformComponent>(entity, out var consoleXform);
            TryComp <RadarConsoleComponent>(entity, out var radar);
            var range = radar?.MaxRange ?? 0f;

            TryComp <ShuttleComponent>(consoleXform?.GridUid, out var shuttle);
            var mode = shuttle?.Mode ?? ShuttleMode.Cruise;

            docks ??= GetAllDocks();

            _ui.GetUiOrNull(component.Owner, ShuttleConsoleUiKey.Key)
            ?.SetState(new ShuttleConsoleBoundInterfaceState(
                           mode,
                           range,
                           consoleXform?.Coordinates,
                           consoleXform?.LocalRotation,
                           docks));
        }
Beispiel #7
0
    private void OpenSetupInterface(EntityUid uid, EntityUid player, SurveillanceCameraRouterComponent?camera = null, ActorComponent?actor = null)
    {
        if (!Resolve(uid, ref camera) ||
            !Resolve(player, ref actor))
        {
            return;
        }

        _userInterface.GetUiOrNull(uid, SurveillanceCameraSetupUiKey.Router) !.Open(actor.PlayerSession);
        UpdateSetupInterface(uid, camera);
    }
Beispiel #8
0
        /// <summary>
        ///     Opens the storage UI for an entity
        /// </summary>
        /// <param name="entity">The entity to open the UI for</param>
        public void OpenStorageUI(EntityUid uid, EntityUid entity, ServerStorageComponent?storageComp = null)
        {
            if (!Resolve(uid, ref storageComp))
            {
                return;
            }

            if (!TryComp(entity, out ActorComponent? player))
            {
                return;
            }

            if (storageComp.StorageOpenSound is not null)
            {
                SoundSystem.Play(storageComp.StorageOpenSound.GetSound(), Filter.Pvs(uid, entityManager: EntityManager), uid, storageComp.StorageOpenSound.Params);
            }

            Logger.DebugS(storageComp.LoggerName, $"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity}).");

            _uiSystem.GetUiOrNull(uid, StorageUiKey.Key)?.Open(player.PlayerSession);
        }
        public void UpdateUserInterface(GasTankComponent component, bool initialUpdate = false)
        {
            var internals = GetInternalsComponent(component);

            _ui.GetUiOrNull(component.Owner, SharedGasTankUiKey.Key)?.SetState(
                new GasTankBoundUserInterfaceState
            {
                TankPressure        = component.Air?.Pressure ?? 0,
                OutputPressure      = initialUpdate ? component.OutputPressure : null,
                InternalsConnected  = component.IsConnected,
                CanConnectInternals = IsFunctional(component) && internals != null
            });
        }
Beispiel #10
0
    protected override void UpdateState(RadarConsoleComponent component)
    {
        var xform = Transform(component.Owner);

        var onGrid = xform.ParentUid == xform.GridUid;

        var radarState = new RadarConsoleBoundInterfaceState(
            component.MaxRange,
            onGrid ? xform.Coordinates : null,
            onGrid ? xform.LocalRotation : null,
            new List <DockingInterfaceState>());

        _uiSystem.GetUiOrNull(component.Owner, RadarConsoleUiKey.Key)?.SetState(radarState);
    }
Beispiel #11
0
        public void UpdateUIState(EntityUid uid,
                                  ApcComponent?apc                = null,
                                  BatteryComponent?battery        = null,
                                  ServerUserInterfaceComponent?ui = null)
        {
            if (!Resolve(uid, ref apc, ref battery, ref ui))
            {
                return;
            }

            if (_userInterfaceSystem.GetUiOrNull(uid, ApcUiKey.Key, ui) is { } bui)
            {
                bui.SetState(new ApcBoundInterfaceState(apc.MainBreakerEnabled, apc.LastExternalState, battery.CurrentCharge / battery.MaxCharge));
            }
        }
Beispiel #12
0
        private void UpdateOrderState(CargoOrderConsoleComponent component, EntityUid?station)
        {
            if (station == null ||
                !TryComp <StationCargoOrderDatabaseComponent>(station, out var orderDatabase) ||
                !TryComp <StationBankAccountComponent>(station, out var bankAccount))
            {
                return;
            }

            var state = new CargoConsoleInterfaceState(
                MetaData(station.Value).EntityName,
                GetOrderCount(orderDatabase),
                orderDatabase.Capacity,
                bankAccount.Balance,
                orderDatabase.Orders.Values.ToList());

            _uiSystem.GetUiOrNull(component.Owner, CargoConsoleUiKey.Orders)?.SetState(state);
        }
        private void UpdateState(ShuttleConsoleComponent component, List <DockingInterfaceState>?docks = null)
        {
            EntityUid?entity = component.Owner;

            var getShuttleEv = new ConsoleShuttleEvent
            {
                Console = entity,
            };

            RaiseLocalEvent(entity.Value, ref getShuttleEv);
            entity = getShuttleEv.Console;

            TryComp <TransformComponent>(entity, out var consoleXform);
            TryComp <RadarConsoleComponent>(entity, out var radar);
            var range = radar?.MaxRange ?? 0f;

            TryComp <ShuttleComponent>(consoleXform?.GridUid, out var shuttle);

            var destinations = new List <(EntityUid, string, bool)>();
            var ftlState     = FTLState.Available;
            var ftlTime      = TimeSpan.Zero;

            if (TryComp <FTLComponent>(shuttle?.Owner, out var shuttleFtl))
            {
                ftlState = shuttleFtl.State;
                ftlTime  = _timing.CurTime + TimeSpan.FromSeconds(shuttleFtl.Accumulator);
            }

            // Mass too large
            if (entity != null && shuttle?.Owner != null && (!TryComp <PhysicsComponent>(shuttle?.Owner, out var shuttleBody) ||
                                                             shuttleBody.Mass < 1000f))
            {
                var metaQuery = GetEntityQuery <MetaDataComponent>();

                // Can't go anywhere when in FTL.
                var locked = shuttleFtl != null || Paused(shuttle !.Owner);

                // Can't cache it because it may have a whitelist for the particular console.
                // Include paused as we still want to show CentCom.
                foreach (var comp in EntityQuery <FTLDestinationComponent>(true))
                {
                    // Can't warp to itself or if it's not on the whitelist.
                    if (comp.Owner == shuttle?.Owner ||
                        comp.Whitelist?.IsValid(entity.Value) == false)
                    {
                        continue;
                    }

                    var meta = metaQuery.GetComponent(comp.Owner);
                    var name = meta.EntityName;

                    if (string.IsNullOrEmpty(name))
                    {
                        name = Loc.GetString("shuttle-console-unknown");
                    }

                    var canTravel = !locked &&
                                    comp.Enabled &&
                                    !Paused(comp.Owner, meta) &&
                                    (!TryComp <FTLComponent>(comp.Owner, out var ftl) || ftl.State == FTLState.Cooldown);

                    // Can't travel to same map.
                    if (canTravel && consoleXform?.MapUid == Transform(comp.Owner).MapUid)
                    {
                        canTravel = false;
                    }

                    destinations.Add((comp.Owner, name, canTravel));
                }
            }

            docks ??= GetAllDocks();

            _ui.GetUiOrNull(component.Owner, ShuttleConsoleUiKey.Key)
            ?.SetState(new ShuttleConsoleBoundInterfaceState(
                           ftlState,
                           ftlTime,
                           destinations,
                           range,
                           consoleXform?.Coordinates,
                           consoleXform?.LocalRotation,
                           docks));
        }
    public void UpdateUIState(EntityUid target, PowerMonitoringConsoleComponent?pmcComp = null, NodeContainerComponent?ncComp = null)
    {
        if (!Resolve(target, ref pmcComp))
        {
            return;
        }
        if (!Resolve(target, ref ncComp))
        {
            return;
        }

        var totalSources = 0.0d;
        var totalLoads   = 0.0d;
        var sources      = new List <PowerMonitoringConsoleEntry>();
        var loads        = new List <PowerMonitoringConsoleEntry>();

        PowerMonitoringConsoleEntry LoadOrSource(Component comp, double rate, bool isBattery)
        {
            var md        = MetaData(comp.Owner);
            var prototype = md.EntityPrototype?.ID ?? "";

            return(new PowerMonitoringConsoleEntry(md.EntityName, prototype, rate, isBattery));
        }

        // Right, so, here's what needs to be considered here.
        var netQ = ncComp.GetNode <Node>("hv").NodeGroup as PowerNet;

        if (netQ != null)
        {
            var net = netQ !;
            foreach (PowerConsumerComponent pcc in net.Consumers)
            {
                loads.Add(LoadOrSource(pcc, pcc.DrawRate, false));
                totalLoads += pcc.DrawRate;
            }
            foreach (BatteryChargerComponent pcc in net.Chargers)
            {
                if (!TryComp(pcc.Owner, out PowerNetworkBatteryComponent? batteryComp))
                {
                    continue;
                }
                var rate = batteryComp.NetworkBattery.CurrentReceiving;
                loads.Add(LoadOrSource(pcc, rate, true));
                totalLoads += rate;
            }
            foreach (PowerSupplierComponent pcc in net.Suppliers)
            {
                sources.Add(LoadOrSource(pcc, pcc.MaxSupply, false));
                totalSources += pcc.MaxSupply;
            }
            foreach (BatteryDischargerComponent pcc in net.Dischargers)
            {
                if (!TryComp(pcc.Owner, out PowerNetworkBatteryComponent? batteryComp))
                {
                    continue;
                }
                var rate = batteryComp.NetworkBattery.CurrentSupply;
                sources.Add(LoadOrSource(pcc, rate, true));
                totalSources += rate;
            }
        }
        // Sort
        loads.Sort(CompareLoadOrSources);
        sources.Sort(CompareLoadOrSources);
        // Actually set state.
        var state = new PowerMonitoringConsoleBoundInterfaceState(totalSources, totalLoads, sources.ToArray(), loads.ToArray());

        _userInterfaceSystem.GetUiOrNull(target, PowerMonitoringConsoleUiKey.Key)?.SetState(state);
    }