* add solar flare event (only affects headsets) * add popup * cleaner impl using RadioReceiveAttemptEvent * unused import * handheld radio and intercom work again * Revert "handheld radio and intercom work again" This reverts commit 0032e3c0725a19a465daf1ff1d6b4942a5c14fbb. * add radio source to Radio events * intercoms and handheld radios work now * use Elapsed instead of new field * add configuration * better not touch Elapsed * the * make popup bigger * xml comments for configuration * very minor refactoring * default config is now in yaml * lights can break * use RobustRandom * use file namespace * use RuleStarted * store config in field * a --------- Co-authored-by: AJCM <AJCM@tutanota.com>
74 lines
1.9 KiB
C#
74 lines
1.9 KiB
C#
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;
|
|
|
|
namespace Content.Server.StationEvents.Events;
|
|
|
|
public sealed class SolarFlare : StationEventSystem
|
|
{
|
|
[Dependency] private readonly PoweredLightSystem _poweredLight = default!;
|
|
|
|
public override string Prototype => "SolarFlare";
|
|
|
|
private SolarFlareEventRuleConfiguration _event = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<ActiveRadioComponent, 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 Started()
|
|
{
|
|
base.Started();
|
|
MessLights();
|
|
}
|
|
|
|
private void MessLights()
|
|
{
|
|
foreach (var comp in EntityQuery<PoweredLightComponent>())
|
|
{
|
|
if (RobustRandom.Prob(_event.LightBreakChance))
|
|
{
|
|
var uid = comp.Owner;
|
|
_poweredLight.TryDestroyBulb(uid, comp);
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
if (!RuleStarted)
|
|
return;
|
|
|
|
if (Elapsed > _event.EndAfter)
|
|
{
|
|
ForceEndSelf();
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void OnRadioSendAttempt(EntityUid uid, ActiveRadioComponent component, RadioReceiveAttemptEvent args)
|
|
{
|
|
if (RuleStarted && _event.AffectedChannels.Contains(args.Channel.ID))
|
|
if (!_event.OnlyJamHeadsets || (HasComp<HeadsetComponent>(uid) || HasComp<HeadsetComponent>(args.RadioSource)))
|
|
args.Cancel();
|
|
}
|
|
}
|