nuke minor refactor and fixes (#18100)

* minor nuke refactor, no longer require disk to toggle anchor

* file scope

* fix unanchored prototype

* normal nuke reanchor pro

* somehow fixed everything pro

* !

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-07-17 19:37:33 +00:00
committed by GitHub
parent 99bad20c48
commit 3bdfcbe56d
2 changed files with 557 additions and 554 deletions

View File

@@ -16,22 +16,22 @@ using Robust.Shared.Containers;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Random; using Robust.Shared.Random;
namespace Content.Server.Nuke namespace Content.Server.Nuke;
{
public sealed class NukeSystem : EntitySystem public sealed class NukeSystem : EntitySystem
{ {
[Dependency] private readonly AlertLevelSystem _alertLevel = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly ExplosionSystem _explosions = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!; [Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
[Dependency] private readonly PopupSystem _popups = default!; [Dependency] private readonly PopupSystem _popups = default!;
[Dependency] private readonly ExplosionSystem _explosions = default!; [Dependency] private readonly ServerGlobalSoundSystem _sound = default!;
[Dependency] private readonly AlertLevelSystem _alertLevel = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly ServerGlobalSoundSystem _soundSystem = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!; [Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
/// <summary> /// <summary>
/// Used to calculate when the nuke song should start playing for maximum kino with the nuke sfx /// Used to calculate when the nuke song should start playing for maximum kino with the nuke sfx
@@ -173,19 +173,22 @@ namespace Content.Server.Nuke
private async void OnAnchorButtonPressed(EntityUid uid, NukeComponent component, NukeAnchorMessage args) private async void OnAnchorButtonPressed(EntityUid uid, NukeComponent component, NukeAnchorMessage args)
{ {
if (!component.DiskSlot.HasItem) // malicious client sanity check
return; if (component.Status == NukeStatus.ARMED)
if (!EntityManager.TryGetComponent(uid, out TransformComponent? transform))
return; return;
// manually set transform anchor (bypassing anchorable) // manually set transform anchor (bypassing anchorable)
// todo: it will break pullable system // todo: it will break pullable system
_xformSystem.SetCoordinates(uid, transform, transform.Coordinates.SnapToGrid()); var xform = Transform(uid);
if (transform.Anchored) if (xform.Anchored)
_xformSystem.Unanchor(uid, transform); {
_transform.Unanchor(uid, xform);
}
else else
_xformSystem.AnchorEntity(uid, transform); {
_transform.SetCoordinates(uid, xform, xform.Coordinates.SnapToGrid());
_transform.AnchorEntity(uid, xform);
}
UpdateUserInterface(uid, component); UpdateUserInterface(uid, component);
} }
@@ -287,7 +290,7 @@ namespace Content.Server.Nuke
// should play // should play
if (nuke.RemainingTime <= NukeSongLength + nuke.AlertSoundTime + NukeSongBuffer && !nuke.PlayedNukeSong) if (nuke.RemainingTime <= NukeSongLength + nuke.AlertSoundTime + NukeSongBuffer && !nuke.PlayedNukeSong)
{ {
_soundSystem.DispatchStationEventMusic(uid, nuke.ArmMusic, StationEventMusicType.Nuke); _sound.DispatchStationEventMusic(uid, nuke.ArmMusic, StationEventMusicType.Nuke);
nuke.PlayedNukeSong = true; nuke.PlayedNukeSong = true;
} }
@@ -295,7 +298,7 @@ namespace Content.Server.Nuke
if (nuke.RemainingTime <= nuke.AlertSoundTime && !nuke.PlayedAlertSound) if (nuke.RemainingTime <= nuke.AlertSoundTime && !nuke.PlayedAlertSound)
{ {
nuke.AlertAudioStream = _audio.Play(nuke.AlertSound, Filter.Broadcast(), uid, true); nuke.AlertAudioStream = _audio.Play(nuke.AlertSound, Filter.Broadcast(), uid, true);
_soundSystem.StopStationEventMusic(uid, StationEventMusicType.Nuke); _sound.StopStationEventMusic(uid, StationEventMusicType.Nuke);
nuke.PlayedAlertSound = true; nuke.PlayedAlertSound = true;
} }
@@ -360,9 +363,7 @@ namespace Content.Server.Nuke
if (ui == null) if (ui == null)
return; return;
var anchored = false; var anchored = Transform(uid).Anchored;
if (EntityManager.TryGetComponent(uid, out TransformComponent? transform))
anchored = transform.Anchored;
var allowArm = component.DiskSlot.HasItem && var allowArm = component.DiskSlot.HasItem &&
(component.Status == NukeStatus.AWAIT_ARM || (component.Status == NukeStatus.AWAIT_ARM ||
@@ -457,10 +458,10 @@ namespace Content.Server.Nuke
var sender = Loc.GetString("nuke-component-announcement-sender"); var sender = Loc.GetString("nuke-component-announcement-sender");
_chatSystem.DispatchStationAnnouncement(stationUid ?? uid, announcement, sender, false, null, Color.Red); _chatSystem.DispatchStationAnnouncement(stationUid ?? uid, announcement, sender, false, null, Color.Red);
_soundSystem.PlayGlobalOnStation(uid, _audio.GetSound(component.ArmSound)); _sound.PlayGlobalOnStation(uid, _audio.GetSound(component.ArmSound));
_itemSlots.SetLock(uid, component.DiskSlot, true); _itemSlots.SetLock(uid, component.DiskSlot, true);
_xformSystem.AnchorEntity(uid, nukeXform); _transform.AnchorEntity(uid, nukeXform);
component.Status = NukeStatus.ARMED; component.Status = NukeStatus.ARMED;
UpdateUserInterface(uid, component); UpdateUserInterface(uid, component);
} }
@@ -486,8 +487,8 @@ namespace Content.Server.Nuke
_chatSystem.DispatchStationAnnouncement(uid, announcement, sender, false); _chatSystem.DispatchStationAnnouncement(uid, announcement, sender, false);
component.PlayedNukeSong = false; component.PlayedNukeSong = false;
_soundSystem.PlayGlobalOnStation(uid, _audio.GetSound(component.DisarmSound)); _sound.PlayGlobalOnStation(uid, _audio.GetSound(component.DisarmSound));
_soundSystem.StopStationEventMusic(uid, StationEventMusicType.Nuke); _sound.StopStationEventMusic(uid, StationEventMusicType.Nuke);
// disable sound and reset it // disable sound and reset it
component.PlayedAlertSound = false; component.PlayedAlertSound = false;
@@ -540,8 +541,8 @@ namespace Content.Server.Nuke
OwningStation = transform.GridUid, OwningStation = transform.GridUid,
}); });
_soundSystem.StopStationEventMusic(uid, StationEventMusicType.Nuke); _sound.StopStationEventMusic(uid, StationEventMusicType.Nuke);
EntityManager.DeleteEntity(uid); Del(uid);
} }
/// <summary> /// <summary>
@@ -560,7 +561,7 @@ namespace Content.Server.Nuke
private void DisarmBombDoafter(EntityUid uid, EntityUid user, NukeComponent nuke) private void DisarmBombDoafter(EntityUid uid, EntityUid user, NukeComponent nuke)
{ {
var doafter = new DoAfterArgs(user, nuke.DisarmDoafterLength, new NukeDisarmDoAfterEvent(), uid, target: uid) var doAfter = new DoAfterArgs(user, nuke.DisarmDoafterLength, new NukeDisarmDoAfterEvent(), uid, target: uid)
{ {
BreakOnDamage = true, BreakOnDamage = true,
BreakOnTargetMove = true, BreakOnTargetMove = true,
@@ -568,7 +569,7 @@ namespace Content.Server.Nuke
NeedHand = true NeedHand = true
}; };
if (!_doAfterSystem.TryStartDoAfter(doafter)) if (!_doAfter.TryStartDoAfter(doAfter))
return; return;
_popups.PopupEntity(Loc.GetString("nuke-component-doafter-warning"), user, _popups.PopupEntity(Loc.GetString("nuke-component-doafter-warning"), user,
@@ -589,4 +590,4 @@ namespace Content.Server.Nuke
{ {
} }
}

View File

@@ -63,6 +63,8 @@
components: components:
- type: Transform - type: Transform
anchored: false anchored: false
- type: Physics
bodyType: Dynamic
- type: entity - type: entity
parent: StorageTank parent: StorageTank