using Content.Shared.Research.Prototypes; using Robust.Shared.GameStates; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List; namespace Content.Shared.Research.Components { [NetworkedComponent()] public abstract class SharedTechnologyDatabaseComponent : Component { [DataField("technologies", customTypeSerializer: typeof(PrototypeIdListSerializer))] public readonly List TechnologyIds = new(); /// /// Returns whether a technology is unlocked on this database or not. /// /// The technology to be checked /// Whether it is unlocked or not public bool IsTechnologyUnlocked(string technologyId) { return TechnologyIds.Contains(technologyId); } /// /// Returns whether a technology can be unlocked on this database, /// taking parent technologies into account. /// /// The technology to be checked /// Whether it could be unlocked or not public bool CanUnlockTechnology(TechnologyPrototype technology) { if (IsTechnologyUnlocked(technology.ID)) return false; var protoMan = IoCManager.Resolve(); foreach (var technologyId in technology.RequiredTechnologies) { protoMan.TryIndex(technologyId, out TechnologyPrototype? requiredTechnology); if (requiredTechnology == null) return false; if (!IsTechnologyUnlocked(requiredTechnology.ID)) return false; } return true; } } [Serializable, NetSerializable] public sealed class TechnologyDatabaseState : ComponentState { public List Technologies; public TechnologyDatabaseState(List technologies) { Technologies = technologies; } public TechnologyDatabaseState(List technologies) { Technologies = new List(); foreach (var technology in technologies) { Technologies.Add(technology.ID); } } } }