TraversalDistorterSystem.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Content.Server.Popups;
  2. using Content.Server.Power.EntitySystems;
  3. using Content.Server.Xenoarchaeology.Equipment.Components;
  4. using Content.Shared.Examine;
  5. using Content.Shared.Interaction;
  6. using Content.Shared.Placeable;
  7. using Robust.Shared.Timing;
  8. namespace Content.Server.Xenoarchaeology.Equipment.Systems;
  9. public sealed class TraversalDistorterSystem : EntitySystem
  10. {
  11. [Dependency] private readonly IGameTiming _timing = default!;
  12. /// <inheritdoc/>
  13. public override void Initialize()
  14. {
  15. SubscribeLocalEvent<TraversalDistorterComponent, MapInitEvent>(OnInit);
  16. SubscribeLocalEvent<TraversalDistorterComponent, ExaminedEvent>(OnExamine);
  17. SubscribeLocalEvent<TraversalDistorterComponent, ItemPlacedEvent>(OnItemPlaced);
  18. SubscribeLocalEvent<TraversalDistorterComponent, ItemRemovedEvent>(OnItemRemoved);
  19. }
  20. private void OnInit(EntityUid uid, TraversalDistorterComponent component, MapInitEvent args)
  21. {
  22. component.NextActivation = _timing.CurTime;
  23. }
  24. /// <summary>
  25. /// Switches the state of the traversal distorter between up and down.
  26. /// </summary>
  27. /// <param name="uid">The distorter's entity</param>
  28. /// <param name="component">The component on the entity</param>
  29. /// <returns>If the distorter changed state</returns>
  30. public bool SetState(EntityUid uid, TraversalDistorterComponent component, bool isDown)
  31. {
  32. if (!this.IsPowered(uid, EntityManager))
  33. return false;
  34. if (_timing.CurTime < component.NextActivation)
  35. return false;
  36. component.NextActivation = _timing.CurTime + component.ActivationDelay;
  37. component.BiasDirection = isDown ? BiasDirection.Down : BiasDirection.Up;
  38. return true;
  39. }
  40. private void OnExamine(EntityUid uid, TraversalDistorterComponent component, ExaminedEvent args)
  41. {
  42. string examine = string.Empty;
  43. switch (component.BiasDirection)
  44. {
  45. case BiasDirection.Up:
  46. examine = Loc.GetString("traversal-distorter-desc-up");
  47. break;
  48. case BiasDirection.Down:
  49. examine = Loc.GetString("traversal-distorter-desc-down");
  50. break;
  51. }
  52. args.PushMarkup(examine);
  53. }
  54. private void OnItemPlaced(EntityUid uid, TraversalDistorterComponent component, ref ItemPlacedEvent args)
  55. {
  56. var bias = EnsureComp<BiasedArtifactComponent>(args.OtherEntity);
  57. bias.Provider = uid;
  58. }
  59. private void OnItemRemoved(EntityUid uid, TraversalDistorterComponent component, ref ItemRemovedEvent args)
  60. {
  61. var otherEnt = args.OtherEntity;
  62. if (TryComp<BiasedArtifactComponent>(otherEnt, out var bias) && bias.Provider == uid)
  63. RemComp(otherEnt, bias);
  64. }
  65. }