diff --git a/Content.Server/GameObjects/Components/Power/PowerDevice.cs b/Content.Server/GameObjects/Components/Power/PowerDevice.cs index 6f12d69222..870805c9f9 100644 --- a/Content.Server/GameObjects/Components/Power/PowerDevice.cs +++ b/Content.Server/GameObjects/Components/Power/PowerDevice.cs @@ -98,7 +98,7 @@ namespace Content.Server.GameObjects.Components.Power } private Powernet.Priority _priority = Powernet.Priority.Medium; - [ViewVariables] + [ViewVariables(VVAccess.ReadWrite)] public bool IsPowerCut { get => _isPowerCut; diff --git a/Content.Server/GameObjects/Components/Research/ResearchPointSourceComponent.cs b/Content.Server/GameObjects/Components/Research/ResearchPointSourceComponent.cs index 5b50e45182..6f7aedb757 100644 --- a/Content.Server/GameObjects/Components/Research/ResearchPointSourceComponent.cs +++ b/Content.Server/GameObjects/Components/Research/ResearchPointSourceComponent.cs @@ -1,3 +1,4 @@ +using Content.Server.GameObjects.Components.Power; using Content.Server.GameObjects.EntitySystems; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; @@ -13,19 +14,32 @@ namespace Content.Server.GameObjects.Components.Research private int _pointsPerSecond; private bool _active; + private PowerDeviceComponent _powerDevice; [ViewVariables] public int PointsPerSecond { get => _pointsPerSecond; - set => value = _pointsPerSecond; + set => _pointsPerSecond = value; } [ViewVariables] public bool Active { get => _active; - set => value = _active; + set => _active = value; + } + + /// + /// Whether this can be used to produce research points. + /// + /// If no is found, it's assumed power is not required. + public bool CanProduce => Active && (_powerDevice is null || _powerDevice.Powered); + + public override void Initialize() + { + base.Initialize(); + Owner.TryGetComponent(out _powerDevice); } public override void ExposeData(ObjectSerializer serializer) diff --git a/Content.Server/GameObjects/Components/Research/ResearchServerComponent.cs b/Content.Server/GameObjects/Components/Research/ResearchServerComponent.cs index 27c3f10e2a..2258c9af6b 100644 --- a/Content.Server/GameObjects/Components/Research/ResearchServerComponent.cs +++ b/Content.Server/GameObjects/Components/Research/ResearchServerComponent.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Content.Server.GameObjects.Components.Power; using Content.Server.GameObjects.EntitySystems; using Content.Shared.Research; using Robust.Shared.GameObjects; @@ -16,24 +17,23 @@ namespace Content.Server.GameObjects.Components.Research public override string Name => "ResearchServer"; - [ViewVariables(VVAccess.ReadWrite)] - public string ServerName => _serverName; + [ViewVariables(VVAccess.ReadWrite)] public string ServerName => _serverName; private string _serverName = "RDSERVER"; private float _timer = 0f; public TechnologyDatabaseComponent Database { get; private set; } - [ViewVariables(VVAccess.ReadWrite)] - private int _points = 0; + [ViewVariables(VVAccess.ReadWrite)] private int _points = 0; - [ViewVariables(VVAccess.ReadOnly)] - public int Id { get; private set; } + [ViewVariables(VVAccess.ReadOnly)] public int Id { get; private set; } // You could optimize research by keeping a list of unlocked recipes too. [ViewVariables(VVAccess.ReadOnly)] public IReadOnlyList UnlockedTechnologies => Database.Technologies; + [ViewVariables(VVAccess.ReadOnly)] public List PointSources { get; } = new List(); + [ViewVariables(VVAccess.ReadOnly)] public List Clients { get; } = new List(); @@ -51,21 +51,31 @@ namespace Content.Server.GameObjects.Components.Research { var points = 0; - foreach (var source in PointSources) + if (CanRun) { - if (source.Active) points += source.PointsPerSecond; + foreach (var source in PointSources) + { + if (source.CanProduce) points += source.PointsPerSecond; + } } return points; } } + /// If no is found, it's assumed power is not required. + [ViewVariables] + public bool CanRun => _powerDevice is null || _powerDevice.Powered; + + private PowerDeviceComponent _powerDevice; + public override void Initialize() { base.Initialize(); Id = ServerCount++; IoCManager.Resolve()?.GetEntitySystem()?.RegisterServer(this); Database = Owner.GetComponent(); + Owner.TryGetComponent(out _powerDevice); } /// @@ -84,7 +94,8 @@ namespace Content.Server.GameObjects.Components.Research public bool CanUnlockTechnology(TechnologyPrototype technology) { - if (!Database.CanUnlockTechnology(technology) || _points < technology.RequiredPoints || Database.IsTechnologyUnlocked(technology)) return false; + if (!Database.CanUnlockTechnology(technology) || _points < technology.RequiredPoints || + Database.IsTechnologyUnlocked(technology)) return false; return true; } @@ -98,7 +109,7 @@ namespace Content.Server.GameObjects.Components.Research { if (!CanUnlockTechnology(technology)) return false; var result = Database.UnlockTechnology(technology); - if(result) + if (result) _points -= technology.RequiredPoints; return result; } @@ -151,6 +162,7 @@ namespace Content.Server.GameObjects.Components.Research public void Update(float frameTime) { + if (!CanRun) return; _timer += frameTime; if (_timer < 1f) return; _timer = 0f;