Some Power nullable & ComponentDependency (#3050)
* Power nullability * AME nullability * re-adds EnsureComponents * conflict fix * Update Content.Server/GameObjects/Components/Power/PowerNetComponents/RadiationCollectorComponent.cs Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * removes duplicate component assignment Co-authored-by: py01 <pyronetics01@gmail.com> Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
#nullable enable
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.ComponentDependencies;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
{
|
||||
@@ -13,10 +16,10 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
public override string Name => "BatteryDischarger";
|
||||
|
||||
[ViewVariables]
|
||||
private BatteryComponent _battery;
|
||||
[ComponentDependency] private BatteryComponent? _battery = default!;
|
||||
|
||||
[ViewVariables]
|
||||
private PowerSupplierComponent _supplier;
|
||||
[ComponentDependency] private PowerSupplierComponent? _supplier = default!;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int ActiveSupplyRate { get => _activeSupplyRate; set => SetActiveSupplyRate(value); }
|
||||
@@ -31,14 +34,16 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_battery = Owner.EnsureComponent<BatteryComponent>();
|
||||
_supplier = Owner.EnsureComponent<PowerSupplierComponent>();
|
||||
Owner.EnsureComponentWarn<BatteryComponent>();
|
||||
Owner.EnsureComponentWarn<PowerSupplierComponent>();
|
||||
UpdateSupplyRate();
|
||||
}
|
||||
|
||||
public void Update(float frameTime)
|
||||
{
|
||||
if (_battery == null)
|
||||
return;
|
||||
|
||||
//Simplified implementation - if the battery is empty, and charge is being added to the battery
|
||||
//at a lower rate that this is using it, the charge is used without creating power supply.
|
||||
_battery.CurrentCharge -= ActiveSupplyRate * frameTime;
|
||||
@@ -47,6 +52,9 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
|
||||
private void UpdateSupplyRate()
|
||||
{
|
||||
if (_battery == null)
|
||||
return;
|
||||
|
||||
if (_battery.BatteryState == BatteryState.Empty)
|
||||
{
|
||||
SetSupplierSupplyRate(0);
|
||||
@@ -59,6 +67,9 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
|
||||
private void SetSupplierSupplyRate(int newSupplierSupplyRate)
|
||||
{
|
||||
if (_supplier == null)
|
||||
return;
|
||||
|
||||
if (_supplier.SupplyRate != newSupplierSupplyRate)
|
||||
{
|
||||
_supplier.SupplyRate = newSupplierSupplyRate;
|
||||
|
||||
Reference in New Issue
Block a user