Add anchorable flags (#25667)

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.
This commit is contained in:
metalgearsloth
2024-02-29 09:00:12 +11:00
committed by GitHub
parent dddec4dcc6
commit 5425742617
4 changed files with 35 additions and 11 deletions

View File

@@ -1,16 +1,21 @@
using Content.Shared.Construction.EntitySystems; using Content.Shared.Construction.EntitySystems;
using Content.Shared.Tools; using Content.Shared.Tools;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Construction.Components namespace Content.Shared.Construction.Components
{ {
[RegisterComponent, Access(typeof(AnchorableSystem))] [RegisterComponent, Access(typeof(AnchorableSystem)), NetworkedComponent, AutoGenerateComponentState]
public sealed partial class AnchorableComponent : Component public sealed partial class AnchorableComponent : Component
{ {
[DataField("tool", customTypeSerializer: typeof(PrototypeIdSerializer<ToolQualityPrototype>))] [DataField]
public string Tool { get; private set; } = "Anchoring"; public ProtoId<ToolQualityPrototype> Tool { get; private set; } = "Anchoring";
[DataField("snap")] [DataField, AutoNetworkedField]
public AnchorableFlags Flags = AnchorableFlags.Anchorable | AnchorableFlags.Unanchorable;
[DataField]
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public bool Snap { get; private set; } = true; public bool Snap { get; private set; } = true;
@@ -18,10 +23,18 @@ namespace Content.Shared.Construction.Components
/// Base delay to use for anchoring. /// Base delay to use for anchoring.
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
[DataField("delay")] [DataField]
public float Delay = 1f; public float Delay = 1f;
} }
[Flags]
public enum AnchorableFlags : byte
{
None = 0,
Anchorable = 1 << 0,
Unanchorable = 1 << 1,
}
public abstract class BaseAnchoredAttemptEvent : CancellableEntityEventArgs public abstract class BaseAnchoredAttemptEvent : CancellableEntityEventArgs
{ {
public EntityUid User { get; } public EntityUid User { get; }

View File

@@ -69,6 +69,9 @@ public sealed partial class AnchorableSystem : EntitySystem
if (!Valid(uid, userUid, usingUid, false)) if (!Valid(uid, userUid, usingUid, false))
return; 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()); _tool.UseTool(usingUid, userUid, uid, anchorable.Delay, usingTool.Qualities, new TryUnanchorCompletedEvent());
} }
@@ -181,16 +184,10 @@ public sealed partial class AnchorableSystem : EntitySystem
if (transform.Anchored) if (transform.Anchored)
{ {
TryUnAnchor(uid, userUid, usingUid, anchorable, transform, usingTool); 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 else
{ {
TryAnchor(uid, userUid, usingUid, anchorable, transform, pullable, usingTool); 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)) if (!Valid(uid, userUid, usingUid, true, anchorable, usingTool))
return; 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) && if (TryComp<PhysicsComponent>(uid, out var anchorBody) &&
!TileFree(transform.Coordinates, anchorBody)) !TileFree(transform.Coordinates, anchorBody))
{ {
@@ -246,6 +246,12 @@ public sealed partial class AnchorableSystem : EntitySystem
if (!Resolve(usingUid, ref usingTool)) if (!Resolve(usingUid, ref usingTool))
return false; return false;
if (anchoring && (anchorable.Flags & AnchorableFlags.Anchorable) == 0x0)
return false;
if (!anchoring && (anchorable.Flags & AnchorableFlags.Unanchorable) == 0x0)
return false;
BaseAnchoredAttemptEvent attempt = BaseAnchoredAttemptEvent attempt =
anchoring ? new AnchorAttemptEvent(userUid, usingUid) : new UnanchorAttemptEvent(userUid, usingUid); anchoring ? new AnchorAttemptEvent(userUid, usingUid) : new UnanchorAttemptEvent(userUid, usingUid);

View File

@@ -6,6 +6,8 @@
components: components:
- type: InteractionOutline - type: InteractionOutline
- type: Anchorable - type: Anchorable
flags:
- Anchorable
- type: CollideOnAnchor - type: CollideOnAnchor
- type: Physics - type: Physics
canCollide: false canCollide: false

View File

@@ -964,6 +964,9 @@
state: request state: request
- map: ["computerLayerKeys"] - map: ["computerLayerKeys"]
state: tech_key state: tech_key
- type: Anchorable
flags:
- Anchorable
- type: CargoPalletConsole - type: CargoPalletConsole
- type: ActivatableUI - type: ActivatableUI
key: enum.CargoPalletConsoleUiKey.Sale key: enum.CargoPalletConsoleUiKey.Sale