From 7d08061304de8511980ed02c6d5bb3fb3b80c4af Mon Sep 17 00:00:00 2001
From: Vordenburg <114301317+Vordenburg@users.noreply.github.com>
Date: Sat, 5 Aug 2023 17:28:06 -0400
Subject: [PATCH] Make anchoring nukes require enough nearby floor (#18720)
* Make anchoring nukes require enough nearby floor
* Remove unused Anchorable event subscriptions
The nuke doesn't have Anchorable so this never comes up.
---
Content.Server/Nuke/NukeComponent.cs | 7 +++
Content.Server/Nuke/NukeSystem.cs | 46 ++++++++-----------
.../Locale/en-US/nuke/nuke-component.ftl | 2 +-
3 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/Content.Server/Nuke/NukeComponent.cs b/Content.Server/Nuke/NukeComponent.cs
index 728998af5e..dca093f053 100644
--- a/Content.Server/Nuke/NukeComponent.cs
+++ b/Content.Server/Nuke/NukeComponent.cs
@@ -175,5 +175,12 @@ namespace Content.Server.Nuke
public bool PlayedAlertSound = false;
public IPlayingAudioStream? AlertAudioStream = default;
+
+ ///
+ /// The radius from the nuke for which there must be floor tiles for it to be anchorable.
+ ///
+ [ViewVariables(VVAccess.ReadWrite)]
+ [DataField("requiredFloorRadius")]
+ public float RequiredFloorRadius = 7;
}
}
diff --git a/Content.Server/Nuke/NukeSystem.cs b/Content.Server/Nuke/NukeSystem.cs
index 625c958cde..525503ff37 100644
--- a/Content.Server/Nuke/NukeSystem.cs
+++ b/Content.Server/Nuke/NukeSystem.cs
@@ -5,14 +5,15 @@ using Content.Server.Explosion.EntitySystems;
using Content.Server.Popups;
using Content.Server.Station.Systems;
using Content.Shared.Audio;
-using Content.Shared.Construction.Components;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Coordinates.Helpers;
using Content.Shared.DoAfter;
+using Content.Shared.Maps;
using Content.Shared.Nuke;
using Content.Shared.Popups;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
+using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Random;
@@ -23,7 +24,9 @@ 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 IMapManager _mapManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
+ [Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
[Dependency] private readonly PopupSystem _popups = default!;
[Dependency] private readonly ServerGlobalSoundSystem _sound = default!;
@@ -53,9 +56,6 @@ public sealed class NukeSystem : EntitySystem
SubscribeLocalEvent(OnItemSlotChanged);
SubscribeLocalEvent(OnItemSlotChanged);
- // anchoring logic
- SubscribeLocalEvent(OnAnchorAttempt);
- SubscribeLocalEvent(OnUnanchorAttempt);
// Shouldn't need re-anchoring.
SubscribeLocalEvent(OnAnchorChanged);
@@ -133,28 +133,6 @@ public sealed class NukeSystem : EntitySystem
#region Anchor
- private void OnAnchorAttempt(EntityUid uid, NukeComponent component, AnchorAttemptEvent args)
- {
- CheckAnchorAttempt(uid, component, args);
- }
-
- private void OnUnanchorAttempt(EntityUid uid, NukeComponent component, UnanchorAttemptEvent args)
- {
- CheckAnchorAttempt(uid, component, args);
- }
-
- private void CheckAnchorAttempt(EntityUid uid, NukeComponent component, BaseAnchoredAttemptEvent args)
- {
- // cancel any anchor attempt if armed
- if (component.Status == NukeStatus.ARMED)
- {
- var msg = Loc.GetString("nuke-component-cant-anchor");
- _popups.PopupEntity(msg, uid, args.User);
-
- args.Cancel();
- }
- }
-
private void OnAnchorChanged(EntityUid uid, NukeComponent component, ref AnchorStateChangedEvent args)
{
UpdateUserInterface(uid, component);
@@ -186,6 +164,22 @@ public sealed class NukeSystem : EntitySystem
}
else
{
+ if (!_mapManager.TryGetGrid(xform.GridUid, out var grid))
+ return;
+
+ var worldPos = _transform.GetWorldPosition(xform);
+
+ foreach (var tile in grid.GetTilesIntersecting(new Circle(worldPos, component.RequiredFloorRadius), false))
+ {
+ if (!tile.IsSpace(_tileDefManager))
+ continue;
+
+ var msg = Loc.GetString("nuke-component-cant-anchor-floor");
+ _popups.PopupEntity(msg, uid, args.Session, PopupType.MediumCaution);
+
+ return;
+ }
+
_transform.SetCoordinates(uid, xform, xform.Coordinates.SnapToGrid());
_transform.AnchorEntity(uid, xform);
}
diff --git a/Resources/Locale/en-US/nuke/nuke-component.ftl b/Resources/Locale/en-US/nuke/nuke-component.ftl
index 319fc33e15..92f2675ba6 100644
--- a/Resources/Locale/en-US/nuke/nuke-component.ftl
+++ b/Resources/Locale/en-US/nuke/nuke-component.ftl
@@ -1,4 +1,4 @@
-nuke-component-cant-anchor = The bolts seems to be blocked without disk!
+nuke-component-cant-anchor-floor = The anchoring bolts fail to lock into the floor!
nuke-component-announcement-sender = Nuclear Fission Explosive
nuke-component-announcement-armed = Attention! The station's self-destruct mechanism has been engaged at global coordinates {$position}. {$time} seconds until detonation. If this was made in error, the mechanism may still be disarmed.
nuke-component-announcement-unarmed = The station's self-destruct was deactivated! Have a nice day!