From 28fcc2f84de0e7d3e0abce94fbf200f1fd3703b7 Mon Sep 17 00:00:00 2001 From: RedFoxIV <38788538+RedFoxIV@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:36:06 +0300 Subject: [PATCH 1/2] We don't care if you're low, we will never let you go --- .../SharedHandsSystem.Interactions.cs | 5 ++- .../Interaction/SharedInteractionSystem.cs | 20 ++++++++++- Content.Shared/Verbs/Verb.cs | 11 ++++++ .../Components/WieldableComponent.cs | 6 ++++ Content.Shared/Wieldable/WieldableSystem.cs | 35 ++++++++++++++++++- 5 files changed, 74 insertions(+), 3 deletions(-) diff --git a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Interactions.cs b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Interactions.cs index 6d4d332479..ddeb95d05e 100644 --- a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Interactions.cs +++ b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Interactions.cs @@ -149,7 +149,10 @@ public bool TryUseItemInHand(EntityUid uid, bool altInteract = false, HandsCompo return false; if (altInteract) - return _interactionSystem.AltInteract(uid, held); + if(hand == handsComp.ActiveHand) // WD EDIT START + return _interactionSystem.ActiveHandAltInteract(uid, held) || _interactionSystem.AltInteract(uid, held); // todo: should these be merged into one method? + else // WD EDIT END + return _interactionSystem.AltInteract(uid, held); else return _interactionSystem.UseInHandInteraction(uid, held); } diff --git a/Content.Shared/Interaction/SharedInteractionSystem.cs b/Content.Shared/Interaction/SharedInteractionSystem.cs index 2bc256fd6a..3feac1ab96 100644 --- a/Content.Shared/Interaction/SharedInteractionSystem.cs +++ b/Content.Shared/Interaction/SharedInteractionSystem.cs @@ -1090,7 +1090,7 @@ public bool UseInHandInteraction( public bool AltInteract(EntityUid user, EntityUid target) { // Get list of alt-interact verbs - var verbs = _verbSystem.GetLocalVerbs(target, user, typeof(AlternativeVerb)); + var verbs = _verbSystem.GetLocalVerbs(target, user, typeof(AlternativeVerb)).Where(verb => ((AlternativeVerb) verb).InActiveHandOnly == false); // WD EDIT if (!verbs.Any()) return false; @@ -1098,6 +1098,24 @@ public bool AltInteract(EntityUid user, EntityUid target) _verbSystem.ExecuteVerb(verbs.First(), user, target); return true; } + + // WD EDIT START + /// + /// Very alternative interactions on an entity. + /// + /// True if the interaction was handled, false otherwise. + public bool ActiveHandAltInteract(EntityUid user, EntityUid target) + { + // Get list of alt-interact verbs + var verbs = _verbSystem.GetLocalVerbs(target, user, typeof(AlternativeVerb)).Where(verb => ((AlternativeVerb)verb).InActiveHandOnly == true); + + if (!verbs.Any()) + return false; + + _verbSystem.ExecuteVerb(verbs.First(), user, target); + return true; + } + // WD EDIT END #endregion public void DroppedInteraction(EntityUid user, EntityUid item) diff --git a/Content.Shared/Verbs/Verb.cs b/Content.Shared/Verbs/Verb.cs index 660a3bdf94..4399fcadbd 100644 --- a/Content.Shared/Verbs/Verb.cs +++ b/Content.Shared/Verbs/Verb.cs @@ -310,6 +310,17 @@ public sealed class AlternativeVerb : Verb { public override int TypePriority => 2; public new static string DefaultTextStyleClass = "AlternativeVerb"; + // WD EDIT START + /// + /// If true, this verb can only be triggered by alt-interacting (alt-Z) with the parent item + /// while holding it in the active hand, or via context menu. The latter does not require holding in active hand. + /// + /// + /// On alt-Z, if item returns no with being true, other s will be considered. + /// This is not true for the reverse: alt-clicking an item not in your main hand will not proc an if it's is true. + /// + public bool InActiveHandOnly = false; // todo: better name? + // WD EDIT END public override bool DefaultDoContactInteraction => true; public AlternativeVerb() : base() diff --git a/Content.Shared/Wieldable/Components/WieldableComponent.cs b/Content.Shared/Wieldable/Components/WieldableComponent.cs index 5dc6abbbbe..11830b1264 100644 --- a/Content.Shared/Wieldable/Components/WieldableComponent.cs +++ b/Content.Shared/Wieldable/Components/WieldableComponent.cs @@ -37,6 +37,12 @@ public sealed partial class WieldableComponent : Component public string? WieldedInhandPrefix = "wielded"; public string? OldInhandPrefix = null; + // WD EDIT START + /// + /// Requires item to be alt-used (alt-Z / alt-click in active hand) to be wielded. + /// + public bool AltUseInHand = false; + // WD EDIT END } [Serializable, NetSerializable] diff --git a/Content.Shared/Wieldable/WieldableSystem.cs b/Content.Shared/Wieldable/WieldableSystem.cs index 8dea528985..0a46369787 100644 --- a/Content.Shared/Wieldable/WieldableSystem.cs +++ b/Content.Shared/Wieldable/WieldableSystem.cs @@ -42,6 +42,7 @@ public override void Initialize() SubscribeLocalEvent(OnItemLeaveHand); SubscribeLocalEvent(OnVirtualItemDeleted); SubscribeLocalEvent>(AddToggleWieldVerb); + SubscribeLocalEvent>(AddAltWieldVerb); // WD EDIT SubscribeLocalEvent(OnDeselectWieldable); SubscribeLocalEvent(OnMeleeAttempt); @@ -143,9 +144,41 @@ private void AddToggleWieldVerb(EntityUid uid, WieldableComponent component, Get args.Verbs.Add(verb); } + // WD EDIT START + /// + /// Copypasted + /// + private void AddAltWieldVerb(EntityUid uid, WieldableComponent component, GetVerbsEvent args) + { + if (!component.AltUseInHand) + return; + + if (args.Hands == null || !args.CanAccess || !args.CanInteract) + return; + + if (!_handsSystem.IsHolding(args.User, uid, out _, args.Hands)) + return; + + // TODO VERB TOOLTIPS Make CanWield or some other function return string, set as verb tooltip and disable + // verb. Or just don't add it to the list if the action is not executable. + + // TODO VERBS ICON + AlternativeVerb verb = new() + { + Text = component.Wielded ? Loc.GetString("wieldable-verb-text-unwield") : Loc.GetString("wieldable-verb-text-wield"), + Act = component.Wielded + ? () => TryUnwield(uid, component, args.User) + : () => TryWield(uid, component, args.User), + InActiveHandOnly = true + }; + + args.Verbs.Add(verb); + } + // WD EDIT END + private void OnUseInHand(EntityUid uid, WieldableComponent component, UseInHandEvent args) { - if (args.Handled) + if (args.Handled || component.AltUseInHand) // WD EDIT return; if (!component.Wielded) From 73a773ba8fab23a75bd11f544782c33c5ab2b1dc Mon Sep 17 00:00:00 2001 From: RedFoxIV <38788538+RedFoxIV@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:46:29 +0300 Subject: [PATCH 2/2] :sob: --- Content.Shared/Wieldable/Components/WieldableComponent.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Content.Shared/Wieldable/Components/WieldableComponent.cs b/Content.Shared/Wieldable/Components/WieldableComponent.cs index 11830b1264..46b6463c5a 100644 --- a/Content.Shared/Wieldable/Components/WieldableComponent.cs +++ b/Content.Shared/Wieldable/Components/WieldableComponent.cs @@ -39,8 +39,9 @@ public sealed partial class WieldableComponent : Component public string? OldInhandPrefix = null; // WD EDIT START /// - /// Requires item to be alt-used (alt-Z / alt-click in active hand) to be wielded. + /// Requires item to be alt-used in hand (alt-Z / alt-click in active hand) to be wielded. /// + [DataField] public bool AltUseInHand = false; // WD EDIT END }