1
0

RoomFillSystem.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Robust.Shared.Map.Components;
  2. namespace Content.Server.Procedural;
  3. public sealed class RoomFillSystem : EntitySystem
  4. {
  5. [Dependency] private readonly DungeonSystem _dungeon = default!;
  6. [Dependency] private readonly SharedMapSystem _maps = default!;
  7. public override void Initialize()
  8. {
  9. base.Initialize();
  10. SubscribeLocalEvent<RoomFillComponent, MapInitEvent>(OnRoomFillMapInit);
  11. }
  12. private void OnRoomFillMapInit(EntityUid uid, RoomFillComponent component, MapInitEvent args)
  13. {
  14. var xform = Transform(uid);
  15. if (xform.GridUid != null)
  16. {
  17. var random = new Random();
  18. var room = _dungeon.GetRoomPrototype(random, component.RoomWhitelist, component.MinSize, component.MaxSize);
  19. if (room != null)
  20. {
  21. var mapGrid = Comp<MapGridComponent>(xform.GridUid.Value);
  22. _dungeon.SpawnRoom(
  23. xform.GridUid.Value,
  24. mapGrid,
  25. _maps.LocalToTile(xform.GridUid.Value, mapGrid, xform.Coordinates) - new Vector2i(room.Size.X/2,room.Size.Y/2),
  26. room,
  27. random,
  28. null,
  29. clearExisting: component.ClearExisting,
  30. rotation: component.Rotation);
  31. }
  32. else
  33. {
  34. Log.Error($"Unable to find matching room prototype for {ToPrettyString(uid)}");
  35. }
  36. }
  37. // Final cleanup
  38. QueueDel(uid);
  39. }
  40. }