SprayPainterSystem.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Content.Server.Atmos.Piping.Components;
  2. using Content.Server.Atmos.Piping.EntitySystems;
  3. using Content.Shared.DoAfter;
  4. using Content.Shared.Interaction;
  5. using Content.Shared.SprayPainter;
  6. using Content.Shared.SprayPainter.Components;
  7. namespace Content.Server.SprayPainter;
  8. /// <summary>
  9. /// Handles spraying pipes using a spray painter.
  10. /// Airlocks are handled in shared.
  11. /// </summary>
  12. public sealed class SprayPainterSystem : SharedSprayPainterSystem
  13. {
  14. [Dependency] private readonly AtmosPipeColorSystem _pipeColor = default!;
  15. public override void Initialize()
  16. {
  17. base.Initialize();
  18. SubscribeLocalEvent<SprayPainterComponent, SprayPainterPipeDoAfterEvent>(OnPipeDoAfter);
  19. SubscribeLocalEvent<AtmosPipeColorComponent, InteractUsingEvent>(OnPipeInteract);
  20. }
  21. private void OnPipeDoAfter(Entity<SprayPainterComponent> ent, ref SprayPainterPipeDoAfterEvent args)
  22. {
  23. if (args.Handled || args.Cancelled)
  24. return;
  25. if (args.Args.Target is not {} target)
  26. return;
  27. if (!TryComp<AtmosPipeColorComponent>(target, out var color))
  28. return;
  29. Audio.PlayPvs(ent.Comp.SpraySound, ent);
  30. _pipeColor.SetColor(target, color, args.Color);
  31. args.Handled = true;
  32. }
  33. private void OnPipeInteract(Entity<AtmosPipeColorComponent> ent, ref InteractUsingEvent args)
  34. {
  35. if (args.Handled)
  36. return;
  37. if (!TryComp<SprayPainterComponent>(args.Used, out var painter) || painter.PickedColor is not {} colorName)
  38. return;
  39. if (!painter.ColorPalette.TryGetValue(colorName, out var color))
  40. return;
  41. var doAfterEventArgs = new DoAfterArgs(EntityManager, args.User, painter.PipeSprayTime, new SprayPainterPipeDoAfterEvent(color), args.Used, target: ent, used: args.Used)
  42. {
  43. BreakOnMove = true,
  44. BreakOnDamage = true,
  45. // multiple pipes can be sprayed at once just not the same one
  46. DuplicateCondition = DuplicateConditions.SameTarget,
  47. NeedHand = true,
  48. };
  49. args.Handled = DoAfter.TryStartDoAfter(doAfterEventArgs);
  50. }
  51. }