Raise hand (un)equipped events on container insert/remove (#15664)

This commit is contained in:
Menshin
2023-04-23 21:38:52 +02:00
committed by GitHub
parent 5272198729
commit c1ef48cee9
7 changed files with 56 additions and 33 deletions

View File

@@ -10,6 +10,25 @@ namespace Content.Shared.Hands.EntitySystems;
public abstract partial class SharedHandsSystem : EntitySystem
{
private void InitializePickup()
{
SubscribeLocalEvent<HandsComponent, EntInsertedIntoContainerMessage>(HandleEntityInserted);
}
protected virtual void HandleEntityInserted(EntityUid uid, HandsComponent hands, EntInsertedIntoContainerMessage args)
{
if (!TryGetHand(uid, args.Container.ID, out var hand))
{
return;
}
var didEquip = new DidEquipHandEvent(uid, args.Entity, hand);
RaiseLocalEvent(uid, didEquip, false);
var gotEquipped = new GotEquippedHandEvent(uid, args.Entity, hand);
RaiseLocalEvent(args.Entity, gotEquipped, false);
}
/// <summary>
/// Maximum pickup distance for which the pickup animation plays.
/// </summary>
@@ -208,17 +227,6 @@ public abstract partial class SharedHandsSystem : EntitySystem
Dirty(hands);
var didEquip = new DidEquipHandEvent(uid, entity, hand);
RaiseLocalEvent(uid, didEquip, false);
var gotEquipped = new GotEquippedHandEvent(uid, entity, hand);
RaiseLocalEvent(entity, gotEquipped, true);
// TODO this should REALLY be a cancellable thing, not a handled event.
// If one of the interactions resulted in the item being dropped, return early.
if (gotEquipped.Handled)
return;
if (hand == hands.ActiveHand)
RaiseLocalEvent(entity, new HandSelectedEvent(uid), false);
}