Files
crystall-punk-14/Content.Server/StationEvents/Events/SolarFlare.cs

79 lines
2.5 KiB
C#
Raw Normal View History

using Content.Server.GameTicking.Rules.Configurations;
using Content.Server.Radio.Components;
using Content.Server.Radio;
using Robust.Shared.Random;
using Content.Server.Light.EntitySystems;
using Content.Server.Light.Components;
2023-02-19 06:27:56 +13:00
using Content.Shared.Radio.Components;
2023-03-07 02:35:59 +03:00
using Content.Shared.Doors.Components;
using Content.Shared.Doors.Systems;
namespace Content.Server.StationEvents.Events;
public sealed class SolarFlare : StationEventSystem
{
[Dependency] private readonly PoweredLightSystem _poweredLight = default!;
2023-03-07 02:35:59 +03:00
[Dependency] private readonly SharedDoorSystem _door = default!;
public override string Prototype => "SolarFlare";
private SolarFlareEventRuleConfiguration _event = default!;
2023-03-07 02:35:59 +03:00
private float _effectTimer = 0;
public override void Initialize()
{
base.Initialize();
2023-03-24 03:02:41 +03:00
SubscribeLocalEvent<RadioReceiveAttemptEvent>(OnRadioSendAttempt);
}
public override void Added()
{
base.Added();
if (Configuration is not SolarFlareEventRuleConfiguration ev)
return;
_event = ev;
_event.EndAfter = RobustRandom.Next(ev.MinEndAfter, ev.MaxEndAfter);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if (!RuleStarted)
return;
2023-03-07 02:35:59 +03:00
_effectTimer -= frameTime;
if (_effectTimer < 0)
{
_effectTimer += 1;
var lightQuery = EntityQueryEnumerator<PoweredLightComponent>();
while (lightQuery.MoveNext(out var uid, out var light))
2023-03-07 02:35:59 +03:00
{
if (RobustRandom.Prob(_event.LightBreakChancePerSecond))
_poweredLight.TryDestroyBulb(uid, light);
2023-03-07 02:35:59 +03:00
}
var airlockQuery = EntityQueryEnumerator<AirlockComponent, DoorComponent>();
while (airlockQuery.MoveNext(out var uid, out var airlock, out var door))
2023-03-07 02:35:59 +03:00
{
if (airlock.AutoClose && RobustRandom.Prob(_event.DoorToggleChancePerSecond))
_door.TryToggleDoor(uid, door);
2023-03-07 02:35:59 +03:00
}
}
if (Elapsed > _event.EndAfter)
{
ForceEndSelf();
return;
}
}
2023-03-24 03:02:41 +03:00
private void OnRadioSendAttempt(ref RadioReceiveAttemptEvent args)
{
if (RuleStarted && _event.AffectedChannels.Contains(args.Channel.ID))
2023-03-24 03:02:41 +03:00
if (!_event.OnlyJamHeadsets || (HasComp<HeadsetComponent>(args.RadioReceiver) || HasComp<HeadsetComponent>(args.RadioSource)))
args.Cancelled = true;
}
}