Files
wwdpublic/Content.Server/Announcements/AnnounceCommand.cs
DEATHB4DEFEAT e3bc8d4c0e Random Announcer System (#415)
# Description

Replaces every instance of station announcements with an announcer
system meant to handle audio and messages for various announcers defined
in prototypes instead of each server replacing the scattered files
inconsistently with whatever singular thing they want to hear announce
messages.

# TODO

- [x] Systems
- [x] CVars
- [x] Sounds
- [x] Client volume slider
- [x] Collections
- [x] Prototypes
- [x] Events
- [x] Commands
- [x] PR media
- [x] Deglobalize
- [x] Passthrough localization parameters to overrides
- [x] Make every announcer follow the template
- [x] Move sounds into subdirectories
- [x] Make announcement IDs camelCased
- [x] Test announcement localizations
- [x] Weighted announcer lists

---

<details><summary><h1>Media</h1></summary>
<p>


https://github.com/Simple-Station/Parkstation-Friendly-Chainsaw/assets/77995199/caf5805d-acb0-4140-b344-875a8f79e5ee

</p>
</details>

---

# Changelog

🆑
- add: Added 4 new announcers that will randomly be selected every shift
2024-07-12 16:13:50 -04:00

91 lines
3.6 KiB
C#

using System.Linq;
using Content.Server.Administration;
using Content.Server.Announcements.Systems;
using Content.Shared.Administration;
using Content.Shared.Announcements.Prototypes;
using Robust.Shared.Console;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
namespace Content.Server.Announcements
{
[AdminCommand(AdminFlags.Admin)]
public sealed class AnnounceCommand : IConsoleCommand
{
public string Command => "announce";
public string Description => "Send an in-game announcement.";
public string Help => $"{Command} <sender> <message> <sound> <announcer>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var announcer = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AnnouncerSystem>();
var proto = IoCManager.Resolve<IPrototypeManager>();
switch (args.Length)
{
case 0:
shell.WriteError("Not enough arguments! Need at least 1.");
return;
case 1:
announcer.SendAnnouncement(announcer.GetAnnouncementId("CommandReport"), Filter.Broadcast(),
args[0], "Central Command", Color.Gold);
break;
case 2:
announcer.SendAnnouncement(announcer.GetAnnouncementId("CommandReport"), Filter.Broadcast(),
args[1], args[0], Color.Gold);
break;
case 3:
announcer.SendAnnouncement(announcer.GetAnnouncementId(args[2]), Filter.Broadcast(), args[1],
args[0], Color.Gold);
break;
case 4:
if (!proto.TryIndex(args[3], out AnnouncerPrototype? prototype))
{
shell.WriteError($"No announcer prototype with ID {args[3]} found!");
return;
}
announcer.SendAnnouncement(args[2], Filter.Broadcast(), args[1], args[0], Color.Gold, null,
prototype);
break;
}
shell.WriteLine("Sent!");
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
switch (args.Length)
{
case 3:
{
var list = new List<string>();
foreach (var prototype in IoCManager.Resolve<IPrototypeManager>()
.EnumeratePrototypes<AnnouncerPrototype>()
.SelectMany<AnnouncerPrototype, string>(p => p.Announcements.Select(a => a.ID)))
{
if (!list.Contains(prototype))
list.Add(prototype);
}
return CompletionResult.FromHintOptions(list, Loc.GetString("admin-announce-hint-sound"));
}
case 4:
{
var list = new List<string>();
foreach (var prototype in IoCManager.Resolve<IPrototypeManager>()
.EnumeratePrototypes<AnnouncerPrototype>())
{
if (!list.Contains(prototype.ID))
list.Add(prototype.ID);
}
return CompletionResult.FromHintOptions(list, Loc.GetString("admin-announce-hint-voice"));
}
default:
return CompletionResult.Empty;
}
}
}
}