Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Co-authored-by: unknown <wainzor1337@gmail.com> Co-authored-by: ScarKy0 <scarky0@onet.eu>
55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using Content.Shared.Inventory;
|
|
|
|
namespace Content.Shared.Actions;
|
|
|
|
/// <summary>
|
|
/// <see cref="ActionGrantComponent"/>
|
|
/// </summary>
|
|
public sealed class ActionGrantSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedActionsSystem _actions = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<ActionGrantComponent, MapInitEvent>(OnMapInit);
|
|
SubscribeLocalEvent<ActionGrantComponent, ComponentShutdown>(OnShutdown);
|
|
SubscribeLocalEvent<ItemActionGrantComponent, GetItemActionsEvent>(OnItemGet);
|
|
}
|
|
|
|
private void OnItemGet(Entity<ItemActionGrantComponent> ent, ref GetItemActionsEvent args)
|
|
{
|
|
|
|
if (!TryComp(ent.Owner, out ActionGrantComponent? grant))
|
|
return;
|
|
|
|
if (ent.Comp.ActiveIfWorn && (args.SlotFlags == null || args.SlotFlags == SlotFlags.POCKET))
|
|
return;
|
|
|
|
foreach (var action in grant.ActionEntities)
|
|
{
|
|
args.AddAction(action);
|
|
}
|
|
}
|
|
|
|
private void OnMapInit(Entity<ActionGrantComponent> ent, ref MapInitEvent args)
|
|
{
|
|
foreach (var action in ent.Comp.Actions)
|
|
{
|
|
EntityUid? actionEnt = null;
|
|
_actions.AddAction(ent.Owner, ref actionEnt, action);
|
|
|
|
if (actionEnt != null)
|
|
ent.Comp.ActionEntities.Add(actionEnt.Value);
|
|
}
|
|
}
|
|
|
|
private void OnShutdown(Entity<ActionGrantComponent> ent, ref ComponentShutdown args)
|
|
{
|
|
foreach (var actionEnt in ent.Comp.ActionEntities)
|
|
{
|
|
_actions.RemoveAction(ent.Owner, actionEnt);
|
|
}
|
|
}
|
|
}
|