Refactor actions to be entities with components (#19900)

This commit is contained in:
DrSmugleaf
2023-09-08 18:16:05 -07:00
committed by GitHub
parent e18f731b91
commit c71f97e3a2
210 changed files with 10693 additions and 11714 deletions

View File

@@ -1,7 +1,5 @@
using Content.Server.Actions;
using Content.Server.Popups;
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Xenoarchaeology.XenoArtifacts;
using Robust.Shared.Prototypes;
@@ -12,32 +10,29 @@ public partial class ArtifactSystem
[Dependency] private readonly ActionsSystem _actions = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[ValidatePrototypeId<EntityPrototype>] private const string ArtifactActivateActionId = "ActionArtifactActivate";
/// <summary>
/// Used to add the artifact activation action (hehe), which lets sentient artifacts activate themselves,
/// either through admemery or the sentience effect.
/// </summary>
public void InitializeActions()
{
SubscribeLocalEvent<ArtifactComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<ArtifactComponent, MapInitEvent>(OnStartup);
SubscribeLocalEvent<ArtifactComponent, ComponentRemove>(OnRemove);
SubscribeLocalEvent<ArtifactComponent, ArtifactSelfActivateEvent>(OnSelfActivate);
}
private void OnStartup(EntityUid uid, ArtifactComponent component, ComponentStartup args)
private void OnStartup(EntityUid uid, ArtifactComponent component, MapInitEvent args)
{
if (_prototype.TryIndex<InstantActionPrototype>("ArtifactActivate", out var proto))
{
_actions.AddAction(uid, new InstantAction(proto), null);
}
RandomizeArtifact(uid, component);
_actions.AddAction(uid, Spawn(ArtifactActivateActionId), null);
}
private void OnRemove(EntityUid uid, ArtifactComponent component, ComponentRemove args)
{
if (_prototype.TryIndex<InstantActionPrototype>("ArtifactActivate", out var proto))
{
_actions.RemoveAction(uid, new InstantAction(proto));
}
_actions.RemoveAction(uid, ArtifactActivateActionId);
}
private void OnSelfActivate(EntityUid uid, ArtifactComponent component, ArtifactSelfActivateEvent args)
@@ -52,4 +47,3 @@ public partial class ArtifactSystem
args.Handled = true;
}
}