1
0

DungeonJob.PostGenCorridorClutter.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Threading.Tasks;
  2. using Content.Shared.Procedural;
  3. using Content.Shared.Procedural.PostGeneration;
  4. using Content.Shared.Storage;
  5. using Robust.Shared.Physics.Components;
  6. using Robust.Shared.Random;
  7. namespace Content.Server.Procedural.DungeonJob;
  8. public sealed partial class DungeonJob
  9. {
  10. /// <summary>
  11. /// <see cref="CorridorClutterDunGen"/>
  12. /// </summary>
  13. private async Task PostGen(CorridorClutterDunGen gen, DungeonData data, Dungeon dungeon, HashSet<Vector2i> reservedTiles, Random random)
  14. {
  15. var physicsQuery = _entManager.GetEntityQuery<PhysicsComponent>();
  16. var count = (int) Math.Ceiling(dungeon.CorridorTiles.Count * gen.Chance);
  17. while (count > 0)
  18. {
  19. var tile = random.Pick(dungeon.CorridorTiles);
  20. var enumerator = _maps.GetAnchoredEntitiesEnumerator(_gridUid, _grid, tile);
  21. var blocked = false;
  22. while (enumerator.MoveNext(out var ent))
  23. {
  24. if (!physicsQuery.TryGetComponent(ent, out var physics) ||
  25. !physics.CanCollide ||
  26. !physics.Hard)
  27. {
  28. continue;
  29. }
  30. blocked = true;
  31. break;
  32. }
  33. if (blocked)
  34. continue;
  35. count--;
  36. var protos = EntitySpawnCollection.GetSpawns(gen.Contents, random);
  37. var coords = _maps.ToCenterCoordinates(_gridUid, tile, _grid);
  38. _entManager.SpawnEntities(coords, protos);
  39. await SuspendIfOutOfTime();
  40. if (!ValidateResume())
  41. return;
  42. }
  43. }
  44. }