room spawner

This commit is contained in:
Ed
2024-07-17 16:33:28 +03:00
parent 0a42834dbe
commit 951e553926
3 changed files with 101 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
using Content.Shared.Procedural;
using Content.Shared.Random;
using Robust.Shared.Prototypes;
namespace Content.Server._CP14.Procedural.RoomSpawner;
/// <summary>
///
/// </summary>
[RegisterComponent, Access(typeof(CP14RoomSpawnerSystem))]
public sealed partial class CP14RoomSpawnerComponent : Component
{
[DataField(required: true)]
public ProtoId<WeightedRandomPrototype> RoomsRandom = new();
[DataField]
public bool Rotation = true;
[DataField]
public bool ClearExisting = true;
}

View File

@@ -0,0 +1,53 @@
using Content.Server.Procedural;
using Content.Shared.Procedural;
using Content.Shared.Random.Helpers;
using Robust.Server.GameObjects;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server._CP14.Procedural.RoomSpawner;
public sealed class CP14RoomSpawnerSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly DungeonSystem _dungeon = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly SharedMapSystem _maps = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CP14RoomSpawnerComponent, MapInitEvent>(OnMapInit);
}
private void OnMapInit(Entity<CP14RoomSpawnerComponent> spawner, ref MapInitEvent args)
{
if (!_proto.TryIndex(spawner.Comp.RoomsRandom, out var rooms))
return;
var roomProto = rooms.Pick(_random);
if (!_proto.TryIndex<DungeonRoomPrototype>(roomProto, out var room))
return;
var gridUid = Transform(spawner).GridUid;
if (!TryComp<MapGridComponent>(gridUid, out var gridComp))
return;
var random = new Random();
_dungeon.SpawnRoom(
gridUid.Value,
gridComp,
_maps.LocalToTile(gridUid.Value, gridComp, Transform(spawner).Coordinates),
room,
random,
null,
spawner.Comp.ClearExisting,
spawner.Comp.Rotation);
}
}

View File

@@ -0,0 +1,27 @@
- type: weightedRandom
id: CP14RoomSpawnerCaelid
weights:
LavaBrig17x5a: 1
LavaBrig17x5b: 1
LavaBrig7x7a: 1
LavaBrig7x7b: 1
LavaBrig7x7c: 1
LavaBrig7x7d: 1
LavaBrig11x5a: 1
- type: entity
id: CP14BaseRoomSpawner
name: room spawner
parent: MarkerBase
placement:
mode: SnapgridCenter
components:
- type: Transform
anchored: true
- type: Clickable
- type: InteractionOutline
- type: Sprite
layers:
- state: green
- type: CP14RoomSpawner
roomsRandom: CP14RoomSpawnerCaelid