Research machinery requires power (#516)
* Fixed ResearchPointSourceComponent properties * ResearchPointSourceComponent requires power * ResearchServerComponent requires power
This commit is contained in:
committed by
Pieter-Jan Briers
parent
c4ea6e53e8
commit
c20ba98a1e
@@ -98,7 +98,7 @@ namespace Content.Server.GameObjects.Components.Power
|
|||||||
}
|
}
|
||||||
private Powernet.Priority _priority = Powernet.Priority.Medium;
|
private Powernet.Priority _priority = Powernet.Priority.Medium;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public bool IsPowerCut
|
public bool IsPowerCut
|
||||||
{
|
{
|
||||||
get => _isPowerCut;
|
get => _isPowerCut;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Content.Server.GameObjects.Components.Power;
|
||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
@@ -13,19 +14,32 @@ namespace Content.Server.GameObjects.Components.Research
|
|||||||
|
|
||||||
private int _pointsPerSecond;
|
private int _pointsPerSecond;
|
||||||
private bool _active;
|
private bool _active;
|
||||||
|
private PowerDeviceComponent _powerDevice;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public int PointsPerSecond
|
public int PointsPerSecond
|
||||||
{
|
{
|
||||||
get => _pointsPerSecond;
|
get => _pointsPerSecond;
|
||||||
set => value = _pointsPerSecond;
|
set => _pointsPerSecond = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public bool Active
|
public bool Active
|
||||||
{
|
{
|
||||||
get => _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)
|
public override void ExposeData(ObjectSerializer serializer)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Content.Server.GameObjects.Components.Power;
|
||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
using Content.Shared.Research;
|
using Content.Shared.Research;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
@@ -16,24 +17,23 @@ namespace Content.Server.GameObjects.Components.Research
|
|||||||
|
|
||||||
public override string Name => "ResearchServer";
|
public override string Name => "ResearchServer";
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)] public string ServerName => _serverName;
|
||||||
public string ServerName => _serverName;
|
|
||||||
|
|
||||||
private string _serverName = "RDSERVER";
|
private string _serverName = "RDSERVER";
|
||||||
private float _timer = 0f;
|
private float _timer = 0f;
|
||||||
public TechnologyDatabaseComponent Database { get; private set; }
|
public TechnologyDatabaseComponent Database { get; private set; }
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)] private int _points = 0;
|
||||||
private int _points = 0;
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
[ViewVariables(VVAccess.ReadOnly)] public int Id { get; private set; }
|
||||||
public int Id { get; private set; }
|
|
||||||
|
|
||||||
// You could optimize research by keeping a list of unlocked recipes too.
|
// You could optimize research by keeping a list of unlocked recipes too.
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
public IReadOnlyList<TechnologyPrototype> UnlockedTechnologies => Database.Technologies;
|
public IReadOnlyList<TechnologyPrototype> UnlockedTechnologies => Database.Technologies;
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
public List<ResearchPointSourceComponent> PointSources { get; } = new List<ResearchPointSourceComponent>();
|
public List<ResearchPointSourceComponent> PointSources { get; } = new List<ResearchPointSourceComponent>();
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
public List<ResearchClientComponent> Clients { get; } = new List<ResearchClientComponent>();
|
public List<ResearchClientComponent> Clients { get; } = new List<ResearchClientComponent>();
|
||||||
|
|
||||||
@@ -51,21 +51,31 @@ namespace Content.Server.GameObjects.Components.Research
|
|||||||
{
|
{
|
||||||
var points = 0;
|
var points = 0;
|
||||||
|
|
||||||
|
if (CanRun)
|
||||||
|
{
|
||||||
foreach (var source in PointSources)
|
foreach (var source in PointSources)
|
||||||
{
|
{
|
||||||
if (source.Active) points += source.PointsPerSecond;
|
if (source.CanProduce) points += source.PointsPerSecond;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return points;
|
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()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
Id = ServerCount++;
|
Id = ServerCount++;
|
||||||
IoCManager.Resolve<IEntitySystemManager>()?.GetEntitySystem<ResearchSystem>()?.RegisterServer(this);
|
IoCManager.Resolve<IEntitySystemManager>()?.GetEntitySystem<ResearchSystem>()?.RegisterServer(this);
|
||||||
Database = Owner.GetComponent<TechnologyDatabaseComponent>();
|
Database = Owner.GetComponent<TechnologyDatabaseComponent>();
|
||||||
|
Owner.TryGetComponent(out _powerDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -84,7 +94,8 @@ namespace Content.Server.GameObjects.Components.Research
|
|||||||
|
|
||||||
public bool CanUnlockTechnology(TechnologyPrototype technology)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +109,7 @@ namespace Content.Server.GameObjects.Components.Research
|
|||||||
{
|
{
|
||||||
if (!CanUnlockTechnology(technology)) return false;
|
if (!CanUnlockTechnology(technology)) return false;
|
||||||
var result = Database.UnlockTechnology(technology);
|
var result = Database.UnlockTechnology(technology);
|
||||||
if(result)
|
if (result)
|
||||||
_points -= technology.RequiredPoints;
|
_points -= technology.RequiredPoints;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -151,6 +162,7 @@ namespace Content.Server.GameObjects.Components.Research
|
|||||||
|
|
||||||
public void Update(float frameTime)
|
public void Update(float frameTime)
|
||||||
{
|
{
|
||||||
|
if (!CanRun) return;
|
||||||
_timer += frameTime;
|
_timer += frameTime;
|
||||||
if (_timer < 1f) return;
|
if (_timer < 1f) return;
|
||||||
_timer = 0f;
|
_timer = 0f;
|
||||||
|
|||||||
Reference in New Issue
Block a user