mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 21:48:58 +03:00
# 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
95 lines
3.7 KiB
C#
95 lines
3.7 KiB
C#
using Content.Server.Administration.Logs;
|
|
using Content.Server.Chat.Systems;
|
|
using Content.Server.Popups;
|
|
using Content.Shared.Access.Systems;
|
|
using Content.Shared.CCVar;
|
|
using Content.Shared.Chat;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.NukeOps;
|
|
using Content.Shared.UserInterface;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Timing;
|
|
using Content.Server.Announcements.Systems;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Content.Server.NukeOps;
|
|
|
|
/// <summary>
|
|
/// This handles nukeops special war mode declaration device and directly using nukeops game rule
|
|
/// </summary>
|
|
public sealed class WarDeclaratorSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
|
|
[Dependency] private readonly ChatSystem _chat = default!;
|
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
|
[Dependency] private readonly AccessReaderSystem _accessReaderSystem = default!;
|
|
[Dependency] private readonly AnnouncerSystem _announcer = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<WarDeclaratorComponent, MapInitEvent>(OnMapInit);
|
|
|
|
SubscribeLocalEvent<WarDeclaratorComponent, ActivatableUIOpenAttemptEvent>(OnAttemptOpenUI);
|
|
SubscribeLocalEvent<WarDeclaratorComponent, WarDeclaratorActivateMessage>(OnActivated);
|
|
}
|
|
|
|
private void OnMapInit(Entity<WarDeclaratorComponent> ent, ref MapInitEvent args)
|
|
{
|
|
ent.Comp.Message = Loc.GetString("war-declarator-default-message");
|
|
ent.Comp.DisableAt = _gameTiming.CurTime + TimeSpan.FromMinutes(ent.Comp.WarDeclarationDelay);
|
|
}
|
|
|
|
private void OnAttemptOpenUI(Entity<WarDeclaratorComponent> ent, ref ActivatableUIOpenAttemptEvent args)
|
|
{
|
|
if (!_accessReaderSystem.IsAllowed(args.User, ent))
|
|
{
|
|
var msg = Loc.GetString("war-declarator-not-working");
|
|
_popupSystem.PopupEntity(msg, ent);
|
|
args.Cancel();
|
|
return;
|
|
}
|
|
|
|
UpdateUI(ent, ent.Comp.CurrentStatus);
|
|
}
|
|
|
|
private void OnActivated(Entity<WarDeclaratorComponent> ent, ref WarDeclaratorActivateMessage args)
|
|
{
|
|
if (args.Session.AttachedEntity is not {} playerEntity)
|
|
return;
|
|
|
|
var ev = new WarDeclaredEvent(ent.Comp.CurrentStatus, ent);
|
|
RaiseLocalEvent(ref ev);
|
|
|
|
if (ent.Comp.DisableAt < _gameTiming.CurTime)
|
|
ev.Status = WarConditionStatus.NoWarTimeout;
|
|
|
|
ent.Comp.CurrentStatus = ev.Status;
|
|
|
|
var maxLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength);
|
|
var message = SharedChatSystem.SanitizeAnnouncement(args.Message, maxLength);
|
|
if (ent.Comp.AllowEditingMessage && message != string.Empty)
|
|
ent.Comp.Message = message;
|
|
|
|
if (ev.Status == WarConditionStatus.WarReady)
|
|
{
|
|
var title = Loc.GetString(ent.Comp.SenderTitle);
|
|
_announcer.SendAnnouncement("war", Filter.Broadcast(), ent.Comp.Message, title, ent.Comp.Color);
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"{ToPrettyString(playerEntity):player} has declared war with this text: {ent.Comp.Message}");
|
|
}
|
|
|
|
UpdateUI(ent, ev.Status);
|
|
}
|
|
|
|
private void UpdateUI(Entity<WarDeclaratorComponent> ent, WarConditionStatus? status = null)
|
|
{
|
|
_userInterfaceSystem.TrySetUiState(
|
|
ent,
|
|
WarDeclaratorUiKey.Key,
|
|
new WarDeclaratorBoundUserInterfaceState(status, ent.Comp.DisableAt, ent.Comp.ShuttleDisabledTime));
|
|
}
|
|
}
|