DungeonJob.PostGenWallMount.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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.Random;
  6. namespace Content.Server.Procedural.DungeonJob;
  7. public sealed partial class DungeonJob
  8. {
  9. /// <summary>
  10. /// <see cref="WallMountDunGen"/>
  11. /// </summary>
  12. private async Task PostGen(WallMountDunGen gen, DungeonData data, Dungeon dungeon, HashSet<Vector2i> reservedTiles, Random random)
  13. {
  14. if (!data.Tiles.TryGetValue(DungeonDataKey.FallbackTile, out var tileProto))
  15. {
  16. _sawmill.Error($"Tried to run {nameof(WallMountDunGen)} without any dungeon data set which is unsupported");
  17. return;
  18. }
  19. var tileDef = _prototype.Index(tileProto);
  20. if (!data.SpawnGroups.TryGetValue(DungeonDataKey.WallMounts, out var spawnProto))
  21. {
  22. // caves can have no walls
  23. return;
  24. }
  25. var checkedTiles = new HashSet<Vector2i>();
  26. var allExterior = new HashSet<Vector2i>(dungeon.CorridorExteriorTiles);
  27. allExterior.UnionWith(dungeon.RoomExteriorTiles);
  28. var count = 0;
  29. foreach (var neighbor in allExterior)
  30. {
  31. // Occupado
  32. if (dungeon.RoomTiles.Contains(neighbor) || checkedTiles.Contains(neighbor) || !_anchorable.TileFree(_grid, neighbor, DungeonSystem.CollisionLayer, DungeonSystem.CollisionMask))
  33. continue;
  34. if (!random.Prob(gen.Prob) || !checkedTiles.Add(neighbor))
  35. continue;
  36. _maps.SetTile(_gridUid, _grid, neighbor, _tile.GetVariantTile(tileDef, random));
  37. var gridPos = _maps.GridTileToLocal(_gridUid, _grid, neighbor);
  38. var protoNames = EntitySpawnCollection.GetSpawns(_prototype.Index(spawnProto).Entries, random);
  39. _entManager.SpawnEntities(gridPos, protoNames);
  40. count += protoNames.Count;
  41. if (count > 20)
  42. {
  43. count -= 20;
  44. await SuspendDungeon();
  45. if (!ValidateResume())
  46. return;
  47. }
  48. }
  49. }
  50. }