RND Rework [Death to Techweb] (#16370)

* Techweb rework

* more ui work

* finishing ui

* Finish all the C# logic

* the techs + lathes

* remove old-tech

* mirror-review
This commit is contained in:
Nemanja
2023-05-15 16:17:30 -04:00
committed by GitHub
parent a71d9c8eff
commit 9efc727fe1
51 changed files with 1732 additions and 1401 deletions

View File

@@ -105,8 +105,10 @@ public sealed partial class ResearchSystem
/// <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)
public bool TryGetClientServer(EntityUid uid,
[NotNullWhen(returnValue: true)] out EntityUid? server,
[NotNullWhen(returnValue: true)] out ResearchServerComponent? serverComponent,
ResearchClientComponent? component = null)
{
server = null;
serverComponent = null;
@@ -117,11 +119,10 @@ public sealed partial class ResearchSystem
if (component.Server == null)
return false;
if (!TryComp<ResearchServerComponent>(component.Server, out var sc))
if (!TryComp(component.Server, out serverComponent))
return false;
server = component.Server;
serverComponent = sc;
return true;
}
}

View File

@@ -33,18 +33,17 @@ public sealed partial class ResearchSystem
ResearchConsoleBoundInterfaceState state;
if (TryGetClientServer(uid, out var server, out var serverComponent, clientComponent))
if (TryGetClientServer(uid, out _, out var serverComponent, clientComponent))
{
var points = clientComponent.ConnectedToServer ? serverComponent.Points : 0;
var pointsPerSecond = clientComponent.ConnectedToServer ? PointsPerSecond(server.Value, serverComponent) : 0;
state = new ResearchConsoleBoundInterfaceState(points, pointsPerSecond);
state = new ResearchConsoleBoundInterfaceState(points);
}
else
{
state = new ResearchConsoleBoundInterfaceState(default, default);
state = new ResearchConsoleBoundInterfaceState(default);
}
_uiSystem.TrySetUiState(component.Owner, ResearchConsoleUiKey.Key, state);
_uiSystem.TrySetUiState(uid, ResearchConsoleUiKey.Key, state);
}
private void OnPointsChanged(EntityUid uid, ResearchConsoleComponent component, ref ResearchServerPointsChangedEvent args)

View File

