ArtifactSystem.Actions.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Content.Server.Actions;
  2. using Content.Server.Popups;
  3. using Content.Shared.Xenoarchaeology.XenoArtifacts;
  4. using Robust.Shared.Prototypes;
  5. namespace Content.Server.Xenoarchaeology.XenoArtifacts;
  6. public partial class ArtifactSystem
  7. {
  8. [Dependency] private readonly ActionsSystem _actions = default!;
  9. [Dependency] private readonly PopupSystem _popup = default!;
  10. [ValidatePrototypeId<EntityPrototype>] private const string ArtifactActivateActionId = "ActionArtifactActivate";
  11. /// <summary>
  12. /// Used to add the artifact activation action (hehe), which lets sentient artifacts activate themselves,
  13. /// either through admemery or the sentience effect.
  14. /// </summary>
  15. public void InitializeActions()
  16. {
  17. SubscribeLocalEvent<ArtifactComponent, MapInitEvent>(OnMapInit);
  18. SubscribeLocalEvent<ArtifactComponent, ComponentRemove>(OnRemove);
  19. SubscribeLocalEvent<ArtifactComponent, ArtifactSelfActivateEvent>(OnSelfActivate);
  20. }
  21. private void OnMapInit(EntityUid uid, ArtifactComponent component, MapInitEvent args)
  22. {
  23. RandomizeArtifact(uid, component);
  24. _actions.AddAction(uid, ref component.ActivateActionEntity, ArtifactActivateActionId);
  25. }
  26. private void OnRemove(EntityUid uid, ArtifactComponent component, ComponentRemove args)
  27. {
  28. _actions.RemoveAction(uid, component.ActivateActionEntity);
  29. }
  30. private void OnSelfActivate(EntityUid uid, ArtifactComponent component, ArtifactSelfActivateEvent args)
  31. {
  32. if (component.CurrentNodeId == null)
  33. return;
  34. var curNode = GetNodeFromId(component.CurrentNodeId.Value, component).Id;
  35. _popup.PopupEntity(Loc.GetString("activate-artifact-popup-self", ("node", curNode)), uid, uid);
  36. TryActivateArtifact(uid, uid, component);
  37. args.Handled = true;
  38. }
  39. }