2023-05-17 23:35:40 +03:00
|
|
|
using Content.Server.AlertLevel;
|
2022-11-08 21:00:20 +01:00
|
|
|
using Content.Server.CartridgeLoader;
|
|
|
|
|
using Content.Server.DeviceNetwork.Components;
|
2022-03-07 14:41:50 +03:00
|
|
|
using Content.Server.Instruments;
|
2021-10-03 07:05:52 +03:00
|
|
|
using Content.Server.Light.EntitySystems;
|
|
|
|
|
using Content.Server.Light.Events;
|
2023-07-27 22:25:55 +02:00
|
|
|
using Content.Server.MassMedia.Components;
|
|
|
|
|
using Content.Server.MassMedia.Systems;
|
2023-06-18 11:33:19 -07:00
|
|
|
using Content.Server.Mind;
|
2022-02-08 04:39:23 -05:00
|
|
|
using Content.Server.PDA.Ringer;
|
2022-07-23 18:58:28 -07:00
|
|
|
using Content.Server.Station.Systems;
|
2023-05-01 06:30:08 +00:00
|
|
|
using Content.Server.Store.Components;
|
|
|
|
|
using Content.Server.Store.Systems;
|
2023-07-22 21:19:51 -07:00
|
|
|
using Content.Shared.Access.Components;
|
2023-09-11 09:42:41 +10:00
|
|
|
using Content.Shared.CartridgeLoader;
|
2023-09-04 06:31:10 +01:00
|
|
|
using Content.Shared.Light.Components;
|
2021-10-03 07:05:52 +03:00
|
|
|
using Content.Shared.PDA;
|
|
|
|
|
using Robust.Server.GameObjects;
|
2023-06-07 07:22:19 -07:00
|
|
|
using Robust.Server.Player;
|
2021-11-20 18:26:01 +13:00
|
|
|
using Robust.Shared.Containers;
|
2021-10-03 07:05:52 +03:00
|
|
|
|
|
|
|
|
namespace Content.Server.PDA
|
|
|
|
|
{
|
2023-06-15 03:44:28 +02:00
|
|
|
public sealed class PdaSystem : SharedPdaSystem
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
2023-05-01 06:30:08 +00:00
|
|
|
[Dependency] private readonly CartridgeLoaderSystem _cartridgeLoader = default!;
|
|
|
|
|
[Dependency] private readonly InstrumentSystem _instrument = default!;
|
|
|
|
|
[Dependency] private readonly RingerSystem _ringer = default!;
|
|
|
|
|
[Dependency] private readonly StationSystem _station = default!;
|
|
|
|
|
[Dependency] private readonly StoreSystem _store = default!;
|
|
|
|
|
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
2021-10-03 07:05:52 +03:00
|
|
|
[Dependency] private readonly UnpoweredFlashlightSystem _unpoweredFlashlight = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2021-10-05 14:29:03 +11:00
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
SubscribeLocalEvent<PdaComponent, LightToggleEvent>(OnLightToggle);
|
2023-06-07 07:22:19 -07:00
|
|
|
|
|
|
|
|
// UI Events:
|
2023-06-15 03:44:28 +02:00
|
|
|
SubscribeLocalEvent<PdaComponent, PdaRequestUpdateInterfaceMessage>(OnUiMessage);
|
|
|
|
|
SubscribeLocalEvent<PdaComponent, PdaToggleFlashlightMessage>(OnUiMessage);
|
|
|
|
|
SubscribeLocalEvent<PdaComponent, PdaShowRingtoneMessage>(OnUiMessage);
|
|
|
|
|
SubscribeLocalEvent<PdaComponent, PdaShowMusicMessage>(OnUiMessage);
|
|
|
|
|
SubscribeLocalEvent<PdaComponent, PdaShowUplinkMessage>(OnUiMessage);
|
|
|
|
|
SubscribeLocalEvent<PdaComponent, PdaLockUplinkMessage>(OnUiMessage);
|
2023-06-24 14:02:59 +02:00
|
|
|
|
|
|
|
|
SubscribeLocalEvent<StationRenamedEvent>(OnStationRenamed);
|
|
|
|
|
SubscribeLocalEvent<AlertLevelChangedEvent>(OnAlertLevelChanged);
|
2021-10-03 07:05:52 +03:00
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
protected override void OnComponentInit(EntityUid uid, PdaComponent pda, ComponentInit args)
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
2021-12-16 23:42:02 +13:00
|
|
|
base.OnComponentInit(uid, pda, args);
|
|
|
|
|
|
2023-09-11 21:20:46 +10:00
|
|
|
if (!HasComp<UserInterfaceComponent>(uid))
|
2022-03-30 15:56:58 +13:00
|
|
|
return;
|
|
|
|
|
|
2023-05-17 23:35:40 +03:00
|
|
|
UpdateAlertLevel(uid, pda);
|
2023-05-01 06:30:08 +00:00
|
|
|
UpdateStationName(uid, pda);
|
2021-10-03 07:05:52 +03:00
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
protected override void OnItemInserted(EntityUid uid, PdaComponent pda, EntInsertedIntoContainerMessage args)
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
2021-12-16 23:42:02 +13:00
|
|
|
base.OnItemInserted(uid, pda, args);
|
2023-05-01 06:30:08 +00:00
|
|
|
UpdatePdaUi(uid, pda);
|
2021-11-20 18:26:01 +13:00
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
protected override void OnItemRemoved(EntityUid uid, PdaComponent pda, EntRemovedFromContainerMessage args)
|
2021-11-20 18:26:01 +13:00
|
|
|
{
|
2023-09-11 09:42:41 +10:00
|
|
|
if (args.Container.ID != pda.IdSlot.ID && args.Container.ID != pda.PenSlot.ID)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// TODO: This is super cursed just use compstates please.
|
|
|
|
|
if (MetaData(uid).EntityLifeStage >= EntityLifeStage.Terminating)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-12-16 23:42:02 +13:00
|
|
|
base.OnItemRemoved(uid, pda, args);
|
2023-05-01 06:30:08 +00:00
|
|
|
UpdatePdaUi(uid, pda);
|
2021-10-03 07:05:52 +03:00
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
private void OnLightToggle(EntityUid uid, PdaComponent pda, LightToggleEvent args)
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
|
|
|
|
pda.FlashlightOn = args.IsOn;
|
2023-05-01 06:30:08 +00:00
|
|
|
UpdatePdaUi(uid, pda);
|
2021-10-03 07:05:52 +03:00
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
public void SetOwner(EntityUid uid, PdaComponent pda, string ownerName)
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
|
|
|
|
pda.OwnerName = ownerName;
|
2023-05-01 06:30:08 +00:00
|
|
|
UpdatePdaUi(uid, pda);
|
2021-10-03 07:05:52 +03:00
|
|
|
}
|
|
|
|
|
|
2023-06-24 14:02:59 +02:00
|
|
|
private void OnStationRenamed(StationRenamedEvent ev)
|
2022-07-23 18:58:28 -07:00
|
|
|
{
|
2023-06-24 14:02:59 +02:00
|
|
|
UpdateAllPdaUisOnStation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAlertLevelChanged(AlertLevelChangedEvent args)
|
|
|
|
|
{
|
|
|
|
|
UpdateAllPdaUisOnStation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateAllPdaUisOnStation()
|
|
|
|
|
{
|
|
|
|
|
var query = EntityQueryEnumerator<PdaComponent>();
|
|
|
|
|
while (query.MoveNext(out var ent, out var comp))
|
|
|
|
|
{
|
|
|
|
|
UpdatePdaUi(ent, comp);
|
|
|
|
|
}
|
2022-07-23 18:58:28 -07:00
|
|
|
}
|
|
|
|
|
|
2023-05-01 06:30:08 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Send new UI state to clients, call if you modify something like uplink.
|
|
|
|
|
/// </summary>
|
2023-09-11 09:42:41 +10:00
|
|
|
public void UpdatePdaUi(EntityUid uid, PdaComponent? pda = null)
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
2023-09-11 09:42:41 +10:00
|
|
|
if (!Resolve(uid, ref pda, false))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!_ui.TryGetUi(uid, PdaUiKey.Key, out var ui))
|
2022-01-10 05:24:21 +13:00
|
|
|
return;
|
2021-10-03 07:05:52 +03:00
|
|
|
|
2023-05-01 06:30:08 +00:00
|
|
|
var address = GetDeviceNetAddress(uid);
|
|
|
|
|
var hasInstrument = HasComp<InstrumentComponent>(uid);
|
|
|
|
|
var showUplink = HasComp<StoreComponent>(uid) && IsUnlocked(uid);
|
2022-03-30 15:56:58 +13:00
|
|
|
|
2023-05-17 23:35:40 +03:00
|
|
|
UpdateStationName(uid, pda);
|
|
|
|
|
UpdateAlertLevel(uid, pda);
|
|
|
|
|
// TODO: Update the level and name of the station with each call to UpdatePdaUi is only needed for latejoin players.
|
|
|
|
|
// TODO: If someone can implement changing the level and name of the station when changing the PDA grid, this can be removed.
|
|
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
// TODO don't make this depend on cartridge loader!?!?
|
|
|
|
|
if (!TryComp(uid, out CartridgeLoaderComponent? loader))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var programs = _cartridgeLoader.GetAvailablePrograms(uid, loader);
|
2023-07-22 21:19:51 -07:00
|
|
|
var id = CompOrNull<IdCardComponent>(pda.ContainedId);
|
2023-06-15 03:44:28 +02:00
|
|
|
var state = new PdaUpdateState(
|
2023-09-11 09:42:41 +10:00
|
|
|
programs,
|
|
|
|
|
GetNetEntity(loader.ActiveProgram),
|
2023-05-17 23:35:40 +03:00
|
|
|
pda.FlashlightOn,
|
|
|
|
|
pda.PenSlot.HasItem,
|
2023-06-24 14:02:59 +02:00
|
|
|
new PdaIdInfoText
|
|
|
|
|
{
|
|
|
|
|
ActualOwnerName = pda.OwnerName,
|
2023-07-22 21:19:51 -07:00
|
|
|
IdOwner = id?.FullName,
|
|
|
|
|
JobTitle = id?.JobTitle,
|
2023-06-24 14:02:59 +02:00
|
|
|
StationAlertLevel = pda.StationAlertLevel,
|
|
|
|
|
StationAlertColor = pda.StationAlertColor
|
|
|
|
|
},
|
2023-05-17 23:35:40 +03:00
|
|
|
pda.StationName,
|
|
|
|
|
showUplink,
|
|
|
|
|
hasInstrument,
|
|
|
|
|
address);
|
|
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
_ui.SetUiState(ui, state);
|
2021-10-03 07:05:52 +03:00
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
private void OnUiMessage(EntityUid uid, PdaComponent pda, PdaRequestUpdateInterfaceMessage msg)
|
2023-06-07 07:22:19 -07:00
|
|
|
{
|
2023-06-15 03:44:28 +02:00
|
|
|
if (!PdaUiKey.Key.Equals(msg.UiKey))
|
2023-06-07 07:22:19 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
UpdatePdaUi(uid, pda);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
private void OnUiMessage(EntityUid uid, PdaComponent pda, PdaToggleFlashlightMessage msg)
|
2023-06-07 07:22:19 -07:00
|
|
|
{
|
2023-06-15 03:44:28 +02:00
|
|
|
if (!PdaUiKey.Key.Equals(msg.UiKey))
|
2023-06-07 07:22:19 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (TryComp<UnpoweredFlashlightComponent>(uid, out var flashlight))
|
|
|
|
|
_unpoweredFlashlight.ToggleLight(uid, flashlight);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
private void OnUiMessage(EntityUid uid, PdaComponent pda, PdaShowRingtoneMessage msg)
|
2023-06-07 07:22:19 -07:00
|
|
|
{
|
2023-06-15 03:44:28 +02:00
|
|
|
if (!PdaUiKey.Key.Equals(msg.UiKey))
|
2023-06-07 07:22:19 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (HasComp<RingerComponent>(uid))
|
|
|
|
|
_ringer.ToggleRingerUI(uid, (IPlayerSession) msg.Session);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
private void OnUiMessage(EntityUid uid, PdaComponent pda, PdaShowMusicMessage msg)
|
2023-06-07 07:22:19 -07:00
|
|
|
{
|
2023-06-15 03:44:28 +02:00
|
|
|
if (!PdaUiKey.Key.Equals(msg.UiKey))
|
2023-06-07 07:22:19 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (TryComp<InstrumentComponent>(uid, out var instrument))
|
|
|
|
|
_instrument.ToggleInstrumentUi(uid, (IPlayerSession) msg.Session, instrument);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
private void OnUiMessage(EntityUid uid, PdaComponent pda, PdaShowUplinkMessage msg)
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
2023-06-15 03:44:28 +02:00
|
|
|
if (!PdaUiKey.Key.Equals(msg.UiKey))
|
2023-06-07 07:22:19 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// check if its locked again to prevent malicious clients opening locked uplinks
|
|
|
|
|
if (TryComp<StoreComponent>(uid, out var store) && IsUnlocked(uid))
|
|
|
|
|
_store.ToggleUi(msg.Session.AttachedEntity!.Value, uid, store);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
private void OnUiMessage(EntityUid uid, PdaComponent pda, PdaLockUplinkMessage msg)
|
2023-06-07 07:22:19 -07:00
|
|
|
{
|
2023-06-15 03:44:28 +02:00
|
|
|
if (!PdaUiKey.Key.Equals(msg.UiKey))
|
2023-06-07 07:22:19 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (TryComp<RingerUplinkComponent>(uid, out var uplink))
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
2023-06-07 07:22:19 -07:00
|
|
|
_ringer.LockUplink(uid, uplink);
|
|
|
|
|
UpdatePdaUi(uid, pda);
|
2021-10-03 07:05:52 +03:00
|
|
|
}
|
|
|
|
|
}
|
2022-03-30 15:56:58 +13:00
|
|
|
|
2023-05-01 06:30:08 +00:00
|
|
|
private bool IsUnlocked(EntityUid uid)
|
|
|
|
|
{
|
2023-06-07 07:22:19 -07:00
|
|
|
return !TryComp<RingerUplinkComponent>(uid, out var uplink) || uplink.Unlocked;
|
2023-05-01 06:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
private void UpdateStationName(EntityUid uid, PdaComponent pda)
|
2022-07-23 18:58:28 -07:00
|
|
|
{
|
2023-05-01 06:30:08 +00:00
|
|
|
var station = _station.GetOwningStation(uid);
|
2022-07-23 18:58:28 -07:00
|
|
|
pda.StationName = station is null ? null : Name(station.Value);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
private void UpdateAlertLevel(EntityUid uid, PdaComponent pda)
|
2023-05-17 23:35:40 +03:00
|
|
|
{
|
|
|
|
|
var station = _station.GetOwningStation(uid);
|
|
|
|
|
if (!TryComp(station, out AlertLevelComponent? alertComp) ||
|
|
|
|
|
alertComp.AlertLevels == null)
|
|
|
|
|
return;
|
|
|
|
|
pda.StationAlertLevel = alertComp.CurrentLevel;
|
|
|
|
|
if (alertComp.AlertLevels.Levels.TryGetValue(alertComp.CurrentLevel, out var details))
|
|
|
|
|
pda.StationAlertColor = details.Color;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-08 21:00:20 +01:00
|
|
|
private string? GetDeviceNetAddress(EntityUid uid)
|
|
|
|
|
{
|
|
|
|
|
string? address = null;
|
|
|
|
|
|
|
|
|
|
if (TryComp(uid, out DeviceNetworkComponent? deviceNetworkComponent))
|
|
|
|
|
{
|
|
|
|
|
address = deviceNetworkComponent?.Address;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return address;
|
2022-03-30 15:56:58 +13:00
|
|
|
}
|
2021-10-03 07:05:52 +03:00
|
|
|
}
|
|
|
|
|
}
|