1
0

DungeonJob.PostGenCornerClutter.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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="CornerClutterDunGen"/>
  12. /// </summary>
  13. private async Task PostGen(CornerClutterDunGen gen, DungeonData data, Dungeon dungeon, HashSet<Vector2i> reservedTiles, Random random)
  14. {
  15. if (!data.SpawnGroups.TryGetValue(DungeonDataKey.CornerClutter, out var corner))
  16. {
  17. _sawmill.Error(Environment.StackTrace);
  18. return;
  19. }
  20. foreach (var tile in dungeon.CorridorTiles)
  21. {
  22. var blocked = _anchorable.TileFree(_grid, tile, DungeonSystem.CollisionLayer, DungeonSystem.CollisionMask);
  23. if (blocked)
  24. continue;
  25. // If at least 2 adjacent tiles are blocked consider it a corner
  26. for (var i = 0; i < 4; i++)
  27. {
  28. var dir = (Direction) (i * 2);
  29. blocked = HasWall(tile + dir.ToIntVec());
  30. if (!blocked)
  31. continue;
  32. var nextDir = (Direction) ((i + 1) * 2 % 8);
  33. blocked = HasWall(tile + nextDir.ToIntVec());
  34. if (!blocked)
  35. continue;
  36. if (random.Prob(gen.Chance))
  37. {
  38. var coords = _maps.GridTileToLocal(_gridUid, _grid, tile);
  39. var protos = EntitySpawnCollection.GetSpawns(_prototype.Index(corner).Entries, random);
  40. _entManager.SpawnEntities(coords, protos);
  41. }
  42. break;
  43. }
  44. }
  45. }
  46. }