Add solar flare event (#13749)
* 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>
This commit is contained in:
@@ -0,0 +1,40 @@
|
|||||||
|
using Content.Shared.Radio;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||||
|
|
||||||
|
namespace Content.Server.GameTicking.Rules.Configurations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Solar Flare event specific configuration
|
||||||
|
/// </summary>
|
||||||
|
public sealed class SolarFlareEventRuleConfiguration : StationEventRuleConfiguration
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// In seconds, most early moment event can end
|
||||||
|
/// </summary>
|
||||||
|
[DataField("minEndAfter")]
|
||||||
|
public int MinEndAfter;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// In seconds, most late moment event can end
|
||||||
|
/// </summary>
|
||||||
|
[DataField("maxEndAfter")]
|
||||||
|
public int MaxEndAfter;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If true, only headsets affected, but e.g. handheld radio will still work
|
||||||
|
/// </summary>
|
||||||
|
[DataField("onlyJamHeadsets")]
|
||||||
|
public bool OnlyJamHeadsets;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Channels that will be disabled for a duration of event
|
||||||
|
/// </summary>
|
||||||
|
[DataField("affectedChannels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
|
||||||
|
public readonly HashSet<string> AffectedChannels = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Chance any given light bulb breaks due to event
|
||||||
|
/// </summary>
|
||||||
|
[DataField("lightBreakChance")]
|
||||||
|
public float LightBreakChance;
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ namespace Content.Server.GameTicking.Rules.Configurations;
|
|||||||
/// game rules.
|
/// game rules.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public sealed class StationEventRuleConfiguration : GameRuleConfiguration
|
public class StationEventRuleConfiguration : GameRuleConfiguration
|
||||||
{
|
{
|
||||||
[DataField("id", required: true)]
|
[DataField("id", required: true)]
|
||||||
private string _id = default!;
|
private string _id = default!;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public sealed class HeadsetSystem : EntitySystem
|
|||||||
&& TryComp(component.Headset, out HeadsetComponent? headset)
|
&& TryComp(component.Headset, out HeadsetComponent? headset)
|
||||||
&& headset.Channels.Contains(args.Channel.ID))
|
&& headset.Channels.Contains(args.Channel.ID))
|
||||||
{
|
{
|
||||||
_radio.SendRadioMessage(uid, args.Message, args.Channel);
|
_radio.SendRadioMessage(uid, args.Message, args.Channel, component.Headset);
|
||||||
args.Channel = null; // prevent duplicate messages from other listeners.
|
args.Channel = null; // prevent duplicate messages from other listeners.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ public sealed class RadioDeviceSystem : EntitySystem
|
|||||||
return; // no feedback loops please.
|
return; // no feedback loops please.
|
||||||
|
|
||||||
if (_recentlySent.Add((args.Message, args.Source)))
|
if (_recentlySent.Add((args.Message, args.Source)))
|
||||||
_radio.SendRadioMessage(args.Source, args.Message, _protoMan.Index<RadioChannelPrototype>(component.BroadcastChannel));
|
_radio.SendRadioMessage(args.Source, args.Message, _protoMan.Index<RadioChannelPrototype>(component.BroadcastChannel), uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnAttemptListen(EntityUid uid, RadioMicrophoneComponent component, ListenAttemptEvent args)
|
private void OnAttemptListen(EntityUid uid, RadioMicrophoneComponent component, ListenAttemptEvent args)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using Content.Server.Administration.Logs;
|
|||||||
using Content.Server.Chat.Systems;
|
using Content.Server.Chat.Systems;
|
||||||
using Content.Server.Radio.Components;
|
using Content.Server.Radio.Components;
|
||||||
using Content.Server.VoiceMask;
|
using Content.Server.VoiceMask;
|
||||||
|
using Content.Server.Popups;
|
||||||
using Content.Shared.Chat;
|
using Content.Shared.Chat;
|
||||||
using Content.Shared.Database;
|
using Content.Shared.Database;
|
||||||
using Content.Shared.Radio;
|
using Content.Shared.Radio;
|
||||||
@@ -9,6 +10,7 @@ using Robust.Server.GameObjects;
|
|||||||
using Robust.Shared.Network;
|
using Robust.Shared.Network;
|
||||||
using Robust.Shared.Replays;
|
using Robust.Shared.Replays;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
using Content.Shared.Popups;
|
||||||
|
|
||||||
namespace Content.Server.Radio.EntitySystems;
|
namespace Content.Server.Radio.EntitySystems;
|
||||||
|
|
||||||
@@ -20,6 +22,7 @@ public sealed class RadioSystem : EntitySystem
|
|||||||
[Dependency] private readonly INetManager _netMan = default!;
|
[Dependency] private readonly INetManager _netMan = default!;
|
||||||
[Dependency] private readonly IReplayRecordingManager _replay = default!;
|
[Dependency] private readonly IReplayRecordingManager _replay = default!;
|
||||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||||
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||||
|
|
||||||
// set used to prevent radio feedback loops.
|
// set used to prevent radio feedback loops.
|
||||||
private readonly HashSet<string> _messages = new();
|
private readonly HashSet<string> _messages = new();
|
||||||
@@ -46,7 +49,7 @@ public sealed class RadioSystem : EntitySystem
|
|||||||
_netMan.ServerSendMessage(args.ChatMsg, actor.PlayerSession.ConnectedClient);
|
_netMan.ServerSendMessage(args.ChatMsg, actor.PlayerSession.ConnectedClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendRadioMessage(EntityUid source, string message, RadioChannelPrototype channel)
|
public void SendRadioMessage(EntityUid source, string message, RadioChannelPrototype channel, EntityUid? radioSource = null)
|
||||||
{
|
{
|
||||||
// TODO if radios ever garble / modify messages, feedback-prevention needs to be handled better than this.
|
// TODO if radios ever garble / modify messages, feedback-prevention needs to be handled better than this.
|
||||||
if (!_messages.Add(message))
|
if (!_messages.Add(message))
|
||||||
@@ -66,8 +69,9 @@ public sealed class RadioSystem : EntitySystem
|
|||||||
EntityUid.Invalid);
|
EntityUid.Invalid);
|
||||||
var chatMsg = new MsgChatMessage { Message = chat };
|
var chatMsg = new MsgChatMessage { Message = chat };
|
||||||
|
|
||||||
var ev = new RadioReceiveEvent(message, source, channel, chatMsg);
|
var ev = new RadioReceiveEvent(message, source, channel, chatMsg, radioSource);
|
||||||
var attemptEv = new RadioReceiveAttemptEvent(message, source, channel);
|
var attemptEv = new RadioReceiveAttemptEvent(message, source, channel, radioSource);
|
||||||
|
bool sentAtLeastOnce = false;
|
||||||
|
|
||||||
foreach (var radio in EntityQuery<ActiveRadioComponent>())
|
foreach (var radio in EntityQuery<ActiveRadioComponent>())
|
||||||
{
|
{
|
||||||
@@ -82,9 +86,11 @@ public sealed class RadioSystem : EntitySystem
|
|||||||
attemptEv.Uncancel();
|
attemptEv.Uncancel();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
sentAtLeastOnce = true;
|
||||||
RaiseLocalEvent(radio.Owner, ev);
|
RaiseLocalEvent(radio.Owner, ev);
|
||||||
}
|
}
|
||||||
|
if (!sentAtLeastOnce)
|
||||||
|
_popupSystem.PopupEntity(Loc.GetString("failed-to-send-message"), source, PopupType.MediumCaution);
|
||||||
|
|
||||||
if (name != Name(source))
|
if (name != Name(source))
|
||||||
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Radio message from {ToPrettyString(source):user} as {name} on {channel.LocalizedName}: {message}");
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Radio message from {ToPrettyString(source):user} as {name} on {channel.LocalizedName}: {message}");
|
||||||
|
|||||||
@@ -9,13 +9,15 @@ public sealed class RadioReceiveEvent : EntityEventArgs
|
|||||||
public readonly EntityUid Source;
|
public readonly EntityUid Source;
|
||||||
public readonly RadioChannelPrototype Channel;
|
public readonly RadioChannelPrototype Channel;
|
||||||
public readonly MsgChatMessage ChatMsg;
|
public readonly MsgChatMessage ChatMsg;
|
||||||
|
public readonly EntityUid? RadioSource;
|
||||||
|
|
||||||
public RadioReceiveEvent(string message, EntityUid source, RadioChannelPrototype channel, MsgChatMessage chatMsg)
|
public RadioReceiveEvent(string message, EntityUid source, RadioChannelPrototype channel, MsgChatMessage chatMsg, EntityUid? radioSource)
|
||||||
{
|
{
|
||||||
Message = message;
|
Message = message;
|
||||||
Source = source;
|
Source = source;
|
||||||
Channel = channel;
|
Channel = channel;
|
||||||
ChatMsg = chatMsg;
|
ChatMsg = chatMsg;
|
||||||
|
RadioSource = radioSource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,11 +26,13 @@ public sealed class RadioReceiveAttemptEvent : CancellableEntityEventArgs
|
|||||||
public readonly string Message;
|
public readonly string Message;
|
||||||
public readonly EntityUid Source;
|
public readonly EntityUid Source;
|
||||||
public readonly RadioChannelPrototype Channel;
|
public readonly RadioChannelPrototype Channel;
|
||||||
|
public readonly EntityUid? RadioSource;
|
||||||
|
|
||||||
public RadioReceiveAttemptEvent(string message, EntityUid source, RadioChannelPrototype channel)
|
public RadioReceiveAttemptEvent(string message, EntityUid source, RadioChannelPrototype channel, EntityUid? radioSource)
|
||||||
{
|
{
|
||||||
Message = message;
|
Message = message;
|
||||||
Source = source;
|
Source = source;
|
||||||
Channel = channel;
|
Channel = channel;
|
||||||
|
RadioSource = radioSource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
73
Content.Server/StationEvents/Events/SolarFlare.cs
Normal file
73
Content.Server/StationEvents/Events/SolarFlare.cs
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
1
Resources/Locale/en-US/radio/radio-event.ftl
Normal file
1
Resources/Locale/en-US/radio/radio-event.ftl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
failed-to-send-message = Failed to send message!
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
station-event-solar-flare-start-announcement = A solar flare has been detected near the station. Some communication channels may not function.
|
||||||
|
station-event-solar-flare-end-announcement = The solar flare ended. Communication channels no longer affected.
|
||||||
@@ -162,6 +162,23 @@
|
|||||||
startAudio:
|
startAudio:
|
||||||
path: /Audio/Announcements/attention.ogg
|
path: /Audio/Announcements/attention.ogg
|
||||||
|
|
||||||
|
- type: gameRule
|
||||||
|
id: SolarFlare
|
||||||
|
config: !type:SolarFlareEventRuleConfiguration
|
||||||
|
id: SolarFlare
|
||||||
|
weight: 10
|
||||||
|
startAnnouncement: station-event-solar-flare-start-announcement
|
||||||
|
endAnnouncement: station-event-solar-flare-end-announcement
|
||||||
|
startAudio:
|
||||||
|
path: /Audio/Announcements/attention.ogg
|
||||||
|
minEndAfter: 120
|
||||||
|
maxEndAfter: 240
|
||||||
|
onlyJamHeadsets: true
|
||||||
|
affectedChannels:
|
||||||
|
- Common
|
||||||
|
- Service
|
||||||
|
lightBreakChance: 0.05
|
||||||
|
|
||||||
- type: gameRule
|
- type: gameRule
|
||||||
id: VentClog
|
id: VentClog
|
||||||
config:
|
config:
|
||||||
|
|||||||
Reference in New Issue
Block a user