]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Ranged Holosigns (#25120)
authorPlykiya <58439124+Plykiya@users.noreply.github.com>
Wed, 14 Feb 2024 05:25:59 +0000 (21:25 -0800)
committerGitHub <noreply@github.com>
Wed, 14 Feb 2024 05:25:59 +0000 (00:25 -0500)
* Changed holo signs to be ranged and used on click rather than Z.

* Updated comments

* Failed attempt at ignoring walls

* Getting rid of unused libraries

---------

Co-authored-by: Plykiya <plykiya@protonmail.com>
Content.Server/Holosign/HolosignSystem.cs

index f0fc3bbe142df990bb0b6b0b324394b7a477f771..c52272e957f6bfda32d0671d4dbda08a535d3d31 100644 (file)
@@ -1,19 +1,21 @@
-using Content.Shared.Interaction.Events;\r
 using Content.Shared.Examine;\r
 using Content.Shared.Coordinates.Helpers;\r
 using Content.Server.Power.Components;\r
 using Content.Server.PowerCell;\r
+using Content.Shared.Interaction;\r
 \r
 namespace Content.Server.Holosign;\r
 \r
 public sealed class HolosignSystem : EntitySystem\r
 {\r
     [Dependency] private readonly PowerCellSystem _powerCell = default!;\r
+    [Dependency] private readonly SharedTransformSystem _transform = default!;\r
+\r
 \r
     public override void Initialize()\r
     {\r
         base.Initialize();\r
-        SubscribeLocalEvent<HolosignProjectorComponent, UseInHandEvent>(OnUse);\r
+        SubscribeLocalEvent<HolosignProjectorComponent, BeforeRangedInteractEvent>(OnBeforeInteract);\r
         SubscribeLocalEvent<HolosignProjectorComponent, ExaminedEvent>(OnExamine);\r
     }\r
 \r
@@ -36,16 +38,21 @@ public sealed class HolosignSystem : EntitySystem
         }\r
     }\r
 \r
-    private void OnUse(EntityUid uid, HolosignProjectorComponent component, UseInHandEvent args)\r
+    private void OnBeforeInteract(EntityUid uid, HolosignProjectorComponent component, BeforeRangedInteractEvent args)\r
     {\r
-        if (args.Handled ||\r
-            !_powerCell.TryGetBatteryFromSlot(uid, out var battery) ||\r
-            !battery.TryUseCharge(component.ChargeUse))\r
+\r
+        if (args.Handled\r
+            || !args.CanReach // prevent placing out of range\r
+            || !_powerCell.TryUseCharge(uid, component.ChargeUse) // if no battery or no charge, doesn't work\r
+            )\r
             return;\r
 \r
-        // TODO: Too tired to deal\r
-        var holo = EntityManager.SpawnEntity(component.SignProto, Transform(args.User).Coordinates.SnapToGrid(EntityManager));\r
-        Transform(holo).Anchored = true;\r
+        // places the holographic sign at the click location, snapped to grid.\r
+        // overlapping of the same holo on one tile remains allowed to allow holofan refreshes\r
+        var holoUid = EntityManager.SpawnEntity(component.SignProto, args.ClickLocation.SnapToGrid(EntityManager));\r
+        var xform = Transform(holoUid);\r
+        if (!xform.Anchored)\r
+            _transform.AnchorEntity(holoUid, xform); // anchor to prevent any tempering with (don't know what could even interact with it)\r
 \r
         args.Handled = true;\r
     }\r