ECS and bandaid research (#9251)
This commit is contained in:
@@ -70,7 +70,7 @@ namespace Content.Client.Entry
|
|||||||
factory.DoAutoRegistrations();
|
factory.DoAutoRegistrations();
|
||||||
factory.IgnoreMissingComponents();
|
factory.IgnoreMissingComponents();
|
||||||
|
|
||||||
factory.RegisterClass<SharedResearchConsoleComponent>();
|
// Do not add to these, they are legacy.
|
||||||
factory.RegisterClass<SharedLatheComponent>();
|
factory.RegisterClass<SharedLatheComponent>();
|
||||||
factory.RegisterClass<SharedSpawnPointComponent>();
|
factory.RegisterClass<SharedSpawnPointComponent>();
|
||||||
factory.RegisterClass<SharedVendingMachineComponent>();
|
factory.RegisterClass<SharedVendingMachineComponent>();
|
||||||
@@ -78,6 +78,7 @@ namespace Content.Client.Entry
|
|||||||
factory.RegisterClass<SharedChemMasterComponent>();
|
factory.RegisterClass<SharedChemMasterComponent>();
|
||||||
factory.RegisterClass<SharedGravityGeneratorComponent>();
|
factory.RegisterClass<SharedGravityGeneratorComponent>();
|
||||||
factory.RegisterClass<SharedAMEControllerComponent>();
|
factory.RegisterClass<SharedAMEControllerComponent>();
|
||||||
|
// Do not add to the above, they are legacy
|
||||||
|
|
||||||
prototypes.RegisterIgnore("accent");
|
prototypes.RegisterIgnore("accent");
|
||||||
prototypes.RegisterIgnore("material");
|
prototypes.RegisterIgnore("material");
|
||||||
|
|||||||
@@ -21,14 +21,14 @@ namespace Content.Client.Research
|
|||||||
|
|
||||||
if (curState is not TechnologyDatabaseState state) return;
|
if (curState is not TechnologyDatabaseState state) return;
|
||||||
|
|
||||||
_technologies.Clear();
|
Technologies.Clear();
|
||||||
|
|
||||||
var protoManager = IoCManager.Resolve<IPrototypeManager>();
|
var protoManager = IoCManager.Resolve<IPrototypeManager>();
|
||||||
|
|
||||||
foreach (var techID in state.Technologies)
|
foreach (var techID in state.Technologies)
|
||||||
{
|
{
|
||||||
if (!protoManager.TryIndex(techID, out TechnologyPrototype? technology)) continue;
|
if (!protoManager.TryIndex(techID, out TechnologyPrototype? technology)) continue;
|
||||||
_technologies.Add(technology);
|
Technologies.Add(technology);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnDatabaseUpdated?.Invoke();
|
OnDatabaseUpdated?.Invoke();
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
|
using Content.Shared.Research.Components;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using static Content.Shared.Research.Components.SharedResearchClientComponent;
|
|
||||||
|
|
||||||
namespace Content.Client.Research.UI
|
namespace Content.Client.Research.UI
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
|
using Content.Shared.Research.Components;
|
||||||
using Content.Shared.Research.Prototypes;
|
using Content.Shared.Research.Prototypes;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.IoC;
|
|
||||||
using static Content.Shared.Research.Components.SharedResearchConsoleComponent;
|
|
||||||
|
|
||||||
namespace Content.Client.Research.UI
|
namespace Content.Client.Research.UI
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public sealed class NetworkConfiguratorSystem : EntitySystem
|
|||||||
|
|
||||||
private void TryAddNetworkDevice(EntityUid? targetUid, EntityUid userUid, NetworkConfiguratorComponent configurator, DeviceNetworkComponent? device = null)
|
private void TryAddNetworkDevice(EntityUid? targetUid, EntityUid userUid, NetworkConfiguratorComponent configurator, DeviceNetworkComponent? device = null)
|
||||||
{
|
{
|
||||||
if (!targetUid.HasValue || !Resolve(targetUid.Value, ref device))
|
if (!targetUid.HasValue || !Resolve(targetUid.Value, ref device, false))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(device.Address))
|
if (string.IsNullOrEmpty(device.Address))
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ using Content.Server.Materials;
|
|||||||
using Content.Server.Popups;
|
using Content.Server.Popups;
|
||||||
using Content.Server.Power.Components;
|
using Content.Server.Power.Components;
|
||||||
using Content.Server.Power.EntitySystems;
|
using Content.Server.Power.EntitySystems;
|
||||||
|
using Content.Server.Research;
|
||||||
using Content.Server.Stack;
|
using Content.Server.Stack;
|
||||||
using Content.Server.UserInterface;
|
using Content.Server.UserInterface;
|
||||||
|
using Content.Shared.Research.Components;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
@@ -274,14 +276,16 @@ namespace Content.Server.Lathe
|
|||||||
|
|
||||||
case LatheServerSelectionMessage _:
|
case LatheServerSelectionMessage _:
|
||||||
if (!TryComp(uid, out ResearchClientComponent? researchClient)) return;
|
if (!TryComp(uid, out ResearchClientComponent? researchClient)) return;
|
||||||
researchClient.OpenUserInterface(message.Session);
|
IoCManager.Resolve<IEntitySystemManager>()
|
||||||
|
.GetEntitySystem<UserInterfaceSystem>()
|
||||||
|
.TryOpen(uid, ResearchClientUiKey.Key, message.Session);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LatheServerSyncMessage _:
|
case LatheServerSyncMessage _:
|
||||||
if (!TryComp(uid, out TechnologyDatabaseComponent? database)
|
if (!TryComp(uid, out TechnologyDatabaseComponent? database)
|
||||||
|| !TryComp(uid, out ProtolatheDatabaseComponent? protoDatabase)) return;
|
|| !TryComp(uid, out ProtolatheDatabaseComponent? protoDatabase)) return;
|
||||||
|
|
||||||
if (database.SyncWithServer())
|
if (IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ResearchSystem>().SyncWithServer(database))
|
||||||
protoDatabase.Sync();
|
protoDatabase.Sync();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,96 +1,12 @@
|
|||||||
using Content.Server.UserInterface;
|
namespace Content.Server.Research.Components
|
||||||
using Content.Shared.Research.Components;
|
|
||||||
using Robust.Server.GameObjects;
|
|
||||||
using Robust.Server.Player;
|
|
||||||
|
|
||||||
namespace Content.Server.Research.Components
|
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[Virtual]
|
[Virtual]
|
||||||
public class ResearchClientComponent : SharedResearchClientComponent
|
public class ResearchClientComponent : Component
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
|
||||||
|
|
||||||
// TODO: Create GUI for changing RD server.
|
|
||||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ResearchClientUiKey.Key);
|
|
||||||
|
|
||||||
public bool ConnectedToServer => Server != null;
|
public bool ConnectedToServer => Server != null;
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
public ResearchServerComponent? Server { get; set; }
|
public ResearchServerComponent? Server { get; set; }
|
||||||
|
|
||||||
public bool RegisterServer(ResearchServerComponent? server)
|
|
||||||
{
|
|
||||||
var result = server != null && server.RegisterClient(this);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnregisterFromServer()
|
|
||||||
{
|
|
||||||
Server?.UnregisterClient(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
|
|
||||||
// For now it just registers on the first server it can find.
|
|
||||||
var servers = _entitySystemManager.GetEntitySystem<ResearchSystem>().Servers;
|
|
||||||
|
|
||||||
if (servers.Count > 0)
|
|
||||||
RegisterServer(servers[0]);
|
|
||||||
|
|
||||||
if (UserInterface != null)
|
|
||||||
{
|
|
||||||
UserInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OpenUserInterface(IPlayerSession session)
|
|
||||||
{
|
|
||||||
UpdateUserInterface();
|
|
||||||
UserInterface?.Open(session);
|
|
||||||
}
|
|
||||||
public void UpdateUserInterface()
|
|
||||||
{
|
|
||||||
UserInterface?.SetState(GetNewUiState());
|
|
||||||
}
|
|
||||||
|
|
||||||
private ResearchClientBoundInterfaceState GetNewUiState()
|
|
||||||
{
|
|
||||||
var rd = _entitySystemManager.GetEntitySystem<ResearchSystem>();
|
|
||||||
|
|
||||||
return new ResearchClientBoundInterfaceState(rd.Servers.Count, rd.GetServerNames(),
|
|
||||||
rd.GetServerIds(), ConnectedToServer ? Server!.Id : -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage msg)
|
|
||||||
{
|
|
||||||
switch (msg.Message)
|
|
||||||
{
|
|
||||||
case ResearchClientSyncMessage _:
|
|
||||||
UpdateUserInterface();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ResearchClientServerSelectedMessage selectedMessage:
|
|
||||||
UnregisterFromServer();
|
|
||||||
RegisterServer(_entitySystemManager.GetEntitySystem<ResearchSystem>().GetServerById(selectedMessage.ServerId));
|
|
||||||
UpdateUserInterface();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ResearchClientServerDeselectedMessage _:
|
|
||||||
UnregisterFromServer();
|
|
||||||
UpdateUserInterface();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Shutdown()
|
|
||||||
{
|
|
||||||
base.Shutdown();
|
|
||||||
UnregisterFromServer();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,89 +1,5 @@
|
|||||||
using Content.Server.Power.Components;
|
|
||||||
using Content.Server.UserInterface;
|
|
||||||
using Content.Shared.Research.Components;
|
|
||||||
using Content.Shared.Research.Prototypes;
|
|
||||||
using Robust.Server.GameObjects;
|
|
||||||
using Robust.Shared.Prototypes;
|
|
||||||
|
|
||||||
namespace Content.Server.Research.Components
|
namespace Content.Server.Research.Components
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class ResearchConsoleComponent : SharedResearchConsoleComponent
|
public sealed class ResearchConsoleComponent : Component {}
|
||||||
{
|
|
||||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
||||||
|
|
||||||
[ViewVariables] private bool Powered => !_entMan.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
|
||||||
|
|
||||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ResearchConsoleUiKey.Key);
|
|
||||||
|
|
||||||
protected override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
|
|
||||||
Owner.EnsureComponentWarn<ServerUserInterfaceComponent>();
|
|
||||||
|
|
||||||
if (UserInterface != null)
|
|
||||||
{
|
|
||||||
UserInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
Owner.EnsureComponent<ResearchClientComponent>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage message)
|
|
||||||
{
|
|
||||||
if (!_entMan.TryGetComponent(Owner, out TechnologyDatabaseComponent? database))
|
|
||||||
return;
|
|
||||||
if (!_entMan.TryGetComponent(Owner, out ResearchClientComponent? client))
|
|
||||||
return;
|
|
||||||
if (!Powered)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (message.Message)
|
|
||||||
{
|
|
||||||
case ConsoleUnlockTechnologyMessage msg:
|
|
||||||
if (!_prototypeManager.TryIndex(msg.Id, out TechnologyPrototype? tech)) break;
|
|
||||||
if (client.Server == null) break;
|
|
||||||
if (!client.Server.CanUnlockTechnology(tech)) break;
|
|
||||||
if (client.Server.UnlockTechnology(tech))
|
|
||||||
{
|
|
||||||
database.SyncWithServer();
|
|
||||||
database.Dirty();
|
|
||||||
UpdateUserInterface();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ConsoleServerSyncMessage _:
|
|
||||||
database.SyncWithServer();
|
|
||||||
UpdateUserInterface();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ConsoleServerSelectionMessage _:
|
|
||||||
client.OpenUserInterface(message.Session);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Method to update the user interface on the clients.
|
|
||||||
/// </summary>
|
|
||||||
public void UpdateUserInterface()
|
|
||||||
{
|
|
||||||
UserInterface?.SetState(GetNewUiState());
|
|
||||||
}
|
|
||||||
|
|
||||||
private ResearchConsoleBoundInterfaceState GetNewUiState()
|
|
||||||
{
|
|
||||||
if (!_entMan.TryGetComponent(Owner, out ResearchClientComponent? client) ||
|
|
||||||
client.Server == null)
|
|
||||||
return new ResearchConsoleBoundInterfaceState(default, default);
|
|
||||||
|
|
||||||
var points = client.ConnectedToServer ? client.Server.Point : 0;
|
|
||||||
var pointsPerSecond = client.ConnectedToServer ? client.Server.PointsPerSecond : 0;
|
|
||||||
|
|
||||||
return new ResearchConsoleBoundInterfaceState(points, pointsPerSecond);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
using Content.Server.Power.Components;
|
|
||||||
|
|
||||||
namespace Content.Server.Research.Components
|
namespace Content.Server.Research.Components
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
@@ -9,8 +7,6 @@ namespace Content.Server.Research.Components
|
|||||||
private int _pointsPerSecond;
|
private int _pointsPerSecond;
|
||||||
[DataField("active")]
|
[DataField("active")]
|
||||||
private bool _active;
|
private bool _active;
|
||||||
private ApcPowerReceiverComponent? _powerReceiver;
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public int PointsPerSecond
|
public int PointsPerSecond
|
||||||
{
|
{
|
||||||
@@ -24,18 +20,5 @@ namespace Content.Server.Research.Components
|
|||||||
get => _active;
|
get => _active;
|
||||||
set => _active = value;
|
set => _active = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether this can be used to produce research points.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>If no <see cref="ApcPowerReceiverComponent"/> is found, it's assumed power is not required.</remarks>
|
|
||||||
[ViewVariables]
|
|
||||||
public bool CanProduce => Active && (_powerReceiver is null || _powerReceiver.Powered);
|
|
||||||
|
|
||||||
protected override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out _powerReceiver);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,163 +1,22 @@
|
|||||||
using Content.Server.Power.Components;
|
|
||||||
using Content.Shared.Research.Prototypes;
|
|
||||||
|
|
||||||
namespace Content.Server.Research.Components
|
namespace Content.Server.Research.Components
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class ResearchServerComponent : Component
|
public sealed class ResearchServerComponent : Component
|
||||||
{
|
{
|
||||||
public static int ServerCount = 0;
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)] public string ServerName => _serverName;
|
[ViewVariables(VVAccess.ReadWrite)] public string ServerName => _serverName;
|
||||||
|
|
||||||
[DataField("servername")]
|
[DataField("servername")]
|
||||||
private string _serverName = "RDSERVER";
|
private string _serverName = "RDSERVER";
|
||||||
private float _timer = 0f;
|
|
||||||
public TechnologyDatabaseComponent? Database { get; private set; }
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("points")] private int _points = 0;
|
[ViewVariables(VVAccess.ReadWrite)] [DataField("points")]
|
||||||
|
public int Points = 0;
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadOnly)] public int Id { get; private set; }
|
[ViewVariables(VVAccess.ReadOnly)] public int Id { get; private set; }
|
||||||
|
|
||||||
// You could optimize research by keeping a list of unlocked recipes too.
|
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
|
||||||
public IReadOnlyList<TechnologyPrototype>? UnlockedTechnologies => Database?.Technologies;
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
public List<ResearchPointSourceComponent> PointSources { get; } = new();
|
public List<ResearchPointSourceComponent> PointSources { get; } = new();
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
public List<ResearchClientComponent> Clients { get; } = new();
|
public List<ResearchClientComponent> Clients { get; } = new();
|
||||||
|
|
||||||
public int Point => _points;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// How many points per second this R&D server gets.
|
|
||||||
/// The value is calculated from all point sources connected to it.
|
|
||||||
/// </summary>
|
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
|
||||||
public int PointsPerSecond
|
|
||||||
{
|
|
||||||
// This could be changed to PointsPerMinute quite easily for optimization.
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var points = 0;
|
|
||||||
|
|
||||||
if (CanRun)
|
|
||||||
{
|
|
||||||
foreach (var source in PointSources)
|
|
||||||
{
|
|
||||||
if (source.CanProduce) points += source.PointsPerSecond;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return points;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <remarks>If no <see cref="ApcPowerReceiverComponent"/> is found, it's assumed power is not required.</remarks>
|
|
||||||
[ViewVariables]
|
|
||||||
public bool CanRun => _powerReceiver is null || _powerReceiver.Powered;
|
|
||||||
|
|
||||||
private ApcPowerReceiverComponent? _powerReceiver;
|
|
||||||
|
|
||||||
protected override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
Id = ServerCount++;
|
|
||||||
EntitySystem.Get<ResearchSystem>()?.RegisterServer(this);
|
|
||||||
Database = Owner.EnsureComponent<TechnologyDatabaseComponent>();
|
|
||||||
IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out _powerReceiver);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Shutdown()
|
|
||||||
{
|
|
||||||
base.Shutdown();
|
|
||||||
EntitySystem.Get<ResearchSystem>()?.UnregisterServer(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool CanUnlockTechnology(TechnologyPrototype technology)
|
|
||||||
{
|
|
||||||
if (Database == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!Database.CanUnlockTechnology(technology) ||
|
|
||||||
_points < technology.RequiredPoints ||
|
|
||||||
Database.IsTechnologyUnlocked(technology))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Unlocks a technology, but only if there are enough research points for it.
|
|
||||||
/// If there are, it subtracts the amount of points from the total.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="technology"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool UnlockTechnology(TechnologyPrototype technology)
|
|
||||||
{
|
|
||||||
if (!CanUnlockTechnology(technology)) return false;
|
|
||||||
var result = Database?.UnlockTechnology(technology) ?? false;
|
|
||||||
if (result)
|
|
||||||
_points -= technology.RequiredPoints;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check whether a technology is unlocked or not.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="technology"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool IsTechnologyUnlocked(TechnologyPrototype technology)
|
|
||||||
{
|
|
||||||
return Database?.IsTechnologyUnlocked(technology) ?? false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Registers a remote client on this research server.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="client"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool RegisterClient(ResearchClientComponent client)
|
|
||||||
{
|
|
||||||
if (client is ResearchPointSourceComponent source)
|
|
||||||
{
|
|
||||||
if (PointSources.Contains(source)) return false;
|
|
||||||
PointSources.Add(source);
|
|
||||||
source.Server = this;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Clients.Contains(client)) return false;
|
|
||||||
Clients.Add(client);
|
|
||||||
client.Server = this;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Unregisters a remote client from this server.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="client"></param>
|
|
||||||
public void UnregisterClient(ResearchClientComponent client)
|
|
||||||
{
|
|
||||||
if (client is ResearchPointSourceComponent source)
|
|
||||||
{
|
|
||||||
PointSources.Remove(source);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Clients.Remove(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(float frameTime)
|
|
||||||
{
|
|
||||||
if (!CanRun) return;
|
|
||||||
_timer += frameTime;
|
|
||||||
if (_timer < 1f) return;
|
|
||||||
_timer = 0f;
|
|
||||||
_points += PointsPerSecond;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,73 +1,7 @@
|
|||||||
using Content.Shared.Research.Components;
|
using Content.Shared.Research.Components;
|
||||||
using Content.Shared.Research.Prototypes;
|
|
||||||
|
|
||||||
namespace Content.Server.Research.Components
|
namespace Content.Server.Research.Components
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class TechnologyDatabaseComponent : SharedTechnologyDatabaseComponent
|
public sealed class TechnologyDatabaseComponent : SharedTechnologyDatabaseComponent {}
|
||||||
{
|
|
||||||
public override ComponentState GetComponentState()
|
|
||||||
{
|
|
||||||
return new TechnologyDatabaseState(_technologies);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Synchronizes this database against other,
|
|
||||||
/// adding all technologies from the other that
|
|
||||||
/// this one doesn't have.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="otherDatabase">The other database</param>
|
|
||||||
/// <param name="twoway">Whether the other database should be synced against this one too or not.</param>
|
|
||||||
public void Sync(TechnologyDatabaseComponent otherDatabase, bool twoway = true)
|
|
||||||
{
|
|
||||||
foreach (var tech in otherDatabase.Technologies)
|
|
||||||
{
|
|
||||||
if (!IsTechnologyUnlocked(tech)) AddTechnology(tech);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (twoway)
|
|
||||||
otherDatabase.Sync(this, false);
|
|
||||||
|
|
||||||
Dirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// If there's a research client component attached to the owner entity,
|
|
||||||
/// and the research client is connected to a research server, this method
|
|
||||||
/// syncs against the research server, and the server against the local database.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Whether it could sync or not</returns>
|
|
||||||
public bool SyncWithServer()
|
|
||||||
{
|
|
||||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out ResearchClientComponent? client)) return false;
|
|
||||||
if (client.Server?.Database == null) return false;
|
|
||||||
|
|
||||||
Sync(client.Server.Database);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// If possible, unlocks a technology on this database.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="technology"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool UnlockTechnology(TechnologyPrototype technology)
|
|
||||||
{
|
|
||||||
if (!CanUnlockTechnology(technology)) return false;
|
|
||||||
|
|
||||||
AddTechnology(technology);
|
|
||||||
Dirty();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds a technology to the database without checking if it could be unlocked.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="technology"></param>
|
|
||||||
public void AddTechnology(TechnologyPrototype technology)
|
|
||||||
{
|
|
||||||
_technologies.Add(technology);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
87
Content.Server/Research/Systems/ResearchSystem.Client.cs
Normal file
87
Content.Server/Research/Systems/ResearchSystem.Client.cs
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
using Content.Server.Research.Components;
|
||||||
|
using Content.Shared.Research.Components;
|
||||||
|
|
||||||
|
namespace Content.Server.Research;
|
||||||
|
|
||||||
|
public sealed partial class ResearchSystem
|
||||||
|
{
|
||||||
|
private void InitializeClient()
|
||||||
|
{
|
||||||
|
SubscribeLocalEvent<ResearchClientComponent, ComponentStartup>(OnClientStartup);
|
||||||
|
SubscribeLocalEvent<ResearchClientComponent, ComponentShutdown>(OnClientShutdown);
|
||||||
|
SubscribeLocalEvent<ResearchClientComponent, BoundUIOpenedEvent>(OnClientUIOpen);
|
||||||
|
|
||||||
|
SubscribeLocalEvent<ResearchClientComponent, ResearchClientSyncMessage>(OnClientSyncMessage);
|
||||||
|
SubscribeLocalEvent<ResearchClientComponent, ResearchClientServerSelectedMessage>(OnClientSelected);
|
||||||
|
SubscribeLocalEvent<ResearchClientComponent, ResearchClientServerDeselectedMessage>(OnClientDeselected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region UI
|
||||||
|
|
||||||
|
private void OnClientDeselected(EntityUid uid, ResearchClientComponent component, ResearchClientServerDeselectedMessage args)
|
||||||
|
{
|
||||||
|
UnregisterClientServer(component);
|
||||||
|
UpdateClientInterface(component);
|
||||||
|
|
||||||
|
if (TryComp<ResearchConsoleComponent>(uid, out var console))
|
||||||
|
{
|
||||||
|
UpdateConsoleInterface(console, component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnClientSelected(EntityUid uid, ResearchClientComponent component, ResearchClientServerSelectedMessage args)
|
||||||
|
{
|
||||||
|
UnregisterClientServer(component);
|
||||||
|
RegisterClientServer(component, GetServerById(args.ServerId));
|
||||||
|
UpdateClientInterface(component);
|
||||||
|
|
||||||
|
if (TryComp<ResearchConsoleComponent>(uid, out var console))
|
||||||
|
{
|
||||||
|
UpdateConsoleInterface(console, component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnClientSyncMessage(EntityUid uid, ResearchClientComponent component, ResearchClientSyncMessage args)
|
||||||
|
{
|
||||||
|
UpdateClientInterface(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private void OnClientStartup(EntityUid uid, ResearchClientComponent component, ComponentStartup args)
|
||||||
|
{
|
||||||
|
if (Servers.Count > 0)
|
||||||
|
RegisterClientServer(component, Servers[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnClientShutdown(EntityUid uid, ResearchClientComponent component, ComponentShutdown args)
|
||||||
|
{
|
||||||
|
UnregisterClientServer(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnClientUIOpen(EntityUid uid, ResearchClientComponent component, BoundUIOpenedEvent args)
|
||||||
|
{
|
||||||
|
UpdateClientInterface(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateClientInterface(ResearchClientComponent component)
|
||||||
|
{
|
||||||
|
var state = new ResearchClientBoundInterfaceState(Servers.Count, GetServerNames(),
|
||||||
|
GetServerIds(), component.ConnectedToServer ? component.Server!.Id : -1);
|
||||||
|
|
||||||
|
_uiSystem.GetUiOrNull(component.Owner, ResearchClientUiKey.Key)?.SetState(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool RegisterClientServer(ResearchClientComponent component, ResearchServerComponent? server = null)
|
||||||
|
{
|
||||||
|
if (server == null) return false;
|
||||||
|
return RegisterServerClient(server, component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UnregisterClientServer(ResearchClientComponent component)
|
||||||
|
{
|
||||||
|
if (component.Server == null) return;
|
||||||
|
|
||||||
|
UnregisterServerClient(component.Server, component);
|
||||||
|
}
|
||||||
|
}
|
||||||
74
Content.Server/Research/Systems/ResearchSystem.Console.cs
Normal file
74
Content.Server/Research/Systems/ResearchSystem.Console.cs
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
using Content.Server.Power.EntitySystems;
|
||||||
|
using Content.Server.Research.Components;
|
||||||
|
using Content.Shared.Research.Components;
|
||||||
|
using Content.Shared.Research.Prototypes;
|
||||||
|
using Robust.Server.Player;
|
||||||
|
|
||||||
|
namespace Content.Server.Research;
|
||||||
|
|
||||||
|
public sealed partial class ResearchSystem
|
||||||
|
{
|
||||||
|
private void InitializeConsole()
|
||||||
|
{
|
||||||
|
SubscribeLocalEvent<ResearchConsoleComponent, ConsoleUnlockTechnologyMessage>(OnConsoleUnlock);
|
||||||
|
SubscribeLocalEvent<ResearchConsoleComponent, ConsoleServerSyncMessage>(OnConsoleSync);
|
||||||
|
SubscribeLocalEvent<ResearchConsoleComponent, ConsoleServerSelectionMessage>(OnConsoleSelect);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnConsoleSelect(EntityUid uid, ResearchConsoleComponent component, ConsoleServerSelectionMessage args)
|
||||||
|
{
|
||||||
|
if (!HasComp<TechnologyDatabaseComponent>(uid) ||
|
||||||
|
!HasComp<ResearchClientComponent>(uid) ||
|
||||||
|
!this.IsPowered(uid, EntityManager))
|
||||||
|
return;
|
||||||
|
|
||||||
|
_uiSystem.TryOpen(uid, ResearchClientUiKey.Key, (IPlayerSession) args.Session);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnConsoleSync(EntityUid uid, ResearchConsoleComponent component, ConsoleServerSyncMessage args)
|
||||||
|
{
|
||||||
|
if (!TryComp<TechnologyDatabaseComponent>(uid, out var database) ||
|
||||||
|
!HasComp<ResearchClientComponent>(uid) ||
|
||||||
|
!this.IsPowered(uid, EntityManager))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SyncWithServer(database);
|
||||||
|
UpdateConsoleInterface(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnConsoleUnlock(EntityUid uid, ResearchConsoleComponent component, ConsoleUnlockTechnologyMessage args)
|
||||||
|
{
|
||||||
|
if (!TryComp<TechnologyDatabaseComponent>(uid, out var database) ||
|
||||||
|
!TryComp<ResearchClientComponent>(uid, out var client) ||
|
||||||
|
!this.IsPowered(uid, EntityManager))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!_prototypeManager.TryIndex(args.Id, out TechnologyPrototype? tech) ||
|
||||||
|
client.Server == null ||
|
||||||
|
!CanUnlockTechnology(client.Server, tech)) return;
|
||||||
|
|
||||||
|
if (!UnlockTechnology(client.Server, tech)) return;
|
||||||
|
|
||||||
|
SyncWithServer(database);
|
||||||
|
Dirty(database);
|
||||||
|
UpdateConsoleInterface(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateConsoleInterface(ResearchConsoleComponent component, ResearchClientComponent? clientComponent = null)
|
||||||
|
{
|
||||||
|
ResearchConsoleBoundInterfaceState state;
|
||||||
|
|
||||||
|
if (!Resolve(component.Owner, ref clientComponent, false) ||
|
||||||
|
clientComponent.Server == null)
|
||||||
|
{
|
||||||
|
state = new ResearchConsoleBoundInterfaceState(default, default);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var points = clientComponent.ConnectedToServer ? clientComponent.Server.Points : 0;
|
||||||
|
var pointsPerSecond = clientComponent.ConnectedToServer ? PointsPerSecond(clientComponent.Server) : 0;
|
||||||
|
state = new ResearchConsoleBoundInterfaceState(points, pointsPerSecond);
|
||||||
|
}
|
||||||
|
_uiSystem.GetUiOrNull(component.Owner, ResearchConsoleUiKey.Key)?.SetState(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using Content.Server.Power.EntitySystems;
|
||||||
|
using Content.Server.Research.Components;
|
||||||
|
|
||||||
|
namespace Content.Server.Research;
|
||||||
|
|
||||||
|
public sealed partial class ResearchSystem
|
||||||
|
{
|
||||||
|
public bool CanProduce(ResearchPointSourceComponent component)
|
||||||
|
{
|
||||||
|
return component.Active && this.IsPowered(component.Owner, EntityManager);
|
||||||
|
}
|
||||||
|
}
|
||||||
109
Content.Server/Research/Systems/ResearchSystem.Server.cs
Normal file
109
Content.Server/Research/Systems/ResearchSystem.Server.cs
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
using Content.Server.Power.EntitySystems;
|
||||||
|
using Content.Server.Research.Components;
|
||||||
|
using Content.Shared.Research.Prototypes;
|
||||||
|
|
||||||
|
namespace Content.Server.Research;
|
||||||
|
|
||||||
|
public sealed partial class ResearchSystem
|
||||||
|
{
|
||||||
|
private void InitializeServer()
|
||||||
|
{
|
||||||
|
SubscribeLocalEvent<ResearchServerComponent, ComponentStartup>(OnServerStartup);
|
||||||
|
SubscribeLocalEvent<ResearchServerComponent, ComponentShutdown>(OnServerShutdown);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnServerShutdown(EntityUid uid, ResearchServerComponent component, ComponentShutdown args)
|
||||||
|
{
|
||||||
|
UnregisterServer(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnServerStartup(EntityUid uid, ResearchServerComponent component, ComponentStartup args)
|
||||||
|
{
|
||||||
|
RegisterServer(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CanRun(ResearchServerComponent component)
|
||||||
|
{
|
||||||
|
return this.IsPowered(component.Owner, EntityManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateServer(ResearchServerComponent component, int time)
|
||||||
|
{
|
||||||
|
if (!CanRun(component)) return;
|
||||||
|
component.Points += PointsPerSecond(component) * time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RegisterServerClient(ResearchServerComponent component, ResearchClientComponent clientComponent)
|
||||||
|
{
|
||||||
|
// TODO: This is shit but I'm just trying to fix RND for now until it gets bulldozed
|
||||||
|
if (TryComp<ResearchPointSourceComponent>(clientComponent.Owner, out var source))
|
||||||
|
{
|
||||||
|
if (component.PointSources.Contains(source)) return false;
|
||||||
|
component.PointSources.Add(source);
|
||||||
|
source.Server = component;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (component.Clients.Contains(clientComponent)) return false;
|
||||||
|
component.Clients.Add(clientComponent);
|
||||||
|
clientComponent.Server = component;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnregisterServerClient(ResearchServerComponent component, ResearchClientComponent clientComponent)
|
||||||
|
{
|
||||||
|
if (TryComp<ResearchPointSourceComponent>(clientComponent.Owner, out var source))
|
||||||
|
{
|
||||||
|
component.PointSources.Remove(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
component.Clients.Remove(clientComponent);
|
||||||
|
clientComponent.Server = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsTechnologyUnlocked(ResearchServerComponent component, TechnologyPrototype prototype,
|
||||||
|
TechnologyDatabaseComponent? databaseComponent = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(component.Owner, ref databaseComponent, false)) return false;
|
||||||
|
return databaseComponent.IsTechnologyUnlocked(prototype);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CanUnlockTechnology(ResearchServerComponent component, TechnologyPrototype technology, TechnologyDatabaseComponent? databaseComponent = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(component.Owner, ref databaseComponent, false))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!databaseComponent.CanUnlockTechnology(technology) ||
|
||||||
|
component.Points < technology.RequiredPoints ||
|
||||||
|
IsTechnologyUnlocked(component, technology, databaseComponent))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UnlockTechnology(ResearchServerComponent component, TechnologyPrototype prototype,
|
||||||
|
TechnologyDatabaseComponent? databaseComponent = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(component.Owner, ref databaseComponent, false)) return false;
|
||||||
|
|
||||||
|
if (!CanUnlockTechnology(component, prototype, databaseComponent)) return false;
|
||||||
|
var result = UnlockTechnology(databaseComponent, prototype);
|
||||||
|
if (result)
|
||||||
|
component.Points -= prototype.RequiredPoints;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int PointsPerSecond(ResearchServerComponent component)
|
||||||
|
{
|
||||||
|
var points = 0;
|
||||||
|
|
||||||
|
if (CanRun(component))
|
||||||
|
{
|
||||||
|
foreach (var source in component.PointSources)
|
||||||
|
{
|
||||||
|
if (CanProduce(source)) points += source.PointsPerSecond;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
}
|
||||||
78
Content.Server/Research/Systems/ResearchSystem.Technology.cs
Normal file
78
Content.Server/Research/Systems/ResearchSystem.Technology.cs
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
using Content.Server.Research.Components;
|
||||||
|
using Content.Shared.Research.Components;
|
||||||
|
using Content.Shared.Research.Prototypes;
|
||||||
|
using Robust.Shared.GameStates;
|
||||||
|
|
||||||
|
namespace Content.Server.Research;
|
||||||
|
|
||||||
|
public sealed partial class ResearchSystem
|
||||||
|
{
|
||||||
|
private void InitializeTechnology()
|
||||||
|
{
|
||||||
|
SubscribeLocalEvent<TechnologyDatabaseComponent, ComponentGetState>(OnTechnologyGetState);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTechnologyGetState(EntityUid uid, TechnologyDatabaseComponent component, ref ComponentGetState args)
|
||||||
|
{
|
||||||
|
args.State = new TechnologyDatabaseState(component.Technologies);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Synchronizes this database against other,
|
||||||
|
/// adding all technologies from the other that
|
||||||
|
/// this one doesn't have.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="otherDatabase">The other database</param>
|
||||||
|
/// <param name="twoway">Whether the other database should be synced against this one too or not.</param>
|
||||||
|
public void Sync(TechnologyDatabaseComponent component, TechnologyDatabaseComponent otherDatabase, bool twoway = true)
|
||||||
|
{
|
||||||
|
foreach (var tech in otherDatabase.Technologies)
|
||||||
|
{
|
||||||
|
if (!component.IsTechnologyUnlocked(tech)) AddTechnology(component, tech);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (twoway)
|
||||||
|
Sync(otherDatabase, component, false);
|
||||||
|
|
||||||
|
Dirty(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If there's a research client component attached to the owner entity,
|
||||||
|
/// and the research client is connected to a research server, this method
|
||||||
|
/// syncs against the research server, and the server against the local database.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Whether it could sync or not</returns>
|
||||||
|
public bool SyncWithServer(TechnologyDatabaseComponent component, ResearchClientComponent? clientComponent = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(component.Owner, ref clientComponent, false)) return false;
|
||||||
|
if (!TryComp<TechnologyDatabaseComponent>(clientComponent.Server?.Owner, out var clientDatabase)) return false;
|
||||||
|
|
||||||
|
Sync(component, clientDatabase);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If possible, unlocks a technology on this database.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="technology"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool UnlockTechnology(TechnologyDatabaseComponent component, TechnologyPrototype technology)
|
||||||
|
{
|
||||||
|
if (!component.CanUnlockTechnology(technology)) return false;
|
||||||
|
|
||||||
|
AddTechnology(component, technology);
|
||||||
|
Dirty(component);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a technology to the database without checking if it could be unlocked.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="technology"></param>
|
||||||
|
public void AddTechnology(TechnologyDatabaseComponent component, TechnologyPrototype technology)
|
||||||
|
{
|
||||||
|
component.Technologies.Add(technology);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,18 @@
|
|||||||
using Content.Server.Research.Components;
|
using Content.Server.Research.Components;
|
||||||
|
using Content.Shared.Research.Components;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using Robust.Server.GameObjects;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
namespace Content.Server.Research
|
namespace Content.Server.Research
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public sealed class ResearchSystem : EntitySystem
|
public sealed partial class ResearchSystem : EntitySystem
|
||||||
{
|
{
|
||||||
private const float ResearchConsoleUIUpdateTime = 30f;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
|
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
||||||
|
|
||||||
|
private const int ResearchConsoleUIUpdateTime = 5;
|
||||||
|
|
||||||
private float _timer = ResearchConsoleUIUpdateTime;
|
private float _timer = ResearchConsoleUIUpdateTime;
|
||||||
private readonly List<ResearchServerComponent> _servers = new();
|
private readonly List<ResearchServerComponent> _servers = new();
|
||||||
@@ -15,6 +21,10 @@ namespace Content.Server.Research
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
InitializeClient();
|
||||||
|
InitializeConsole();
|
||||||
|
InitializeServer();
|
||||||
|
InitializeTechnology();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool RegisterServer(ResearchServerComponent server)
|
public bool RegisterServer(ResearchServerComponent server)
|
||||||
@@ -67,19 +77,20 @@ namespace Content.Server.Research
|
|||||||
{
|
{
|
||||||
_timer += frameTime;
|
_timer += frameTime;
|
||||||
|
|
||||||
|
while (_timer > ResearchConsoleUIUpdateTime)
|
||||||
|
{
|
||||||
foreach (var server in _servers)
|
foreach (var server in _servers)
|
||||||
{
|
{
|
||||||
server.Update(frameTime);
|
UpdateServer(server, ResearchConsoleUIUpdateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_timer >= ResearchConsoleUIUpdateTime)
|
|
||||||
{
|
|
||||||
foreach (var console in EntityManager.EntityQuery<ResearchConsoleComponent>())
|
foreach (var console in EntityManager.EntityQuery<ResearchConsoleComponent>())
|
||||||
{
|
{
|
||||||
console.UpdateUserInterface();
|
if (!_uiSystem.IsUiOpen(console.Owner, ResearchConsoleUiKey.Key)) continue;
|
||||||
|
UpdateConsoleInterface(console);
|
||||||
}
|
}
|
||||||
|
|
||||||
_timer = 0f;
|
_timer -= ResearchConsoleUIUpdateTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,14 @@
|
|||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.Research.Components
|
namespace Content.Shared.Research.Components
|
||||||
{
|
|
||||||
[Virtual]
|
|
||||||
public class SharedResearchClientComponent : Component
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Request that the server updates the client.
|
/// Sent to the server when the client deselects a research server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class ResearchClientSyncMessage : BoundUserInterfaceMessage
|
public sealed class ResearchClientServerDeselectedMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
|
public ResearchClientServerDeselectedMessage()
|
||||||
public ResearchClientSyncMessage()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,12 +28,13 @@ namespace Content.Shared.Research.Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sent to the server when the client deselects a research server.
|
/// Request that the server updates the client.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class ResearchClientServerDeselectedMessage : BoundUserInterfaceMessage
|
public sealed class ResearchClientSyncMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
public ResearchClientServerDeselectedMessage()
|
|
||||||
|
public ResearchClientSyncMessage()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,5 +62,3 @@ namespace Content.Shared.Research.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
using Robust.Shared.GameStates;
|
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.Research.Components
|
namespace Content.Shared.Research.Components
|
||||||
{
|
{
|
||||||
[NetworkedComponent()]
|
|
||||||
[Virtual]
|
|
||||||
public class SharedResearchConsoleComponent : Component
|
|
||||||
{
|
|
||||||
|
|
||||||
[NetSerializable, Serializable]
|
[NetSerializable, Serializable]
|
||||||
public enum ResearchConsoleUiKey
|
public enum ResearchConsoleUiKey : byte
|
||||||
{
|
{
|
||||||
Key,
|
Key,
|
||||||
}
|
}
|
||||||
@@ -51,4 +45,3 @@ namespace Content.Shared.Research.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,18 +11,13 @@ namespace Content.Shared.Research.Components
|
|||||||
{
|
{
|
||||||
[DataField("technologies")] private List<string> _technologyIds = new();
|
[DataField("technologies")] private List<string> _technologyIds = new();
|
||||||
|
|
||||||
protected List<TechnologyPrototype> _technologies = new();
|
public List<TechnologyPrototype> Technologies = new();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A read-only list of unlocked technologies.
|
|
||||||
/// </summary>
|
|
||||||
public IReadOnlyList<TechnologyPrototype> Technologies => _technologies;
|
|
||||||
|
|
||||||
void ISerializationHooks.BeforeSerialization()
|
void ISerializationHooks.BeforeSerialization()
|
||||||
{
|
{
|
||||||
var techIds = new List<string>();
|
var techIds = new List<string>();
|
||||||
|
|
||||||
foreach (var tech in _technologies)
|
foreach (var tech in Technologies)
|
||||||
{
|
{
|
||||||
techIds.Add(tech.ID);
|
techIds.Add(tech.ID);
|
||||||
}
|
}
|
||||||
@@ -38,7 +33,7 @@ namespace Content.Shared.Research.Components
|
|||||||
{
|
{
|
||||||
if (prototypeManager.TryIndex(id, out TechnologyPrototype? tech))
|
if (prototypeManager.TryIndex(id, out TechnologyPrototype? tech))
|
||||||
{
|
{
|
||||||
_technologies.Add(tech);
|
Technologies.Add(tech);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,7 +56,7 @@ namespace Content.Shared.Research.Components
|
|||||||
{
|
{
|
||||||
List<string> techIds = new List<string>();
|
List<string> techIds = new List<string>();
|
||||||
|
|
||||||
foreach (var tech in _technologies)
|
foreach (var tech in Technologies)
|
||||||
{
|
{
|
||||||
techIds.Add(tech.ID);
|
techIds.Add(tech.ID);
|
||||||
}
|
}
|
||||||
@@ -76,7 +71,7 @@ namespace Content.Shared.Research.Components
|
|||||||
/// <returns>Whether it is unlocked or not</returns>
|
/// <returns>Whether it is unlocked or not</returns>
|
||||||
public bool IsTechnologyUnlocked(TechnologyPrototype technology)
|
public bool IsTechnologyUnlocked(TechnologyPrototype technology)
|
||||||
{
|
{
|
||||||
return _technologies.Contains(technology);
|
return Technologies.Contains(technology);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
- state: rndpointsource
|
- state: rndpointsource
|
||||||
shader: unshaded
|
shader: unshaded
|
||||||
map: ["enum.PowerDeviceVisualLayers.Powered"]
|
map: ["enum.PowerDeviceVisualLayers.Powered"]
|
||||||
|
- type: ResearchClient
|
||||||
- type: ResearchPointSource
|
- type: ResearchPointSource
|
||||||
pointspersecond: 100
|
pointspersecond: 100
|
||||||
active: true
|
active: true
|
||||||
|
|||||||
Reference in New Issue
Block a user