* fix: don't run pickup effects on verb creation * review * redundant --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
using Content.Shared.Hands;
|
|
using Content.Shared.Hands.EntitySystems;
|
|
using Content.Shared.Inventory.VirtualItem;
|
|
using Content.Shared.Popups;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Shared.Item;
|
|
|
|
public sealed class MultiHandedItemSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly SharedHandsSystem _hands = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
[Dependency] private readonly SharedVirtualItemSystem _virtualItem = default!;
|
|
|
|
/// <inheritdoc/>
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<MultiHandedItemComponent, GettingPickedUpAttemptEvent>(OnAttemptPickup);
|
|
SubscribeLocalEvent<MultiHandedItemComponent, VirtualItemDeletedEvent>(OnVirtualItemDeleted);
|
|
SubscribeLocalEvent<MultiHandedItemComponent, GotEquippedHandEvent>(OnEquipped);
|
|
SubscribeLocalEvent<MultiHandedItemComponent, GotUnequippedHandEvent>(OnUnequipped);
|
|
}
|
|
|
|
private void OnEquipped(Entity<MultiHandedItemComponent> ent, ref GotEquippedHandEvent args)
|
|
{
|
|
for (var i = 0; i < ent.Comp.HandsNeeded - 1; i++)
|
|
{
|
|
_virtualItem.TrySpawnVirtualItemInHand(ent.Owner, args.User);
|
|
}
|
|
}
|
|
|
|
private void OnUnequipped(Entity<MultiHandedItemComponent> ent, ref GotUnequippedHandEvent args)
|
|
{
|
|
_virtualItem.DeleteInHandsMatching(args.User, ent.Owner);
|
|
}
|
|
|
|
private void OnAttemptPickup(Entity<MultiHandedItemComponent> ent, ref GettingPickedUpAttemptEvent args)
|
|
{
|
|
if (args.Cancelled || _hands.CountFreeHands(args.User) >= ent.Comp.HandsNeeded)
|
|
return;
|
|
|
|
args.Cancel();
|
|
|
|
if (args.ShowPopup)
|
|
_popup.PopupPredictedCursor(
|
|
Loc.GetString("multi-handed-item-pick-up-fail",
|
|
("number", ent.Comp.HandsNeeded - 1),
|
|
("item", ent.Owner)),
|
|
args.User);
|
|
}
|
|
|
|
private void OnVirtualItemDeleted(Entity<MultiHandedItemComponent> ent, ref VirtualItemDeletedEvent args)
|
|
{
|
|
if (args.BlockingEntity != ent.Owner || _timing.ApplyingState)
|
|
return;
|
|
|
|
_hands.TryDrop(args.User, ent.Owner);
|
|
}
|
|
}
|