|
| 1 | +using Content.Server.Chat.Systems; |
| 2 | +using Content.Server.Ghost.Components; |
| 3 | +using Content.Shared.Random.Helpers; |
| 4 | +using Robust.Shared.Prototypes; |
| 5 | +using Robust.Shared.Random; |
| 6 | +using Robust.Shared.Timing; |
| 7 | + |
| 8 | +namespace Content.Server.Ghost; |
| 9 | + |
| 10 | +public sealed class SpookySpeakerSystem : EntitySystem |
| 11 | +{ |
| 12 | + [Dependency] private readonly IPrototypeManager _proto = default!; |
| 13 | + [Dependency] private readonly IRobustRandom _random = default!; |
| 14 | + [Dependency] private readonly IGameTiming _timing = default!; |
| 15 | + [Dependency] private readonly ChatSystem _chat = default!; |
| 16 | + |
| 17 | + public override void Initialize() |
| 18 | + { |
| 19 | + base.Initialize(); |
| 20 | + |
| 21 | + SubscribeLocalEvent<SpookySpeakerComponent, GhostBooEvent>(OnGhostBoo); |
| 22 | + } |
| 23 | + |
| 24 | + private void OnGhostBoo(Entity<SpookySpeakerComponent> entity, ref GhostBooEvent args) |
| 25 | + { |
| 26 | + // Only activate sometimes, so groups don't all trigger together |
| 27 | + if (!_random.Prob(entity.Comp.SpeakChance)) |
| 28 | + return; |
| 29 | + |
| 30 | + var curTime = _timing.CurTime; |
| 31 | + // Enforce a delay between messages to prevent spam |
| 32 | + if (curTime < entity.Comp.NextSpeakTime) |
| 33 | + return; |
| 34 | + |
| 35 | + if (!_proto.TryIndex(entity.Comp.MessageSet, out var messages)) |
| 36 | + return; |
| 37 | + |
| 38 | + // Grab a random localized message from the set |
| 39 | + var message = _random.Pick(messages); |
| 40 | + // Chatcode moment: messages starting with '.' are considered radio messages unless prefixed with '>' |
| 41 | + // So this is a stupid trick to make the "...Oooo"-style messages work. |
| 42 | + message = '>' + message; |
| 43 | + // Say the message |
| 44 | + _chat.TrySendInGameICMessage(entity, message, InGameICChatType.Speak, hideChat: true); |
| 45 | + |
| 46 | + // Set the delay for the next message |
| 47 | + entity.Comp.NextSpeakTime = curTime + entity.Comp.Cooldown; |
| 48 | + |
| 49 | + args.Handled = true; |
| 50 | + } |
| 51 | +} |
0 commit comments