Fix item actions (#6383)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.Actions.Components;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Robust.Shared.GameObjects;
|
||||
using System;
|
||||
|
||||
@@ -18,18 +19,42 @@ namespace Content.Shared.Actions
|
||||
base.Initialize();
|
||||
|
||||
UpdatesOutsidePrediction = true;
|
||||
SubscribeLocalEvent<ItemActionsComponent, UnequippedHandEvent>(OnHandUnequipped);
|
||||
SubscribeLocalEvent<ItemActionsComponent, GotEquippedEvent>(OnGotEquipped);
|
||||
SubscribeLocalEvent<ItemActionsComponent, EquippedHandEvent>(OnHandEquipped);
|
||||
SubscribeLocalEvent<ItemActionsComponent, UnequippedHandEvent>((uid, comp, _) => OnUnequipped(uid, comp));
|
||||
SubscribeLocalEvent<ItemActionsComponent, GotUnequippedEvent>((uid, comp, _) => OnUnequipped(uid, comp));
|
||||
}
|
||||
|
||||
private void OnGotEquipped(EntityUid uid, ItemActionsComponent component, GotEquippedEvent args)
|
||||
{
|
||||
if (!TryComp(args.Equipee, out SharedActionsComponent? actionsComponent))
|
||||
return;
|
||||
|
||||
component.Holder = args.Equipee;
|
||||
component.HolderActionsComponent = actionsComponent;
|
||||
component.IsEquipped = true;
|
||||
component.GrantOrUpdateAllToHolder();
|
||||
}
|
||||
|
||||
private void OnHandEquipped(EntityUid uid, ItemActionsComponent component, EquippedHandEvent args)
|
||||
{
|
||||
component.EquippedHand(args.User, args.Hand);
|
||||
if (!TryComp(args.User, out SharedActionsComponent? actionsComponent))
|
||||
return;
|
||||
|
||||
component.Holder = args.User;
|
||||
component.HolderActionsComponent = actionsComponent;
|
||||
component.IsEquipped = true;
|
||||
component.InHand = args.Hand;
|
||||
component.GrantOrUpdateAllToHolder();
|
||||
}
|
||||
|
||||
private void OnHandUnequipped(EntityUid uid, ItemActionsComponent component, UnequippedHandEvent args)
|
||||
private void OnUnequipped(EntityUid uid, ItemActionsComponent component)
|
||||
{
|
||||
component.UnequippedHand();
|
||||
component.RevokeAllFromHolder();
|
||||
component.Holder = null;
|
||||
component.HolderActionsComponent = null;
|
||||
component.IsEquipped = false;
|
||||
component.InHand = null;
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
|
||||
Reference in New Issue
Block a user