SharedPuddleSystem.Spillable.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using Content.Shared.Chemistry.Components;
  2. using Content.Shared.Database;
  3. using Content.Shared.DoAfter;
  4. using Content.Shared.Examine;
  5. using Content.Shared.FixedPoint;
  6. using Content.Shared.Fluids.Components;
  7. using Content.Shared.Nutrition.EntitySystems;
  8. using Content.Shared.Spillable;
  9. using Content.Shared.Verbs;
  10. using Content.Shared.Weapons.Melee;
  11. namespace Content.Shared.Fluids;
  12. public abstract partial class SharedPuddleSystem
  13. {
  14. [Dependency] protected readonly OpenableSystem Openable = default!;
  15. protected virtual void InitializeSpillable()
  16. {
  17. SubscribeLocalEvent<SpillableComponent, ExaminedEvent>(OnExamined);
  18. SubscribeLocalEvent<SpillableComponent, GetVerbsEvent<Verb>>(AddSpillVerb);
  19. }
  20. private void OnExamined(Entity<SpillableComponent> entity, ref ExaminedEvent args)
  21. {
  22. using (args.PushGroup(nameof(SpillableComponent)))
  23. {
  24. args.PushMarkup(Loc.GetString("spill-examine-is-spillable"));
  25. if (HasComp<MeleeWeaponComponent>(entity))
  26. args.PushMarkup(Loc.GetString("spill-examine-spillable-weapon"));
  27. }
  28. }
  29. private void AddSpillVerb(Entity<SpillableComponent> entity, ref GetVerbsEvent<Verb> args)
  30. {
  31. if (!args.CanAccess || !args.CanInteract || args.Hands == null)
  32. return;
  33. if (!_solutionContainerSystem.TryGetSolution(args.Target, entity.Comp.SolutionName, out var soln, out var solution))
  34. return;
  35. if (Openable.IsClosed(args.Target))
  36. return;
  37. if (solution.Volume == FixedPoint2.Zero)
  38. return;
  39. Verb verb = new()
  40. {
  41. Text = Loc.GetString("spill-target-verb-get-data-text")
  42. };
  43. // TODO VERB ICONS spill icon? pouring out a glass/beaker?
  44. if (entity.Comp.SpillDelay == null)
  45. {
  46. var target = args.Target;
  47. verb.Act = () =>
  48. {
  49. var puddleSolution = _solutionContainerSystem.SplitSolution(soln.Value, solution.Volume);
  50. TrySpillAt(Transform(target).Coordinates, puddleSolution, out _);
  51. if (TryComp<InjectorComponent>(entity, out var injectorComp))
  52. {
  53. injectorComp.ToggleState = InjectorToggleMode.Draw;
  54. Dirty(entity, injectorComp);
  55. }
  56. };
  57. }
  58. else
  59. {
  60. var user = args.User;
  61. verb.Act = () =>
  62. {
  63. _doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, user, entity.Comp.SpillDelay ?? 0, new SpillDoAfterEvent(), entity.Owner, target: entity.Owner)
  64. {
  65. BreakOnDamage = true,
  66. BreakOnMove = true,
  67. NeedHand = true,
  68. });
  69. };
  70. }
  71. verb.Impact = LogImpact.Medium; // dangerous reagent reaction are logged separately.
  72. verb.DoContactInteraction = true;
  73. args.Verbs.Add(verb);
  74. }
  75. }