2024-06-21 06:15:55 +03:00
|
|
|
|
using Content.Server.Power.Components;
|
|
|
|
|
|
using Content.Shared.Lightning;
|
2024-03-16 18:30:57 +03:00
|
|
|
|
using Content.Shared.PowerCell;
|
|
|
|
|
|
using Content.Shared.PowerCell.Components;
|
2024-06-21 06:15:55 +03:00
|
|
|
|
using Content.Shared.Weapons.Ranged.Components;
|
2024-03-16 18:30:57 +03:00
|
|
|
|
|
2024-06-21 06:15:55 +03:00
|
|
|
|
namespace Content.Server._White.Lighting.Pointlight.Battery;
|
2024-03-16 18:30:57 +03:00
|
|
|
|
|
|
|
|
|
|
public sealed class PointLightBatterySystem : SharedLightningSystem
|
|
|
|
|
|
{
|
|
|
|
|
|
[Dependency] private readonly SharedPointLightSystem _pointLightSystem = default!;
|
|
|
|
|
|
[Dependency] private readonly SharedPowerCellSystem _cell = default!;
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
SubscribeLocalEvent<PointLightBatteryComponent, PowerCellChangedEvent>(OnBatteryLoose);
|
2024-06-21 06:15:55 +03:00
|
|
|
|
SubscribeLocalEvent<PointLightBatteryComponent, ChargeChangedEvent>(OnBatteryChargeChanged);
|
2024-03-16 18:30:57 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnBatteryLoose(EntityUid uid, PointLightBatteryComponent component, PowerCellChangedEvent args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!component.RequireBattery)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (!_pointLightSystem.TryGetLight(uid, out var pointLightComponent))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
var isBatteryCharged = _cell.HasDrawCharge(uid);
|
|
|
|
|
|
_pointLightSystem.SetEnabled(uid, isBatteryCharged && !args.Ejected, pointLightComponent);
|
|
|
|
|
|
|
|
|
|
|
|
RaiseLocalEvent(uid, new PointLightToggleEvent(isBatteryCharged && !args.Ejected), true);
|
|
|
|
|
|
}
|
2024-06-21 06:15:55 +03:00
|
|
|
|
|
|
|
|
|
|
private void OnBatteryChargeChanged(EntityUid uid, PointLightBatteryComponent component, ChargeChangedEvent args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!component.RequireBattery)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (!_pointLightSystem.TryGetLight(uid, out var pointLightComponent))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
var isBatteryCharged = TryComp<ProjectileBatteryAmmoProviderComponent>(uid, out var projectileBattery) && projectileBattery.Shots > 0;
|
|
|
|
|
|
_pointLightSystem.SetEnabled(uid, isBatteryCharged, pointLightComponent);
|
|
|
|
|
|
|
|
|
|
|
|
RaiseLocalEvent(uid, new PointLightToggleEvent(isBatteryCharged), true);
|
|
|
|
|
|
}
|
2024-03-16 18:30:57 +03:00
|
|
|
|
}
|