Verb predict (#5638)
This commit is contained in:
@@ -3,6 +3,7 @@ using Content.Shared.Acts;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
@@ -12,6 +13,7 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
@@ -24,6 +26,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
{
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -174,7 +177,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
if (slot.Item != null)
|
||||
hands.TryPutInAnyHand(slot.Item.Value);
|
||||
|
||||
Insert(uid, slot, args.Used);
|
||||
Insert(uid, slot, args.Used, args.User, true);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
@@ -186,13 +189,32 @@ 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)
|
||||
private void Insert(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user, bool userAudio = false)
|
||||
{
|
||||
slot.ContainerSlot.Insert(item);
|
||||
// ContainerSlot automatically raises a directed EntInsertedIntoContainerMessage
|
||||
|
||||
if (slot.InsertSound != null)
|
||||
SoundSystem.Play(Filter.Pvs(uid), slot.InsertSound.GetSound(), uid, slot.SoundOptions);
|
||||
PlaySound(uid, slot.InsertSound, slot.SoundOptions, userAudio ? null : user);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Plays a sound
|
||||
/// </summary>
|
||||
/// <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>
|
||||
private void PlaySound(EntityUid uid, SoundSpecifier? sound, AudioParams audioParams, EntityUid? excluded)
|
||||
{
|
||||
if (sound == null || !_gameTiming.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
var filter = Filter.Pvs(uid);
|
||||
|
||||
if (excluded != null)
|
||||
filter = filter.RemoveWhereAttachedEntity(entity => entity == excluded.Value);
|
||||
|
||||
SoundSystem.Play(filter, sound.GetSound(), uid, audioParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -228,7 +250,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
/// Tries to insert item into a specific slot.
|
||||
/// </summary>
|
||||
/// <returns>False if failed to insert item</returns>
|
||||
public bool TryInsert(EntityUid uid, string id, EntityUid item, ItemSlotsComponent? itemSlots = null)
|
||||
public bool TryInsert(EntityUid uid, string id, EntityUid item, EntityUid? user, ItemSlotsComponent? itemSlots = null)
|
||||
{
|
||||
if (!Resolve(uid, ref itemSlots))
|
||||
return false;
|
||||
@@ -236,19 +258,19 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
if (!itemSlots.Slots.TryGetValue(id, out var slot))
|
||||
return false;
|
||||
|
||||
return TryInsert(uid, slot, item);
|
||||
return TryInsert(uid, slot, item, user);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to insert item into a specific slot.
|
||||
/// </summary>
|
||||
/// <returns>False if failed to insert item</returns>
|
||||
public bool TryInsert(EntityUid uid, ItemSlot slot, EntityUid item)
|
||||
public bool TryInsert(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user)
|
||||
{
|
||||
if (!CanInsert(uid, item, slot))
|
||||
return false;
|
||||
|
||||
Insert(uid, slot, item);
|
||||
Insert(uid, slot, item, user);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -271,7 +293,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
if (!_actionBlockerSystem.CanInteract(user) && hands.Drop(item))
|
||||
return false;
|
||||
|
||||
Insert(uid, slot, item);
|
||||
Insert(uid, slot, item, user);
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
@@ -281,20 +303,19 @@ 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)
|
||||
private void Eject(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user)
|
||||
{
|
||||
slot.ContainerSlot.Remove(item);
|
||||
// ContainerSlot automatically raises a directed EntRemovedFromContainerMessage
|
||||
|
||||
if (slot.EjectSound != null)
|
||||
SoundSystem.Play(Filter.Pvs(uid), slot.EjectSound.GetSound(), uid, slot.SoundOptions);
|
||||
PlaySound(uid, slot.EjectSound, slot.SoundOptions, user);
|
||||
}
|
||||
|
||||
/// <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, [NotNullWhen(true)] out EntityUid? item)
|
||||
public bool TryEject(EntityUid uid, ItemSlot slot, EntityUid? user, [NotNullWhen(true)] out EntityUid? item)
|
||||
{
|
||||
item = null;
|
||||
|
||||
@@ -302,7 +323,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
return false;
|
||||
|
||||
item = slot.Item;
|
||||
Eject(uid, slot, item.Value);
|
||||
Eject(uid, slot, item.Value, user);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -310,7 +331,8 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
/// Try to eject item from a slot.
|
||||
/// </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, [NotNullWhen(true)] out EntityUid? item, ItemSlotsComponent? itemSlots = null)
|
||||
public bool TryEject(EntityUid uid, string id, EntityUid user,
|
||||
[NotNullWhen(true)] out EntityUid? item, ItemSlotsComponent? itemSlots = null)
|
||||
{
|
||||
item = null;
|
||||
|
||||
@@ -320,7 +342,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
if (!itemSlots.Slots.TryGetValue(id, out var slot))
|
||||
return false;
|
||||
|
||||
return TryEject(uid, slot, out item);
|
||||
return TryEject(uid, slot, user, out item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -333,7 +355,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
/// </returns>
|
||||
public bool TryEjectToHands(EntityUid uid, ItemSlot slot, EntityUid? user)
|
||||
{
|
||||
if (!TryEject(uid, slot, out var item))
|
||||
if (!TryEject(uid, slot, user, out var item))
|
||||
return false;
|
||||
|
||||
if (user != null && EntityManager.TryGetComponent(user.Value, out SharedHandsComponent? hands))
|
||||
@@ -428,7 +450,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);
|
||||
insertVerb.Act = () => Insert(uid, slot, args.Using.Value, args.User);
|
||||
|
||||
if (slot.InsertVerbText != null)
|
||||
{
|
||||
@@ -461,7 +483,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
foreach (var slot in component.Slots.Values)
|
||||
{
|
||||
if (slot.EjectOnBreak && slot.HasItem)
|
||||
TryEject(uid, slot, out var _);
|
||||
TryEject(uid, slot, null, out var _);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user