Electrocution. (#4958)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
This commit is contained in:
committed by
GitHub
parent
66a3d5bf29
commit
ed3bf94a3b
@@ -8,7 +8,14 @@ using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Power.Components
|
||||
{
|
||||
public abstract class BaseNetConnectorComponent<TNetType> : Component
|
||||
public interface IBaseNetConnectorComponent<in TNetType>
|
||||
{
|
||||
public TNetType? Net { set; }
|
||||
public Voltage Voltage { get; }
|
||||
public string? NodeId { get; }
|
||||
}
|
||||
|
||||
public abstract class BaseNetConnectorComponent<TNetType> : Component, IBaseNetConnectorComponent<TNetType>
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Voltage Voltage { get => _voltage; set => SetVoltage(value); }
|
||||
@@ -22,7 +29,7 @@ namespace Content.Server.Power.Components
|
||||
[ViewVariables]
|
||||
private bool _needsNet => _net != null;
|
||||
|
||||
[DataField("node")] [ViewVariables] public string? NodeId;
|
||||
[DataField("node")] [ViewVariables] public string? NodeId { get; set; }
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
|
||||
@@ -3,6 +3,11 @@ using Content.Server.Power.NodeGroups;
|
||||
|
||||
namespace Content.Server.Power.Components
|
||||
{
|
||||
public interface IBasePowerNetComponent : IBaseNetConnectorComponent<IPowerNet>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public abstract class BasePowerNetComponent : BaseNetConnectorComponent<IPowerNet>
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Electrocution;
|
||||
using Content.Server.Stack;
|
||||
using Content.Server.Tools;
|
||||
using Content.Server.Tools.Components;
|
||||
@@ -43,6 +44,8 @@ namespace Content.Server.Power.Components
|
||||
|
||||
if (!await EntitySystem.Get<ToolSystem>().UseTool(eventArgs.Using.Uid, eventArgs.User.Uid, Owner.Uid, 0f, 0.25f, _cuttingQuality)) return false;
|
||||
|
||||
if (EntitySystem.Get<ElectrocutionSystem>().TryDoElectrifiedAct(Owner.Uid, eventArgs.User.Uid)) return false;
|
||||
|
||||
Owner.Delete();
|
||||
var droppedEnt = Owner.EntityManager.SpawnEntity(_cableDroppedOnCutPrototype, eventArgs.ClickLocation);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Content.Server.Power.Components
|
||||
/// Draws power directly from an MV or HV wire it is on top of.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class PowerConsumerComponent : BasePowerNetComponent
|
||||
public class PowerConsumerComponent : BaseNetConnectorComponent<IBasePowerNet>
|
||||
{
|
||||
public override string Name => "PowerConsumer";
|
||||
|
||||
@@ -31,12 +31,12 @@ namespace Content.Server.Power.Components
|
||||
|
||||
public PowerState.Load NetworkLoad { get; } = new();
|
||||
|
||||
protected override void AddSelfToNet(IPowerNet powerNet)
|
||||
protected override void AddSelfToNet(IBasePowerNet powerNet)
|
||||
{
|
||||
powerNet.AddConsumer(this);
|
||||
}
|
||||
|
||||
protected override void RemoveSelfFromNet(IPowerNet powerNet)
|
||||
protected override void RemoveSelfFromNet(IBasePowerNet powerNet)
|
||||
{
|
||||
powerNet.RemoveConsumer(this);
|
||||
}
|
||||
|
||||
@@ -279,6 +279,12 @@ namespace Content.Server.Power.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var consumer in net.Consumers)
|
||||
{
|
||||
netNode.Loads.Add(consumer.NetworkLoad.Id);
|
||||
consumer.NetworkLoad.LinkedNetwork = netNode.Id;
|
||||
}
|
||||
|
||||
foreach (var apc in net.Apcs)
|
||||
{
|
||||
var netBattery = apc.Owner.GetComponent<PowerNetworkBatteryComponent>();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
14
Content.Server/Power/NodeGroups/IBasePowerNet.cs
Normal file
14
Content.Server/Power/NodeGroups/IBasePowerNet.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -171,6 +171,9 @@ namespace Content.Server.Power.Pow3r
|
||||
battery.LoadingDemandMarked = true;
|
||||
}
|
||||
|
||||
network.LastAvailableSupplySum = availableSupplySum;
|
||||
network.LastMaxSupplySum = maxSupplySum;
|
||||
|
||||
var met = Math.Min(demand, availableSupplySum);
|
||||
|
||||
if (met != 0)
|
||||
|
||||
@@ -451,6 +451,9 @@ namespace Content.Server.Power.Pow3r
|
||||
// "Supplying" means the network is connected to the OUTPUT port of the battery.
|
||||
[ViewVariables] public List<NodeId> BatteriesDischarging = new();
|
||||
|
||||
[ViewVariables] public float LastAvailableSupplySum = 0f;
|
||||
[ViewVariables] public float LastMaxSupplySum = 0f;
|
||||
|
||||
[ViewVariables] [JsonIgnore] public int Height;
|
||||
[JsonIgnore] public bool HeightTouched;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user