using Content.Server.Lightning; using Content.Server.Tesla.Components; using Robust.Shared.Random; using Robust.Shared.Timing; namespace Content.Server.Tesla.EntitySystems; /// /// Fires electric arcs at surrounding objects. /// public sealed class LightningArcShooterSystem : EntitySystem { [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly LightningSystem _lightning = default!; [Dependency] private readonly IRobustRandom _random = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnShooterMapInit); } private void OnShooterMapInit(EntityUid uid, LightningArcShooterComponent component, ref MapInitEvent args) { component.NextShootTime = _gameTiming.CurTime + TimeSpan.FromSeconds(component.ShootMaxInterval); } public override void Update(float frameTime) { base.Update(frameTime); var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var arcShooter)) { if (arcShooter.NextShootTime > _gameTiming.CurTime) continue; ArcShoot(uid, arcShooter); var delay = TimeSpan.FromSeconds(_random.NextFloat(arcShooter.ShootMinInterval, arcShooter.ShootMaxInterval)); arcShooter.NextShootTime += delay; } } private void ArcShoot(EntityUid uid, LightningArcShooterComponent component) { var arcs = _random.Next(1, component.MaxLightningArc); _lightning.ShootRandomLightnings(uid, component.ShootRange, arcs, component.LightningPrototype, component.ArcDepth); } }