Files
tbd-station-14/Content.Server/Procedural/RoomFillSystem.cs
Ed 47cb8a0b08 RoomSpawner mask (#33110)
* RoolFill can now spaw rooms with any size

* tile ignoring

* upgrade interior

* simplify

* Update DungeonSystem.Rooms.cs

* center rooms

* Update RoomFillComponent.cs

* Update RoomFillComponent.cs

* Update DungeonSystem.Rooms.cs

* Remove roomfillcoponent from integration test

* Update EntityTest.cs

* remove nullable size, replaced with minsize and maxsize

* clear existing logic refactor

* delete this one
2025-02-12 15:47:48 +03:00

48 lines
1.5 KiB
C#

using Robust.Shared.Map.Components;
namespace Content.Server.Procedural;
public sealed class RoomFillSystem : EntitySystem
{
[Dependency] private readonly DungeonSystem _dungeon = default!;
[Dependency] private readonly SharedMapSystem _maps = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RoomFillComponent, MapInitEvent>(OnRoomFillMapInit);
}
private void OnRoomFillMapInit(EntityUid uid, RoomFillComponent component, MapInitEvent args)
{
var xform = Transform(uid);
if (xform.GridUid != null)
{
var random = new Random();
var room = _dungeon.GetRoomPrototype(random, component.RoomWhitelist, component.MinSize, component.MaxSize);
if (room != null)
{
var mapGrid = Comp<MapGridComponent>(xform.GridUid.Value);
_dungeon.SpawnRoom(
xform.GridUid.Value,
mapGrid,
_maps.LocalToTile(xform.GridUid.Value, mapGrid, xform.Coordinates) - new Vector2i(room.Size.X/2,room.Size.Y/2),
room,
random,
null,
clearExisting: component.ClearExisting,
rotation: component.Rotation);
}
else
{
Log.Error($"Unable to find matching room prototype for {ToPrettyString(uid)}");
}
}
// Final cleanup
QueueDel(uid);
}
}