Files
tbd-station-14/Content.Server/Vocalization/Systems/RadioVocalizationSystem.cs
Crude Oil 9ebf6a24c4 Parroting Parrots part 1: Help maints! SQUAWK! Maints! (#38243)
* parrots have ears. add poly

* high tech parrot functionality

* adjust times

* add accent to radio message

* don't spam everything all at once probably

* learn about the existence of prob(float)

* actually use Prob(float) correctly

* newline

* add pet spawner for poly

* move chance to talk on radio to component

* missing comment

* minor edits and doc additions

* the reviewerrrrrrr

* parrot can't learn when crit or dead

* increase default memory

* rename poly to polly

* crude way to ignore whispers. chatcode please

* This is Polly. It is set to broadcast over the engineering frequency

* add missing initialize

* add displacement map for parrot ears

* review comments - Errant

* minor things

* large rework

* fix attempting to talk when entity has no channels

* use list of active radios again to track channels

* fix bad return, some comments

* fix long learn cooldown

* minor adjustments

* use FromMinutes

* the voices told me to make these changes

* remove default reassignment

* Review changes

* remove polly's accent

* decouple radio stuff from parrotsystem

* minor stuff

* split vocalization and parroting

* minor review work

* re-add missing check

* add admin verb for clearing parrot messages

* minor action icon update

* oops

* increase icon number text size

* Admin erase parrot messages associated with players

* part 1 beck review

* add whitelist and blacklist for parrots

* Downgrade missing component error to warning

* Add comment

* add some missing comments

* Remove active radio entity tracking, use all inventory slots

* Minor changes

* small review stuff

* review radio stuff

* swap ears displacement to invisible death displacement

* remove syncsprite

* vscode why do yo have to hurt my feelings

* review changes

* use checkboth
2025-07-09 12:04:57 -07:00

99 lines
3.4 KiB
C#

using Content.Server.Chat.Systems;
using Content.Server.Radio.Components;
using Content.Server.Vocalization.Components;
using Content.Shared.Chat;
using Content.Shared.Inventory;
using Content.Shared.Radio;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server.Vocalization.Systems;
/// <summary>
/// RadioVocalizationSystem handles vocalizing things via equipped radios when a VocalizeEvent is fired
/// </summary>
public sealed partial class RadioVocalizationSystem : EntitySystem
{
[Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RadioVocalizerComponent, VocalizeEvent>(OnVocalize);
}
/// <summary>
/// Called whenever an entity with a VocalizerComponent tries to speak
/// </summary>
private void OnVocalize(Entity<RadioVocalizerComponent> entity, ref VocalizeEvent args)
{
if (args.Handled)
return;
// set to handled if we succeed in speaking on the radio
args.Handled = TrySpeakRadio(entity.Owner, args.Message);
}
/// <summary>
/// Selects a random radio channel from all ActiveRadio entities in a given entity's inventory
/// If no channels are found, this returns false and sets channel to an empty string
/// </summary>
private bool TryPickRandomRadioChannel(EntityUid entity, out string channel)
{
HashSet<string> potentialChannels = [];
// we don't have to check if this entity has an inventory. GetHandOrInventoryEntities will not yield anything
// if an entity has no inventory or inventory slots
foreach (var item in _inventory.GetHandOrInventoryEntities(entity))
{
if (!TryComp<ActiveRadioComponent>(item, out var radio))
continue;
potentialChannels.UnionWith(radio.Channels);
}
if (potentialChannels.Count == 0)
{
channel = string.Empty;
return false;
}
channel = _random.Pick(potentialChannels);
return true;
}
/// <summary>
/// Attempts to speak on the radio. Returns false if there is no radio or talking on radio fails somehow
/// </summary>
/// <param name="entity">Entity to try and make speak on the radio</param>
/// <param name="message">Message to speak</param>
private bool TrySpeakRadio(Entity<RadioVocalizerComponent?> entity, string message)
{
if (!Resolve(entity, ref entity.Comp))
return false;
if (!_random.Prob(entity.Comp.RadioAttemptChance))
return false;
if (!TryPickRandomRadioChannel(entity, out var channel))
return false;
var channelPrefix = _proto.Index<RadioChannelPrototype>(channel).KeyCode;
// send a whisper using the radio channel prefix and whatever relevant radio channel character
// along with the message. This is analogous to how radio messages are sent by players
_chat.TrySendInGameICMessage(
entity,
$"{SharedChatSystem.RadioChannelPrefix}{channelPrefix} {message}",
InGameICChatType.Whisper,
ChatTransmitRange.Normal);
return true;
}
}