clean up infinite researchsystem shitcode (#13136)
* clean up infinite researchsystem shitcode * fml some more shit * make syncing work logically * naming naming naming
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Content.Shared.Lathe;
|
using Content.Shared.Lathe;
|
||||||
|
using Content.Shared.Research.Components;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
|
|
||||||
@@ -32,11 +33,11 @@ namespace Content.Client.Lathe.UI
|
|||||||
};
|
};
|
||||||
_menu.OnServerListButtonPressed += _ =>
|
_menu.OnServerListButtonPressed += _ =>
|
||||||
{
|
{
|
||||||
SendMessage(new LatheServerSelectionMessage());
|
SendMessage(new ConsoleServerSelectionMessage());
|
||||||
};
|
};
|
||||||
_menu.OnServerSyncButtonPressed += _ =>
|
_menu.OnServerSyncButtonPressed += _ =>
|
||||||
{
|
{
|
||||||
SendMessage(new LatheServerSyncMessage());
|
SendMessage(new ConsoleServerSyncMessage());
|
||||||
};
|
};
|
||||||
_menu.RecipeQueueAction += (recipe, amount) =>
|
_menu.RecipeQueueAction += (recipe, amount) =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using Content.Shared.Lathe;
|
|
||||||
using Content.Shared.Research;
|
using Content.Shared.Research;
|
||||||
|
using Content.Shared.Research.Components;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
|
|
||||||
namespace Content.Client.Research.UI
|
namespace Content.Client.Research.UI
|
||||||
@@ -24,7 +24,7 @@ namespace Content.Client.Research.UI
|
|||||||
|
|
||||||
_menu.OnServerButtonPressed += () =>
|
_menu.OnServerButtonPressed += () =>
|
||||||
{
|
{
|
||||||
SendMessage(new LatheServerSelectionMessage());
|
SendMessage(new ConsoleServerSelectionMessage());
|
||||||
};
|
};
|
||||||
_menu.OnPrintButtonPressed += () =>
|
_menu.OnPrintButtonPressed += () =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ namespace Content.Client.Research.UI
|
|||||||
if (_technologyDatabase == null)
|
if (_technologyDatabase == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return _research.CanUnlockTechnology(_technologyDatabase.Owner, technology, _technologyDatabase);
|
return _research.ArePrerequesitesUnlocked(_technologyDatabase.Owner, technology, _technologyDatabase);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateState(BoundUserInterfaceState state)
|
protected override void UpdateState(BoundUserInterfaceState state)
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ using Content.Server.Lathe.Components;
|
|||||||
using Content.Server.Materials;
|
using Content.Server.Materials;
|
||||||
using Content.Server.Power.Components;
|
using Content.Server.Power.Components;
|
||||||
using Content.Server.Power.EntitySystems;
|
using Content.Server.Power.EntitySystems;
|
||||||
using Content.Server.Research.Components;
|
|
||||||
using Content.Server.Research.Systems;
|
|
||||||
using Content.Server.UserInterface;
|
using Content.Server.UserInterface;
|
||||||
using Content.Shared.Lathe;
|
using Content.Shared.Lathe;
|
||||||
using Content.Shared.Materials;
|
using Content.Shared.Materials;
|
||||||
@@ -14,7 +12,6 @@ using Content.Shared.Research.Components;
|
|||||||
using Content.Shared.Research.Prototypes;
|
using Content.Shared.Research.Prototypes;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.Player;
|
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
@@ -28,7 +25,6 @@ namespace Content.Server.Lathe
|
|||||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||||
[Dependency] private readonly UserInterfaceSystem _uiSys = default!;
|
[Dependency] private readonly UserInterfaceSystem _uiSys = default!;
|
||||||
[Dependency] private readonly ResearchSystem _researchSys = default!;
|
|
||||||
[Dependency] private readonly MaterialStorageSystem _materialStorage = default!;
|
[Dependency] private readonly MaterialStorageSystem _materialStorage = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
@@ -40,6 +36,7 @@ namespace Content.Server.Lathe
|
|||||||
SubscribeLocalEvent<LatheComponent, PowerChangedEvent>(OnPowerChanged);
|
SubscribeLocalEvent<LatheComponent, PowerChangedEvent>(OnPowerChanged);
|
||||||
SubscribeLocalEvent<LatheComponent, RefreshPartsEvent>(OnPartsRefresh);
|
SubscribeLocalEvent<LatheComponent, RefreshPartsEvent>(OnPartsRefresh);
|
||||||
SubscribeLocalEvent<LatheComponent, UpgradeExamineEvent>(OnUpgradeExamine);
|
SubscribeLocalEvent<LatheComponent, UpgradeExamineEvent>(OnUpgradeExamine);
|
||||||
|
SubscribeLocalEvent<LatheComponent, TechnologyDatabaseModifiedEvent>(OnDatabaseModified);
|
||||||
|
|
||||||
SubscribeLocalEvent<LatheComponent, LatheQueueRecipeMessage>(OnLatheQueueRecipeMessage);
|
SubscribeLocalEvent<LatheComponent, LatheQueueRecipeMessage>(OnLatheQueueRecipeMessage);
|
||||||
SubscribeLocalEvent<LatheComponent, LatheSyncRequestMessage>(OnLatheSyncRequestMessage);
|
SubscribeLocalEvent<LatheComponent, LatheSyncRequestMessage>(OnLatheSyncRequestMessage);
|
||||||
@@ -48,8 +45,6 @@ namespace Content.Server.Lathe
|
|||||||
SubscribeLocalEvent<LatheComponent, MaterialAmountChangedEvent>((u,c,_) => UpdateUserInterfaceState(u,c));
|
SubscribeLocalEvent<LatheComponent, MaterialAmountChangedEvent>((u,c,_) => UpdateUserInterfaceState(u,c));
|
||||||
|
|
||||||
SubscribeLocalEvent<TechnologyDatabaseComponent, LatheGetRecipesEvent>(OnGetRecipes);
|
SubscribeLocalEvent<TechnologyDatabaseComponent, LatheGetRecipesEvent>(OnGetRecipes);
|
||||||
SubscribeLocalEvent<ResearchClientComponent, LatheServerSelectionMessage>(OnLatheServerSelectionMessage);
|
|
||||||
SubscribeLocalEvent<TechnologyDatabaseComponent, LatheServerSyncMessage>(OnLatheServerSyncMessage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
@@ -276,6 +271,11 @@ namespace Content.Server.Lathe
|
|||||||
args.AddPercentageUpgrade("lathe-component-upgrade-material-use", component.MaterialUseMultiplier);
|
args.AddPercentageUpgrade("lathe-component-upgrade-material-use", component.MaterialUseMultiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnDatabaseModified(EntityUid uid, LatheComponent component, ref TechnologyDatabaseModifiedEvent args)
|
||||||
|
{
|
||||||
|
UpdateUserInterfaceState(uid, component);
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool HasRecipe(EntityUid uid, LatheRecipePrototype recipe, LatheComponent component)
|
protected override bool HasRecipe(EntityUid uid, LatheRecipePrototype recipe, LatheComponent component)
|
||||||
{
|
{
|
||||||
return GetAvailableRecipes(component).Contains(recipe.ID);
|
return GetAvailableRecipes(component).Contains(recipe.ID);
|
||||||
@@ -300,18 +300,6 @@ namespace Content.Server.Lathe
|
|||||||
{
|
{
|
||||||
UpdateUserInterfaceState(uid, component);
|
UpdateUserInterfaceState(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnLatheServerSelectionMessage(EntityUid uid, ResearchClientComponent component, LatheServerSelectionMessage args)
|
|
||||||
{
|
|
||||||
_uiSys.TryOpen(uid, ResearchClientUiKey.Key, (IPlayerSession) args.Session);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnLatheServerSyncMessage(EntityUid uid, TechnologyDatabaseComponent component, LatheServerSyncMessage args)
|
|
||||||
{
|
|
||||||
_researchSys.SyncWithServer(component);
|
|
||||||
UpdateUserInterfaceState(uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
namespace Content.Server.Research.Components
|
|
||||||
{
|
|
||||||
[RegisterComponent]
|
|
||||||
public sealed class ResearchClientComponent : Component
|
|
||||||
{
|
|
||||||
public bool ConnectedToServer => Server != null;
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
|
||||||
public ResearchServerComponent? Server { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
namespace Content.Server.Research.Components
|
namespace Content.Server.Research.Components;
|
||||||
|
|
||||||
|
[RegisterComponent]
|
||||||
|
public sealed class ResearchConsoleComponent : Component
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
|
||||||
public sealed class ResearchConsoleComponent : Component {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
namespace Content.Server.Research.Components
|
namespace Content.Server.Research.Components;
|
||||||
{
|
|
||||||
[RegisterComponent]
|
|
||||||
public sealed class ResearchPointSourceComponent : Component
|
|
||||||
{
|
|
||||||
[DataField("pointspersecond"), ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
public int PointsPerSecond;
|
|
||||||
|
|
||||||
[DataField("active"), ViewVariables(VVAccess.ReadWrite)]
|
[RegisterComponent]
|
||||||
public bool Active;
|
public sealed class ResearchPointSourceComponent : Component
|
||||||
}
|
{
|
||||||
|
[DataField("pointspersecond"), ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public int PointsPerSecond;
|
||||||
|
|
||||||
|
[DataField("active"), ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public bool Active;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Server.Research.Components;
|
|
||||||
using Content.Server.Popups;
|
using Content.Server.Popups;
|
||||||
using Content.Shared.Research.Prototypes;
|
using Content.Shared.Research.Prototypes;
|
||||||
using Content.Server.Research.Systems;
|
using Content.Server.Research.Systems;
|
||||||
using Robust.Shared.Player;
|
using Content.Shared.Research.Components;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
namespace Content.Server.Research.Disk
|
namespace Content.Server.Research.Disk
|
||||||
@@ -29,7 +28,7 @@ namespace Content.Server.Research.Disk
|
|||||||
if (!TryComp<ResearchServerComponent>(args.Target, out var server))
|
if (!TryComp<ResearchServerComponent>(args.Target, out var server))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_research.ChangePointsOnServer(server.Owner, component.Points, server);
|
_research.AddPointsToServer(server.Owner, component.Points, server);
|
||||||
_popupSystem.PopupEntity(Loc.GetString("research-disk-inserted", ("points", component.Points)), args.Target.Value, args.User);
|
_popupSystem.PopupEntity(Loc.GetString("research-disk-inserted", ("points", component.Points)), args.Target.Value, args.User);
|
||||||
EntityManager.QueueDeleteEntity(uid);
|
EntityManager.QueueDeleteEntity(uid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Server.Research.Components;
|
using Content.Server.Power.EntitySystems;
|
||||||
using Content.Shared.Research.Components;
|
using Content.Shared.Research.Components;
|
||||||
|
using Robust.Server.Player;
|
||||||
|
|
||||||
namespace Content.Server.Research.Systems;
|
namespace Content.Server.Research.Systems;
|
||||||
|
|
||||||
@@ -11,80 +13,116 @@ public sealed partial class ResearchSystem
|
|||||||
SubscribeLocalEvent<ResearchClientComponent, ComponentStartup>(OnClientStartup);
|
SubscribeLocalEvent<ResearchClientComponent, ComponentStartup>(OnClientStartup);
|
||||||
SubscribeLocalEvent<ResearchClientComponent, ComponentShutdown>(OnClientShutdown);
|
SubscribeLocalEvent<ResearchClientComponent, ComponentShutdown>(OnClientShutdown);
|
||||||
SubscribeLocalEvent<ResearchClientComponent, BoundUIOpenedEvent>(OnClientUIOpen);
|
SubscribeLocalEvent<ResearchClientComponent, BoundUIOpenedEvent>(OnClientUIOpen);
|
||||||
|
SubscribeLocalEvent<ResearchClientComponent, ConsoleServerSyncMessage>(OnConsoleSync);
|
||||||
|
SubscribeLocalEvent<ResearchClientComponent, ConsoleServerSelectionMessage>(OnConsoleSelect);
|
||||||
|
|
||||||
SubscribeLocalEvent<ResearchClientComponent, ResearchClientSyncMessage>(OnClientSyncMessage);
|
SubscribeLocalEvent<ResearchClientComponent, ResearchClientSyncMessage>(OnClientSyncMessage);
|
||||||
SubscribeLocalEvent<ResearchClientComponent, ResearchClientServerSelectedMessage>(OnClientSelected);
|
SubscribeLocalEvent<ResearchClientComponent, ResearchClientServerSelectedMessage>(OnClientSelected);
|
||||||
SubscribeLocalEvent<ResearchClientComponent, ResearchClientServerDeselectedMessage>(OnClientDeselected);
|
SubscribeLocalEvent<ResearchClientComponent, ResearchClientServerDeselectedMessage>(OnClientDeselected);
|
||||||
|
SubscribeLocalEvent<ResearchClientComponent, ResearchRegistrationChangedEvent>(OnClientRegistrationChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region UI
|
#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)
|
private void OnClientSelected(EntityUid uid, ResearchClientComponent component, ResearchClientServerSelectedMessage args)
|
||||||
{
|
{
|
||||||
UnregisterClientServer(component);
|
var server = GetServerById(args.ServerId);
|
||||||
RegisterClientServer(component, GetServerById(args.ServerId));
|
if (server == null)
|
||||||
UpdateClientInterface(component);
|
return;
|
||||||
|
|
||||||
if (TryComp<ResearchConsoleComponent>(uid, out var console))
|
UnregisterClient(uid, clientComponent: component);
|
||||||
{
|
RegisterClient(uid, server.Owner, component, server);
|
||||||
UpdateConsoleInterface(console, component);
|
}
|
||||||
}
|
|
||||||
|
private void OnClientDeselected(EntityUid uid, ResearchClientComponent component, ResearchClientServerDeselectedMessage args)
|
||||||
|
{
|
||||||
|
UnregisterClient(uid, clientComponent: component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClientSyncMessage(EntityUid uid, ResearchClientComponent component, ResearchClientSyncMessage args)
|
private void OnClientSyncMessage(EntityUid uid, ResearchClientComponent component, ResearchClientSyncMessage args)
|
||||||
{
|
{
|
||||||
UpdateClientInterface(component);
|
UpdateClientInterface(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnConsoleSelect(EntityUid uid, ResearchClientComponent component, ConsoleServerSelectionMessage args)
|
||||||
|
{
|
||||||
|
if (!HasComp<TechnologyDatabaseComponent>(uid) || !this.IsPowered(uid, EntityManager))
|
||||||
|
return;
|
||||||
|
|
||||||
|
_uiSystem.TryToggleUi(uid, ResearchClientUiKey.Key, (IPlayerSession) args.Session);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnConsoleSync(EntityUid uid, ResearchClientComponent component, ConsoleServerSyncMessage args)
|
||||||
|
{
|
||||||
|
if (!this.IsPowered(uid, EntityManager))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SyncClientWithServer(uid);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private void OnClientRegistrationChanged(EntityUid uid, ResearchClientComponent component, ref ResearchRegistrationChangedEvent args)
|
||||||
|
{
|
||||||
|
UpdateClientInterface(uid, component);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnClientStartup(EntityUid uid, ResearchClientComponent component, ComponentStartup args)
|
private void OnClientStartup(EntityUid uid, ResearchClientComponent component, ComponentStartup args)
|
||||||
{
|
{
|
||||||
var allServers = EntityQuery<ResearchServerComponent>(true).ToArray();
|
var allServers = EntityQuery<ResearchServerComponent>(true).ToArray();
|
||||||
if (allServers.Length > 0)
|
if (allServers.Length > 0)
|
||||||
RegisterClientServer(component, allServers[0]);
|
RegisterClient(uid, allServers[0].Owner, component, allServers[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClientShutdown(EntityUid uid, ResearchClientComponent component, ComponentShutdown args)
|
private void OnClientShutdown(EntityUid uid, ResearchClientComponent component, ComponentShutdown args)
|
||||||
{
|
{
|
||||||
UnregisterClientServer(component);
|
UnregisterClient(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClientUIOpen(EntityUid uid, ResearchClientComponent component, BoundUIOpenedEvent args)
|
private void OnClientUIOpen(EntityUid uid, ResearchClientComponent component, BoundUIOpenedEvent args)
|
||||||
{
|
{
|
||||||
UpdateClientInterface(component);
|
UpdateClientInterface(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateClientInterface(ResearchClientComponent component)
|
private void UpdateClientInterface(EntityUid uid, ResearchClientComponent? component = null)
|
||||||
{
|
{
|
||||||
|
if (!Resolve(uid, ref component, false))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!TryGetClientServer(uid, out _, out var serverComponent, component))
|
||||||
|
return;
|
||||||
|
|
||||||
var names = GetServerNames();
|
var names = GetServerNames();
|
||||||
var state = new ResearchClientBoundInterfaceState(names.Length, names,
|
var state = new ResearchClientBoundInterfaceState(names.Length, names,
|
||||||
GetServerIds(), component.ConnectedToServer ? component.Server!.Id : -1);
|
GetServerIds(), component.ConnectedToServer ? serverComponent.Id : -1);
|
||||||
|
|
||||||
_uiSystem.TrySetUiState(component.Owner, ResearchClientUiKey.Key, state);
|
_uiSystem.TrySetUiState(component.Owner, ResearchClientUiKey.Key, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool RegisterClientServer(ResearchClientComponent component, ResearchServerComponent? server = null)
|
/// <summary>
|
||||||
|
/// Tries to get the server belonging to a client
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uid">The client</param>
|
||||||
|
/// <param name="server">It's server. Null if false.</param>
|
||||||
|
/// <param name="serverComponent">The server's ResearchServerComponent. Null if false</param>
|
||||||
|
/// <param name="component">The client's Researchclient component</param>
|
||||||
|
/// <returns>If the server was successfully retrieved.</returns>
|
||||||
|
public bool TryGetClientServer(EntityUid uid, [NotNullWhen(returnValue: true)] out EntityUid? server,
|
||||||
|
[NotNullWhen(returnValue: true)] out ResearchServerComponent? serverComponent, ResearchClientComponent? component = null)
|
||||||
{
|
{
|
||||||
return server != null && RegisterServerClient(server, component.Owner, component);
|
server = null;
|
||||||
}
|
serverComponent = null;
|
||||||
|
|
||||||
|
if (!Resolve(uid, ref component, false))
|
||||||
|
return false;
|
||||||
|
|
||||||
private void UnregisterClientServer(ResearchClientComponent component)
|
|
||||||
{
|
|
||||||
if (component.Server == null)
|
if (component.Server == null)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
UnregisterServerClient(component.Server, component.Owner, component);
|
if (!TryComp<ResearchServerComponent>(component.Server, out var sc))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
server = component.Server;
|
||||||
|
serverComponent = sc;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
using Content.Server.Power.EntitySystems;
|
using Content.Server.Power.EntitySystems;
|
||||||
using Content.Server.Research.Components;
|
using Content.Server.Research.Components;
|
||||||
using Content.Shared.Research.Components;
|
using Content.Shared.Research.Components;
|
||||||
using Content.Shared.Research.Prototypes;
|
|
||||||
using Robust.Server.Player;
|
|
||||||
|
|
||||||
namespace Content.Server.Research.Systems;
|
namespace Content.Server.Research.Systems;
|
||||||
|
|
||||||
@@ -11,66 +9,39 @@ public sealed partial class ResearchSystem
|
|||||||
private void InitializeConsole()
|
private void InitializeConsole()
|
||||||
{
|
{
|
||||||
SubscribeLocalEvent<ResearchConsoleComponent, ConsoleUnlockTechnologyMessage>(OnConsoleUnlock);
|
SubscribeLocalEvent<ResearchConsoleComponent, ConsoleUnlockTechnologyMessage>(OnConsoleUnlock);
|
||||||
SubscribeLocalEvent<ResearchConsoleComponent, ConsoleServerSyncMessage>(OnConsoleSync);
|
|
||||||
SubscribeLocalEvent<ResearchConsoleComponent, ConsoleServerSelectionMessage>(OnConsoleSelect);
|
|
||||||
SubscribeLocalEvent<ResearchConsoleComponent, ResearchServerPointsChangedEvent>(OnPointsChanged);
|
SubscribeLocalEvent<ResearchConsoleComponent, ResearchServerPointsChangedEvent>(OnPointsChanged);
|
||||||
}
|
SubscribeLocalEvent<ResearchConsoleComponent, ResearchRegistrationChangedEvent>(OnConsoleRegistrationChanged);
|
||||||
|
SubscribeLocalEvent<ResearchConsoleComponent, TechnologyDatabaseModifiedEvent>(OnConsoleDatabaseModified);
|
||||||
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)
|
private void OnConsoleUnlock(EntityUid uid, ResearchConsoleComponent component, ConsoleUnlockTechnologyMessage args)
|
||||||
{
|
{
|
||||||
if (!TryComp<TechnologyDatabaseComponent>(uid, out var database) ||
|
if (!this.IsPowered(uid, EntityManager))
|
||||||
!TryComp<ResearchClientComponent>(uid, out var client) ||
|
|
||||||
!this.IsPowered(uid, EntityManager))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!_prototypeManager.TryIndex(args.Id, out TechnologyPrototype? tech) ||
|
if (!UnlockTechnology(uid, args.Id))
|
||||||
client.Server == null ||
|
|
||||||
!CanUnlockTechnology(client.Server, tech))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!UnlockTechnology(client.Server, tech))
|
SyncClientWithServer(uid);
|
||||||
return;
|
UpdateConsoleInterface(uid, component);
|
||||||
|
|
||||||
SyncWithServer(database);
|
|
||||||
Dirty(database);
|
|
||||||
UpdateConsoleInterface(component);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateConsoleInterface(ResearchConsoleComponent component, ResearchClientComponent? clientComponent = null)
|
private void UpdateConsoleInterface(EntityUid uid, ResearchConsoleComponent? component = null, ResearchClientComponent? clientComponent = null)
|
||||||
{
|
{
|
||||||
|
if (!Resolve(uid, ref component, ref clientComponent, false))
|
||||||
|
return;
|
||||||
|
|
||||||
ResearchConsoleBoundInterfaceState state;
|
ResearchConsoleBoundInterfaceState state;
|
||||||
|
|
||||||
if (!Resolve(component.Owner, ref clientComponent, false) ||
|
if (TryGetClientServer(uid, out var server, out var serverComponent, clientComponent))
|
||||||
clientComponent.Server == null)
|
|
||||||
{
|
{
|
||||||
state = new ResearchConsoleBoundInterfaceState(default, default);
|
var points = clientComponent.ConnectedToServer ? serverComponent.Points : 0;
|
||||||
|
var pointsPerSecond = clientComponent.ConnectedToServer ? PointsPerSecond(server.Value, serverComponent) : 0;
|
||||||
|
state = new ResearchConsoleBoundInterfaceState(points, pointsPerSecond);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var points = clientComponent.ConnectedToServer ? clientComponent.Server.Points : 0;
|
state = new ResearchConsoleBoundInterfaceState(default, default);
|
||||||
var pointsPerSecond = clientComponent.ConnectedToServer ? PointsPerSecond(clientComponent.Server) : 0;
|
|
||||||
state = new ResearchConsoleBoundInterfaceState(points, pointsPerSecond);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_uiSystem.TrySetUiState(component.Owner, ResearchConsoleUiKey.Key, state);
|
_uiSystem.TrySetUiState(component.Owner, ResearchConsoleUiKey.Key, state);
|
||||||
@@ -80,7 +51,17 @@ public sealed partial class ResearchSystem
|
|||||||
{
|
{
|
||||||
if (!_uiSystem.IsUiOpen(uid, ResearchConsoleUiKey.Key))
|
if (!_uiSystem.IsUiOpen(uid, ResearchConsoleUiKey.Key))
|
||||||
return;
|
return;
|
||||||
UpdateConsoleInterface(component);
|
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)
|
||||||
|
{
|
||||||
|
UpdateConsoleInterface(uid, component);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Content.Server.Power.EntitySystems;
|
using Content.Server.Power.EntitySystems;
|
||||||
using Content.Server.Research.Components;
|
using Content.Server.Research.Components;
|
||||||
|
using Content.Shared.Research.Components;
|
||||||
|
|
||||||
namespace Content.Server.Research.Systems;
|
namespace Content.Server.Research.Systems;
|
||||||
|
|
||||||
|
|||||||
@@ -1,97 +1,164 @@
|
|||||||
|
using System.Linq;
|
||||||
using Content.Server.Power.EntitySystems;
|
using Content.Server.Power.EntitySystems;
|
||||||
using Content.Server.Research.Components;
|
|
||||||
using Content.Shared.Research.Components;
|
using Content.Shared.Research.Components;
|
||||||
using Content.Shared.Research.Prototypes;
|
|
||||||
|
|
||||||
namespace Content.Server.Research.Systems;
|
namespace Content.Server.Research.Systems;
|
||||||
|
|
||||||
public sealed partial class ResearchSystem
|
public sealed partial class ResearchSystem
|
||||||
{
|
{
|
||||||
private bool CanRun(ResearchServerComponent component)
|
private void InitializeServer()
|
||||||
{
|
{
|
||||||
return this.IsPowered(component.Owner, EntityManager);
|
SubscribeLocalEvent<ResearchServerComponent, ComponentStartup>(OnServerStartup);
|
||||||
|
SubscribeLocalEvent<ResearchServerComponent, ComponentShutdown>(OnServerShutdown);
|
||||||
|
SubscribeLocalEvent<ResearchServerComponent, TechnologyDatabaseModifiedEvent>(OnServerDatabaseModified);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateServer(ResearchServerComponent component, int time)
|
private void OnServerStartup(EntityUid uid, ResearchServerComponent component, ComponentStartup args)
|
||||||
{
|
{
|
||||||
if (!CanRun(component))
|
var unusedId = EntityQuery<ResearchServerComponent>(true)
|
||||||
|
.Max(s => s.Id) + 1;
|
||||||
|
component.Id = unusedId;
|
||||||
|
Dirty(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnServerShutdown(EntityUid uid, ResearchServerComponent component, ComponentShutdown args)
|
||||||
|
{
|
||||||
|
foreach (var client in new List<EntityUid>(component.Clients))
|
||||||
|
{
|
||||||
|
UnregisterClient(client, uid, serverComponent: component, dirtyServer: false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnServerDatabaseModified(EntityUid uid, ResearchServerComponent component, ref TechnologyDatabaseModifiedEvent args)
|
||||||
|
{
|
||||||
|
foreach (var client in component.Clients)
|
||||||
|
{
|
||||||
|
RaiseLocalEvent(client, ref args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CanRun(EntityUid uid)
|
||||||
|
{
|
||||||
|
return this.IsPowered(uid, EntityManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateServer(EntityUid uid, int time, ResearchServerComponent? component = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref component))
|
||||||
return;
|
return;
|
||||||
ChangePointsOnServer(component.Owner, PointsPerSecond(component) * time, component);
|
|
||||||
|
if (!CanRun(uid))
|
||||||
|
return;
|
||||||
|
AddPointsToServer(uid, PointsPerSecond(uid, component) * time, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool RegisterServerClient(ResearchServerComponent component, EntityUid client, ResearchClientComponent? clientComponent = null)
|
/// <summary>
|
||||||
|
/// Registers a client to the specified server.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">The client being registered</param>
|
||||||
|
/// <param name="server">The server the client is being registered to</param>
|
||||||
|
/// <param name="clientComponent"></param>
|
||||||
|
/// <param name="serverComponent"></param>
|
||||||
|
/// <param name="dirtyServer">Whether or not to dirty the server component after registration</param>
|
||||||
|
/// <returns>Whether or not the client was successfully registered to the server</returns>
|
||||||
|
public bool RegisterClient(EntityUid client, EntityUid server, ResearchClientComponent? clientComponent = null,
|
||||||
|
ResearchServerComponent? serverComponent = null, bool dirtyServer = true)
|
||||||
{
|
{
|
||||||
if (!Resolve(client, ref clientComponent))
|
if (!Resolve(client, ref clientComponent) || !Resolve(server, ref serverComponent))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (component.Clients.Contains(client))
|
if (serverComponent.Clients.Contains(client))
|
||||||
return false;
|
return false;
|
||||||
component.Clients.Add(client);
|
|
||||||
clientComponent.Server = component;
|
serverComponent.Clients.Add(client);
|
||||||
|
clientComponent.Server = server;
|
||||||
|
|
||||||
|
if (dirtyServer)
|
||||||
|
Dirty(serverComponent);
|
||||||
|
|
||||||
|
var ev = new ResearchRegistrationChangedEvent(server);
|
||||||
|
RaiseLocalEvent(client, ref ev);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnregisterServerClient(ResearchServerComponent component, EntityUid client, ResearchClientComponent? clientComponent = null)
|
/// <summary>
|
||||||
|
/// Unregisterse a client from its server
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="clientComponent"></param>
|
||||||
|
/// <param name="dirtyServer"></param>
|
||||||
|
public void UnregisterClient(EntityUid client, ResearchClientComponent? clientComponent = null, bool dirtyServer = true)
|
||||||
{
|
{
|
||||||
if (!Resolve(client, ref clientComponent))
|
if (!Resolve(client, ref clientComponent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
component.Clients.Remove(client);
|
if (clientComponent.Server is not { } server)
|
||||||
|
return;
|
||||||
|
|
||||||
|
UnregisterClient(client, server, clientComponent, dirtyServer: dirtyServer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unregisters a client from its server
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="server"></param>
|
||||||
|
/// <param name="clientComponent"></param>
|
||||||
|
/// <param name="serverComponent"></param>
|
||||||
|
/// <param name="dirtyServer"></param>
|
||||||
|
public void UnregisterClient(EntityUid client, EntityUid server, ResearchClientComponent? clientComponent = null,
|
||||||
|
ResearchServerComponent? serverComponent = null, bool dirtyServer = true)
|
||||||
|
{
|
||||||
|
if (!Resolve(client, ref clientComponent) || !Resolve(server, ref serverComponent))
|
||||||
|
return;
|
||||||
|
|
||||||
|
serverComponent.Clients.Remove(client);
|
||||||
clientComponent.Server = null;
|
clientComponent.Server = null;
|
||||||
|
|
||||||
|
if (dirtyServer)
|
||||||
|
{
|
||||||
|
Dirty(serverComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
var ev = new ResearchRegistrationChangedEvent(null);
|
||||||
|
RaiseLocalEvent(client, ref ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsTechnologyUnlocked(ResearchServerComponent component, TechnologyPrototype prototype,
|
/// <summary>
|
||||||
TechnologyDatabaseComponent? databaseComponent = null)
|
/// Gets the amount of points generated by all the server's sources in a second.
|
||||||
{
|
/// </summary>
|
||||||
if (!Resolve(component.Owner, ref databaseComponent, false))
|
/// <param name="uid"></param>
|
||||||
return false;
|
/// <param name="component"></param>
|
||||||
return IsTechnologyUnlocked(databaseComponent.Owner, prototype.ID, databaseComponent);
|
/// <returns></returns>
|
||||||
}
|
public int PointsPerSecond(EntityUid uid, ResearchServerComponent? component = null)
|
||||||
|
|
||||||
public bool CanUnlockTechnology(ResearchServerComponent component, TechnologyPrototype technology, TechnologyDatabaseComponent? databaseComponent = null)
|
|
||||||
{
|
|
||||||
if (!Resolve(component.Owner, ref databaseComponent, false))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!CanUnlockTechnology(databaseComponent.Owner, technology, databaseComponent) ||
|
|
||||||
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)
|
|
||||||
ChangePointsOnServer(component.Owner, -prototype.RequiredPoints, component);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int PointsPerSecond(ResearchServerComponent component)
|
|
||||||
{
|
{
|
||||||
var points = 0;
|
var points = 0;
|
||||||
|
|
||||||
if (!CanRun(component))
|
if (!Resolve(uid, ref component))
|
||||||
return points;
|
return points;
|
||||||
|
|
||||||
|
if (!CanRun(uid))
|
||||||
|
return points;
|
||||||
|
|
||||||
var ev = new ResearchServerGetPointsPerSecondEvent(component.Owner, points);
|
var ev = new ResearchServerGetPointsPerSecondEvent(component.Owner, points);
|
||||||
foreach (var client in component.Clients)
|
foreach (var client in component.Clients)
|
||||||
{
|
{
|
||||||
RaiseLocalEvent(client, ref ev);
|
RaiseLocalEvent(client, ref ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ev.Points;
|
return ev.Points;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChangePointsOnServer(EntityUid uid, int points, ResearchServerComponent? component = null)
|
/// <summary>
|
||||||
|
/// Adds a specified number of points to a server.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uid">The server</param>
|
||||||
|
/// <param name="points">The amount of points being added</param>
|
||||||
|
/// <param name="component"></param>
|
||||||
|
public void AddPointsToServer(EntityUid uid, int points, ResearchServerComponent? component = null)
|
||||||
{
|
{
|
||||||
|
if (points == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!Resolve(uid, ref component))
|
if (!Resolve(uid, ref component))
|
||||||
return;
|
return;
|
||||||
component.Points += points;
|
component.Points += points;
|
||||||
@@ -100,5 +167,6 @@ public sealed partial class ResearchSystem
|
|||||||
{
|
{
|
||||||
RaiseLocalEvent(client, ref ev);
|
RaiseLocalEvent(client, ref ev);
|
||||||
}
|
}
|
||||||
|
Dirty(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +1,25 @@
|
|||||||
using System.Linq;
|
|
||||||
using Content.Server.Research.Components;
|
|
||||||
using Content.Shared.Research.Components;
|
using Content.Shared.Research.Components;
|
||||||
using Content.Shared.Research.Prototypes;
|
using Content.Shared.Research.Prototypes;
|
||||||
using Robust.Shared.GameStates;
|
|
||||||
|
|
||||||
namespace Content.Server.Research.Systems;
|
namespace Content.Server.Research.Systems;
|
||||||
|
|
||||||
public sealed partial class ResearchSystem
|
public sealed partial class ResearchSystem
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Synchronizes this database against other,
|
/// Syncs the primary entity's database to that of the secondary entity's database.
|
||||||
/// adding all technologies from the other that
|
|
||||||
/// this one doesn't have.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="component"></param>
|
public void Sync(EntityUid primaryUid, EntityUid otherUid, TechnologyDatabaseComponent? primaryDb = null, TechnologyDatabaseComponent? otherDb = null)
|
||||||
/// <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)
|
|
||||||
{
|
{
|
||||||
otherDatabase.TechnologyIds = otherDatabase.TechnologyIds.Union(component.TechnologyIds).ToList();
|
if (!Resolve(primaryUid, ref primaryDb) || !Resolve(otherUid, ref otherDb))
|
||||||
otherDatabase.RecipeIds = otherDatabase.RecipeIds.Union(component.RecipeIds).ToList();
|
return;
|
||||||
|
|
||||||
if (twoway)
|
primaryDb.TechnologyIds = otherDb.TechnologyIds;
|
||||||
Sync(otherDatabase, component, false);
|
primaryDb.RecipeIds = otherDb.RecipeIds;
|
||||||
|
|
||||||
Dirty(component);
|
Dirty(primaryDb);
|
||||||
|
|
||||||
|
var ev = new TechnologyDatabaseModifiedEvent();
|
||||||
|
RaiseLocalEvent(primaryDb.Owner, ref ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -33,46 +28,74 @@ public sealed partial class ResearchSystem
|
|||||||
/// syncs against the research server, and the server against the local database.
|
/// syncs against the research server, and the server against the local database.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Whether it could sync or not</returns>
|
/// <returns>Whether it could sync or not</returns>
|
||||||
public bool SyncWithServer(TechnologyDatabaseComponent component, ResearchClientComponent? clientComponent = null)
|
public bool SyncClientWithServer(EntityUid uid, TechnologyDatabaseComponent? databaseComponent = null, ResearchClientComponent? clientComponent = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(component.Owner, ref clientComponent, false))
|
if (!Resolve(uid, ref databaseComponent, ref clientComponent, false))
|
||||||
return false;
|
|
||||||
if (!TryComp<TechnologyDatabaseComponent>(clientComponent.Server?.Owner, out var clientDatabase))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Sync(component, clientDatabase);
|
if (!TryComp<TechnologyDatabaseComponent>(clientComponent.Server, out var serverDatabase))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Sync(uid, clientComponent.Server.Value, databaseComponent, serverDatabase);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If possible, unlocks a technology on this database.
|
/// Tries to add a technology to a database, checking if it is able to
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="component"></param>
|
/// <returns>If the technology was successfully added</returns>
|
||||||
/// <param name="technology"></param>
|
public bool UnlockTechnology(EntityUid client, string prototypeid, ResearchClientComponent? component = null,
|
||||||
/// <returns></returns>
|
TechnologyDatabaseComponent? databaseComponent = null)
|
||||||
public bool UnlockTechnology(TechnologyDatabaseComponent component, TechnologyPrototype technology)
|
|
||||||
{
|
{
|
||||||
if (!CanUnlockTechnology(component.Owner, technology, component)) return false;
|
if (!_prototypeManager.TryIndex<TechnologyPrototype>(prototypeid, out var prototype))
|
||||||
|
{
|
||||||
|
Logger.Error("invalid technology prototype");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return UnlockTechnology(client, prototype, component, databaseComponent);
|
||||||
|
}
|
||||||
|
|
||||||
AddTechnology(component, technology.ID);
|
/// <summary>
|
||||||
|
/// Tries to add a technology to a database, checking if it is able to
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>If the technology was successfully added</returns>
|
||||||
|
public bool UnlockTechnology(EntityUid client, TechnologyPrototype prototype, ResearchClientComponent? component = null,
|
||||||
|
TechnologyDatabaseComponent? databaseComponent = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(client, ref component, ref databaseComponent, false))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!CanUnlockTechnology(client, prototype, databaseComponent))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (component.Server is not { } server)
|
||||||
|
return false;
|
||||||
|
AddTechnology(server, prototype.ID);
|
||||||
|
AddPointsToServer(server, -prototype.RequiredPoints);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a technology to the database without checking if it could be unlocked.
|
/// Adds a technology to the database without checking if it could be unlocked.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="component"></param>
|
public void AddTechnology(EntityUid uid, string technology, TechnologyDatabaseComponent? component = null)
|
||||||
/// <param name="technology"></param>
|
|
||||||
public void AddTechnology(TechnologyDatabaseComponent component, string technology)
|
|
||||||
{
|
{
|
||||||
|
if (!Resolve(uid, ref component))
|
||||||
|
return;
|
||||||
|
|
||||||
if (!_prototypeManager.TryIndex<TechnologyPrototype>(technology, out var prototype))
|
if (!_prototypeManager.TryIndex<TechnologyPrototype>(technology, out var prototype))
|
||||||
return;
|
return;
|
||||||
AddTechnology(component, prototype);
|
AddTechnology(uid, prototype, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddTechnology(TechnologyDatabaseComponent component, TechnologyPrototype technology)
|
/// <summary>
|
||||||
|
/// Adds a technology to the database without checking if it could be unlocked.
|
||||||
|
/// </summary>
|
||||||
|
public void AddTechnology(EntityUid uid, TechnologyPrototype technology, TechnologyDatabaseComponent? component = null)
|
||||||
{
|
{
|
||||||
|
if (!Resolve(uid, ref component))
|
||||||
|
return;
|
||||||
|
|
||||||
component.TechnologyIds.Add(technology.ID);
|
component.TechnologyIds.Add(technology.ID);
|
||||||
foreach (var unlock in technology.UnlockedRecipes)
|
foreach (var unlock in technology.UnlockedRecipes)
|
||||||
{
|
{
|
||||||
@@ -82,23 +105,63 @@ public sealed partial class ResearchSystem
|
|||||||
}
|
}
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
|
|
||||||
if (!TryComp<ResearchServerComponent>(component.Owner, out var server))
|
var ev = new TechnologyDatabaseModifiedEvent();
|
||||||
return;
|
RaiseLocalEvent(uid, ref ev);
|
||||||
foreach (var client in server.Clients)
|
|
||||||
{
|
|
||||||
if (!TryComp<ResearchConsoleComponent>(client, out var console))
|
|
||||||
continue;
|
|
||||||
UpdateConsoleInterface(console);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddLatheRecipe(TechnologyDatabaseComponent component, string recipe, bool dirty = true)
|
/// <summary>
|
||||||
|
/// Adds a lathe recipe to the specified technology database
|
||||||
|
/// without checking if it can be unlocked.
|
||||||
|
/// </summary>
|
||||||
|
public void AddLatheRecipe(EntityUid uid, string recipe, TechnologyDatabaseComponent? component = null, bool dirty = true)
|
||||||
{
|
{
|
||||||
|
if (!Resolve(uid, ref component))
|
||||||
|
return;
|
||||||
|
|
||||||
if (component.RecipeIds.Contains(recipe))
|
if (component.RecipeIds.Contains(recipe))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
component.RecipeIds.Add(recipe);
|
component.RecipeIds.Add(recipe);
|
||||||
if (dirty)
|
if (dirty)
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
|
|
||||||
|
var ev = new TechnologyDatabaseModifiedEvent();
|
||||||
|
RaiseLocalEvent(uid, ref ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns whether a technology can be unlocked on this database,
|
||||||
|
/// taking parent technologies into account.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Whether it could be unlocked or not</returns>
|
||||||
|
public bool CanUnlockTechnology(EntityUid uid, string technology, TechnologyDatabaseComponent? database = null, ResearchClientComponent? client = null)
|
||||||
|
{
|
||||||
|
if (!_prototypeManager.TryIndex<TechnologyPrototype>(technology, out var prototype))
|
||||||
|
return false;
|
||||||
|
return CanUnlockTechnology(uid, prototype, database, client);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns whether a technology can be unlocked on this database,
|
||||||
|
/// taking parent technologies into account.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Whether it could be unlocked or not</returns>
|
||||||
|
public bool CanUnlockTechnology(EntityUid uid, TechnologyPrototype technology, TechnologyDatabaseComponent? database = null, ResearchClientComponent? client = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref database, ref client))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!TryGetClientServer(uid, out _, out var serverComponent, client))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (serverComponent.Points < technology.RequiredPoints)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (IsTechnologyUnlocked(uid, technology, database))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!ArePrerequesitesUnlocked(uid, technology, database))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Server.Research.Components;
|
using Content.Shared.Research.Components;
|
||||||
using Content.Shared.Research.Systems;
|
using Content.Shared.Research.Systems;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
@@ -18,20 +18,17 @@ namespace Content.Server.Research.Systems
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<ResearchServerComponent, ComponentStartup>(OnStartup);
|
|
||||||
|
|
||||||
InitializeClient();
|
InitializeClient();
|
||||||
InitializeConsole();
|
InitializeConsole();
|
||||||
InitializeSource();
|
InitializeSource();
|
||||||
|
InitializeServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnStartup(EntityUid uid, ResearchServerComponent component, ComponentStartup args)
|
/// <summary>
|
||||||
{
|
/// Gets a server based on it's unique numeric id.
|
||||||
var unusedId = EntityQuery<ResearchServerComponent>(true)
|
/// </summary>
|
||||||
.Max(s => s.Id) + 1;
|
/// <param name="id"></param>
|
||||||
component.Id = unusedId;
|
/// <returns></returns>
|
||||||
}
|
|
||||||
|
|
||||||
public ResearchServerComponent? GetServerById(int id)
|
public ResearchServerComponent? GetServerById(int id)
|
||||||
{
|
{
|
||||||
foreach (var server in EntityQuery<ResearchServerComponent>())
|
foreach (var server in EntityQuery<ResearchServerComponent>())
|
||||||
@@ -43,6 +40,10 @@ namespace Content.Server.Research.Systems
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the names of all the servers.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
public string[] GetServerNames()
|
public string[] GetServerNames()
|
||||||
{
|
{
|
||||||
var allServers = EntityQuery<ResearchServerComponent>(true).ToArray();
|
var allServers = EntityQuery<ResearchServerComponent>(true).ToArray();
|
||||||
@@ -56,6 +57,10 @@ namespace Content.Server.Research.Systems
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the ids of all the servers
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
public int[] GetServerIds()
|
public int[] GetServerIds()
|
||||||
{
|
{
|
||||||
var allServers = EntityQuery<ResearchServerComponent>(true).ToArray();
|
var allServers = EntityQuery<ResearchServerComponent>(true).ToArray();
|
||||||
@@ -77,7 +82,7 @@ namespace Content.Server.Research.Systems
|
|||||||
continue;
|
continue;
|
||||||
server.NextUpdateTime = _timing.CurTime + server.ResearchConsoleUpdateTime;
|
server.NextUpdateTime = _timing.CurTime + server.ResearchConsoleUpdateTime;
|
||||||
|
|
||||||
UpdateServer(server, (int) server.ResearchConsoleUpdateTime.TotalSeconds);
|
UpdateServer(server.Owner, (int) server.ResearchConsoleUpdateTime.TotalSeconds, server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using Content.Server.Research.Components;
|
using Content.Server.Research.Systems;
|
||||||
using Content.Server.Research.Systems;
|
|
||||||
using Content.Server.Research.TechnologyDisk.Components;
|
using Content.Server.Research.TechnologyDisk.Components;
|
||||||
using Content.Server.UserInterface;
|
using Content.Server.UserInterface;
|
||||||
using Content.Shared.Research;
|
using Content.Shared.Research;
|
||||||
|
using Content.Shared.Research.Components;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
@@ -20,6 +20,7 @@ public sealed class DiskConsoleSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
SubscribeLocalEvent<DiskConsoleComponent, DiskConsolePrintDiskMessage>(OnPrintDisk);
|
SubscribeLocalEvent<DiskConsoleComponent, DiskConsolePrintDiskMessage>(OnPrintDisk);
|
||||||
SubscribeLocalEvent<DiskConsoleComponent, ResearchServerPointsChangedEvent>(OnPointsChanged);
|
SubscribeLocalEvent<DiskConsoleComponent, ResearchServerPointsChangedEvent>(OnPointsChanged);
|
||||||
|
SubscribeLocalEvent<DiskConsoleComponent, ResearchRegistrationChangedEvent>(OnRegistrationChanged);
|
||||||
SubscribeLocalEvent<DiskConsoleComponent, BeforeActivatableUIOpenEvent>(OnBeforeUiOpen);
|
SubscribeLocalEvent<DiskConsoleComponent, BeforeActivatableUIOpenEvent>(OnBeforeUiOpen);
|
||||||
|
|
||||||
SubscribeLocalEvent<DiskConsolePrintingComponent, ComponentShutdown>(OnShutdown);
|
SubscribeLocalEvent<DiskConsolePrintingComponent, ComponentShutdown>(OnShutdown);
|
||||||
@@ -41,17 +42,21 @@ public sealed class DiskConsoleSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnPrintDisk(EntityUid uid, DiskConsoleComponent component, DiskConsolePrintDiskMessage args)
|
private void OnPrintDisk(EntityUid uid, DiskConsoleComponent component, DiskConsolePrintDiskMessage args)
|
||||||
{
|
{
|
||||||
if (!TryComp<ResearchClientComponent>(uid, out var client) || client.Server == null)
|
if (HasComp<DiskConsolePrintingComponent>(uid))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (client.Server.Points < component.PricePerDisk)
|
if (!_research.TryGetClientServer(uid, out var server, out var serverComp))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_research.ChangePointsOnServer(client.Server.Owner, -component.PricePerDisk, client.Server);
|
if (serverComp.Points < component.PricePerDisk)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_research.AddPointsToServer(server.Value, -component.PricePerDisk, serverComp);
|
||||||
_audio.PlayPvs(component.PrintSound, uid);
|
_audio.PlayPvs(component.PrintSound, uid);
|
||||||
|
|
||||||
var printing = EnsureComp<DiskConsolePrintingComponent>(uid);
|
var printing = EnsureComp<DiskConsolePrintingComponent>(uid);
|
||||||
printing.FinishTime = _timing.CurTime + component.PrintDuration;
|
printing.FinishTime = _timing.CurTime + component.PrintDuration;
|
||||||
|
UpdateUserInterface(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPointsChanged(EntityUid uid, DiskConsoleComponent component, ref ResearchServerPointsChangedEvent args)
|
private void OnPointsChanged(EntityUid uid, DiskConsoleComponent component, ref ResearchServerPointsChangedEvent args)
|
||||||
@@ -59,6 +64,11 @@ public sealed class DiskConsoleSystem : EntitySystem
|
|||||||
UpdateUserInterface(uid, component);
|
UpdateUserInterface(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnRegistrationChanged(EntityUid uid, DiskConsoleComponent component, ref ResearchRegistrationChangedEvent args)
|
||||||
|
{
|
||||||
|
UpdateUserInterface(uid, component);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnBeforeUiOpen(EntityUid uid, DiskConsoleComponent component, BeforeActivatableUIOpenEvent args)
|
private void OnBeforeUiOpen(EntityUid uid, DiskConsoleComponent component, BeforeActivatableUIOpenEvent args)
|
||||||
{
|
{
|
||||||
UpdateUserInterface(uid, component);
|
UpdateUserInterface(uid, component);
|
||||||
@@ -70,9 +80,9 @@ public sealed class DiskConsoleSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var totalPoints = 0;
|
var totalPoints = 0;
|
||||||
if (TryComp<ResearchClientComponent>(uid, out var client) && client.Server != null)
|
if (_research.TryGetClientServer(uid, out _, out var server))
|
||||||
{
|
{
|
||||||
totalPoints = client.Server.Points;
|
totalPoints = server.Points;
|
||||||
}
|
}
|
||||||
var canPrint = !HasComp<DiskConsolePrintingComponent>(uid) && totalPoints >= component.PricePerDisk;
|
var canPrint = !HasComp<DiskConsolePrintingComponent>(uid) && totalPoints >= component.PricePerDisk;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Server.Popups;
|
using Content.Server.Popups;
|
||||||
using Content.Server.Research.Components;
|
|
||||||
using Content.Server.Research.Systems;
|
using Content.Server.Research.Systems;
|
||||||
using Content.Server.Research.TechnologyDisk.Components;
|
using Content.Server.Research.TechnologyDisk.Components;
|
||||||
using Content.Shared.Examine;
|
using Content.Shared.Examine;
|
||||||
@@ -39,7 +38,7 @@ public sealed class TechnologyDiskSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
foreach (var recipe in component.Recipes)
|
foreach (var recipe in component.Recipes)
|
||||||
{
|
{
|
||||||
_research.AddLatheRecipe(database, recipe, false);
|
_research.AddLatheRecipe(target, recipe, database, false);
|
||||||
}
|
}
|
||||||
Dirty(database);
|
Dirty(database);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ using Content.Server.MachineLinking.Components;
|
|||||||
using Content.Server.MachineLinking.Events;
|
using Content.Server.MachineLinking.Events;
|
||||||
using Content.Server.Paper;
|
using Content.Server.Paper;
|
||||||
using Content.Server.Power.Components;
|
using Content.Server.Power.Components;
|
||||||
using Content.Server.Research.Components;
|
|
||||||
using Content.Server.Research.Systems;
|
using Content.Server.Research.Systems;
|
||||||
using Content.Server.UserInterface;
|
using Content.Server.UserInterface;
|
||||||
using Content.Server.Xenoarchaeology.Equipment.Components;
|
using Content.Server.Xenoarchaeology.Equipment.Components;
|
||||||
@@ -20,7 +19,6 @@ using Robust.Server.GameObjects;
|
|||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Physics.Events;
|
using Robust.Shared.Physics.Events;
|
||||||
using Robust.Shared.Player;
|
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
@@ -333,7 +331,10 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
|
|||||||
/// <param name="args"></param>
|
/// <param name="args"></param>
|
||||||
private void OnDestroyButton(EntityUid uid, AnalysisConsoleComponent component, AnalysisConsoleDestroyButtonPressedMessage args)
|
private void OnDestroyButton(EntityUid uid, AnalysisConsoleComponent component, AnalysisConsoleDestroyButtonPressedMessage args)
|
||||||
{
|
{
|
||||||
if (!TryComp<ResearchClientComponent>(uid, out var client) || client.Server is not { } server || component.AnalyzerEntity == null)
|
if (component.AnalyzerEntity == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!_research.TryGetClientServer(uid, out var server, out var serverComponent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var entToDestroy = GetArtifactForAnalysis(component.AnalyzerEntity);
|
var entToDestroy = GetArtifactForAnalysis(component.AnalyzerEntity);
|
||||||
@@ -346,7 +347,7 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
|
|||||||
ResetAnalyzer(component.AnalyzerEntity.Value);
|
ResetAnalyzer(component.AnalyzerEntity.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
_research.ChangePointsOnServer(server.Owner, _artifact.GetResearchPointValue(entToDestroy.Value), server);
|
_research.AddPointsToServer(server.Value, _artifact.GetResearchPointValue(entToDestroy.Value), serverComponent);
|
||||||
EntityManager.DeleteEntity(entToDestroy.Value);
|
EntityManager.DeleteEntity(entToDestroy.Value);
|
||||||
|
|
||||||
_audio.PlayPvs(component.DestroySound, component.AnalyzerEntity.Value, AudioParams.Default.WithVolume(2f));
|
_audio.PlayPvs(component.DestroySound, component.AnalyzerEntity.Value, AudioParams.Default.WithVolume(2f));
|
||||||
|
|||||||
@@ -24,19 +24,10 @@ public sealed class LatheUpdateState : BoundUserInterfaceState
|
|||||||
/// Sent to the server to sync material storage and the recipe queue.
|
/// Sent to the server to sync material storage and the recipe queue.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class LatheSyncRequestMessage : BoundUserInterfaceMessage { }
|
public sealed class LatheSyncRequestMessage : BoundUserInterfaceMessage
|
||||||
|
{
|
||||||
|
|
||||||
/// <summary>
|
}
|
||||||
/// Sent to the server to sync the lathe's technology database with the research server.
|
|
||||||
/// </summary>
|
|
||||||
[Serializable, NetSerializable]
|
|
||||||
public sealed class LatheServerSyncMessage : BoundUserInterfaceMessage { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sent to the server to open the ResearchClient UI.
|
|
||||||
/// </summary>
|
|
||||||
[Serializable, NetSerializable]
|
|
||||||
public sealed class LatheServerSelectionMessage : BoundUserInterfaceMessage { }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sent to the server when a client queues a new recipe.
|
/// Sent to the server when a client queues a new recipe.
|
||||||
|
|||||||
@@ -2,15 +2,34 @@
|
|||||||
|
|
||||||
namespace Content.Shared.Research.Components
|
namespace Content.Shared.Research.Components
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This is an entity that is able to connect to a <see cref="ResearchServerComponent"/>
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent]
|
||||||
|
public sealed class ResearchClientComponent : Component
|
||||||
|
{
|
||||||
|
public bool ConnectedToServer => Server != null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The server the client is connected to
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
|
public EntityUid? Server { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raised on the client whenever its server is changed
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Server">Its new server</param>
|
||||||
|
[ByRefEvent]
|
||||||
|
public readonly record struct ResearchRegistrationChangedEvent(EntityUid? Server);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sent to the server when the client deselects a research server.
|
/// Sent to the server when the client deselects a research server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class ResearchClientServerDeselectedMessage : BoundUserInterfaceMessage
|
public sealed class ResearchClientServerDeselectedMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
public ResearchClientServerDeselectedMessage()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -33,10 +52,6 @@ namespace Content.Shared.Research.Components
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class ResearchClientSyncMessage : BoundUserInterfaceMessage
|
public sealed class ResearchClientSyncMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
|
|
||||||
public ResearchClientSyncMessage()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[NetSerializable, Serializable]
|
[NetSerializable, Serializable]
|
||||||
@@ -1,21 +1,36 @@
|
|||||||
using Content.Server.Research.Systems;
|
using Robust.Shared.GameStates;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||||
|
|
||||||
namespace Content.Server.Research.Components
|
namespace Content.Shared.Research.Components
|
||||||
{
|
{
|
||||||
[Access(typeof(ResearchSystem))]
|
[RegisterComponent, NetworkedComponent]
|
||||||
[RegisterComponent]
|
|
||||||
public sealed class ResearchServerComponent : Component
|
public sealed class ResearchServerComponent : Component
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The name of the server
|
||||||
|
/// </summary>
|
||||||
[DataField("servername"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField("servername"), ViewVariables(VVAccess.ReadWrite)]
|
||||||
public string ServerName = "RDSERVER";
|
public string ServerName = "RDSERVER";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The amount of points on the server.
|
||||||
|
/// </summary>
|
||||||
[DataField("points"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField("points"), ViewVariables(VVAccess.ReadWrite)]
|
||||||
public int Points;
|
public int Points;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A unique numeric id representing the server
|
||||||
|
/// </summary>
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
public int Id;
|
public int Id;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Entities connected to the server
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This is not safe to read clientside
|
||||||
|
/// </remarks>
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
public List<EntityUid> Clients = new();
|
public List<EntityUid> Clients = new();
|
||||||
|
|
||||||
@@ -26,6 +41,20 @@ namespace Content.Server.Research.Components
|
|||||||
public readonly TimeSpan ResearchConsoleUpdateTime = TimeSpan.FromSeconds(1);
|
public readonly TimeSpan ResearchConsoleUpdateTime = TimeSpan.FromSeconds(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public sealed class ResearchServerState : ComponentState
|
||||||
|
{
|
||||||
|
public string ServerName;
|
||||||
|
public int Points;
|
||||||
|
public int Id;
|
||||||
|
public ResearchServerState(string serverName, int points, int id)
|
||||||
|
{
|
||||||
|
ServerName = serverName;
|
||||||
|
Points = points;
|
||||||
|
Id = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Event raised on a server's clients when the point value of the server is changed.
|
/// Event raised on a server's clients when the point value of the server is changed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -22,15 +22,13 @@ namespace Content.Shared.Research.Components
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class ConsoleServerSyncMessage : BoundUserInterfaceMessage
|
public sealed class ConsoleServerSyncMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
public ConsoleServerSyncMessage()
|
|
||||||
{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class ConsoleServerSelectionMessage : BoundUserInterfaceMessage
|
public sealed class ConsoleServerSelectionMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
public ConsoleServerSelectionMessage()
|
|
||||||
{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
|
|||||||
@@ -8,13 +8,31 @@ namespace Content.Shared.Research.Components
|
|||||||
[RegisterComponent, NetworkedComponent]
|
[RegisterComponent, NetworkedComponent]
|
||||||
public sealed class TechnologyDatabaseComponent : Component
|
public sealed class TechnologyDatabaseComponent : Component
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The ids of all the technologies which have been unlocked.
|
||||||
|
/// </summary>
|
||||||
[DataField("technologyIds", customTypeSerializer: typeof(PrototypeIdListSerializer<TechnologyPrototype>))]
|
[DataField("technologyIds", customTypeSerializer: typeof(PrototypeIdListSerializer<TechnologyPrototype>))]
|
||||||
public List<string> TechnologyIds = new();
|
public List<string> TechnologyIds = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The ids of all the lathe recipes which have been unlocked.
|
||||||
|
/// This is maintained alongside the TechnologyIds
|
||||||
|
/// </summary>
|
||||||
[DataField("recipeIds", customTypeSerializer: typeof(PrototypeIdListSerializer<LatheRecipePrototype>))]
|
[DataField("recipeIds", customTypeSerializer: typeof(PrototypeIdListSerializer<LatheRecipePrototype>))]
|
||||||
public List<string> RecipeIds = new();
|
public List<string> RecipeIds = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event raised on the database whenever its
|
||||||
|
/// technologies or recipes are modified.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This event is forwarded from the
|
||||||
|
/// server to all of it's clients.
|
||||||
|
/// </remarks>
|
||||||
|
[ByRefEvent]
|
||||||
|
public readonly record struct TechnologyDatabaseModifiedEvent;
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class TechnologyDatabaseState : ComponentState
|
public sealed class TechnologyDatabaseState : ComponentState
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,22 +1,35 @@
|
|||||||
using Content.Shared.Research.Components;
|
using Content.Shared.Research.Components;
|
||||||
using Content.Shared.Research.Prototypes;
|
using Content.Shared.Research.Prototypes;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Prototypes;
|
|
||||||
|
|
||||||
namespace Content.Shared.Research.Systems;
|
namespace Content.Shared.Research.Systems;
|
||||||
|
|
||||||
public abstract class SharedResearchSystem : EntitySystem
|
public abstract class SharedResearchSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<ResearchServerComponent, ComponentGetState>(OnServerGetState);
|
||||||
|
SubscribeLocalEvent<ResearchServerComponent, ComponentHandleState>(OnServerHandleState);
|
||||||
SubscribeLocalEvent<TechnologyDatabaseComponent, ComponentGetState>(OnTechnologyGetState);
|
SubscribeLocalEvent<TechnologyDatabaseComponent, ComponentGetState>(OnTechnologyGetState);
|
||||||
SubscribeLocalEvent<TechnologyDatabaseComponent, ComponentHandleState>(OnTechnologyHandleState);
|
SubscribeLocalEvent<TechnologyDatabaseComponent, ComponentHandleState>(OnTechnologyHandleState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnServerGetState(EntityUid uid, ResearchServerComponent component, ref ComponentGetState args)
|
||||||
|
{
|
||||||
|
args.State = new ResearchServerState(component.ServerName, component.Points, component.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnServerHandleState(EntityUid uid, ResearchServerComponent component, ref ComponentHandleState args)
|
||||||
|
{
|
||||||
|
if (args.Current is not ResearchServerState state)
|
||||||
|
return;
|
||||||
|
component.ServerName = state.ServerName;
|
||||||
|
component.Points = state.Points;
|
||||||
|
component.Id = state.Id;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnTechnologyHandleState(EntityUid uid, TechnologyDatabaseComponent component, ref ComponentHandleState args)
|
private void OnTechnologyHandleState(EntityUid uid, TechnologyDatabaseComponent component, ref ComponentHandleState args)
|
||||||
{
|
{
|
||||||
if (args.Current is not TechnologyDatabaseState state)
|
if (args.Current is not TechnologyDatabaseState state)
|
||||||
@@ -34,40 +47,35 @@ public abstract class SharedResearchSystem : EntitySystem
|
|||||||
/// Returns whether a technology is unlocked on this database or not.
|
/// Returns whether a technology is unlocked on this database or not.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Whether it is unlocked or not</returns>
|
/// <returns>Whether it is unlocked or not</returns>
|
||||||
public bool IsTechnologyUnlocked(EntityUid uid, string technologyId, TechnologyDatabaseComponent? component = null)
|
public bool IsTechnologyUnlocked(EntityUid uid, TechnologyPrototype technology, TechnologyDatabaseComponent? component = null)
|
||||||
{
|
{
|
||||||
return Resolve(uid, ref component) && component.TechnologyIds.Contains(technologyId);
|
return Resolve(uid, ref component) && IsTechnologyUnlocked(uid, technology.ID, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns whether a technology is unlocked on this database or not.
|
/// Returns whether a technology is unlocked on this database or not.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Whether it is unlocked or not</returns>
|
/// <returns>Whether it is unlocked or not</returns>
|
||||||
public bool IsTechnologyUnlocked(EntityUid uid, TechnologyPrototype technologyId, TechnologyDatabaseComponent? component = null)
|
public bool IsTechnologyUnlocked(EntityUid uid, string technologyId, TechnologyDatabaseComponent? component = null)
|
||||||
{
|
{
|
||||||
return Resolve(uid, ref component) && IsTechnologyUnlocked(uid, technologyId.ID, component);
|
return Resolve(uid, ref component, false) && component.TechnologyIds.Contains(technologyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns whether a technology can be unlocked on this database,
|
/// Returns whether or not all the prerequisite
|
||||||
/// taking parent technologies into account.
|
/// technologies for a technology are unlocked.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Whether it could be unlocked or not</returns>
|
/// <param name="uid"></param>
|
||||||
public bool CanUnlockTechnology(EntityUid uid, TechnologyPrototype technology, TechnologyDatabaseComponent? component = null)
|
/// <param name="prototype"></param>
|
||||||
|
/// <param name="component"></param>
|
||||||
|
/// <returns>Whether or not the prerequesites are present</returns>
|
||||||
|
public bool ArePrerequesitesUnlocked(EntityUid uid, TechnologyPrototype prototype, TechnologyDatabaseComponent? component = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref component))
|
if (!Resolve(uid, ref component))
|
||||||
return false;
|
return false;
|
||||||
|
foreach (var technologyId in prototype.RequiredTechnologies)
|
||||||
if (IsTechnologyUnlocked(uid, technology.ID, component))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
foreach (var technologyId in technology.RequiredTechnologies)
|
|
||||||
{
|
{
|
||||||
_prototypeManager.TryIndex(technologyId, out TechnologyPrototype? requiredTechnology);
|
if (!IsTechnologyUnlocked(uid, technologyId, component))
|
||||||
if (requiredTechnology == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!IsTechnologyUnlocked(uid, requiredTechnology.ID, component))
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user