Merge branch 'master' into replace-sounds-with-sound-specifier
This commit is contained in:
@@ -38,9 +38,6 @@ namespace Content.Server.Doors.Components
|
||||
[ComponentReference(typeof(SharedDoorComponent))]
|
||||
public class ServerDoorComponent : SharedDoorComponent, IActivate, IInteractUsing, IMapInit
|
||||
{
|
||||
[ComponentDependency]
|
||||
private readonly IDoorCheck? _doorCheck = null;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("board")]
|
||||
private string? _boardPrototype;
|
||||
@@ -67,11 +64,8 @@ namespace Content.Server.Doors.Components
|
||||
_ => throw new ArgumentOutOfRangeException(),
|
||||
};
|
||||
|
||||
if (_doorCheck != null)
|
||||
{
|
||||
_doorCheck.OnStateChange(State);
|
||||
RefreshAutoClose();
|
||||
}
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new DoorStateChangedEvent(State), false);
|
||||
_autoCloseCancelTokenSource?.Cancel();
|
||||
|
||||
Dirty();
|
||||
}
|
||||
@@ -109,7 +103,7 @@ namespace Content.Server.Doors.Components
|
||||
/// Handled in Startup().
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("startOpen")]
|
||||
private bool _startOpen;
|
||||
private bool _startOpen = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the airlock is welded shut. Can be set by the prototype, although this will fail if the door isn't weldable.
|
||||
@@ -143,6 +137,41 @@ namespace Content.Server.Doors.Components
|
||||
[DataField("weldable")]
|
||||
private bool _weldable = true;
|
||||
|
||||
/// <summary>
|
||||
/// Sound to play when the door opens.
|
||||
/// </summary>
|
||||
[DataField("openSound")]
|
||||
public SoundSpecifier? OpenSound;
|
||||
|
||||
/// <summary>
|
||||
/// Sound to play when the door closes.
|
||||
/// </summary>
|
||||
[DataField("closeSound")]
|
||||
public SoundSpecifier? CloseSound;
|
||||
|
||||
/// <summary>
|
||||
/// Sound to play if the door is denied.
|
||||
/// </summary>
|
||||
[DataField("denySound")]
|
||||
public SoundSpecifier? DenySound;
|
||||
|
||||
/// <summary>
|
||||
/// Default time that the door should take to pry open.
|
||||
/// </summary>
|
||||
[DataField("pryTime")]
|
||||
public float PryTime = 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// Minimum interval allowed between deny sounds in milliseconds.
|
||||
/// </summary>
|
||||
[DataField("denySoundMinimumInterval")]
|
||||
public float DenySoundMinimumInterval = 250.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Used to stop people from spamming the deny sound.
|
||||
/// </summary>
|
||||
private TimeSpan LastDenySoundTime = TimeSpan.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the door can currently be welded.
|
||||
/// </summary>
|
||||
@@ -153,6 +182,7 @@ namespace Content.Server.Doors.Components
|
||||
/// </summary>
|
||||
private bool _beingWelded;
|
||||
|
||||
|
||||
//[ViewVariables(VVAccess.ReadWrite)]
|
||||
//[DataField("canCrush")]
|
||||
//private bool _canCrush = true; // TODO implement door crushing
|
||||
@@ -191,7 +221,7 @@ namespace Content.Server.Doors.Components
|
||||
Logger.Warning("{0} prototype loaded with incompatible flags: 'welded' and 'startOpen' are both true.", Owner.Name);
|
||||
return;
|
||||
}
|
||||
QuickOpen();
|
||||
QuickOpen(false);
|
||||
}
|
||||
|
||||
CreateDoorElectronicsBoard();
|
||||
@@ -199,10 +229,10 @@ namespace Content.Server.Doors.Components
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
if (_doorCheck != null && _doorCheck.BlockActivate(eventArgs))
|
||||
{
|
||||
DoorClickShouldActivateEvent ev = new DoorClickShouldActivateEvent(eventArgs);
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, ev, false);
|
||||
if (ev.Handled)
|
||||
return;
|
||||
}
|
||||
|
||||
if (State == DoorState.Open)
|
||||
{
|
||||
@@ -282,12 +312,10 @@ namespace Content.Server.Doors.Components
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(_doorCheck != null)
|
||||
{
|
||||
return _doorCheck.OpenCheck();
|
||||
}
|
||||
|
||||
return true;
|
||||
var ev = new BeforeDoorOpenedEvent();
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, ev, false);
|
||||
return !ev.Cancelled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -304,12 +332,19 @@ namespace Content.Server.Doors.Components
|
||||
_stateChangeCancelTokenSource?.Cancel();
|
||||
_stateChangeCancelTokenSource = new();
|
||||
|
||||
if (OpenSound != null)
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(Owner), OpenSound.GetSound(),
|
||||
AudioParams.Default.WithVolume(-5));
|
||||
}
|
||||
|
||||
Owner.SpawnTimer(OpenTimeOne, async () =>
|
||||
{
|
||||
OnPartialOpen();
|
||||
await Timer.Delay(OpenTimeTwo, _stateChangeCancelTokenSource.Token);
|
||||
|
||||
State = DoorState.Open;
|
||||
RefreshAutoClose();
|
||||
}, _stateChangeCancelTokenSource.Token);
|
||||
}
|
||||
|
||||
@@ -323,7 +358,7 @@ namespace Content.Server.Doors.Components
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new AccessReaderChangeMessage(Owner, false));
|
||||
}
|
||||
|
||||
private void QuickOpen()
|
||||
private void QuickOpen(bool refresh)
|
||||
{
|
||||
if (Occludes && Owner.TryGetComponent(out OccluderComponent? occluder))
|
||||
{
|
||||
@@ -331,6 +366,8 @@ namespace Content.Server.Doors.Components
|
||||
}
|
||||
OnPartialOpen();
|
||||
State = DoorState.Open;
|
||||
if(refresh)
|
||||
RefreshAutoClose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -369,17 +406,19 @@ namespace Content.Server.Doors.Components
|
||||
/// <returns>Boolean describing whether this door can close.</returns>
|
||||
public bool CanCloseGeneric()
|
||||
{
|
||||
if (_doorCheck != null && !_doorCheck.CloseCheck())
|
||||
{
|
||||
var ev = new BeforeDoorClosedEvent();
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, ev, false);
|
||||
if (ev.Cancelled)
|
||||
return false;
|
||||
}
|
||||
|
||||
return !IsSafetyColliding();
|
||||
}
|
||||
|
||||
private bool SafetyCheck()
|
||||
{
|
||||
return (_doorCheck != null && _doorCheck.SafetyCheck()) || _inhibitCrush;
|
||||
var ev = new DoorSafetyEnabledEvent();
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, ev, false);
|
||||
return ev.Safety || _inhibitCrush;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -415,6 +454,13 @@ namespace Content.Server.Doors.Components
|
||||
|
||||
_stateChangeCancelTokenSource?.Cancel();
|
||||
_stateChangeCancelTokenSource = new();
|
||||
|
||||
if (CloseSound != null)
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(Owner), CloseSound.GetSound(),
|
||||
AudioParams.Default.WithVolume(-10));
|
||||
}
|
||||
|
||||
Owner.SpawnTimer(CloseTimeOne, async () =>
|
||||
{
|
||||
// if somebody walked into the door as it was closing, and we don't crush things
|
||||
@@ -507,10 +553,10 @@ namespace Content.Server.Doors.Components
|
||||
|
||||
public void Deny()
|
||||
{
|
||||
if (_doorCheck != null && !_doorCheck.DenyCheck())
|
||||
{
|
||||
var ev = new BeforeDoorDeniedEvent();
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, ev, false);
|
||||
if (ev.Cancelled)
|
||||
return;
|
||||
}
|
||||
|
||||
if (State == DoorState.Open || IsWeldedShut)
|
||||
return;
|
||||
@@ -518,6 +564,25 @@ namespace Content.Server.Doors.Components
|
||||
_stateChangeCancelTokenSource?.Cancel();
|
||||
_stateChangeCancelTokenSource = new();
|
||||
SetAppearance(DoorVisualState.Deny);
|
||||
|
||||
if (DenySound != null)
|
||||
{
|
||||
if (LastDenySoundTime == TimeSpan.Zero)
|
||||
{
|
||||
LastDenySoundTime = _gameTiming.CurTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
var difference = _gameTiming.CurTime - LastDenySoundTime;
|
||||
if (difference < TimeSpan.FromMilliseconds(DenySoundMinimumInterval))
|
||||
return;
|
||||
}
|
||||
|
||||
LastDenySoundTime = _gameTiming.CurTime;
|
||||
SoundSystem.Play(Filter.Pvs(Owner), DenySound.GetSound(),
|
||||
AudioParams.Default.WithVolume(-3));
|
||||
}
|
||||
|
||||
Owner.SpawnTimer(DenyTime, () =>
|
||||
{
|
||||
SetAppearance(DoorVisualState.Closed);
|
||||
@@ -525,19 +590,24 @@ namespace Content.Server.Doors.Components
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the current auto-close timer if there is one. Starts a new one if this is appropriate (i.e. entity has an IDoorCheck component that allows auto-closing).
|
||||
/// Starts a new auto close timer if this is appropriate
|
||||
/// (i.e. event raised is not cancelled).
|
||||
/// </summary>
|
||||
public void RefreshAutoClose()
|
||||
{
|
||||
_autoCloseCancelTokenSource?.Cancel();
|
||||
|
||||
if (State != DoorState.Open || _doorCheck == null || !_doorCheck.AutoCloseCheck())
|
||||
{
|
||||
if (State != DoorState.Open)
|
||||
return;
|
||||
}
|
||||
|
||||
var autoev = new BeforeDoorAutoCloseEvent();
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, autoev, false);
|
||||
if (autoev.Cancelled)
|
||||
return;
|
||||
|
||||
_autoCloseCancelTokenSource = new();
|
||||
|
||||
var realCloseTime = _doorCheck.GetCloseSpeed() ?? AutoCloseDelay;
|
||||
var ev = new DoorGetCloseTimeModifierEvent();
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, ev, false);
|
||||
var realCloseTime = AutoCloseDelay * ev.CloseTimeModifier;
|
||||
|
||||
Owner.SpawnRepeatingTimer(realCloseTime, async () =>
|
||||
{
|
||||
@@ -559,21 +629,18 @@ namespace Content.Server.Doors.Components
|
||||
// for prying doors
|
||||
if (tool.HasQuality(ToolQuality.Prying) && !IsWeldedShut)
|
||||
{
|
||||
var successfulPry = false;
|
||||
var ev = new DoorGetPryTimeModifierEvent();
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, ev, false);
|
||||
|
||||
if (_doorCheck != null)
|
||||
{
|
||||
_doorCheck.OnStartPry(eventArgs);
|
||||
successfulPry = await tool.UseTool(eventArgs.User, Owner,
|
||||
_doorCheck.GetPryTime() ?? 0.5f, ToolQuality.Prying, () => _doorCheck.CanPryCheck(eventArgs));
|
||||
}
|
||||
else
|
||||
{
|
||||
successfulPry = await tool.UseTool(eventArgs.User, Owner, 0.5f, ToolQuality.Prying);
|
||||
}
|
||||
var canEv = new BeforeDoorPryEvent(eventArgs);
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, canEv, false);
|
||||
|
||||
var successfulPry = await tool.UseTool(eventArgs.User, Owner,
|
||||
ev.PryTimeModifier * PryTime, ToolQuality.Prying, () => !canEv.Cancelled);
|
||||
|
||||
if (successfulPry && !IsWeldedShut)
|
||||
{
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new OnDoorPryEvent(eventArgs), false);
|
||||
if (State == DoorState.Closed)
|
||||
{
|
||||
Open();
|
||||
|
||||
Reference in New Issue
Block a user