Electrocution. (#4958)

Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
This commit is contained in:
Vera Aguilera Puerto
2021-10-25 16:21:56 +02:00
committed by GitHub
parent 66a3d5bf29
commit ed3bf94a3b
37 changed files with 934 additions and 30 deletions

View File

@@ -13,7 +13,7 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.Power.NodeGroups
{
public interface IApcNet
public interface IApcNet : IBasePowerNet
{
void AddApc(ApcComponent apc);
@@ -25,20 +25,18 @@ namespace Content.Server.Power.NodeGroups
void QueueNetworkReconnect();
PowerState.Network NetworkNode { get; }
GridId? GridId { get; }
}
[NodeGroup(NodeGroupID.Apc)]
[UsedImplicitly]
public class ApcNet : BaseNetConnectorNodeGroup<BaseApcNetComponent, IApcNet>, IApcNet
public class ApcNet : BaseNetConnectorNodeGroup<IApcNet>, IApcNet
{
private readonly PowerNetSystem _powerNetSystem = EntitySystem.Get<PowerNetSystem>();
[ViewVariables] public readonly List<ApcComponent> Apcs = new();
[ViewVariables] public readonly List<ApcPowerProviderComponent> Providers = new();
[ViewVariables] public readonly List<PowerConsumerComponent> Consumers = new();
//Debug property
[ViewVariables] private int TotalReceivers => Providers.Sum(provider => provider.LinkedReceivers.Count);
@@ -71,7 +69,7 @@ namespace Content.Server.Power.NodeGroups
if (apc.Owner.TryGetComponent(out PowerNetworkBatteryComponent? netBattery))
netBattery.NetworkBattery.LinkedNetworkDischarging = default;
_powerNetSystem.QueueReconnectApcNet(this);
QueueNetworkReconnect();
Apcs.Add(apc);
}
@@ -80,7 +78,7 @@ namespace Content.Server.Power.NodeGroups
if (apc.Owner.TryGetComponent(out PowerNetworkBatteryComponent? netBattery))
netBattery.NetworkBattery.LinkedNetworkDischarging = default;
_powerNetSystem.QueueReconnectApcNet(this);
QueueNetworkReconnect();
Apcs.Remove(apc);
}
@@ -88,14 +86,28 @@ namespace Content.Server.Power.NodeGroups
{
Providers.Add(provider);
_powerNetSystem.QueueReconnectApcNet(this);
QueueNetworkReconnect();
}
public void RemovePowerProvider(ApcPowerProviderComponent provider)
{
Providers.Remove(provider);
_powerNetSystem.QueueReconnectApcNet(this);
QueueNetworkReconnect();
}
public void AddConsumer(PowerConsumerComponent consumer)
{
consumer.NetworkLoad.LinkedNetwork = default;
Consumers.Add(consumer);
QueueNetworkReconnect();
}
public void RemoveConsumer(PowerConsumerComponent consumer)
{
consumer.NetworkLoad.LinkedNetwork = default;
Consumers.Remove(consumer);
QueueNetworkReconnect();
}
public void QueueNetworkReconnect()
@@ -103,7 +115,7 @@ namespace Content.Server.Power.NodeGroups
_powerNetSystem.QueueReconnectApcNet(this);
}
protected override void SetNetConnectorNet(BaseApcNetComponent netConnectorComponent)
protected override void SetNetConnectorNet(IBaseNetConnectorComponent<IApcNet> netConnectorComponent)
{
netConnectorComponent.Net = this;
}

View File

@@ -6,8 +6,7 @@ using Content.Server.Power.Components;
namespace Content.Server.Power.NodeGroups
{
public abstract class BaseNetConnectorNodeGroup<TNetConnector, TNetType> : BaseNodeGroup
where TNetConnector : BaseNetConnectorComponent<TNetType>
public abstract class BaseNetConnectorNodeGroup<TNetType> : BaseNodeGroup
{
public override void LoadNodes(List<Node> groupNodes)
{
@@ -16,7 +15,7 @@ namespace Content.Server.Power.NodeGroups
foreach (var node in groupNodes)
{
var newNetConnectorComponents = node.Owner
.GetAllComponents<TNetConnector>()
.GetAllComponents<IBaseNetConnectorComponent<TNetType>>()
.Where(powerComp => (powerComp.NodeId == null || powerComp.NodeId == node.Name) &&
(NodeGroupID) powerComp.Voltage == node.NodeGroupID)
.ToList();
@@ -28,6 +27,6 @@ namespace Content.Server.Power.NodeGroups
}
}
protected abstract void SetNetConnectorNet(TNetConnector netConnectorComponent);
protected abstract void SetNetConnectorNet(IBaseNetConnectorComponent<TNetType> netConnectorComponent);
}
}

View File

@@ -0,0 +1,14 @@
using Content.Server.Power.Components;
using Content.Server.Power.Pow3r;
namespace Content.Server.Power.NodeGroups
{
public interface IBasePowerNet
{
void AddConsumer(PowerConsumerComponent consumer);
void RemoveConsumer(PowerConsumerComponent consumer);
PowerState.Network NetworkNode { get; }
}
}

View File

@@ -12,16 +12,12 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.Power.NodeGroups
{
public interface IPowerNet
public interface IPowerNet : IBasePowerNet
{
void AddSupplier(PowerSupplierComponent supplier);
void RemoveSupplier(PowerSupplierComponent supplier);
void AddConsumer(PowerConsumerComponent consumer);
void RemoveConsumer(PowerConsumerComponent consumer);
void AddDischarger(BatteryDischargerComponent discharger);
void RemoveDischarger(BatteryDischargerComponent discharger);
@@ -33,7 +29,7 @@ namespace Content.Server.Power.NodeGroups
[NodeGroup(NodeGroupID.HVPower, NodeGroupID.MVPower)]
[UsedImplicitly]
public class PowerNet : BaseNetConnectorNodeGroup<BasePowerNetComponent, IPowerNet>, IPowerNet
public class PowerNet : BaseNetConnectorNodeGroup<IPowerNet>, IPowerNet
{
private readonly PowerNetSystem _powerNetSystem = EntitySystem.Get<PowerNetSystem>();
@@ -59,7 +55,7 @@ namespace Content.Server.Power.NodeGroups
_powerNetSystem.DestroyPowerNet(this);
}
protected override void SetNetConnectorNet(BasePowerNetComponent netConnectorComponent)
protected override void SetNetConnectorNet(IBaseNetConnectorComponent<IPowerNet> netConnectorComponent)
{
netConnectorComponent.Net = this;
}