2021-07-04 18:11:52 +02:00
|
|
|
using Content.Server.Power.Components;
|
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Power.EntitySystems
|
|
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class BatterySystem : EntitySystem
|
2021-07-04 18:11:52 +02:00
|
|
|
{
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2021-07-29 16:55:09 +02:00
|
|
|
SubscribeLocalEvent<NetworkBatteryPreSync>(PreSync);
|
|
|
|
|
SubscribeLocalEvent<NetworkBatteryPostSync>(PostSync);
|
2021-07-04 18:11:52 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-29 16:55:09 +02:00
|
|
|
private void PreSync(NetworkBatteryPreSync ev)
|
2021-07-04 18:11:52 +02:00
|
|
|
{
|
2021-11-18 19:02:17 +00:00
|
|
|
foreach (var (netBat, bat) in EntityManager.EntityQuery<PowerNetworkBatteryComponent, BatteryComponent>())
|
2021-07-29 16:55:09 +02:00
|
|
|
{
|
|
|
|
|
netBat.NetworkBattery.Capacity = bat.MaxCharge;
|
|
|
|
|
netBat.NetworkBattery.CurrentStorage = bat.CurrentCharge;
|
|
|
|
|
}
|
2021-07-04 18:11:52 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-29 16:55:09 +02:00
|
|
|
private void PostSync(NetworkBatteryPostSync ev)
|
2021-07-04 18:11:52 +02:00
|
|
|
{
|
2021-11-18 19:02:17 +00:00
|
|
|
foreach (var (netBat, bat) in EntityManager.EntityQuery<PowerNetworkBatteryComponent, BatteryComponent>())
|
2021-07-29 16:55:09 +02:00
|
|
|
{
|
|
|
|
|
bat.CurrentCharge = netBat.NetworkBattery.CurrentStorage;
|
|
|
|
|
}
|
2021-07-04 18:11:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
2021-11-18 19:02:17 +00:00
|
|
|
foreach (var (comp, batt) in EntityManager.EntityQuery<BatterySelfRechargerComponent, BatteryComponent>())
|
2021-07-04 18:11:52 +02:00
|
|
|
{
|
2021-11-18 19:02:17 +00:00
|
|
|
if (!comp.AutoRecharge) continue;
|
|
|
|
|
if (batt.IsFullyCharged) continue;
|
|
|
|
|
batt.CurrentCharge += comp.AutoRechargeRate * frameTime;
|
2021-07-04 18:11:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|