]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add anchorable flags (#25667)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Wed, 28 Feb 2024 22:00:12 +0000 (09:00 +1100)
committerGitHub <noreply@github.com>
Wed, 28 Feb 2024 22:00:12 +0000 (17:00 -0500)
Added it to cargo pallet and the ATS puter. Small steps. Also moved the log until the anchoring is actually confirmed to prevent dummy logs.

Content.Shared/Construction/Components/AnchorableComponent.cs
Content.Shared/Construction/EntitySystems/AnchorableSystem.cs
Resources/Prototypes/Entities/Objects/Specific/Cargo/cargo_pallet.yml
Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml

index 09bb94f465436eb8bb12ce078a4fe1ce16e87b60..064f839efa5601229906beb3ac930b697234a6fb 100644 (file)
@@ -1,16 +1,21 @@
 using Content.Shared.Construction.EntitySystems;
 using Content.Shared.Tools;
+using Robust.Shared.GameStates;
+using Robust.Shared.Prototypes;
 using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
 
 namespace Content.Shared.Construction.Components
 {
-    [RegisterComponent, Access(typeof(AnchorableSystem))]
+    [RegisterComponent, Access(typeof(AnchorableSystem)), NetworkedComponent, AutoGenerateComponentState]
     public sealed partial class AnchorableComponent : Component
     {
-        [DataField("tool", customTypeSerializer: typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
-        public string Tool { get; private set; } = "Anchoring";
+        [DataField]
+        public ProtoId<ToolQualityPrototype> Tool { get; private set; } = "Anchoring";
 
-        [DataField("snap")]
+        [DataField, AutoNetworkedField]
+        public AnchorableFlags Flags = AnchorableFlags.Anchorable | AnchorableFlags.Unanchorable;
+
+        [DataField]
         [ViewVariables(VVAccess.ReadWrite)]
         public bool Snap { get; private set; } = true;
 
@@ -18,10 +23,18 @@ namespace Content.Shared.Construction.Components
         /// Base delay to use for anchoring.
         /// </summary>
         [ViewVariables(VVAccess.ReadWrite)]
-        [DataField("delay")]
+        [DataField]
         public float Delay = 1f;
     }
 
+    [Flags]
+    public enum AnchorableFlags : byte
+    {
+        None = 0,
+        Anchorable = 1 << 0,
+        Unanchorable = 1 << 1,
+    }
+
     public abstract class BaseAnchoredAttemptEvent : CancellableEntityEventArgs
     {
         public EntityUid User { get; }
index b40c04956228211d16b0dff5a3b1d5cb1cd8876a..70bcfbab43f4964b4d1e4c47e8d097ebdcd517fe 100644 (file)
@@ -69,6 +69,9 @@ public sealed partial class AnchorableSystem : EntitySystem
         if (!Valid(uid, userUid, usingUid, false))
             return;
 
+        // Log unanchor attempt (server only)
+        _adminLogger.Add(LogType.Anchor, LogImpact.Low, $"{ToPrettyString(userUid):user} is trying to unanchor {ToPrettyString(uid):entity} from {transform.Coordinates:targetlocation}");
+
         _tool.UseTool(usingUid, userUid, uid, anchorable.Delay, usingTool.Qualities, new TryUnanchorCompletedEvent());
     }
 
@@ -181,16 +184,10 @@ public sealed partial class AnchorableSystem : EntitySystem
         if (transform.Anchored)
         {
             TryUnAnchor(uid, userUid, usingUid, anchorable, transform, usingTool);
-
-            // Log unanchor attempt (server only)
-            _adminLogger.Add(LogType.Anchor, LogImpact.Low, $"{ToPrettyString(userUid):user} is trying to unanchor {ToPrettyString(uid):entity} from {transform.Coordinates:targetlocation}");
         }
         else
         {
             TryAnchor(uid, userUid, usingUid, anchorable, transform, pullable, usingTool);
-
-            // Log anchor attempt (server only)
-            _adminLogger.Add(LogType.Anchor, LogImpact.Low, $"{ToPrettyString(userUid):user} is trying to anchor {ToPrettyString(uid):entity} to {transform.Coordinates:targetlocation}");
         }
     }
 
@@ -216,6 +213,9 @@ public sealed partial class AnchorableSystem : EntitySystem
         if (!Valid(uid, userUid, usingUid, true, anchorable, usingTool))
             return;
 
+        // Log anchor attempt (server only)
+        _adminLogger.Add(LogType.Anchor, LogImpact.Low, $"{ToPrettyString(userUid):user} is trying to anchor {ToPrettyString(uid):entity} to {transform.Coordinates:targetlocation}");
+
         if (TryComp<PhysicsComponent>(uid, out var anchorBody) &&
             !TileFree(transform.Coordinates, anchorBody))
         {
@@ -246,6 +246,12 @@ public sealed partial class AnchorableSystem : EntitySystem
         if (!Resolve(usingUid, ref usingTool))
             return false;
 
+        if (anchoring && (anchorable.Flags & AnchorableFlags.Anchorable) == 0x0)
+            return false;
+
+        if (!anchoring && (anchorable.Flags & AnchorableFlags.Unanchorable) == 0x0)
+            return false;
+
         BaseAnchoredAttemptEvent attempt =
             anchoring ? new AnchorAttemptEvent(userUid, usingUid) : new UnanchorAttemptEvent(userUid, usingUid);
 
index 4802485654f93d085355bb3d65eca912ae1685a5..925e036e09e5feab8a2ddc8f394a8047506a87c8 100644 (file)
@@ -6,6 +6,8 @@
   components:
   - type: InteractionOutline
   - type: Anchorable
+    flags:
+    - Anchorable
   - type: CollideOnAnchor
   - type: Physics
     canCollide: false
index 7ef969140b504acd17a865f6089c78ac70cacf55..c9011ec91f614bd0e3720286b57d88c92b72fb5e 100644 (file)
       state: request
     - map: ["computerLayerKeys"]
       state: tech_key
+  - type: Anchorable
+    flags:
+    - Anchorable
   - type: CargoPalletConsole
   - type: ActivatableUI
     key: enum.CargoPalletConsoleUiKey.Sale