1
0

RandomHelperSystem.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Numerics;
  2. using Content.Shared.Random.Helpers;
  3. using Robust.Shared.Random;
  4. using Robust.Shared.Utility;
  5. namespace Content.Shared.Random;
  6. /// <summary>
  7. /// System containing various content-related random helpers.
  8. /// </summary>
  9. public sealed class RandomHelperSystem : EntitySystem
  10. {
  11. [Dependency] private readonly SharedTransformSystem _transform = default!;
  12. [Dependency] private readonly IRobustRandom _random = default!;
  13. public void RandomOffset(EntityUid entity, float minX, float maxX, float minY, float maxY)
  14. {
  15. var randomX = _random.NextFloat() * (maxX - minX) + minX;
  16. var randomY = _random.NextFloat() * (maxY - minY) + minY;
  17. var offset = new Vector2(randomX, randomY);
  18. var xform = Transform(entity);
  19. _transform.SetLocalPosition(xform, xform.LocalPosition + offset);
  20. }
  21. public void RandomOffset(EntityUid entity, float min, float max)
  22. {
  23. RandomOffset(entity, min, max, min, max);
  24. }
  25. public void RandomOffset(EntityUid entity, float value)
  26. {
  27. RandomOffset(entity, -value, value);
  28. }
  29. }