remove nesting
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Random;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server._CP14.Procedural.RoomSpawner;
|
||||
@@ -10,7 +11,7 @@ namespace Content.Server._CP14.Procedural.RoomSpawner;
|
||||
public sealed partial class CP14RoomSpawnerComponent : Component
|
||||
{
|
||||
[DataField(required: true)]
|
||||
public ProtoId<WeightedRandomPrototype> RoomsRandom = new();
|
||||
public List<ProtoId<TagPrototype>> RoomsTag;
|
||||
|
||||
[DataField]
|
||||
public bool Rotation = true;
|
||||
|
||||
@@ -29,12 +29,36 @@ public sealed class CP14RoomSpawnerSystem : EntitySystem
|
||||
|
||||
private void SpawnRoom(Entity<CP14RoomSpawnerComponent> spawner)
|
||||
{
|
||||
if (!_proto.TryIndex(spawner.Comp.RoomsRandom, out var rooms))
|
||||
var rooms = new HashSet<DungeonRoomPrototype>();
|
||||
|
||||
foreach (var roomProto in _proto.EnumeratePrototypes<DungeonRoomPrototype>())
|
||||
{
|
||||
var whitelisted = false;
|
||||
|
||||
foreach (var tag in spawner.Comp.RoomsTag)
|
||||
{
|
||||
if (roomProto.Tags.Contains(tag))
|
||||
{
|
||||
whitelisted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!whitelisted)
|
||||
continue;
|
||||
|
||||
rooms.Add(roomProto);
|
||||
}
|
||||
|
||||
if (rooms.Count == 0)
|
||||
{
|
||||
Log.Error($"Unable to find matching rooms by tag for {ToPrettyString(spawner)}");
|
||||
return;
|
||||
}
|
||||
|
||||
var roomProto = rooms.Pick(_random);
|
||||
var selectedRoom = _random.Pick(rooms);
|
||||
|
||||
if (!_proto.TryIndex<DungeonRoomPrototype>(roomProto, out var room))
|
||||
if (!_proto.TryIndex<DungeonRoomPrototype>(selectedRoom, out var room))
|
||||
{
|
||||
Log.Error($"Unable to find matching room prototype ({room}) for {ToPrettyString(spawner)}");
|
||||
return;
|
||||
@@ -57,6 +81,6 @@ public sealed class CP14RoomSpawnerSystem : EntitySystem
|
||||
null,
|
||||
spawner.Comp.ClearExisting,
|
||||
spawner.Comp.Rotation,
|
||||
ignoreTiles: spawner.Comp.IgnoreTiles);
|
||||
spawner.Comp.IgnoreTiles);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,10 @@
|
||||
parent: CP14BaseRoomSpawner
|
||||
components:
|
||||
- type: CP14RoomSpawner
|
||||
roomsRandom: CP14RoomSpawnerXandria
|
||||
roomsTag:
|
||||
- CP14Xandria7x7
|
||||
- type: Sprite
|
||||
layers:
|
||||
- state: room
|
||||
- sprite: _CP14/Markers/RoomBorders/7x7.rsi
|
||||
state: frame
|
||||
|
||||
- type: weightedRandom
|
||||
id: CP14RoomSpawnerXandria
|
||||
weights:
|
||||
CP14Xandria7x7_1: 1
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
# Rooms
|
||||
|
||||
- type: Tag
|
||||
id: CP14Xandria7x7
|
||||
|
||||
# Large
|
||||
# - 17x5
|
||||
# - 7x7
|
||||
- type: dungeonRoom
|
||||
id: CP14Xandria7x7_1
|
||||
size: 7,7
|
||||
atlas: /Maps/_CP14/Procedural/xandria.yml
|
||||
offset: 0,0
|
||||
tags:
|
||||
- CP14Pestle #DEBUG
|
||||
- CP14Xandria7x7
|
||||
Reference in New Issue
Block a user