wielding cleanup (#10525)
This commit is contained in:
@@ -12,7 +12,7 @@ namespace Content.Server.Wieldable.Components
|
|||||||
public SoundSpecifier? WieldSound = new SoundPathSpecifier("/Audio/Effects/thudswoosh.ogg");
|
public SoundSpecifier? WieldSound = new SoundPathSpecifier("/Audio/Effects/thudswoosh.ogg");
|
||||||
|
|
||||||
[DataField("unwieldSound")]
|
[DataField("unwieldSound")]
|
||||||
public SoundSpecifier? UnwieldSound = default!;
|
public SoundSpecifier? UnwieldSound;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of free hands required (excluding the item itself) required
|
/// Number of free hands required (excluding the item itself) required
|
||||||
@@ -23,6 +23,7 @@ namespace Content.Server.Wieldable.Components
|
|||||||
|
|
||||||
public bool Wielded = false;
|
public bool Wielded = false;
|
||||||
|
|
||||||
|
[DataField("wieldedInhandPrefix")]
|
||||||
public string WieldedInhandPrefix = "wielded";
|
public string WieldedInhandPrefix = "wielded";
|
||||||
|
|
||||||
public string? OldInhandPrefix = null;
|
public string? OldInhandPrefix = null;
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ using Content.Shared.Interaction.Events;
|
|||||||
using Content.Shared.Item;
|
using Content.Shared.Item;
|
||||||
using Content.Shared.Popups;
|
using Content.Shared.Popups;
|
||||||
using Content.Shared.Verbs;
|
using Content.Shared.Verbs;
|
||||||
using Robust.Shared.Audio;
|
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Content.Server.Actions.Events;
|
using Content.Server.Actions.Events;
|
||||||
|
|
||||||
@@ -23,6 +22,8 @@ namespace Content.Server.Wieldable
|
|||||||
[Dependency] private readonly HandVirtualItemSystem _virtualItemSystem = default!;
|
[Dependency] private readonly HandVirtualItemSystem _virtualItemSystem = default!;
|
||||||
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
||||||
[Dependency] private readonly SharedItemSystem _itemSystem = default!;
|
[Dependency] private readonly SharedItemSystem _itemSystem = default!;
|
||||||
|
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||||
|
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -56,7 +57,7 @@ namespace Content.Server.Wieldable
|
|||||||
// TODO VERBS ICON + localization
|
// TODO VERBS ICON + localization
|
||||||
InteractionVerb verb = new()
|
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
|
Act = component.Wielded
|
||||||
? () => AttemptUnwield(component.Owner, component, args.User)
|
? () => AttemptUnwield(component.Owner, component, args.User)
|
||||||
: () => AttemptWield(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 (!EntityManager.TryGetComponent<HandsComponent>(user, out var hands))
|
||||||
{
|
{
|
||||||
if(!quiet)
|
if(!quiet)
|
||||||
user.PopupMessage(Loc.GetString("wieldable-component-no-hands"));
|
_popupSystem.PopupEntity(Loc.GetString("wieldable-component-no-hands"), user, Filter.Pvs(user));
|
||||||
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)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,10 +90,18 @@ namespace Content.Server.Wieldable
|
|||||||
if (!_handsSystem.IsHolding(user, uid, out _, hands))
|
if (!_handsSystem.IsHolding(user, uid, out _, hands))
|
||||||
{
|
{
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
{
|
_popupSystem.PopupEntity(Loc.GetString("wieldable-component-not-in-hands", ("item", uid)), user, Filter.Pvs(user));
|
||||||
user.PopupMessage(Loc.GetString("wieldable-component-not-in-hands", ("item", uid)));
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,9 +117,10 @@ namespace Content.Server.Wieldable
|
|||||||
if (!CanWield(used, component, user))
|
if (!CanWield(used, component, user))
|
||||||
return;
|
return;
|
||||||
var ev = new BeforeWieldEvent();
|
var ev = new BeforeWieldEvent();
|
||||||
RaiseLocalEvent(used, ev, false);
|
RaiseLocalEvent(used, ev);
|
||||||
|
|
||||||
if (ev.Cancelled) return;
|
if (ev.Cancelled)
|
||||||
|
return;
|
||||||
|
|
||||||
var doargs = new DoAfterEventArgs(
|
var doargs = new DoAfterEventArgs(
|
||||||
user,
|
user,
|
||||||
@@ -151,7 +147,8 @@ namespace Content.Server.Wieldable
|
|||||||
var ev = new BeforeUnwieldEvent();
|
var ev = new BeforeUnwieldEvent();
|
||||||
RaiseLocalEvent(used, ev, false);
|
RaiseLocalEvent(used, ev, false);
|
||||||
|
|
||||||
if (ev.Cancelled) return;
|
if (ev.Cancelled)
|
||||||
|
return;
|
||||||
|
|
||||||
var targEv = new ItemUnwieldedEvent(user);
|
var targEv = new ItemUnwieldedEvent(user);
|
||||||
var userEv = new UnwieldedItemEvent(used);
|
var userEv = new UnwieldedItemEvent(used);
|
||||||
@@ -178,7 +175,7 @@ namespace Content.Server.Wieldable
|
|||||||
|
|
||||||
if (component.WieldSound != null)
|
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++)
|
for (var i = 0; i < component.FreeHandsRequired; i++)
|
||||||
@@ -186,8 +183,8 @@ namespace Content.Server.Wieldable
|
|||||||
_virtualItemSystem.TrySpawnVirtualItemInHand(uid, args.User.Value);
|
_virtualItemSystem.TrySpawnVirtualItemInHand(uid, args.User.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
args.User.Value.PopupMessage(Loc.GetString("wieldable-component-successful-wield",
|
_popupSystem.PopupEntity(Loc.GetString("wieldable-component-successful-wield",
|
||||||
("item", uid)));
|
("item", uid)), args.User.Value, Filter.Pvs(args.User.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnItemUnwielded(EntityUid uid, WieldableComponent component, ItemUnwieldedEvent args)
|
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 (!args.Force) // don't play sound/popup if this was a forced unwield
|
||||||
{
|
{
|
||||||
if (component.UnwieldSound != null)
|
if (component.UnwieldSound != null)
|
||||||
{
|
_audioSystem.PlayPvs(component.UnwieldSound, uid);
|
||||||
SoundSystem.Play(component.UnwieldSound.GetSound(), Filter.Pvs(uid), uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
args.User.Value.PopupMessage(Loc.GetString("wieldable-component-failed-wield",
|
var message = Loc.GetString("wieldable-component-failed-wield", ("item", uid));
|
||||||
("item", uid)));
|
_popupSystem.PopupEntity(message, args.User.Value, Filter.Pvs(args.User.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
_virtualItemSystem.DeleteInHandsMatching(args.User.Value, uid);
|
_virtualItemSystem.DeleteInHandsMatching(args.User.Value, uid);
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
### Locale for wielding items; i.e. two-handing them
|
### 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-successful-wield = You wield { THE($item) }.
|
||||||
wieldable-component-failed-wield = You unwield { THE($item) }.
|
wieldable-component-failed-wield = You unwield { THE($item) }.
|
||||||
wieldable-component-no-hands = You don't have enough hands!
|
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!
|
wieldable-component-not-in-hands = { CAPITALIZE(THE($item)) } isn't in your hands!
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user