Replace AdvertiseComponent with DatasetVocalizerComponent (#38887)

* Replace AdvertiseComponent with DatasetVocalizerComponent

* No vocalizing while broken or without power

* Kill AdvertiseComponent/System

* This really shouldn't be here

* xmldoc for VocalizerRequiresPowerComponent

* TryIndex -> Index
This commit is contained in:
Tayrtahn
2025-07-10 14:12:24 -04:00
committed by GitHub
parent a97223bc70
commit ecbff409b6
14 changed files with 231 additions and 271 deletions

View File

@@ -1,4 +1,5 @@
using Content.Server.Chat.Systems;
using Content.Server.Power.Components;
using Content.Server.Vocalization.Components;
using Content.Shared.ActionBlocker;
using Robust.Shared.Random;
@@ -18,6 +19,27 @@ public sealed partial class VocalizationSystem : EntitySystem
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<VocalizerComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<VocalizerRequiresPowerComponent, TryVocalizeEvent>(OnRequiresPowerTryVocalize);
}
private void OnMapInit(Entity<VocalizerComponent> ent, ref MapInitEvent args)
{
ent.Comp.NextVocalizeInterval = _random.Next(ent.Comp.MinVocalizeInterval, ent.Comp.MaxVocalizeInterval);
}
private void OnRequiresPowerTryVocalize(Entity<VocalizerRequiresPowerComponent> ent, ref TryVocalizeEvent args)
{
if (!TryComp<ApcPowerReceiverComponent>(ent, out var receiver))
return;
args.Cancelled |= !receiver.Powered;
}
/// <summary>
/// Try speaking by raising a TryVocalizeEvent
/// This event is passed to systems adding a message to it and setting it to handled
@@ -27,6 +49,10 @@ public sealed partial class VocalizationSystem : EntitySystem
var tryVocalizeEvent = new TryVocalizeEvent();
RaiseLocalEvent(entity.Owner, ref tryVocalizeEvent);
// If the event was cancelled, don't speak
if (tryVocalizeEvent.Cancelled)
return;
// if the event was never handled, return
// this happens if there are no components that trigger systems to add a message to this event
if (!tryVocalizeEvent.Handled)
@@ -60,7 +86,7 @@ public sealed partial class VocalizationSystem : EntitySystem
return;
// send the message
_chat.TrySendInGameICMessage(entity, message, InGameICChatType.Speak, ChatTransmitRange.Normal);
_chat.TrySendInGameICMessage(entity, message, InGameICChatType.Speak, entity.Comp.HideChat ? ChatTransmitRange.HideChat : ChatTransmitRange.Normal);
}
public override void Update(float frameTime)
@@ -99,7 +125,7 @@ public sealed partial class VocalizationSystem : EntitySystem
/// <param name="Message">Message to send, this is null when the event is just fired and should be set by a system</param>
/// <param name="Handled">Whether the message was handled by a system</param>
[ByRefEvent]
public record struct TryVocalizeEvent(string? Message = null, bool Handled = false);
public record struct TryVocalizeEvent(string? Message = null, bool Handled = false, bool Cancelled = false);
/// <summary>
/// Fired when the entity wants to vocalize and has a message. Allows for interception by other systems if the