2022-06-28 22:54:08 +10:00
|
|
|
using Content.Server.Power.EntitySystems;
|
|
|
|
|
using Content.Server.Research.Components;
|
2024-02-01 11:45:24 +03:00
|
|
|
using Content.Shared.UserInterface;
|
2023-06-29 14:19:19 -04:00
|
|
|
using Content.Shared.Access.Components;
|
2024-09-03 16:01:38 +03:00
|
|
|
using Content.Shared.Emag.Components;
|
2025-01-30 05:05:47 +01:00
|
|
|
using Content.Shared.Emag.Systems;
|
2024-09-03 16:01:38 +03:00
|
|
|
using Content.Shared.IdentityManagement;
|
2022-06-28 22:54:08 +10:00
|
|
|
using Content.Shared.Research.Components;
|
2023-12-06 02:00:51 -05:00
|
|
|
using Content.Shared.Research.Prototypes;
|
2022-06-28 22:54:08 +10:00
|
|
|
|
2022-12-19 16:14:02 -05:00
|
|
|
namespace Content.Server.Research.Systems;
|
2022-06-28 22:54:08 +10:00
|
|
|
|
|
|
|
|
public sealed partial class ResearchSystem
|
|
|
|
|
{
|
2025-01-30 05:05:47 +01:00
|
|
|
[Dependency] private readonly EmagSystem _emag = default!;
|
|
|
|
|
|
2022-06-28 22:54:08 +10:00
|
|
|
private void InitializeConsole()
|
|
|
|
|
{
|
|
|
|
|
SubscribeLocalEvent<ResearchConsoleComponent, ConsoleUnlockTechnologyMessage>(OnConsoleUnlock);
|
2023-06-21 20:59:57 -04:00
|
|
|
SubscribeLocalEvent<ResearchConsoleComponent, BeforeActivatableUIOpenEvent>(OnConsoleBeforeUiOpened);
|
2022-12-19 16:14:02 -05:00
|
|
|
SubscribeLocalEvent<ResearchConsoleComponent, ResearchServerPointsChangedEvent>(OnPointsChanged);
|
2022-12-25 16:22:23 -05:00
|
|
|
SubscribeLocalEvent<ResearchConsoleComponent, ResearchRegistrationChangedEvent>(OnConsoleRegistrationChanged);
|
|
|
|
|
SubscribeLocalEvent<ResearchConsoleComponent, TechnologyDatabaseModifiedEvent>(OnConsoleDatabaseModified);
|
2025-02-10 21:52:26 -05:00
|
|
|
SubscribeLocalEvent<ResearchConsoleComponent, TechnologyDatabaseSynchronizedEvent>(OnConsoleDatabaseSynchronized);
|
2025-01-30 05:05:47 +01:00
|
|
|
SubscribeLocalEvent<ResearchConsoleComponent, GotEmaggedEvent>(OnEmagged);
|
2022-06-28 22:54:08 +10:00
|
|
|
}
|
|
|
|
|
|
2022-12-25 16:22:23 -05:00
|
|
|
private void OnConsoleUnlock(EntityUid uid, ResearchConsoleComponent component, ConsoleUnlockTechnologyMessage args)
|
2022-06-28 22:54:08 +10:00
|
|
|
{
|
2024-04-26 18:16:24 +10:00
|
|
|
var act = args.Actor;
|
2023-06-29 14:19:19 -04:00
|
|
|
|
2022-12-25 16:22:23 -05:00
|
|
|
if (!this.IsPowered(uid, EntityManager))
|
2022-06-28 22:54:08 +10:00
|
|
|
return;
|
|
|
|
|
|
2023-12-06 02:00:51 -05:00
|
|
|
if (!PrototypeManager.TryIndex<TechnologyPrototype>(args.Id, out var technologyPrototype))
|
|
|
|
|
return;
|
|
|
|
|
|
2024-04-26 18:16:24 +10:00
|
|
|
if (TryComp<AccessReaderComponent>(uid, out var access) && !_accessReader.IsAllowed(act, uid, access))
|
2023-06-29 14:19:19 -04:00
|
|
|
{
|
2024-04-26 18:16:24 +10:00
|
|
|
_popup.PopupEntity(Loc.GetString("research-console-no-access-popup"), act);
|
2023-06-29 14:19:19 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 18:16:24 +10:00
|
|
|
if (!UnlockTechnology(uid, args.Id, act))
|
2022-06-28 22:54:08 +10:00
|
|
|
return;
|
|
|
|
|
|
2025-01-30 05:05:47 +01:00
|
|
|
if (!_emag.CheckFlag(uid, EmagType.Interaction))
|
2024-09-03 16:01:38 +03:00
|
|
|
{
|
|
|
|
|
var getIdentityEvent = new TryGetIdentityShortInfoEvent(uid, act);
|
|
|
|
|
RaiseLocalEvent(getIdentityEvent);
|
|
|
|
|
|
|
|
|
|
var message = Loc.GetString(
|
|
|
|
|
"research-console-unlock-technology-radio-broadcast",
|
|
|
|
|
("technology", Loc.GetString(technologyPrototype.Name)),
|
|
|
|
|
("amount", technologyPrototype.Cost),
|
|
|
|
|
("approver", getIdentityEvent.Title ?? string.Empty)
|
|
|
|
|
);
|
|
|
|
|
_radio.SendRadioMessage(uid, message, component.AnnouncementChannel, uid, escapeMarkup: false);
|
|
|
|
|
}
|
2025-01-30 05:05:47 +01:00
|
|
|
|
2022-12-25 16:22:23 -05:00
|
|
|
SyncClientWithServer(uid);
|
|
|
|
|
UpdateConsoleInterface(uid, component);
|
2022-06-28 22:54:08 +10:00
|
|
|
}
|
|
|
|
|
|
2023-06-21 20:59:57 -04:00
|
|
|
private void OnConsoleBeforeUiOpened(EntityUid uid, ResearchConsoleComponent component, BeforeActivatableUIOpenEvent args)
|
|
|
|
|
{
|
|
|
|
|
SyncClientWithServer(uid);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-25 16:22:23 -05:00
|
|
|
private void UpdateConsoleInterface(EntityUid uid, ResearchConsoleComponent? component = null, ResearchClientComponent? clientComponent = null)
|
2022-06-28 22:54:08 +10:00
|
|
|
{
|
2022-12-25 16:22:23 -05:00
|
|
|
if (!Resolve(uid, ref component, ref clientComponent, false))
|
2022-06-28 22:54:08 +10:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ResearchConsoleBoundInterfaceState state;
|
|
|
|
|
|
2023-05-15 16:17:30 -04:00
|
|
|
if (TryGetClientServer(uid, out _, out var serverComponent, clientComponent))
|
2022-06-28 22:54:08 +10:00
|
|
|
{
|
2022-12-25 16:22:23 -05:00
|
|
|
var points = clientComponent.ConnectedToServer ? serverComponent.Points : 0;
|
2023-05-15 16:17:30 -04:00
|
|
|
state = new ResearchConsoleBoundInterfaceState(points);
|
2022-06-28 22:54:08 +10:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-05-15 16:17:30 -04:00
|
|
|
state = new ResearchConsoleBoundInterfaceState(default);
|
2022-06-28 22:54:08 +10:00
|
|
|
}
|
2022-12-19 16:14:02 -05:00
|
|
|
|
2024-04-26 18:16:24 +10:00
|
|
|
_uiSystem.SetUiState(uid, ResearchConsoleUiKey.Key, state);
|
2022-06-28 22:54:08 +10:00
|
|
|
}
|
2022-12-19 16:14:02 -05:00
|
|
|
|
|
|
|
|
private void OnPointsChanged(EntityUid uid, ResearchConsoleComponent component, ref ResearchServerPointsChangedEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!_uiSystem.IsUiOpen(uid, ResearchConsoleUiKey.Key))
|
|
|
|
|
return;
|
2022-12-25 16:22:23 -05:00
|
|
|
UpdateConsoleInterface(uid, component);
|
2022-12-19 16:14:02 -05:00
|
|
|
}
|
|
|
|
|
|
2022-12-25 16:22:23 -05:00
|
|
|
private void OnConsoleRegistrationChanged(EntityUid uid, ResearchConsoleComponent component, ref ResearchRegistrationChangedEvent args)
|
|
|
|
|
{
|
|
|
|
|
SyncClientWithServer(uid);
|
|
|
|
|
UpdateConsoleInterface(uid, component);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnConsoleDatabaseModified(EntityUid uid, ResearchConsoleComponent component, ref TechnologyDatabaseModifiedEvent args)
|
2025-02-10 21:52:26 -05:00
|
|
|
{
|
|
|
|
|
SyncClientWithServer(uid);
|
|
|
|
|
UpdateConsoleInterface(uid, component);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnConsoleDatabaseSynchronized(EntityUid uid, ResearchConsoleComponent component, ref TechnologyDatabaseSynchronizedEvent args)
|
2022-12-25 16:22:23 -05:00
|
|
|
{
|
|
|
|
|
UpdateConsoleInterface(uid, component);
|
|
|
|
|
}
|
2024-09-03 16:01:38 +03:00
|
|
|
|
2025-01-30 05:05:47 +01:00
|
|
|
private void OnEmagged(Entity<ResearchConsoleComponent> ent, ref GotEmaggedEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!_emag.CompareFlag(args.Type, EmagType.Interaction))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (_emag.CheckFlag(ent, EmagType.Interaction))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
2022-06-28 22:54:08 +10:00
|
|
|
}
|