2021-10-07 13:01:27 +02:00
|
|
|
using Content.Shared.Tools;
|
2021-11-09 08:08:30 +01:00
|
|
|
using Robust.Shared.Analyzers;
|
2019-11-06 17:22:55 +01:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-10-07 13:01:27 +02:00
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
2020-09-08 13:30:22 +02:00
|
|
|
using Robust.Shared.ViewVariables;
|
2019-11-06 17:22:55 +01:00
|
|
|
|
2021-06-19 19:41:26 -07:00
|
|
|
namespace Content.Server.Construction.Components
|
2019-11-06 17:22:55 +01:00
|
|
|
{
|
2021-11-09 08:08:30 +01:00
|
|
|
[RegisterComponent, Friend(typeof(AnchorableSystem))]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class AnchorableComponent : Component
|
2019-11-06 17:22:55 +01:00
|
|
|
{
|
2021-10-07 13:01:27 +02:00
|
|
|
[DataField("tool", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
|
|
|
|
|
public string Tool { get; private set; } = "Anchoring";
|
2020-10-08 17:41:23 +02:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("snap")]
|
2021-11-09 08:08:30 +01:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-04-02 02:29:49 -07:00
|
|
|
public bool Snap { get; private set; } = true;
|
2022-02-07 14:06:11 +11:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Base delay to use for anchoring.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
[DataField("delay")]
|
|
|
|
|
public float Delay = 0.5f;
|
2019-11-06 17:22:55 +01:00
|
|
|
}
|
2021-04-13 13:18:20 +02:00
|
|
|
|
2021-05-16 22:33:21 +02:00
|
|
|
public abstract class BaseAnchoredAttemptEvent : CancellableEntityEventArgs
|
|
|
|
|
{
|
2021-11-09 08:08:30 +01:00
|
|
|
public EntityUid User { get; }
|
|
|
|
|
public EntityUid Tool { get; }
|
2021-04-13 13:18:20 +02:00
|
|
|
|
2021-06-03 09:40:56 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Extra delay to add to the do_after.
|
|
|
|
|
/// Add to this, don't replace it.
|
|
|
|
|
/// Output parameter.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float Delay { get; set; } = 0f;
|
|
|
|
|
|
2021-11-09 08:08:30 +01:00
|
|
|
protected BaseAnchoredAttemptEvent(EntityUid user, EntityUid tool)
|
2021-05-16 22:33:21 +02:00
|
|
|
{
|
|
|
|
|
User = user;
|
|
|
|
|
Tool = tool;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class AnchorAttemptEvent : BaseAnchoredAttemptEvent
|
2021-05-16 22:33:21 +02:00
|
|
|
{
|
2021-11-09 08:08:30 +01:00
|
|
|
public AnchorAttemptEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
|
2021-05-16 22:33:21 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class UnanchorAttemptEvent : BaseAnchoredAttemptEvent
|
2021-05-16 22:33:21 +02:00
|
|
|
{
|
2021-11-09 08:08:30 +01:00
|
|
|
public UnanchorAttemptEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
|
2021-05-16 22:33:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class BaseAnchoredEvent : EntityEventArgs
|
|
|
|
|
{
|
2021-11-09 08:08:30 +01:00
|
|
|
public EntityUid User { get; }
|
|
|
|
|
public EntityUid Tool { get; }
|
2021-05-16 22:33:21 +02:00
|
|
|
|
2021-11-09 08:08:30 +01:00
|
|
|
protected BaseAnchoredEvent(EntityUid user, EntityUid tool)
|
2021-05-16 22:33:21 +02:00
|
|
|
{
|
|
|
|
|
User = user;
|
|
|
|
|
Tool = tool;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-03 09:35:49 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Raised just before the entity's body type is changed.
|
|
|
|
|
/// </summary>
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class BeforeAnchoredEvent : BaseAnchoredEvent
|
2021-06-03 09:35:49 +02:00
|
|
|
{
|
2021-11-09 08:08:30 +01:00
|
|
|
public BeforeAnchoredEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
|
2021-06-03 09:35:49 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-13 06:49:28 +13:00
|
|
|
/// <summary>
|
|
|
|
|
/// Raised when an entity with an anchorable component is anchored. Note that you may instead want the more
|
|
|
|
|
/// general <see cref="AnchorStateChangedEvent"/>. This event has the benefit of having user & tool information,
|
|
|
|
|
/// as a result of interactions mediated by the <see cref="AnchorableSystem"/>.
|
|
|
|
|
/// </summary>
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class UserAnchoredEvent : BaseAnchoredEvent
|
2021-05-16 22:33:21 +02:00
|
|
|
{
|
2022-01-13 06:49:28 +13:00
|
|
|
public UserAnchoredEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
|
2021-05-16 22:33:21 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-03 09:35:49 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Raised just before the entity's body type is changed.
|
|
|
|
|
/// </summary>
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class BeforeUnanchoredEvent : BaseAnchoredEvent
|
2021-06-03 09:35:49 +02:00
|
|
|
{
|
2021-11-09 08:08:30 +01:00
|
|
|
public BeforeUnanchoredEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
|
2021-06-03 09:35:49 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-13 06:49:28 +13:00
|
|
|
/// <summary>
|
|
|
|
|
/// Raised when an entity with an anchorable component is unanchored. Note that you will probably also need to
|
|
|
|
|
/// subscribe to the more general <see cref="AnchorStateChangedEvent"/>, which gets raised BEFORE this one. This
|
|
|
|
|
/// event has the benefit of having user & tool information, whereas the more general event may be due to
|
|
|
|
|
/// explosions or grid-destruction or other interactions not mediated by the <see cref="AnchorableSystem"/>.
|
|
|
|
|
/// </summary>
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class UserUnanchoredEvent : BaseAnchoredEvent
|
2021-05-16 22:33:21 +02:00
|
|
|
{
|
2022-01-13 06:49:28 +13:00
|
|
|
public UserUnanchoredEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
|
2021-05-16 22:33:21 +02:00
|
|
|
}
|
2019-11-06 17:22:55 +01:00
|
|
|
}
|