using Content.Shared.DoAfter;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Lock;
///
/// Allows locking/unlocking, with access determined by AccessReader
///
[RegisterComponent, NetworkedComponent]
[Access(typeof(LockSystem))]
[AutoGenerateComponentState]
public sealed partial class LockComponent : Component
{
///
/// Whether or not the lock is locked.
///
[DataField("locked"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public bool Locked = true;
///
/// If true, will show verbs to lock and unlock the item. Otherwise, it will not.
///
[DataField, AutoNetworkedField]
public bool ShowLockVerbs = true;
///
/// If true will show examine text.
///
[DataField, AutoNetworkedField]
public bool ShowExamine = true;
///
/// Whether or not the lock is locked by simply clicking.
///
[DataField("lockOnClick"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public bool LockOnClick;
///
/// Whether or not the lock is unlocked by simply clicking.
///
[DataField, AutoNetworkedField]
public bool UnlockOnClick = true;
///
/// Whether or not the lock is locked when used it hand.
///
[DataField, AutoNetworkedField]
public bool LockInHand;
///
/// Whether or not the lock is unlocked when used in hand.
///
[DataField, AutoNetworkedField]
public bool UnlockInHand;
///
/// Whether access requirements should be checked for this lock.
///
[DataField, AutoNetworkedField]
public bool UseAccess = true;
///
/// What readers should be checked to determine if an entity has access.
/// If null, all possible readers are checked.
///
[DataField, AutoNetworkedField]
public LockTypes? CheckedLocks;
///
/// Whether any reader needs to be accessed to operate this lock.
/// By default, all readers need to be able to be accessed.
///
[DataField, AutoNetworkedField]
public bool CheckForAnyReaders;
///
/// The sound played when unlocked.
///
[DataField("unlockingSound"), ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier? UnlockSound = new SoundPathSpecifier("/Audio/Machines/door_lock_off.ogg")
{
Params = AudioParams.Default.WithVolume(-5f),
};
///
/// The sound played when locked.
///
[DataField("lockingSound"), ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier? LockSound = new SoundPathSpecifier("/Audio/Machines/door_lock_on.ogg")
{
Params = AudioParams.Default.WithVolume(-5f)
};
///
/// Whether or not an emag disables it.
///
[DataField]
[AutoNetworkedField]
public bool BreakOnAccessBreaker = true;
///
/// Amount of do-after time needed to lock the entity.
///
///
/// If set to zero, no do-after will be used.
///
[DataField]
[AutoNetworkedField]
public TimeSpan LockTime;
///
/// Amount of do-after time needed to unlock the entity.
///
///
/// If set to zero, no do-after will be used.
///
[DataField]
[AutoNetworkedField]
public TimeSpan UnlockTime;
///
/// Whether this lock can be locked again after being unlocked.
///
[DataField, AutoNetworkedField]
public bool AllowRepeatedLocking = true;
}
///
/// Event raised on the lock when a toggle is attempted.
/// Can be cancelled to prevent it.
///
[ByRefEvent]
public record struct LockToggleAttemptEvent(EntityUid User, bool Silent = false, bool Cancelled = false);
///
/// Event raised on the user when a toggle is attempted.
/// Can be cancelled to prevent it.
///
[ByRefEvent]
public record struct UserLockToggleAttemptEvent(EntityUid Target, bool Silent = false, bool Cancelled = false);
///
/// Event raised on a lock after it has been toggled.
///
[ByRefEvent]
public readonly record struct LockToggledEvent(bool Locked);
///
/// Used to lock a lockable entity that has a lock time configured.
///
///
///
[Serializable, NetSerializable]
public sealed partial class LockDoAfter : DoAfterEvent
{
public override DoAfterEvent Clone()
{
return this;
}
}
///
/// Used to unlock a lockable entity that has an unlock time configured.
///
///
///
[Serializable, NetSerializable]
public sealed partial class UnlockDoAfter : DoAfterEvent
{
public override DoAfterEvent Clone()
{
return this;
}
}
[NetSerializable]
[Serializable]
public enum LockVisuals : byte
{
Locked
}