1
0

SpillBehavior.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using Content.Shared.Chemistry.EntitySystems;
  2. using Content.Server.Fluids.EntitySystems;
  3. using Content.Shared.Fluids.Components;
  4. using JetBrains.Annotations;
  5. namespace Content.Server.Destructible.Thresholds.Behaviors
  6. {
  7. [UsedImplicitly]
  8. [DataDefinition]
  9. public sealed partial class SpillBehavior : IThresholdBehavior
  10. {
  11. [DataField]
  12. public string? Solution;
  13. /// <summary>
  14. /// If there is a SpillableComponent on EntityUidowner use it to create a puddle/smear.
  15. /// Or whatever solution is specified in the behavior itself.
  16. /// If none are available do nothing.
  17. /// </summary>
  18. /// <param name="owner">Entity on which behavior is executed</param>
  19. /// <param name="system">system calling the behavior</param>
  20. /// <param name="cause"></param>
  21. public void Execute(EntityUid owner, DestructibleSystem system, EntityUid? cause = null)
  22. {
  23. var solutionContainerSystem = system.EntityManager.System<SharedSolutionContainerSystem>();
  24. var spillableSystem = system.EntityManager.System<PuddleSystem>();
  25. var coordinates = system.EntityManager.GetComponent<TransformComponent>(owner).Coordinates;
  26. if (system.EntityManager.TryGetComponent(owner, out SpillableComponent? spillableComponent) &&
  27. solutionContainerSystem.TryGetSolution(owner, spillableComponent.SolutionName, out _, out var compSolution))
  28. {
  29. spillableSystem.TrySplashSpillAt(owner, coordinates, compSolution, out _, false, user: cause);
  30. }
  31. else if (Solution != null &&
  32. solutionContainerSystem.TryGetSolution(owner, Solution, out _, out var behaviorSolution))
  33. {
  34. spillableSystem.TrySplashSpillAt(owner, coordinates, behaviorSolution, out _, user: cause);
  35. }
  36. }
  37. }
  38. }