wielding cleanup (#10525)
This commit is contained in:
@@ -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<HandsComponent>(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);
|
||||
|
||||
Reference in New Issue
Block a user