Skip to content

Commit

Permalink
fix: sound
Browse files Browse the repository at this point in the history
  • Loading branch information
Spatison committed Aug 29, 2024
1 parent 833134f commit 64a1286
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
15 changes: 5 additions & 10 deletions Content.Server/Hands/Systems/HandsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public override void Initialize()

SubscribeLocalEvent<HandsComponent, BeforeExplodeEvent>(OnExploded);

CommandBinds.Builder
.Bind(ContentKeyFunctions.ThrowItemInHand, new PointerInputCmdHandler(HandleThrowItem))
.Register<HandsSystem>();
SubscribeLocalEvent<HandsComponent, HandleThrowItemEvent>(OnHandleThrowItem); // WD EDIT
}

public override void Shutdown()
Expand Down Expand Up @@ -163,21 +161,18 @@ private void HandlePullStopped(EntityUid uid, HandsComponent component, PullStop

#region interactions

private bool HandleThrowItem(ICommonSession? playerSession, EntityCoordinates coordinates, EntityUid entity)
private void OnHandleThrowItem(EntityUid uid, HandsComponent component, HandleThrowItemEvent args) // WD EDIT
{
if (playerSession?.AttachedEntity is not {Valid: true} player || !Exists(player))
return false;

return ThrowHeldItem(player, coordinates);
ThrowHeldItem(uid, args.Coordinates, hands:component); // WD EDIT
}

/// <summary>
/// Throw the player's currently held item.
/// </summary>
public bool ThrowHeldItem(EntityUid player, EntityCoordinates coordinates, float minDistance = 0.1f)
public bool ThrowHeldItem(EntityUid player, EntityCoordinates coordinates, float minDistance = 0.1f, HandsComponent? hands = null) // WD EDIT
{
if (ContainerSystem.IsEntityInContainer(player) ||
!TryComp(player, out HandsComponent? hands) ||
!Resolve(player, ref hands) || // WD EDIT
hands.ActiveHandEntity is not { } throwEnt ||
!_actionBlockerSystem.CanThrow(player, throwEnt))
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private void InitializeInteractions()
.Bind(ContentKeyFunctions.AltUseItemInHand, InputCmdHandler.FromDelegate(HandleAltUseInHand, handle: false, outsidePrediction: false))
.Bind(ContentKeyFunctions.SwapHands, InputCmdHandler.FromDelegate(SwapHandsPressed, handle: false, outsidePrediction: false))
.Bind(ContentKeyFunctions.Drop, new PointerInputCmdHandler(DropPressed))
.Bind(ContentKeyFunctions.ThrowItemInHand, new PointerInputCmdHandler(HandleThrowItem)) // WD EDIT
.Register<SharedHandsSystem>();
}

Expand Down Expand Up @@ -100,6 +101,19 @@ private bool DropPressed(ICommonSession? session, EntityCoordinates coords, Enti
// always send to server.
return false;
}

// WD EDIT START
private bool HandleThrowItem(ICommonSession? session, EntityCoordinates coords, EntityUid netEntity)
{
if (session?.AttachedEntity != null && TryComp<HandsComponent>(session.AttachedEntity.Value, out var hands) && hands.ActiveHandEntity != null)
{
RaiseLocalEvent(session.AttachedEntity.Value, new HandleThrowItemEvent(coords));
RaiseLocalEvent(hands.ActiveHandEntity.Value, new ThrowItemEvent(session.AttachedEntity.Value, coords));
}

return false;
}
// WD EDIT END
#endregion

public bool TryActivateItemInHand(EntityUid uid, HandsComponent? handsComp = null, string? handName = null)
Expand Down Expand Up @@ -205,3 +219,16 @@ private void HandleExamined(EntityUid uid, HandsComponent handsComp, ExaminedEve
}
}
}

// WD EDIT START
public struct HandleThrowItemEvent(EntityCoordinates coordinates)
{
public EntityCoordinates Coordinates = coordinates;
}

public struct ThrowItemEvent(EntityUid user, EntityCoordinates coordinates)
{
public EntityUid User = user;
public EntityCoordinates Coordinates = coordinates;
}
// WD EDIT END
3 changes: 0 additions & 3 deletions Content.Shared/Item/ItemToggle/SharedItemToggleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ private void OnIsHotEvent(EntityUid uid, ItemToggleHotComponent itemToggleHot, I
/// </summary>
private void UpdateActiveSound(EntityUid uid, ItemToggleActiveSoundComponent activeSound, ref ItemToggledEvent args)
{
if (_netManager.IsClient) // WD EDIT
return;

if (args.Activated)
{
if (activeSound.ActiveSound != null && activeSound.PlayingStream == null)
Expand Down
9 changes: 9 additions & 0 deletions Content.Shared/Wieldable/WieldableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public override void Initialize()
SubscribeLocalEvent<WieldableComponent, UseInHandEvent>(OnUseInHand, before: [typeof(SharedGunSystem)]);
SubscribeLocalEvent<WieldableComponent, ItemUnwieldedEvent>(OnItemUnwielded);
SubscribeLocalEvent<WieldableComponent, GotUnequippedHandEvent>(OnItemLeaveHand);
SubscribeLocalEvent<WieldableComponent, ThrowItemEvent>(OnThrowItem);
SubscribeLocalEvent<WieldableComponent, VirtualItemDeletedEvent>(OnVirtualItemDeleted);
SubscribeLocalEvent<WieldableComponent, GetVerbsEvent<InteractionVerb>>(AddToggleWieldVerb);

Expand Down Expand Up @@ -261,6 +262,14 @@ private void OnItemLeaveHand(EntityUid uid, WieldableComponent component, GotUne
RaiseLocalEvent(uid, new ItemUnwieldedEvent(args.User, force: true), true);
}

private void OnThrowItem(EntityUid uid, WieldableComponent component, ThrowItemEvent args)
{
if (!component.Wielded)
return;

RaiseLocalEvent(uid, new ItemUnwieldedEvent(args.User, force: true), true);
}

private void OnVirtualItemDeleted(EntityUid uid, WieldableComponent component, VirtualItemDeletedEvent args)
{
if (args.BlockingEntity == uid && component.Wielded)
Expand Down

0 comments on commit 64a1286

Please sign in to comment.