@@ -49,7 +49,7 @@ public sealed partial class ResearchSystem
if (!CanRun(uid))
return;
AddPointsToServer(uid, PointsPerSecond(uid, component) * time, component);
ModifyServerPoints(uid, GetPointsPerSecond(uid, component) * time, component);
}
/// <summary>
@@ -60,15 +60,14 @@ public sealed partial class ResearchSystem
/// <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,
public void RegisterClient(EntityUid client, EntityUid server, ResearchClientComponent? clientComponent = null,
ResearchServerComponent? serverComponent = null, bool dirtyServer = true)
{
if (!Resolve(client, ref clientComponent) || !Resolve(server, ref serverComponent))
return false;
return;
if (serverComponent.Clients.Contains(client))
return false;
return;
serverComponent.Clients.Add(client);
clientComponent.Server = server;
@@ -78,7 +77,6 @@ public sealed partial class ResearchSystem
var ev = new ResearchRegistrationChangedEvent(server);
RaiseLocalEvent(client, ref ev);
return true;
}
/// <summary>
@@ -130,7 +128,7 @@ public sealed partial class ResearchSystem
/// <param name="uid"></param>
/// <param name="component"></param>
/// <returns></returns>
public int PointsPerSecond(EntityUid uid, ResearchServerComponent? component = null)
public int GetPointsPerSecond(EntityUid uid, ResearchServerComponent? component = null)
{
var points = 0;
@@ -154,7 +152,7 @@ public sealed partial class ResearchSystem
/// <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)
public void ModifyServerPoints(EntityUid uid, int points, ResearchServerComponent? component = null)
{
if (points == 0)
return;

View File

@@ -1,5 +1,6 @@
using Content.Shared.Research.Components;
using Content.Shared.Research.Prototypes;
using JetBrains.Annotations;
namespace Content.Server.Research.Systems;
@@ -13,13 +14,16 @@ public sealed partial class ResearchSystem
if (!Resolve(primaryUid, ref primaryDb) || !Resolve(otherUid, ref otherDb))
return;
primaryDb.TechnologyIds = otherDb.TechnologyIds;
primaryDb.RecipeIds = otherDb.RecipeIds;
primaryDb.MainDiscipline = otherDb.MainDiscipline;
primaryDb.CurrentTechnologyCards = otherDb.CurrentTechnologyCards;
primaryDb.SupportedDisciplines = otherDb.SupportedDisciplines;
primaryDb.UnlockedTechnologies = otherDb.UnlockedTechnologies;
primaryDb.UnlockedRecipes = otherDb.UnlockedRecipes;
Dirty(primaryDb);
var ev = new TechnologyDatabaseModifiedEvent();
RaiseLocalEvent(primaryDb.Owner, ref ev);
RaiseLocalEvent(primaryUid, ref ev);
}
/// <summary>
@@ -28,16 +32,15 @@ public sealed partial class ResearchSystem
/// syncs against the research server, and the server against the local database.
/// </summary>
/// <returns>Whether it could sync or not</returns>
public bool SyncClientWithServer(EntityUid uid, TechnologyDatabaseComponent? databaseComponent = null, ResearchClientComponent? clientComponent = null)
public void SyncClientWithServer(EntityUid uid, TechnologyDatabaseComponent? databaseComponent = null, ResearchClientComponent? clientComponent = null)
{
if (!Resolve(uid, ref databaseComponent, ref clientComponent, false))
return false;
return;
if (!TryComp<TechnologyDatabaseComponent>(clientComponent.Server, out var serverDatabase))
return false;
return;
Sync(uid, clientComponent.Server.Value, databaseComponent, serverDatabase);
return true;
}
/// <summary>
@@ -45,45 +48,49 @@ public sealed partial class ResearchSystem
/// </summary>
/// <returns>If the technology was successfully added</returns>
public bool UnlockTechnology(EntityUid client, string prototypeid, ResearchClientComponent? component = null,
TechnologyDatabaseComponent? databaseComponent = null)
TechnologyDatabaseComponent? clientDatabase = null)
{
if (!_prototypeManager.TryIndex<TechnologyPrototype>(prototypeid, out var prototype))
{
Logger.Error("invalid technology prototype");
if (!PrototypeManager.TryIndex<TechnologyPrototype>(prototypeid, out var prototype))
return false;
}
return UnlockTechnology(client, prototype, component, databaseComponent);
return UnlockTechnology(client, prototype, component, clientDatabase);
}
/// <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)
public bool UnlockTechnology(EntityUid client,
TechnologyPrototype prototype,
ResearchClientComponent? component = null,
TechnologyDatabaseComponent? clientDatabase = null)
{
if (!Resolve(client, ref component, ref databaseComponent, false))
if (!Resolve(client, ref component, ref clientDatabase, false))
return false;
if (!CanUnlockTechnology(client, prototype, databaseComponent))
if (!TryGetClientServer(client, out var serverEnt, out _, component))
return false;
if (component.Server is not { } server)
if (!CanServerUnlockTechnology(client, prototype, clientDatabase, component))
return false;
AddTechnology(server, prototype.ID);
AddPointsToServer(server, -prototype.RequiredPoints);
AddTechnology(serverEnt.Value, prototype);
TrySetMainDiscipline(prototype, serverEnt.Value);
ModifyServerPoints(serverEnt.Value, -prototype.Cost);
UpdateTechnologyCards(serverEnt.Value);
return true;
}
/// <summary>
/// Adds a technology to the database without checking if it could be unlocked.
/// </summary>
[PublicAPI]
public void AddTechnology(EntityUid uid, string technology, TechnologyDatabaseComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
if (!_prototypeManager.TryIndex<TechnologyPrototype>(technology, out var prototype))
if (!PrototypeManager.TryIndex<TechnologyPrototype>(technology, out var prototype))
return;
AddTechnology(uid, prototype, component);
}
@@ -96,12 +103,19 @@ public sealed partial class ResearchSystem
if (!Resolve(uid, ref component))
return;
component.TechnologyIds.Add(technology.ID);
foreach (var unlock in technology.UnlockedRecipes)
//todo this needs to support some other stuff, too
foreach (var generic in technology.GenericUnlocks)
{
if (component.RecipeIds.Contains(unlock))
if (generic.PurchaseEvent != null)
RaiseLocalEvent(generic.PurchaseEvent);
}
component.UnlockedTechnologies.Add(technology.ID);
foreach (var unlock in technology.RecipeUnlocks)
{
if (component.UnlockedRecipes.Contains(unlock))
continue;
component.RecipeIds.Add(unlock);
component.UnlockedRecipes.Add(unlock);
}
Dirty(component);
@@ -113,17 +127,16 @@ public sealed partial class ResearchSystem
/// 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)
public void AddLatheRecipe(EntityUid uid, string recipe, TechnologyDatabaseComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
if (component.RecipeIds.Contains(recipe))
if (component.UnlockedRecipes.Contains(recipe))
return;
component.RecipeIds.Add(recipe);
if (dirty)
Dirty(component);
component.UnlockedRecipes.Add(recipe);
Dirty(component);
var ev = new TechnologyDatabaseModifiedEvent();
RaiseLocalEvent(uid, ref ev);
@@ -134,34 +147,36 @@ public sealed partial class ResearchSystem
/// 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)
public bool CanServerUnlockTechnology(EntityUid uid,
TechnologyPrototype 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))
if (!Resolve(uid, ref client, ref database, false))
return false;
if (!TryGetClientServer(uid, out _, out var serverComponent, client))
if (!TryGetClientServer(uid, out _, out var serverComp, client))
return false;
if (serverComponent.Points < technology.RequiredPoints)
if (!IsTechnologyAvailable(database, technology))
return false;
if (IsTechnologyUnlocked(uid, technology, database))
if (technology.Cost > serverComp.Points)
return false;
if (!ArePrerequesitesUnlocked(uid, technology, database))
return false;
return true;
}
private void OnDatabaseRegistrationChanged(EntityUid uid, TechnologyDatabaseComponent component, ref ResearchRegistrationChangedEvent args)
{
if (args.Server != null)
return;
component.MainDiscipline = null;
component.CurrentTechnologyCards = new List<string>();
component.SupportedDisciplines = new List<string>();
component.UnlockedTechnologies = new List<string>();
component.UnlockedRecipes = new List<string>();
Dirty(component);
}
}

View File

@@ -4,7 +4,6 @@ using Content.Shared.Research.Components;
using Content.Shared.Research.Systems;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Server.Research.Systems
@@ -13,7 +12,6 @@ namespace Content.Server.Research.Systems
public sealed partial class ResearchSystem : SharedResearchSystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
public override void Initialize()
@@ -23,6 +21,8 @@ namespace Content.Server.Research.Systems
InitializeConsole();
InitializeSource();
InitializeServer();
SubscribeLocalEvent<TechnologyDatabaseComponent, ResearchRegistrationChangedEvent>(OnDatabaseRegistrationChanged);
}
/// <summary>