SharedHypospraySystem.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Content.Shared.Chemistry.Components;
  2. using Content.Shared.Timing;
  3. using Content.Shared.Verbs;
  4. using Content.Shared.Popups;
  5. using Robust.Shared.Player;
  6. using Content.Shared.Administration.Logs;
  7. namespace Content.Shared.Chemistry.EntitySystems;
  8. public abstract class SharedHypospraySystem : EntitySystem
  9. {
  10. [Dependency] protected readonly UseDelaySystem _useDelay = default!;
  11. [Dependency] protected readonly SharedPopupSystem _popup = default!;
  12. [Dependency] protected readonly SharedSolutionContainerSystem _solutionContainers = default!;
  13. [Dependency] protected readonly ISharedAdminLogManager _adminLogger = default!;
  14. [Dependency] protected readonly ReactiveSystem _reactiveSystem = default!;
  15. public override void Initialize()
  16. {
  17. SubscribeLocalEvent<HyposprayComponent, GetVerbsEvent<AlternativeVerb>>(AddToggleModeVerb);
  18. }
  19. // <summary>
  20. // Uses the OnlyMobs field as a check to implement the ability
  21. // to draw from jugs and containers with the hypospray
  22. // Toggleable to allow people to inject containers if they prefer it over drawing
  23. // </summary>
  24. private void AddToggleModeVerb(Entity<HyposprayComponent> entity, ref GetVerbsEvent<AlternativeVerb> args)
  25. {
  26. if (!args.CanAccess || !args.CanInteract || args.Hands == null || entity.Comp.InjectOnly)
  27. return;
  28. var (_, component) = entity;
  29. var user = args.User;
  30. var verb = new AlternativeVerb
  31. {
  32. Text = Loc.GetString("hypospray-verb-mode-label"),
  33. Act = () =>
  34. {
  35. ToggleMode(entity, user);
  36. }
  37. };
  38. args.Verbs.Add(verb);
  39. }
  40. private void ToggleMode(Entity<HyposprayComponent> entity, EntityUid user)
  41. {
  42. SetMode(entity, !entity.Comp.OnlyAffectsMobs);
  43. string msg = entity.Comp.OnlyAffectsMobs ? "hypospray-verb-mode-inject-mobs-only" : "hypospray-verb-mode-inject-all";
  44. _popup.PopupClient(Loc.GetString(msg), entity, user);
  45. }
  46. public void SetMode(Entity<HyposprayComponent> entity, bool onlyAffectsMobs)
  47. {
  48. if (entity.Comp.OnlyAffectsMobs == onlyAffectsMobs)
  49. return;
  50. entity.Comp.OnlyAffectsMobs = onlyAffectsMobs;
  51. Dirty(entity);
  52. }
  53. }