Raise hand (un)equipped events on container insert/remove (#15664)
This commit is contained in:
@@ -7,6 +7,25 @@ namespace Content.Shared.Hands.EntitySystems;
|
||||
|
||||
public abstract partial class SharedHandsSystem : EntitySystem
|
||||
{
|
||||
private void InitializeDrop()
|
||||
{
|
||||
SubscribeLocalEvent<HandsComponent, EntRemovedFromContainerMessage>(HandleEntityRemoved);
|
||||
}
|
||||
|
||||
protected virtual void HandleEntityRemoved(EntityUid uid, HandsComponent hands, EntRemovedFromContainerMessage args)
|
||||
{
|
||||
if (!TryGetHand(uid, args.Container.ID, out var hand))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var gotUnequipped = new GotUnequippedHandEvent(uid, args.Entity, hand);
|
||||
RaiseLocalEvent(args.Entity, gotUnequipped, false);
|
||||
|
||||
var didUnequip = new DidUnequipHandEvent(uid, args.Entity, hand);
|
||||
RaiseLocalEvent(uid, didUnequip, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the contents of a hand is able to be removed from its container.
|
||||
/// </summary>
|
||||
@@ -154,12 +173,6 @@ public abstract partial class SharedHandsSystem : EntitySystem
|
||||
if (doDropInteraction)
|
||||
_interactionSystem.DroppedInteraction(uid, entity);
|
||||
|
||||
var gotUnequipped = new GotUnequippedHandEvent(uid, entity, hand);
|
||||
RaiseLocalEvent(entity, gotUnequipped, false);
|
||||
|
||||
var didUnequip = new DidUnequipHandEvent(uid, entity, hand);
|
||||
RaiseLocalEvent(uid, didUnequip, true);
|
||||
|
||||
if (hand == handsComp.ActiveHand)
|
||||
RaiseLocalEvent(entity, new HandDeselectedEvent(uid), false);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ public abstract partial class SharedHandsSystem : EntitySystem
|
||||
base.Initialize();
|
||||
|
||||
InitializeInteractions();
|
||||
InitializeDrop();
|
||||
InitializePickup();
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
|
||||
Reference in New Issue
Block a user