Research machinery requires power (#516)

* Fixed ResearchPointSourceComponent properties

* ResearchPointSourceComponent requires power

* ResearchServerComponent requires power
This commit is contained in:
DamianX
2020-01-17 15:34:40 +01:00
committed by Pieter-Jan Briers
parent c4ea6e53e8
commit c20ba98a1e
3 changed files with 39 additions and 13 deletions

View File

@@ -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;

View File

@@ -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;
}
/// <summary>
/// Whether this can be used to produce research points.
/// </summary>
/// <remarks>If no <see cref="PowerDeviceComponent"/> is found, it's assumed power is not required.</remarks>
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)

View File

@@ -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<TechnologyPrototype> UnlockedTechnologies => Database.Technologies;
[ViewVariables(VVAccess.ReadOnly)]
public List<ResearchPointSourceComponent> PointSources { get; } = new List<ResearchPointSourceComponent>();
[ViewVariables(VVAccess.ReadOnly)]
public List<ResearchClientComponent> Clients { get; } = new List<ResearchClientComponent>();
@@ -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;
}
}
/// <remarks>If no <see cref="PowerDeviceComponent"/> is found, it's assumed power is not required.</remarks>
[ViewVariables]
public bool CanRun => _powerDevice is null || _powerDevice.Powered;
private PowerDeviceComponent _powerDevice;
public override void Initialize()
{
base.Initialize();
Id = ServerCount++;
IoCManager.Resolve<IEntitySystemManager>()?.GetEntitySystem<ResearchSystem>()?.RegisterServer(this);
Database = Owner.GetComponent<TechnologyDatabaseComponent>();
Owner.TryGetComponent(out _powerDevice);
}
/// <inheritdoc />
@@ -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;