159 lines
6.3 KiB
C#
159 lines
6.3 KiB
C#
using Content.Server.Power.EntitySystems;
|
|
using Content.Server.Research.Components;
|
|
using Content.Shared.UserInterface;
|
|
using Content.Shared.Access.Components;
|
|
using Content.Shared.Emag.Components;
|
|
using Content.Shared.Emag.Systems;
|
|
using Content.Shared.IdentityManagement;
|
|
using Content.Shared.Research.Components;
|
|
using Content.Shared.Research.Prototypes;
|
|
using Content.Shared._NF.Research; // NF: R&D Console Rework
|
|
using System.Linq; // R&D Console Rework
|
|
|
|
namespace Content.Server.Research.Systems;
|
|
|
|
public sealed partial class ResearchSystem
|
|
{
|
|
// [Dependency] private readonly EmagSystem _emag = default!; // Frontier: silent R&D computers, useless
|
|
|
|
private void InitializeConsole()
|
|
{
|
|
SubscribeLocalEvent<ResearchConsoleComponent, ConsoleUnlockTechnologyMessage>(OnConsoleUnlock);
|
|
SubscribeLocalEvent<ResearchConsoleComponent, BeforeActivatableUIOpenEvent>(OnConsoleBeforeUiOpened);
|
|
SubscribeLocalEvent<ResearchConsoleComponent, ResearchServerPointsChangedEvent>(OnPointsChanged);
|
|
SubscribeLocalEvent<ResearchConsoleComponent, ResearchRegistrationChangedEvent>(OnConsoleRegistrationChanged);
|
|
SubscribeLocalEvent<ResearchConsoleComponent, TechnologyDatabaseModifiedEvent>(OnConsoleDatabaseModified);
|
|
SubscribeLocalEvent<ResearchConsoleComponent, TechnologyDatabaseSynchronizedEvent>(OnConsoleDatabaseSynchronized);
|
|
//SubscribeLocalEvent<ResearchConsoleComponent, GotEmaggedEvent>(OnEmagged); // Frontier: silent R&D computers, useless
|
|
}
|
|
|
|
private void OnConsoleUnlock(EntityUid uid, ResearchConsoleComponent component, ConsoleUnlockTechnologyMessage args)
|
|
{
|
|
var act = args.Actor;
|
|
|
|
if (!this.IsPowered(uid, EntityManager))
|
|
return;
|
|
|
|
if (!PrototypeManager.TryIndex<TechnologyPrototype>(args.Id, out var technologyPrototype))
|
|
return;
|
|
|
|
if (TryComp<AccessReaderComponent>(uid, out var access) && !_accessReader.IsAllowed(act, uid, access))
|
|
{
|
|
_popup.PopupEntity(Loc.GetString("research-console-no-access-popup"), act);
|
|
return;
|
|
}
|
|
|
|
if (!UnlockTechnology(uid, args.Id, act))
|
|
return;
|
|
|
|
// Frontier: silent R&D computers, useless
|
|
/*
|
|
if (!_emag.CheckFlag(uid, EmagType.Interaction))
|
|
{
|
|
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);
|
|
}
|
|
*/
|
|
// End Frontier
|
|
|
|
SyncClientWithServer(uid);
|
|
UpdateConsoleInterface(uid, component);
|
|
}
|
|
|
|
private void OnConsoleBeforeUiOpened(EntityUid uid, ResearchConsoleComponent component, BeforeActivatableUIOpenEvent args)
|
|
{
|
|
SyncClientWithServer(uid);
|
|
UpdateConsoleInterface(uid, component); // Frontier: ensure first open has a valid tech state
|
|
}
|
|
|
|
private void UpdateConsoleInterface(EntityUid uid, ResearchConsoleComponent? component = null, ResearchClientComponent? clientComponent = null)
|
|
{
|
|
if (!Resolve(uid, ref component, ref clientComponent, false))
|
|
return;
|
|
|
|
// Goobstation: R&D Console Rework Start
|
|
var allTechs = PrototypeManager.EnumeratePrototypes<TechnologyPrototype>();
|
|
Dictionary<string, ResearchAvailability> techList;
|
|
var points = 0;
|
|
|
|
if (TryGetClientServer(uid, out var serverUid, out var server, clientComponent) &&
|
|
TryComp<TechnologyDatabaseComponent>(serverUid, out var db))
|
|
{
|
|
var unlockedTechs = new HashSet<string>(db.UnlockedTechnologies);
|
|
techList = allTechs.ToDictionary(
|
|
proto => proto.ID,
|
|
proto =>
|
|
{
|
|
if (unlockedTechs.Contains(proto.ID))
|
|
return ResearchAvailability.Researched;
|
|
|
|
var prereqsMet = proto.TechnologyPrerequisites.All(p => unlockedTechs.Contains(p));
|
|
var canAfford = server.Points >= proto.Cost;
|
|
|
|
return prereqsMet ?
|
|
(canAfford ? ResearchAvailability.Available : ResearchAvailability.PrereqsMet)
|
|
: ResearchAvailability.Unavailable;
|
|
});
|
|
|
|
if (clientComponent != null)
|
|
points = clientComponent.ConnectedToServer ? server.Points : 0;
|
|
}
|
|
else
|
|
{
|
|
techList = allTechs.ToDictionary(proto => proto.ID, _ => ResearchAvailability.Unavailable);
|
|
}
|
|
|
|
_uiSystem.SetUiState(uid, ResearchConsoleUiKey.Key,
|
|
new ResearchConsoleBoundInterfaceState(points, techList));
|
|
// Goobstation: R&D Console Rework End
|
|
}
|
|
|
|
private void OnPointsChanged(EntityUid uid, ResearchConsoleComponent component, ref ResearchServerPointsChangedEvent args)
|
|
{
|
|
if (!_uiSystem.IsUiOpen(uid, ResearchConsoleUiKey.Key))
|
|
return;
|
|
UpdateConsoleInterface(uid, component);
|
|
}
|
|
|
|
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)
|
|
{
|
|
SyncClientWithServer(uid);
|
|
UpdateConsoleInterface(uid, component);
|
|
}
|
|
|
|
private void OnConsoleDatabaseSynchronized(EntityUid uid, ResearchConsoleComponent component, ref TechnologyDatabaseSynchronizedEvent args)
|
|
{
|
|
UpdateConsoleInterface(uid, component);
|
|
}
|
|
|
|
// Frontier: unneeded emag call
|
|
/*
|
|
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;
|
|
}
|
|
*/
|
|
// End Frontier: unneeded emag call
|
|
|
|
}
|