committed by
GitHub
parent
ea60a81fdf
commit
103bc19508
42
Content.Server/Power/EntitySystems/BatterySystem.cs
Normal file
42
Content.Server/Power/EntitySystems/BatterySystem.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
#nullable enable
|
||||
using Content.Server.Power.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Power.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class BatterySystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<BatteryComponent, NetworkBatteryPreSync>(PreSync);
|
||||
SubscribeLocalEvent<BatteryComponent, NetworkBatteryPostSync>(PostSync);
|
||||
}
|
||||
|
||||
private void PreSync(EntityUid uid, BatteryComponent component, NetworkBatteryPreSync args)
|
||||
{
|
||||
var networkBattery = ComponentManager.GetComponent<PowerNetworkBatteryComponent>(uid);
|
||||
|
||||
networkBattery.NetworkBattery.Capacity = component.MaxCharge;
|
||||
networkBattery.NetworkBattery.CurrentStorage = component.CurrentCharge;
|
||||
}
|
||||
|
||||
private void PostSync(EntityUid uid, BatteryComponent component, NetworkBatteryPostSync args)
|
||||
{
|
||||
var networkBattery = ComponentManager.GetComponent<PowerNetworkBatteryComponent>(uid);
|
||||
|
||||
component.CurrentCharge = networkBattery.NetworkBattery.CurrentStorage;
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var comp in ComponentManager.EntityQuery<BatteryComponent>())
|
||||
{
|
||||
comp.OnUpdate(frameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user