mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
# Description This PR fully replaces the "Tier 3 Tech Lockout" with a research softcap. How it works is that technologies are allowed to set a softcap contribution, meaning that they multiplicatively increase the cost of all other research by a certain amount. By default, this is done by all Tier 3 Technologies. Essentially, this means that you're no longer limited to a single research category's tier 3 selections. Instead the costs of research increase the more capstones you unlock. The current cost increase for research is displayed on the console. <details><summary><h1>Media</h1></summary> <p>  </p> </details> # Changelog 🆑 - remove: Removed the "Tier 3 Tech Lockout" mechanic. You are no longer limited to 1 discipline worth of t3 research. - add: Research is now "Softcapped" by Tier 3 unlocks. Each unlocked Tier 3 technology multiplicatively increases the cost of all other research. Rushing a capstone can be quite expensive, as will be getting multiple capstones. I hope you're glad that you can build more than one prober now without guaranteeing the station will explode. (cherry picked from commit b7da1f4ff64ca3ce8c4dc4545186573174b3e89c)
177 lines
6.9 KiB
C#
177 lines
6.9 KiB
C#
using Content.Shared.Database;
|
|
using Content.Shared.Research.Components;
|
|
using Content.Shared.Research.Prototypes;
|
|
using JetBrains.Annotations;
|
|
|
|
namespace Content.Server.Research.Systems;
|
|
|
|
public sealed partial class ResearchSystem
|
|
{
|
|
/// <summary>
|
|
/// Syncs the primary entity's database to that of the secondary entity's database.
|
|
/// </summary>
|
|
public void Sync(EntityUid primaryUid, EntityUid otherUid, TechnologyDatabaseComponent? primaryDb = null, TechnologyDatabaseComponent? otherDb = null)
|
|
{
|
|
if (!Resolve(primaryUid, ref primaryDb) || !Resolve(otherUid, ref otherDb))
|
|
return;
|
|
|
|
primaryDb.MainDiscipline = otherDb.MainDiscipline;
|
|
primaryDb.CurrentTechnologyCards = otherDb.CurrentTechnologyCards;
|
|
primaryDb.SupportedDisciplines = otherDb.SupportedDisciplines;
|
|
primaryDb.UnlockedTechnologies = otherDb.UnlockedTechnologies;
|
|
primaryDb.UnlockedRecipes = otherDb.UnlockedRecipes;
|
|
|
|
Dirty(primaryUid, primaryDb);
|
|
|
|
var ev = new TechnologyDatabaseModifiedEvent();
|
|
RaiseLocalEvent(primaryUid, ref ev);
|
|
}
|
|
|
|
/// <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 void SyncClientWithServer(EntityUid uid, TechnologyDatabaseComponent? databaseComponent = null, ResearchClientComponent? clientComponent = null)
|
|
{
|
|
if (!Resolve(uid, ref databaseComponent, ref clientComponent, false))
|
|
return;
|
|
|
|
if (!TryComp<TechnologyDatabaseComponent>(clientComponent.Server, out var serverDatabase))
|
|
return;
|
|
|
|
Sync(uid, clientComponent.Server.Value, databaseComponent, serverDatabase);
|
|
}
|
|
|
|
/// <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,
|
|
string prototypeid,
|
|
EntityUid user,
|
|
ResearchClientComponent? component = null,
|
|
TechnologyDatabaseComponent? clientDatabase = null)
|
|
{
|
|
if (!PrototypeManager.TryIndex<TechnologyPrototype>(prototypeid, out var prototype))
|
|
return false;
|
|
|
|
return UnlockTechnology(client, prototype, user, 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,
|
|
EntityUid user,
|
|
ResearchClientComponent? component = null,
|
|
TechnologyDatabaseComponent? clientDatabase = null)
|
|
{
|
|
if (!Resolve(client, ref component, ref clientDatabase, false)
|
|
|| !TryGetClientServer(client, out var serverEnt, out _, component)
|
|
|| !CanServerUnlockTechnology(client, prototype, clientDatabase, component)
|
|
|| !PrototypeManager.TryIndex(prototype.Discipline, out var disciplinePrototype)
|
|
|| !TryComp<ResearchServerComponent>(serverEnt.Value, out var researchServer)
|
|
|| prototype.Cost * clientDatabase.SoftCapMultiplier > researchServer.Points)
|
|
return false;
|
|
|
|
if (prototype.Tier >= disciplinePrototype.LockoutTier)
|
|
{
|
|
clientDatabase.SoftCapMultiplier *= prototype.SoftCapContribution;
|
|
researchServer.CurrentSoftCapMultiplier *= prototype.SoftCapContribution;
|
|
}
|
|
|
|
AddTechnology(serverEnt.Value, prototype);
|
|
TrySetMainDiscipline(prototype, serverEnt.Value);
|
|
ModifyServerPoints(serverEnt.Value, -(int) (prototype.Cost * clientDatabase.SoftCapMultiplier));
|
|
UpdateTechnologyCards(serverEnt.Value);
|
|
|
|
_adminLog.Add(LogType.Action, LogImpact.Medium,
|
|
$"{ToPrettyString(user):player} unlocked {prototype.ID} (discipline: {prototype.Discipline}, tier: {prototype.Tier}) at {ToPrettyString(client)}, for server {ToPrettyString(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))
|
|
return;
|
|
AddTechnology(uid, prototype, component);
|
|
}
|
|
|
|
/// <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;
|
|
|
|
//todo this needs to support some other stuff, too
|
|
foreach (var generic in technology.GenericUnlocks)
|
|
{
|
|
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.UnlockedRecipes.Add(unlock);
|
|
}
|
|
Dirty(uid, 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 CanServerUnlockTechnology(EntityUid uid,
|
|
TechnologyPrototype technology,
|
|
TechnologyDatabaseComponent? database = null,
|
|
ResearchClientComponent? client = null)
|
|
{
|
|
|
|
if (!Resolve(uid, ref client, ref database, false))
|
|
return false;
|
|
|
|
if (!TryGetClientServer(uid, out _, out var serverComp, client))
|
|
return false;
|
|
|
|
if (!IsTechnologyAvailable(database, technology))
|
|
return false;
|
|
|
|
if (technology.Cost * database.SoftCapMultiplier > serverComp.Points)
|
|
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(uid, component);
|
|
}
|
|
}
|