Fix eject sounds sometimes not playing. (#6013)
This commit is contained in:
@@ -177,7 +177,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
if (slot.Item != null)
|
||||
hands.TryPutInAnyHand(slot.Item.Value);
|
||||
|
||||
Insert(uid, slot, args.Used, args.User, true);
|
||||
Insert(uid, slot, args.Used, args.User);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
@@ -189,12 +189,14 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
/// Insert an item into a slot. This does not perform checks, so make sure to also use <see
|
||||
/// cref="CanInsert"/> or just use <see cref="TryInsert"/> instead.
|
||||
/// </summary>
|
||||
private void Insert(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user, bool userAudio = false)
|
||||
/// <param name="excludeUserAudio">If true, will exclude the user when playing sound. Does nothing client-side.
|
||||
/// Useful for predicted interactions</param>
|
||||
private void Insert(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user, bool excludeUserAudio = false)
|
||||
{
|
||||
slot.ContainerSlot.Insert(item);
|
||||
// ContainerSlot automatically raises a directed EntInsertedIntoContainerMessage
|
||||
|
||||
PlaySound(uid, slot.InsertSound, slot.SoundOptions, userAudio ? null : user);
|
||||
PlaySound(uid, slot.InsertSound, slot.SoundOptions, excludeUserAudio ? user : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -203,7 +205,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
/// <param name="uid">Source of the sound</param>
|
||||
/// <param name="sound">The sound</param>
|
||||
/// <param name="excluded">Optional (server-side) argument used to prevent sending the audio to a specific
|
||||
/// user.</param>
|
||||
/// user. When run client-side, exclusion does nothing.</param>
|
||||
private void PlaySound(EntityUid uid, SoundSpecifier? sound, AudioParams audioParams, EntityUid? excluded)
|
||||
{
|
||||
if (sound == null || !_gameTiming.IsFirstTimePredicted)
|
||||
@@ -304,19 +306,21 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
/// Eject an item into a slot. This does not perform checks (e.g., is the slot locked?), so you should
|
||||
/// probably just use <see cref="TryEject"/> instead.
|
||||
/// </summary>
|
||||
private void Eject(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user)
|
||||
/// <param name="excludeUserAudio">If true, will exclude the user when playing sound. Does nothing client-side.
|
||||
/// Useful for predicted interactions</param>
|
||||
private void Eject(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user, bool excludeUserAudio = false)
|
||||
{
|
||||
slot.ContainerSlot.Remove(item);
|
||||
// ContainerSlot automatically raises a directed EntRemovedFromContainerMessage
|
||||
|
||||
PlaySound(uid, slot.EjectSound, slot.SoundOptions, user);
|
||||
PlaySound(uid, slot.EjectSound, slot.SoundOptions, excludeUserAudio ? user : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to eject an item from a slot.
|
||||
/// </summary>
|
||||
/// <returns>False if item slot is locked or has no item inserted</returns>
|
||||
public bool TryEject(EntityUid uid, ItemSlot slot, EntityUid? user, [NotNullWhen(true)] out EntityUid? item)
|
||||
public bool TryEject(EntityUid uid, ItemSlot slot, EntityUid? user, [NotNullWhen(true)] out EntityUid? item, bool excludeUserAudio = false)
|
||||
{
|
||||
item = null;
|
||||
|
||||
@@ -324,7 +328,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
return false;
|
||||
|
||||
item = slot.Item;
|
||||
Eject(uid, slot, item.Value, user);
|
||||
Eject(uid, slot, item.Value, user, excludeUserAudio);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -333,7 +337,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
/// </summary>
|
||||
/// <returns>False if the id is not valid, the item slot is locked, or it has no item inserted</returns>
|
||||
public bool TryEject(EntityUid uid, string id, EntityUid user,
|
||||
[NotNullWhen(true)] out EntityUid? item, ItemSlotsComponent? itemSlots = null)
|
||||
[NotNullWhen(true)] out EntityUid? item, ItemSlotsComponent? itemSlots = null, bool excludeUserAudio = false)
|
||||
{
|
||||
item = null;
|
||||
|
||||
@@ -343,7 +347,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
if (!itemSlots.Slots.TryGetValue(id, out var slot))
|
||||
return false;
|
||||
|
||||
return TryEject(uid, slot, user, out item);
|
||||
return TryEject(uid, slot, user, out item, excludeUserAudio);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -354,9 +358,9 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
/// False if the id is not valid, the item slot is locked, or it has no item inserted. True otherwise, even
|
||||
/// if the user has no hands.
|
||||
/// </returns>
|
||||
public bool TryEjectToHands(EntityUid uid, ItemSlot slot, EntityUid? user)
|
||||
public bool TryEjectToHands(EntityUid uid, ItemSlot slot, EntityUid? user, bool excludeUserAudio = false)
|
||||
{
|
||||
if (!TryEject(uid, slot, user, out var item))
|
||||
if (!TryEject(uid, slot, user, out var item, excludeUserAudio))
|
||||
return false;
|
||||
|
||||
if (user != null && EntityManager.TryGetComponent(user.Value, out SharedHandsComponent? hands))
|
||||
@@ -390,7 +394,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
: EntityManager.GetComponent<MetaDataComponent>(slot.Item!.Value).EntityName ?? string.Empty;
|
||||
|
||||
Verb verb = new();
|
||||
verb.Act = () => TryEjectToHands(uid, slot, args.User);
|
||||
verb.Act = () => TryEjectToHands(uid, slot, args.User, excludeUserAudio: true);
|
||||
|
||||
if (slot.EjectVerbText == null)
|
||||
{
|
||||
@@ -425,7 +429,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
: EntityManager.GetComponent<MetaDataComponent>(slot.Item!.Value).EntityName ?? string.Empty;
|
||||
|
||||
Verb takeVerb = new();
|
||||
takeVerb.Act = () => TryEjectToHands(uid, slot, args.User);
|
||||
takeVerb.Act = () => TryEjectToHands(uid, slot, args.User, excludeUserAudio: true);
|
||||
takeVerb.IconTexture = "/Textures/Interface/VerbIcons/pickup.svg.192dpi.png";
|
||||
|
||||
if (slot.EjectVerbText == null)
|
||||
@@ -451,7 +455,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
: EntityManager.GetComponent<MetaDataComponent>(args.Using.Value).EntityName ?? string.Empty;
|
||||
|
||||
Verb insertVerb = new();
|
||||
insertVerb.Act = () => Insert(uid, slot, args.Using.Value, args.User);
|
||||
insertVerb.Act = () => Insert(uid, slot, args.Using.Value, args.User, excludeUserAudio: true);
|
||||
|
||||
if (slot.InsertVerbText != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user