Fix guns appearing to cycle bolt when wielded (#28756)
Adds a check during wielding to see if the code is running clientside, and if so skip the part responsible for creating the virtual items. This is necessary because TrySpawnVirtualItem is blocked from running clientside, so trying to spawn the virtual items for wielding causes the client to always believe the wield has failed. This erroneous failure leads to the display of incorrect feedback until the server's successful wield attempt makes it to the client. The added check prevents wielding from failing in this way and therefore allows the client to behave as expected.
This commit is contained in:
@@ -17,6 +17,7 @@ using Content.Shared.Weapons.Ranged.Events;
|
||||
using Content.Shared.Weapons.Ranged.Systems;
|
||||
using Content.Shared.Wieldable.Components;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Wieldable;
|
||||
@@ -32,6 +33,7 @@ public sealed class WieldableSystem : EntitySystem
|
||||
[Dependency] private readonly UseDelaySystem _delay = default!;
|
||||
[Dependency] private readonly SharedGunSystem _gun = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly INetManager _netManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -213,6 +215,11 @@ public sealed class WieldableSystem : EntitySystem
|
||||
if (component.WieldSound != null)
|
||||
_audioSystem.PlayPredicted(component.WieldSound, used, user);
|
||||
|
||||
//This section handles spawning the virtual item(s) to occupy the required additional hand(s).
|
||||
//Since the client can't currently predict entity spawning, only do this if this is running serverside.
|
||||
//Remove this check if TrySpawnVirtualItem in SharedVirtualItemSystem is allowed to complete clientside.
|
||||
if (_netManager.IsServer)
|
||||
{
|
||||
var virtuals = new List<EntityUid>();
|
||||
for (var i = 0; i < component.FreeHandsRequired; i++)
|
||||
{
|
||||
@@ -229,6 +236,7 @@ public sealed class WieldableSystem : EntitySystem
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (TryComp(used, out UseDelayComponent? useDelay)
|
||||
&& !_delay.TryResetDelay((used, useDelay), true))
|
||||
|
||||
Reference in New Issue
Block a user