From 98cdb12b4f492aaa720271aa3242a7bfae240525 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Thu, 11 Aug 2022 18:53:35 -0400 Subject: [PATCH] wielding cleanup (#10525) --- .../Components/WieldableComponent.cs | 3 +- Content.Server/Wieldable/WieldableSystem.cs | 57 +++++++++---------- .../en-US/wieldable/wieldable-component.ftl | 8 ++- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/Content.Server/Wieldable/Components/WieldableComponent.cs b/Content.Server/Wieldable/Components/WieldableComponent.cs index 2966c9e8d8..f54d87e239 100644 --- a/Content.Server/Wieldable/Components/WieldableComponent.cs +++ b/Content.Server/Wieldable/Components/WieldableComponent.cs @@ -12,7 +12,7 @@ namespace Content.Server.Wieldable.Components public SoundSpecifier? WieldSound = new SoundPathSpecifier("/Audio/Effects/thudswoosh.ogg"); [DataField("unwieldSound")] - public SoundSpecifier? UnwieldSound = default!; + public SoundSpecifier? UnwieldSound; /// /// Number of free hands required (excluding the item itself) required @@ -23,6 +23,7 @@ namespace Content.Server.Wieldable.Components public bool Wielded = false; + [DataField("wieldedInhandPrefix")] public string WieldedInhandPrefix = "wielded"; public string? OldInhandPrefix = null; diff --git a/Content.Server/Wieldable/WieldableSystem.cs b/Content.Server/Wieldable/WieldableSystem.cs index 91b15f1ed6..3b322cc12d 100644 --- a/Content.Server/Wieldable/WieldableSystem.cs +++ b/Content.Server/Wieldable/WieldableSystem.cs @@ -10,7 +10,6 @@ using Content.Shared.Interaction.Events; using Content.Shared.Item; using Content.Shared.Popups; using Content.Shared.Verbs; -using Robust.Shared.Audio; using Robust.Shared.Player; using Content.Server.Actions.Events; @@ -23,6 +22,8 @@ namespace Content.Server.Wieldable [Dependency] private readonly HandVirtualItemSystem _virtualItemSystem = default!; [Dependency] private readonly SharedHandsSystem _handsSystem = default!; [Dependency] private readonly SharedItemSystem _itemSystem = default!; + [Dependency] private readonly SharedPopupSystem _popupSystem = default!; + [Dependency] private readonly SharedAudioSystem _audioSystem = default!; public override void Initialize() { @@ -56,7 +57,7 @@ namespace Content.Server.Wieldable // TODO VERBS ICON + localization InteractionVerb verb = new() { - Text = component.Wielded ? "Unwield" : "Wield", + Text = component.Wielded ? Loc.GetString("wieldable-verb-text-unwield") : Loc.GetString("wieldable-verb-text-wield"), Act = component.Wielded ? () => AttemptUnwield(component.Owner, component, args.User) : () => AttemptWield(component.Owner, component, args.User) @@ -81,21 +82,7 @@ namespace Content.Server.Wieldable if (!EntityManager.TryGetComponent(user, out var hands)) { if(!quiet) - user.PopupMessage(Loc.GetString("wieldable-component-no-hands")); - return false; - } - - if (hands.CountFreeHands() - < component.FreeHandsRequired) - { - // TODO FLUENT need function to change 'hands' to 'hand' when there's only 1 required - if (!quiet) - { - user.PopupMessage(Loc.GetString("wieldable-component-not-enough-free-hands", - ("number", component.FreeHandsRequired), - ("item", uid))); - } - + _popupSystem.PopupEntity(Loc.GetString("wieldable-component-no-hands"), user, Filter.Pvs(user)); return false; } @@ -103,10 +90,18 @@ namespace Content.Server.Wieldable if (!_handsSystem.IsHolding(user, uid, out _, hands)) { if (!quiet) - { - user.PopupMessage(Loc.GetString("wieldable-component-not-in-hands", ("item", uid))); - } + _popupSystem.PopupEntity(Loc.GetString("wieldable-component-not-in-hands", ("item", uid)), user, Filter.Pvs(user)); + return false; + } + if (hands.CountFreeHands() < component.FreeHandsRequired) + { + if (!quiet) + { + var message = Loc.GetString("wieldable-component-not-enough-free-hands", + ("number", component.FreeHandsRequired), ("item", uid)); + _popupSystem.PopupEntity(message, user, Filter.Pvs(user)); + } return false; } @@ -122,9 +117,10 @@ namespace Content.Server.Wieldable if (!CanWield(used, component, user)) return; var ev = new BeforeWieldEvent(); - RaiseLocalEvent(used, ev, false); + RaiseLocalEvent(used, ev); - if (ev.Cancelled) return; + if (ev.Cancelled) + return; var doargs = new DoAfterEventArgs( user, @@ -151,7 +147,8 @@ namespace Content.Server.Wieldable var ev = new BeforeUnwieldEvent(); RaiseLocalEvent(used, ev, false); - if (ev.Cancelled) return; + if (ev.Cancelled) + return; var targEv = new ItemUnwieldedEvent(user); var userEv = new UnwieldedItemEvent(used); @@ -178,7 +175,7 @@ namespace Content.Server.Wieldable if (component.WieldSound != null) { - SoundSystem.Play(component.WieldSound.GetSound(), Filter.Pvs(uid), uid); + _audioSystem.PlayPvs(component.WieldSound, uid); } for (var i = 0; i < component.FreeHandsRequired; i++) @@ -186,8 +183,8 @@ namespace Content.Server.Wieldable _virtualItemSystem.TrySpawnVirtualItemInHand(uid, args.User.Value); } - args.User.Value.PopupMessage(Loc.GetString("wieldable-component-successful-wield", - ("item", uid))); + _popupSystem.PopupEntity(Loc.GetString("wieldable-component-successful-wield", + ("item", uid)), args.User.Value, Filter.Pvs(args.User.Value)); } private void OnItemUnwielded(EntityUid uid, WieldableComponent component, ItemUnwieldedEvent args) @@ -207,12 +204,10 @@ namespace Content.Server.Wieldable if (!args.Force) // don't play sound/popup if this was a forced unwield { if (component.UnwieldSound != null) - { - SoundSystem.Play(component.UnwieldSound.GetSound(), Filter.Pvs(uid), uid); - } + _audioSystem.PlayPvs(component.UnwieldSound, uid); - args.User.Value.PopupMessage(Loc.GetString("wieldable-component-failed-wield", - ("item", uid))); + var message = Loc.GetString("wieldable-component-failed-wield", ("item", uid)); + _popupSystem.PopupEntity(message, args.User.Value, Filter.Pvs(args.User.Value)); } _virtualItemSystem.DeleteInHandsMatching(args.User.Value, uid); diff --git a/Resources/Locale/en-US/wieldable/wieldable-component.ftl b/Resources/Locale/en-US/wieldable/wieldable-component.ftl index 1e955875cf..7abffaf6a7 100644 --- a/Resources/Locale/en-US/wieldable/wieldable-component.ftl +++ b/Resources/Locale/en-US/wieldable/wieldable-component.ftl @@ -1,8 +1,14 @@ ### Locale for wielding items; i.e. two-handing them +wieldable-verb-text-wield = Wield +wieldable-verb-text-unwield = Unwield + wieldable-component-successful-wield = You wield { THE($item) }. wieldable-component-failed-wield = You unwield { THE($item) }. wieldable-component-no-hands = You don't have enough hands! -wieldable-component-not-enough-free-hands = You need { $number } free hands to wield { THE($item) }. +wieldable-component-not-enough-free-hands = {$number -> + [one] You need a free hand to wield { THE($item) }. + *[other] You need { $number } free hands to wield { THE($item) }. +} wieldable-component-not-in-hands = { CAPITALIZE(THE($item)) } isn't in your hands!