Add collision teleport portals and ledge-safe movement in VNext dungeons
This commit is contained in:
@@ -26,6 +26,7 @@ public class DungeonGeneratorVNext
|
||||
private readonly Dictionary<DungeonRoom, List<TemplateMobSpawn>> _templateMobSpawnsByRoom = new();
|
||||
private readonly Dictionary<(int X, int Y), List<PlacedTile>> _templateTilesByCell = new();
|
||||
private readonly Dictionary<int, TileDefinition> _tileDefinitionsById = new();
|
||||
private readonly Dictionary<int, ObjectTemplate> _objectTemplatesById = new();
|
||||
private static readonly JsonSerializerOptions _jsonOptions = new() { PropertyNameCaseInsensitive = true };
|
||||
|
||||
public DungeonGeneratorVNext(GameDbContext db, int seed, int tier = 1, ILogger<DungeonGeneratorVNext>? logger = null)
|
||||
@@ -49,6 +50,7 @@ public class DungeonGeneratorVNext
|
||||
_templateMobSpawnsByRoom.Clear();
|
||||
_templateTilesByCell.Clear();
|
||||
_tileDefinitionsById.Clear();
|
||||
_objectTemplatesById.Clear();
|
||||
_selectedPalette = await SelectPaletteAsync();
|
||||
await LoadRoomTemplatesAsync();
|
||||
|
||||
@@ -236,6 +238,39 @@ public class DungeonGeneratorVNext
|
||||
_tileDefinitionsById[def.Id] = def;
|
||||
}
|
||||
|
||||
var objectTemplateIds = new HashSet<int>();
|
||||
foreach (var room in _roomTemplates)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(room.ObjectPlacementsJson)) continue;
|
||||
try
|
||||
{
|
||||
var objects = JsonSerializer.Deserialize<List<BuilderObjectPlacement>>(room.ObjectPlacementsJson, _jsonOptions);
|
||||
if (objects == null) continue;
|
||||
foreach (var obj in objects)
|
||||
{
|
||||
if (obj.ObjectTemplateId > 0)
|
||||
{
|
||||
objectTemplateIds.Add(obj.ObjectTemplateId);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Keep generation resilient if a room has malformed object placement JSON.
|
||||
}
|
||||
}
|
||||
|
||||
if (objectTemplateIds.Count > 0)
|
||||
{
|
||||
var objectTemplates = await _db.ObjectTemplates
|
||||
.Where(o => o.IsEnabled && objectTemplateIds.Contains(o.Id))
|
||||
.ToListAsync();
|
||||
foreach (var template in objectTemplates)
|
||||
{
|
||||
_objectTemplatesById[template.Id] = template;
|
||||
}
|
||||
}
|
||||
|
||||
_logger?.LogInformation(
|
||||
"VNext room templates loaded: {Count} templates (palette={PaletteId})",
|
||||
_roomTemplates.Count,
|
||||
@@ -457,6 +492,7 @@ public class DungeonGeneratorVNext
|
||||
}
|
||||
|
||||
StampRoomTemplateTiles(layout, room, template);
|
||||
StampRoomTemplateObjects(layout, room, template);
|
||||
LoadTemplateMobSpawns(room, template);
|
||||
}
|
||||
}
|
||||
@@ -593,6 +629,61 @@ public class DungeonGeneratorVNext
|
||||
}
|
||||
}
|
||||
|
||||
private void StampRoomTemplateObjects(DungeonLayoutV2 layout, DungeonRoom room, BuilderRoomTemplate template)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(template.ObjectPlacementsJson)) return;
|
||||
|
||||
try
|
||||
{
|
||||
var objects = JsonSerializer.Deserialize<List<BuilderObjectPlacement>>(template.ObjectPlacementsJson, _jsonOptions);
|
||||
if (objects == null || objects.Count == 0) return;
|
||||
|
||||
foreach (var obj in objects)
|
||||
{
|
||||
if (!_objectTemplatesById.TryGetValue(obj.ObjectTemplateId, out var objectTemplate))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int worldX = room.X + obj.X;
|
||||
int worldY = room.Y + obj.Y;
|
||||
if (worldX < 0 || worldY < 0 || worldX >= layout.Width || worldY >= layout.Height)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
layout.Objects.Add(new PlacedObject
|
||||
{
|
||||
X = worldX,
|
||||
Y = worldY,
|
||||
ObjectTemplateId = objectTemplate.Id,
|
||||
Name = objectTemplate.Name,
|
||||
Type = objectTemplate.Type.ToString(),
|
||||
SpriteSheetId = objectTemplate.SpriteSheetId ?? 0,
|
||||
FrameIndex = objectTemplate.FrameIndex,
|
||||
BlocksMovement = objectTemplate.BlocksMovement,
|
||||
IsInteractable = objectTemplate.IsInteractable,
|
||||
IsTrap = objectTemplate.Type == ObjectTemplateType.Trap || objectTemplate.Type == ObjectTemplateType.Hazard,
|
||||
TrapDamage = objectTemplate.Damage,
|
||||
LootTableId = objectTemplate.LootTableId,
|
||||
TriggeredByWalk = objectTemplate.TriggeredByWalk,
|
||||
InteractionType = objectTemplate.InteractionType.ToString(),
|
||||
MetadataJson = string.IsNullOrWhiteSpace(obj.OverridesJson) ? null : obj.OverridesJson
|
||||
});
|
||||
|
||||
if (objectTemplate.BlocksMovement)
|
||||
{
|
||||
layout.Walkable![worldX, worldY] = false;
|
||||
layout.Tiles[worldX, worldY] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogWarning(ex, "VNext failed parsing ObjectPlacementsJson for template {TemplateId}:{TemplateName}", template.Id, template.Name);
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateSpawnsAndChests(DungeonLayoutV2 layout, List<DungeonRoom> rooms)
|
||||
{
|
||||
layout.MobSpawns.Clear();
|
||||
|
||||
Reference in New Issue
Block a user