Fix item actions (#6383)

This commit is contained in:
Leon Friedrich
2022-01-31 20:07:03 +13:00
committed by GitHub
parent 9a9bfda101
commit af13751600
2 changed files with 29 additions and 25 deletions

View File

@@ -178,27 +178,6 @@ namespace Content.Shared.Actions.Components
{ {
GrantOrUpdate(actionType, toggleOn: toggleOn); GrantOrUpdate(actionType, toggleOn: toggleOn);
} }
public void EquippedHand(EntityUid user, Hand hand)
{
// this entity cannot be granted actions if no actions component
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<SharedActionsComponent?>(user, out var actionsComponent))
return;
Holder = user;
HolderActionsComponent = actionsComponent;
IsEquipped = true;
InHand = hand;
GrantOrUpdateAllToHolder();
}
public void UnequippedHand()
{
RevokeAllFromHolder();
Holder = null;
HolderActionsComponent = null;
IsEquipped = false;
InHand = null;
}
} }
/// <summary> /// <summary>

View File

@@ -1,5 +1,6 @@
using Content.Shared.Actions.Components; using Content.Shared.Actions.Components;
using Content.Shared.Hands; using Content.Shared.Hands;
using Content.Shared.Inventory.Events;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using System; using System;
@@ -18,18 +19,42 @@ namespace Content.Shared.Actions
base.Initialize(); base.Initialize();
UpdatesOutsidePrediction = true; UpdatesOutsidePrediction = true;
SubscribeLocalEvent<ItemActionsComponent, UnequippedHandEvent>(OnHandUnequipped); SubscribeLocalEvent<ItemActionsComponent, GotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<ItemActionsComponent, EquippedHandEvent>(OnHandEquipped); 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) 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) public override void Update(float frameTime)