using Content.Server.Research.Components; using Content.Shared.Research.Components; using Content.Shared.Research.Prototypes; using Robust.Shared.GameStates; namespace Content.Server.Research; public sealed partial class ResearchSystem { private void InitializeTechnology() { SubscribeLocalEvent(OnTechnologyGetState); } private void OnTechnologyGetState(EntityUid uid, TechnologyDatabaseComponent component, ref ComponentGetState args) { args.State = new TechnologyDatabaseState(component.Technologies); } /// /// Synchronizes this database against other, /// adding all technologies from the other that /// this one doesn't have. /// /// The other database /// Whether the other database should be synced against this one too or not. public void Sync(TechnologyDatabaseComponent component, TechnologyDatabaseComponent otherDatabase, bool twoway = true) { foreach (var tech in otherDatabase.Technologies) { if (!component.IsTechnologyUnlocked(tech)) AddTechnology(component, tech); } if (twoway) Sync(otherDatabase, component, false); Dirty(component); } /// /// 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. /// /// Whether it could sync or not public bool SyncWithServer(TechnologyDatabaseComponent component, ResearchClientComponent? clientComponent = null) { if (!Resolve(component.Owner, ref clientComponent, false)) return false; if (!TryComp(clientComponent.Server?.Owner, out var clientDatabase)) return false; Sync(component, clientDatabase); return true; } /// /// If possible, unlocks a technology on this database. /// /// /// public bool UnlockTechnology(TechnologyDatabaseComponent component, TechnologyPrototype technology) { if (!component.CanUnlockTechnology(technology)) return false; AddTechnology(component, technology); Dirty(component); return true; } /// /// Adds a technology to the database without checking if it could be unlocked. /// /// public void AddTechnology(TechnologyDatabaseComponent component, TechnologyPrototype technology) { component.Technologies.Add(technology); } }