Nuke fixes (#6868)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Alex Evgrashin
2022-02-24 03:00:51 +03:00
committed by GitHub
parent b5165051f6
commit df970b2283
11 changed files with 97 additions and 91 deletions

View File

@@ -88,6 +88,11 @@ namespace Content.Client.Nuke
secondMsg = Loc.GetString("nuke-user-interface-second-status-time", secondMsg = Loc.GetString("nuke-user-interface-second-status-time",
("time", state.RemainingTime)); ("time", state.RemainingTime));
break; break;
case NukeStatus.COOLDOWN:
firstMsg = Loc.GetString("nuke-user-interface-first-status-device-cooldown");
secondMsg = Loc.GetString("nuke-user-interface-second-status-cooldown-time",
("time", state.CooldownTime));
break;
default: default:
// shouldn't normally be here // shouldn't normally be here
firstMsg = Loc.GetString("nuke-user-interface-status-error"); firstMsg = Loc.GetString("nuke-user-interface-status-error");

View File

@@ -3,9 +3,6 @@ using Content.Server.Administration;
using Content.Shared.Administration; using Content.Shared.Administration;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Console; using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Content.Server.Nuke.Commands namespace Content.Server.Nuke.Commands
{ {

View File

@@ -1,5 +1,3 @@
using Robust.Shared.GameObjects;
namespace Content.Server.Nuke namespace Content.Server.Nuke
{ {
/// <summary> /// <summary>

View File

@@ -1,7 +1,4 @@
using Content.Server.Paper; using Content.Server.Paper;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Content.Server.Nuke namespace Content.Server.Nuke
{ {

View File

@@ -1,9 +1,6 @@
using Content.Server.Chat.Managers; using Content.Server.Chat.Managers;
using Content.Server.Communications; using Content.Server.Communications;
using Content.Shared.GameTicking; using Content.Shared.GameTicking;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Random; using Robust.Shared.Random;
namespace Content.Server.Nuke namespace Content.Server.Nuke
@@ -17,7 +14,7 @@ namespace Content.Server.Nuke
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IChatManager _chat = default!; [Dependency] private readonly IChatManager _chat = default!;
public const int CodeLength = 6; private const int CodeLength = 6;
public string Code { get; private set; } = default!; public string Code { get; private set; } = default!;
public override void Initialize() public override void Initialize()
@@ -47,7 +44,7 @@ namespace Content.Server.Nuke
public void GenerateNewCode() public void GenerateNewCode()
{ {
var ret = ""; var ret = "";
for (int i = 0; i < CodeLength; i++) for (var i = 0; i < CodeLength; i++)
{ {
var c = (char) _random.Next('0', '9' + 1); var c = (char) _random.Next('0', '9' + 1);
ret += c; ret += c;

View File

@@ -1,17 +1,13 @@
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using Content.Shared.Nuke; using Content.Shared.Nuke;
using Content.Shared.Sound; using Content.Shared.Sound;
using Robust.Shared.Analyzers;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Nuke namespace Content.Server.Nuke
{ {
/// <summary> /// <summary>
/// Nuclear device that can devistate an entire station. /// Nuclear device that can devastate an entire station.
/// Basicaly a station self-destruction mechanism. /// Basically a station self-destruction mechanism.
/// To activate it, user needs to insert an authorization disk and enter a secret code. /// To activate it, user needs to insert an authorization disk and enter a secret code.
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
@@ -25,6 +21,13 @@ namespace Content.Server.Nuke
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public int Timer = 180; public int Timer = 180;
/// <summary>
/// How long until the bomb can arm again after deactivation.
/// Used to prevent announcements spam.
/// </summary>
[DataField("cooldown")]
public int Cooldown = 30;
/// <summary> /// <summary>
/// The <see cref="ItemSlot"/> that stores the nuclear disk. The entity whitelist, sounds, and some other /// The <see cref="ItemSlot"/> that stores the nuclear disk. The entity whitelist, sounds, and some other
/// behaviours are specified by this <see cref="ItemSlot"/> definition. Make sure the whitelist, is correct /// behaviours are specified by this <see cref="ItemSlot"/> definition. Make sure the whitelist, is correct
@@ -50,13 +53,13 @@ namespace Content.Server.Nuke
public SoundSpecifier KeypadPressSound = new SoundPathSpecifier("/Audio/Machines/Nuke/general_beep.ogg"); public SoundSpecifier KeypadPressSound = new SoundPathSpecifier("/Audio/Machines/Nuke/general_beep.ogg");
[DataField("accessGrantedSound")] [DataField("accessGrantedSound")]
public SoundSpecifier AccessGrantedSound = new SoundPathSpecifier("/Audio/Machines/Nuke/general_beep.ogg"); public SoundSpecifier AccessGrantedSound = new SoundPathSpecifier("/Audio/Machines/Nuke/confirm_beep.ogg");
[DataField("accessDeniedSound")] [DataField("accessDeniedSound")]
public SoundSpecifier AccessDeniedSound = new SoundPathSpecifier("/Audio/Machines/Nuke/angry_beep.ogg"); public SoundSpecifier AccessDeniedSound = new SoundPathSpecifier("/Audio/Machines/Nuke/angry_beep.ogg");
[DataField("alertSound")] [DataField("alertSound")]
public SoundSpecifier AlertSound = new SoundPathSpecifier("/Audio/Machines/alarm.ogg"); public SoundSpecifier AlertSound = new SoundPathSpecifier("/Audio/Machines/Nuke/nuke_alarm.ogg");
[DataField("armSound")] [DataField("armSound")]
public SoundSpecifier ArmSound = new SoundPathSpecifier("/Audio/Misc/notice1.ogg"); public SoundSpecifier ArmSound = new SoundPathSpecifier("/Audio/Misc/notice1.ogg");
@@ -71,7 +74,13 @@ namespace Content.Server.Nuke
public float RemainingTime; public float RemainingTime;
/// <summary> /// <summary>
/// Curent nuclear code buffer. Entered manually by players. /// Time until bomb cooldown will expire in seconds.
/// </summary>
[ViewVariables]
public float CooldownTime;
/// <summary>
/// Current nuclear code buffer. Entered manually by players.
/// If valid it will allow arm/disarm bomb. /// If valid it will allow arm/disarm bomb.
/// </summary> /// </summary>
[ViewVariables] [ViewVariables]

View File

@@ -1,24 +1,15 @@
using System.Collections.Generic;
using Content.Server.Chat.Managers; using Content.Server.Chat.Managers;
using Content.Server.Construction.Components; using Content.Server.Construction.Components;
using Content.Server.Coordinates.Helpers; using Content.Server.Coordinates.Helpers;
using Content.Server.Popups; using Content.Server.Popups;
using Content.Server.UserInterface; using Content.Server.UserInterface;
using Content.Shared.ActionBlocker;
using Content.Shared.Audio; using Content.Shared.Audio;
using Content.Shared.Body.Components; using Content.Shared.Body.Components;
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Nuke; using Content.Shared.Nuke;
using Content.Shared.Sound; using Content.Shared.Sound;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Player; using Robust.Shared.Player;
namespace Content.Server.Nuke namespace Content.Server.Nuke
@@ -31,14 +22,11 @@ namespace Content.Server.Nuke
[Dependency] private readonly IEntityLookup _lookup = default!; [Dependency] private readonly IEntityLookup _lookup = default!;
[Dependency] private readonly IChatManager _chat = default!; [Dependency] private readonly IChatManager _chat = default!;
private readonly HashSet<EntityUid> _tickingBombs = new();
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<NukeComponent, ComponentInit>(OnInit); SubscribeLocalEvent<NukeComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<NukeComponent, ComponentRemove>(OnRemove); SubscribeLocalEvent<NukeComponent, ComponentRemove>(OnRemove);
SubscribeLocalEvent<NukeComponent, ActivateInWorldEvent>(OnActivate);
SubscribeLocalEvent<NukeComponent, EntInsertedIntoContainerMessage>(OnItemSlotChanged); SubscribeLocalEvent<NukeComponent, EntInsertedIntoContainerMessage>(OnItemSlotChanged);
SubscribeLocalEvent<NukeComponent, EntRemovedFromContainerMessage>(OnItemSlotChanged); SubscribeLocalEvent<NukeComponent, EntRemovedFromContainerMessage>(OnItemSlotChanged);
@@ -68,35 +56,24 @@ namespace Content.Server.Nuke
public override void Update(float frameTime) public override void Update(float frameTime)
{ {
base.Update(frameTime); base.Update(frameTime);
foreach (var uid in _tickingBombs)
var query = EntityQuery<NukeComponent>();
foreach (var nuke in query)
{ {
if (!EntityManager.TryGetComponent(uid, out NukeComponent nuke)) switch (nuke.Status)
continue;
nuke.RemainingTime -= frameTime;
// play alert sound if time is running out
if (nuke.RemainingTime <= nuke.AlertSoundTime && !nuke.PlayedAlertSound)
{ {
nuke.AlertAudioStream = SoundSystem.Play(Filter.Broadcast(), nuke.AlertSound.GetSound()); case NukeStatus.ARMED:
nuke.PlayedAlertSound = true; TickTimer(nuke.Owner, frameTime, nuke);
} break;
case NukeStatus.COOLDOWN:
if (nuke.RemainingTime <= 0) TickCooldown(nuke.Owner, frameTime, nuke);
{ break;
nuke.RemainingTime = 0;
ActivateBomb(uid, nuke);
}
else
{
UpdateUserInterface(uid, nuke);
} }
} }
} }
private void OnRemove(EntityUid uid, NukeComponent component, ComponentRemove args) private void OnRemove(EntityUid uid, NukeComponent component, ComponentRemove args)
{ {
_tickingBombs.Remove(uid);
_itemSlots.RemoveItemSlot(uid, component.DiskSlot); _itemSlots.RemoveItemSlot(uid, component.DiskSlot);
} }
@@ -111,18 +88,6 @@ namespace Content.Server.Nuke
UpdateUserInterface(uid, component); UpdateUserInterface(uid, component);
} }
private void OnActivate(EntityUid uid, NukeComponent component, ActivateInWorldEvent args)
{
if (args.Handled)
return;
if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
return;
ShowUI(uid, actor.PlayerSession, component);
args.Handled = true;
}
#region Anchor #region Anchor
private void OnAnchorAttempt(EntityUid uid, NukeComponent component, AnchorAttemptEvent args) private void OnAnchorAttempt(EntityUid uid, NukeComponent component, AnchorAttemptEvent args)
{ {
@@ -188,7 +153,7 @@ namespace Content.Server.Nuke
private void OnKeypadButtonPressed(EntityUid uid, NukeComponent component, NukeKeypadMessage args) private void OnKeypadButtonPressed(EntityUid uid, NukeComponent component, NukeKeypadMessage args)
{ {
PlaydSound(uid, component.KeypadPressSound, 0.125f, component); PlaySound(uid, component.KeypadPressSound, 0.125f, component);
if (component.Status != NukeStatus.AWAIT_CODE) if (component.Status != NukeStatus.AWAIT_CODE)
return; return;
@@ -202,7 +167,7 @@ namespace Content.Server.Nuke
private void OnClearButtonPressed(EntityUid uid, NukeComponent component, NukeKeypadClearMessage args) private void OnClearButtonPressed(EntityUid uid, NukeComponent component, NukeKeypadClearMessage args)
{ {
PlaydSound(uid, component.KeypadPressSound, 0f, component); PlaySound(uid, component.KeypadPressSound, 0f, component);
if (component.Status != NukeStatus.AWAIT_CODE) if (component.Status != NukeStatus.AWAIT_CODE)
return; return;
@@ -227,6 +192,48 @@ namespace Content.Server.Nuke
} }
#endregion #endregion
private void TickCooldown(EntityUid uid, float frameTime, NukeComponent? nuke = null)
{
if (!Resolve(uid, ref nuke))
return;
nuke.CooldownTime -= frameTime;
if (nuke.CooldownTime <= 0)
{
// reset nuke to default state
nuke.CooldownTime = 0;
nuke.Status = NukeStatus.AWAIT_ARM;
UpdateStatus(uid, nuke);
}
UpdateUserInterface(nuke.Owner, nuke);
}
private void TickTimer(EntityUid uid, float frameTime, NukeComponent? nuke = null)
{
if (!Resolve(uid, ref nuke))
return;
nuke.RemainingTime -= frameTime;
// play alert sound if time is running out
if (nuke.RemainingTime <= nuke.AlertSoundTime && !nuke.PlayedAlertSound)
{
nuke.AlertAudioStream = SoundSystem.Play(Filter.Broadcast(), nuke.AlertSound.GetSound());
nuke.PlayedAlertSound = true;
}
if (nuke.RemainingTime <= 0)
{
nuke.RemainingTime = 0;
ActivateBomb(uid, nuke);
}
else
{
UpdateUserInterface(uid, nuke);
}
}
private void UpdateStatus(EntityUid uid, NukeComponent? component = null) private void UpdateStatus(EntityUid uid, NukeComponent? component = null)
{ {
if (!Resolve(uid, ref component)) if (!Resolve(uid, ref component))
@@ -252,12 +259,12 @@ namespace Content.Server.Nuke
{ {
component.Status = NukeStatus.AWAIT_ARM; component.Status = NukeStatus.AWAIT_ARM;
component.RemainingTime = component.Timer; component.RemainingTime = component.Timer;
PlaydSound(uid, component.AccessGrantedSound, 0, component); PlaySound(uid, component.AccessGrantedSound, 0, component);
} }
else else
{ {
component.EnteredCode = ""; component.EnteredCode = "";
PlaydSound(uid, component.AccessDeniedSound, 0, component); PlaySound(uid, component.AccessDeniedSound, 0, component);
} }
break; break;
} }
@@ -270,17 +277,6 @@ namespace Content.Server.Nuke
} }
} }
private void ShowUI(EntityUid uid, IPlayerSession session, NukeComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
var ui = component.Owner.GetUIOrNull(NukeUiKey.Key);
ui?.Open(session);
UpdateUserInterface(uid, component);
}
private void UpdateUserInterface(EntityUid uid, NukeComponent? component = null) private void UpdateUserInterface(EntityUid uid, NukeComponent? component = null)
{ {
if (!Resolve(uid, ref component)) if (!Resolve(uid, ref component))
@@ -306,20 +302,21 @@ namespace Content.Server.Nuke
IsAnchored = anchored, IsAnchored = anchored,
AllowArm = allowArm, AllowArm = allowArm,
EnteredCodeLength = component.EnteredCode.Length, EnteredCodeLength = component.EnteredCode.Length,
MaxCodeLength = _codes.Code.Length MaxCodeLength = _codes.Code.Length,
CooldownTime = (int) component.CooldownTime
}; };
ui.SetState(state); ui.SetState(state);
} }
private void PlaydSound(EntityUid uid, SoundSpecifier sound, float varyPitch = 0f, private void PlaySound(EntityUid uid, SoundSpecifier sound, float varyPitch = 0f,
NukeComponent? component = null) NukeComponent? component = null)
{ {
if (!Resolve(uid, ref component)) if (!Resolve(uid, ref component))
return; return;
SoundSystem.Play(Filter.Pvs(uid), sound.GetSound(), SoundSystem.Play(Filter.Pvs(uid), sound.GetSound(),
uid, AudioHelpers.WithVariation(varyPitch)); uid, AudioHelpers.WithVariation(varyPitch).WithVolume(-5f));
} }
#region Public API #region Public API
@@ -344,7 +341,6 @@ namespace Content.Server.Nuke
SoundSystem.Play(Filter.Broadcast(), component.ArmSound.GetSound()); SoundSystem.Play(Filter.Broadcast(), component.ArmSound.GetSound());
component.Status = NukeStatus.ARMED; component.Status = NukeStatus.ARMED;
_tickingBombs.Add(uid);
UpdateUserInterface(uid, component); UpdateUserInterface(uid, component);
} }
@@ -371,8 +367,10 @@ namespace Content.Server.Nuke
component.PlayedAlertSound = false; component.PlayedAlertSound = false;
component.AlertAudioStream?.Stop(); component.AlertAudioStream?.Stop();
component.Status = NukeStatus.AWAIT_ARM; // start bomb cooldown
_tickingBombs.Remove(uid); component.Status = NukeStatus.COOLDOWN;
component.CooldownTime = component.Cooldown;
UpdateUserInterface(uid, component); UpdateUserInterface(uid, component);
} }
@@ -407,7 +405,7 @@ namespace Content.Server.Nuke
{ {
var entUid = ent; var entUid = ent;
if (!EntityManager.EntityExists(entUid)) if (!EntityManager.EntityExists(entUid))
continue;; continue;
if (EntityManager.TryGetComponent(entUid, out SharedBodyComponent? body)) if (EntityManager.TryGetComponent(entUid, out SharedBodyComponent? body))
body.Gib(); body.Gib();

View File

@@ -15,7 +15,8 @@ namespace Content.Shared.Nuke
AWAIT_DISK, AWAIT_DISK,
AWAIT_CODE, AWAIT_CODE,
AWAIT_ARM, AWAIT_ARM,
ARMED ARMED,
COOLDOWN
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]
@@ -24,6 +25,7 @@ namespace Content.Shared.Nuke
public bool DiskInserted; public bool DiskInserted;
public NukeStatus Status; public NukeStatus Status;
public int RemainingTime; public int RemainingTime;
public int CooldownTime;
public bool IsAnchored; public bool IsAnchored;
public int EnteredCodeLength; public int EnteredCodeLength;
public int MaxCodeLength; public int MaxCodeLength;

Binary file not shown.

View File

@@ -16,12 +16,13 @@ nuke-user-interface-first-status-input-code = INPUT CODE
nuke-user-interface-first-status-input-time = INPUT TIME nuke-user-interface-first-status-input-time = INPUT TIME
nuke-user-interface-first-status-device-ready = DEVICE READY nuke-user-interface-first-status-device-ready = DEVICE READY
nuke-user-interface-first-status-device-armed = DEVICE ARMED nuke-user-interface-first-status-device-armed = DEVICE ARMED
nuke-user-interface-first-status-device-cooldown = DEACTIVATED
nuke-user-interface-status-error = ERROR nuke-user-interface-status-error = ERROR
## Lower status ## Lower status
nuke-user-interface-second-status-await-disk = AWAIT DISK nuke-user-interface-second-status-await-disk = AWAIT DISK
nuke-user-interface-second-status-time = TIME: {$time} nuke-user-interface-second-status-time = TIME: {$time}
nuke-user-interface-second-status-current-code = CODE: {$code} nuke-user-interface-second-status-current-code = CODE: {$code}
nuke-user-interface-second-status-cooldown-time = WAIT: {$time}

View File

@@ -31,6 +31,8 @@
tags: tags:
- NukeDisk - NukeDisk
- type: InteractionOutline - type: InteractionOutline
- type: ActivatableUI
key: enum.NukeUiKey.Key
- type: UserInterface - type: UserInterface
interfaces: interfaces:
- key: enum.NukeUiKey.Key - key: enum.NukeUiKey.Key