mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
Fix dungeon spawn + ftl overlap (#31413)
* Fix dungeon spawn + ftl overlap * Better fixes
This commit is contained in:
@@ -4,6 +4,7 @@ using Content.Server.Decals;
|
||||
using Content.Server.NPC.Components;
|
||||
using Content.Server.NPC.HTN;
|
||||
using Content.Server.NPC.Systems;
|
||||
using Content.Server.Shuttles.Systems;
|
||||
using Content.Shared.Construction.EntitySystems;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Procedural;
|
||||
@@ -51,6 +52,8 @@ public sealed partial class DungeonJob : Job<List<Dungeon>>
|
||||
private readonly EntityUid _gridUid;
|
||||
private readonly MapGridComponent _grid;
|
||||
|
||||
private readonly EntityCoordinates? _targetCoordinates;
|
||||
|
||||
private readonly ISawmill _sawmill;
|
||||
|
||||
public DungeonJob(
|
||||
@@ -70,6 +73,7 @@ public sealed partial class DungeonJob : Job<List<Dungeon>>
|
||||
EntityUid gridUid,
|
||||
int seed,
|
||||
Vector2i position,
|
||||
EntityCoordinates? targetCoordinates = null,
|
||||
CancellationToken cancellation = default) : base(maxTime, cancellation)
|
||||
{
|
||||
_sawmill = sawmill;
|
||||
@@ -94,6 +98,7 @@ public sealed partial class DungeonJob : Job<List<Dungeon>>
|
||||
_gridUid = gridUid;
|
||||
_seed = seed;
|
||||
_position = position;
|
||||
_targetCoordinates = targetCoordinates;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -151,6 +156,12 @@ public sealed partial class DungeonJob : Job<List<Dungeon>>
|
||||
// To make it slightly more deterministic treat this RNG as separate ig.
|
||||
|
||||
// Post-processing after finishing loading.
|
||||
if (_targetCoordinates != null)
|
||||
{
|
||||
var oldMap = _xformQuery.Comp(_gridUid).MapUid;
|
||||
_entManager.System<ShuttleSystem>().TryFTLProximity(_gridUid, _targetCoordinates.Value);
|
||||
_entManager.DeleteEntity(oldMap);
|
||||
}
|
||||
|
||||
// Defer splitting so they don't get spammed and so we don't have to worry about tracking the grid along the way.
|
||||
_grid.CanSplit = true;
|
||||
|
||||
@@ -188,11 +188,16 @@ public sealed partial class DungeonSystem : SharedDungeonSystem
|
||||
return mapId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a dungeon in the background with the specified config.
|
||||
/// </summary>
|
||||
/// <param name="coordinates">Coordinates to move the dungeon to afterwards. Will delete the original map</param>
|
||||
public void GenerateDungeon(DungeonConfig gen,
|
||||
EntityUid gridUid,
|
||||
MapGridComponent grid,
|
||||
Vector2i position,
|
||||
int seed)
|
||||
int seed,
|
||||
EntityCoordinates? coordinates = null)
|
||||
{
|
||||
var cancelToken = new CancellationTokenSource();
|
||||
var job = new DungeonJob.DungeonJob(
|
||||
@@ -212,6 +217,7 @@ public sealed partial class DungeonSystem : SharedDungeonSystem
|
||||
gridUid,
|
||||
seed,
|
||||
position,
|
||||
coordinates,
|
||||
cancelToken.Token);
|
||||
|
||||
_dungeonJobs.Add(job, cancelToken);
|
||||
@@ -243,6 +249,7 @@ public sealed partial class DungeonSystem : SharedDungeonSystem
|
||||
gridUid,
|
||||
seed,
|
||||
position,
|
||||
null,
|
||||
cancelToken.Token);
|
||||
|
||||
_dungeonJobs.Add(job, cancelToken);
|
||||
|
||||
@@ -85,7 +85,7 @@ public sealed partial class ShuttleSystem
|
||||
_mapManager.DeleteMap(mapId);
|
||||
}
|
||||
|
||||
private bool TryDungeonSpawn(Entity<MapGridComponent?> targetGrid, MapId mapId, DungeonSpawnGroup group, out EntityUid spawned)
|
||||
private bool TryDungeonSpawn(Entity<MapGridComponent?> targetGrid, DungeonSpawnGroup group, out EntityUid spawned)
|
||||
{
|
||||
spawned = EntityUid.Invalid;
|
||||
|
||||
@@ -110,11 +110,12 @@ public sealed partial class ShuttleSystem
|
||||
spawnCoords = spawnCoords.Offset(_random.NextVector2(distancePadding + group.MinimumDistance, distancePadding + group.MaximumDistance));
|
||||
}
|
||||
|
||||
var spawnMapCoords = _transform.ToMapCoordinates(spawnCoords);
|
||||
_maps.CreateMap(out var mapId);
|
||||
|
||||
var spawnedGrid = _mapManager.CreateGridEntity(mapId);
|
||||
|
||||
_transform.SetMapCoordinates(spawnedGrid, spawnMapCoords);
|
||||
_dungeon.GenerateDungeon(dungeonProto, spawnedGrid.Owner, spawnedGrid.Comp, Vector2i.Zero, _random.Next());
|
||||
_transform.SetMapCoordinates(spawnedGrid, new MapCoordinates(Vector2.Zero, mapId));
|
||||
_dungeon.GenerateDungeon(dungeonProto, spawnedGrid.Owner, spawnedGrid.Comp, Vector2i.Zero, _random.Next(), spawnCoords);
|
||||
|
||||
spawned = spawnedGrid.Owner;
|
||||
return true;
|
||||
@@ -192,7 +193,7 @@ public sealed partial class ShuttleSystem
|
||||
switch (group)
|
||||
{
|
||||
case DungeonSpawnGroup dungeon:
|
||||
if (!TryDungeonSpawn(targetGrid.Value, mapId, dungeon, out spawned))
|
||||
if (!TryDungeonSpawn(targetGrid.Value, dungeon, out spawned))
|
||||
continue;
|
||||
|
||||
break;
|
||||
|
||||
@@ -51,7 +51,7 @@ public sealed partial class ShuttleSystem : SharedShuttleSystem
|
||||
[Dependency] private readonly MetaDataSystem _metadata = default!;
|
||||
[Dependency] private readonly PvsOverrideSystem _pvs = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
|
||||
[Dependency] private readonly SharedMapSystem _maps = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly ShuttleConsoleSystem _console = default!;
|
||||
|
||||
Reference in New Issue
Block a user