More hand fixes (#12502)

This commit is contained in:
Leon Friedrich
2022-11-10 14:04:47 +13:00
committed by GitHub
parent 672ece25d0
commit c60c8e6138
3 changed files with 22 additions and 19 deletions

View File

@@ -245,12 +245,7 @@ namespace Content.Client.Hands.Systems
public void UIHandAltActivateItem(string handName) public void UIHandAltActivateItem(string handName)
{ {
if (!TryGetPlayerHands(out var hands) RaisePredictiveEvent(new RequestHandAltInteractEvent(handName));
|| !hands.Hands.TryGetValue(handName, out var hand)
|| hand.HeldEntity is not { Valid: true } entity)
return;
EntityManager.RaisePredictiveEvent(new RequestHandAltInteractEvent(entity));
} }
#region visuals #region visuals

View File

@@ -57,7 +57,7 @@ public abstract partial class SharedHandsSystem : EntitySystem
private void HandleActivateItemInHand(RequestActivateInHandEvent msg, EntitySessionEventArgs args) private void HandleActivateItemInHand(RequestActivateInHandEvent msg, EntitySessionEventArgs args)
{ {
if (args.SenderSession.AttachedEntity != null) if (args.SenderSession.AttachedEntity != null)
TryActivateItemInHand(args.SenderSession.AttachedEntity.Value); TryActivateItemInHand(args.SenderSession.AttachedEntity.Value, null, msg.HandName);
} }
private void HandleInteractUsingInHand(RequestHandInteractUsingEvent msg, EntitySessionEventArgs args) private void HandleInteractUsingInHand(RequestHandInteractUsingEvent msg, EntitySessionEventArgs args)
@@ -69,7 +69,7 @@ public abstract partial class SharedHandsSystem : EntitySystem
private void HandleHandAltInteract(RequestHandAltInteractEvent msg, EntitySessionEventArgs args) private void HandleHandAltInteract(RequestHandAltInteractEvent msg, EntitySessionEventArgs args)
{ {
if (args.SenderSession.AttachedEntity != null) if (args.SenderSession.AttachedEntity != null)
TryUseItemInHand(args.SenderSession.AttachedEntity.Value, true); TryUseItemInHand(args.SenderSession.AttachedEntity.Value, true, handName: msg.HandName);
} }
private void SwapHandsPressed(ICommonSession? session) private void SwapHandsPressed(ICommonSession? session)
@@ -96,15 +96,19 @@ public abstract partial class SharedHandsSystem : EntitySystem
} }
#endregion #endregion
public bool TryActivateItemInHand(EntityUid uid, SharedHandsComponent? handsComp = null) public bool TryActivateItemInHand(EntityUid uid, SharedHandsComponent? handsComp = null, string? handName = null)
{ {
if (!Resolve(uid, ref handsComp, false)) if (!Resolve(uid, ref handsComp, false))
return false; return false;
if (handsComp.ActiveHandEntity == null) Hand? hand;
return false; if (handName == null || !handsComp.Hands.TryGetValue(handName, out hand))
hand = handsComp.ActiveHand;
return _interactionSystem.InteractionActivate(uid, handsComp.ActiveHandEntity.Value); if (hand?.HeldEntity is not { } held)
return false;
return _interactionSystem.InteractionActivate(uid, held);
} }
public bool TryInteractHandWithActiveHand(EntityUid uid, string handName, SharedHandsComponent? handsComp = null) public bool TryInteractHandWithActiveHand(EntityUid uid, string handName, SharedHandsComponent? handsComp = null)
@@ -125,18 +129,22 @@ public abstract partial class SharedHandsSystem : EntitySystem
return true; return true;
} }
public bool TryUseItemInHand(EntityUid uid, bool altInteract = false, SharedHandsComponent? handsComp = null) public bool TryUseItemInHand(EntityUid uid, bool altInteract = false, SharedHandsComponent? handsComp = null, string? handName = null)
{ {
if (!Resolve(uid, ref handsComp, false)) if (!Resolve(uid, ref handsComp, false))
return false; return false;
if (handsComp.ActiveHandEntity == null) Hand? hand;
if (handName == null || !handsComp.Hands.TryGetValue(handName, out hand))
hand = handsComp.ActiveHand;
if (hand?.HeldEntity is not { } held)
return false; return false;
if (altInteract) if (altInteract)
return _interactionSystem.AltInteract(uid, handsComp.ActiveHandEntity.Value); return _interactionSystem.AltInteract(uid, held);
else else
return _interactionSystem.UseInHandInteraction(uid, handsComp.ActiveHandEntity.Value); return _interactionSystem.UseInHandInteraction(uid, held);
} }
/// <summary> /// <summary>

View File

@@ -273,11 +273,11 @@ namespace Content.Shared.Hands
[Serializable, NetSerializable] [Serializable, NetSerializable]
public sealed class RequestHandAltInteractEvent : EntityEventArgs public sealed class RequestHandAltInteractEvent : EntityEventArgs
{ {
public EntityUid Entity { get; } public string HandName { get; }
public RequestHandAltInteractEvent(EntityUid entity) public RequestHandAltInteractEvent(string handName)
{ {
Entity = entity; HandName = handName;
} }
} }