Fix some bugs in stations and do a little cleanup. (#10787)
This commit is contained in:
@@ -173,7 +173,7 @@ public sealed class AlertLevelSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
if (detail.Sound != null)
|
if (detail.Sound != null)
|
||||||
{
|
{
|
||||||
var filter = _stationSystem.GetInStation(station);
|
var filter = _stationSystem.GetInOwningStation(station);
|
||||||
SoundSystem.Play(detail.Sound.GetSound(), filter, detail.Sound.Params);
|
SoundSystem.Play(detail.Sound.GetSound(), filter, detail.Sound.Params);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public sealed class ServerGlobalSoundSystem : SharedGlobalSoundSystem
|
|||||||
|
|
||||||
private Filter GetStationAndPvs(EntityUid source)
|
private Filter GetStationAndPvs(EntityUid source)
|
||||||
{
|
{
|
||||||
var stationFilter = _stationSystem.GetInStation(source);
|
var stationFilter = _stationSystem.GetInOwningStation(source);
|
||||||
stationFilter.AddPlayersByPvs(source, entityManager: EntityManager);
|
stationFilter.AddPlayersByPvs(source, entityManager: EntityManager);
|
||||||
return stationFilter;
|
return stationFilter;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Server.Chat;
|
|
||||||
using Content.Server.Chat.Managers;
|
|
||||||
using Content.Server.Chat.Systems;
|
using Content.Server.Chat.Systems;
|
||||||
using Content.Server.GameTicking;
|
using Content.Server.GameTicking;
|
||||||
using Content.Server.Station.Components;
|
using Content.Server.Station.Components;
|
||||||
@@ -61,6 +59,8 @@ public sealed class StationSystem : EntitySystem
|
|||||||
SubscribeLocalEvent<StationDataComponent, ComponentAdd>(OnStationAdd);
|
SubscribeLocalEvent<StationDataComponent, ComponentAdd>(OnStationAdd);
|
||||||
SubscribeLocalEvent<StationDataComponent, ComponentShutdown>(OnStationDeleted);
|
SubscribeLocalEvent<StationDataComponent, ComponentShutdown>(OnStationDeleted);
|
||||||
SubscribeLocalEvent<StationDataComponent, EntParentChangedMessage>(OnParentChanged);
|
SubscribeLocalEvent<StationDataComponent, EntParentChangedMessage>(OnParentChanged);
|
||||||
|
SubscribeLocalEvent<StationMemberComponent, ComponentShutdown>(OnStationGridDeleted);
|
||||||
|
SubscribeLocalEvent<StationMemberComponent, PostGridSplitEvent>(OnStationSplitEvent);
|
||||||
|
|
||||||
_configurationManager.OnValueChanged(CCVars.StationOffset, x => _randomStationOffset = x, true);
|
_configurationManager.OnValueChanged(CCVars.StationOffset, x => _randomStationOffset = x, true);
|
||||||
_configurationManager.OnValueChanged(CCVars.MaxStationOffset, x => _maxRandomStationOffset = x, true);
|
_configurationManager.OnValueChanged(CCVars.MaxStationOffset, x => _maxRandomStationOffset = x, true);
|
||||||
@@ -69,6 +69,22 @@ public sealed class StationSystem : EntitySystem
|
|||||||
_player.PlayerStatusChanged += OnPlayerStatusChanged;
|
_player.PlayerStatusChanged += OnPlayerStatusChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnStationSplitEvent(EntityUid uid, StationMemberComponent component, ref PostGridSplitEvent args)
|
||||||
|
{
|
||||||
|
AddGridToStation(component.Station, args.Grid); // Add the new grid as a member.
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnStationGridDeleted(EntityUid uid, StationMemberComponent component, ComponentShutdown args)
|
||||||
|
{
|
||||||
|
if (!TryComp<StationDataComponent>(component.Station, out var stationData))
|
||||||
|
return;
|
||||||
|
|
||||||
|
stationData.Grids.Remove(uid);
|
||||||
|
|
||||||
|
// TODO: Remove this when we find out what's mysteriously pulling the rug under us maps wise.
|
||||||
|
_sawmill.Debug($"Station grid is being deleted, trace is: {Environment.StackTrace}");
|
||||||
|
}
|
||||||
|
|
||||||
public override void Shutdown()
|
public override void Shutdown()
|
||||||
{
|
{
|
||||||
base.Shutdown();
|
base.Shutdown();
|
||||||
@@ -109,6 +125,11 @@ public sealed class StationSystem : EntitySystem
|
|||||||
Logger.Error($"Station entity {ToPrettyString(uid)} is getting deleted mid-round. Trace: {Environment.StackTrace}");
|
Logger.Error($"Station entity {ToPrettyString(uid)} is getting deleted mid-round. Trace: {Environment.StackTrace}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var grid in component.Grids)
|
||||||
|
{
|
||||||
|
RemComp<StationMemberComponent>(grid);
|
||||||
|
}
|
||||||
|
|
||||||
_stations.Remove(uid);
|
_stations.Remove(uid);
|
||||||
RaiseNetworkEvent(new StationsUpdatedEvent(_stations), Filter.Broadcast());
|
RaiseNetworkEvent(new StationsUpdatedEvent(_stations), Filter.Broadcast());
|
||||||
}
|
}
|
||||||
@@ -175,14 +196,12 @@ public sealed class StationSystem : EntitySystem
|
|||||||
if (!dict.Any())
|
if (!dict.Any())
|
||||||
{
|
{
|
||||||
// Oh jeez, no stations got loaded.
|
// Oh jeez, no stations got loaded.
|
||||||
// We'll just take the first grid and setup that, then.
|
// We'll yell about it, but the thing this used to do with creating a dummy is kinda pointless now.
|
||||||
|
_sawmill.Error($"There were no station grids for {ev.GameMap.ID}!");
|
||||||
var grid = ev.Grids[0];
|
|
||||||
|
|
||||||
AddGrid("Station", grid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over all PartOfStation
|
// Iterate over all PartOfStation
|
||||||
|
// TODO: Remove this whenever pillar finally gets replaced. It's the sole user.
|
||||||
foreach (var grid in ev.Grids)
|
foreach (var grid in ev.Grids)
|
||||||
{
|
{
|
||||||
if (!TryComp<PartOfStationComponent>(grid, out var partOfStation))
|
if (!TryComp<PartOfStationComponent>(grid, out var partOfStation))
|
||||||
@@ -204,11 +223,12 @@ public sealed class StationSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnRoundEnd(GameRunLevelChangedEvent eventArgs)
|
private void OnRoundEnd(GameRunLevelChangedEvent eventArgs)
|
||||||
{
|
{
|
||||||
if (eventArgs.New != GameRunLevel.PreRoundLobby) return;
|
if (eventArgs.New != GameRunLevel.PreRoundLobby)
|
||||||
|
return;
|
||||||
|
|
||||||
foreach (var entity in _stations)
|
foreach (var entity in _stations)
|
||||||
{
|
{
|
||||||
Del(entity);
|
DeleteStation(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +255,13 @@ public sealed class StationSystem : EntitySystem
|
|||||||
return largestGrid;
|
return largestGrid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Filter GetInStation(EntityUid source, float range = 32f)
|
/// <summary>
|
||||||
|
/// Tries to retrieve a filter for everything in the station the source is on.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source">The entity to use to find the station.</param>
|
||||||
|
/// <param name="range">The range around the station</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Filter GetInOwningStation(EntityUid source, float range = 32f)
|
||||||
{
|
{
|
||||||
var station = GetOwningStation(source);
|
var station = GetOwningStation(source);
|
||||||
|
|
||||||
@@ -261,7 +287,8 @@ public sealed class StationSystem : EntitySystem
|
|||||||
foreach (var gridUid in dataComponent.Grids)
|
foreach (var gridUid in dataComponent.Grids)
|
||||||
{
|
{
|
||||||
if (!_mapManager.TryGetGrid(gridUid, out var grid) ||
|
if (!_mapManager.TryGetGrid(gridUid, out var grid) ||
|
||||||
!xformQuery.TryGetComponent(gridUid, out var xform)) continue;
|
!xformQuery.TryGetComponent(gridUid, out var xform))
|
||||||
|
continue;
|
||||||
|
|
||||||
var mapId = xform.MapID;
|
var mapId = xform.MapID;
|
||||||
var position = _transform.GetWorldPosition(xform, xformQuery);
|
var position = _transform.GetWorldPosition(xform, xformQuery);
|
||||||
@@ -277,17 +304,20 @@ public sealed class StationSystem : EntitySystem
|
|||||||
foreach (var session in Filter.GetAllPlayers(_player))
|
foreach (var session in Filter.GetAllPlayers(_player))
|
||||||
{
|
{
|
||||||
var entity = session.AttachedEntity;
|
var entity = session.AttachedEntity;
|
||||||
if (entity == null || !xformQuery.TryGetComponent(entity, out var xform)) continue;
|
if (entity == null || !xformQuery.TryGetComponent(entity, out var xform))
|
||||||
|
continue;
|
||||||
|
|
||||||
var mapId = xform.MapID;
|
var mapId = xform.MapID;
|
||||||
|
|
||||||
if (!mapIds.Contains(mapId)) continue;
|
if (!mapIds.Contains(mapId))
|
||||||
|
continue;
|
||||||
|
|
||||||
var position = _transform.GetWorldPosition(xform, xformQuery);
|
var position = _transform.GetWorldPosition(xform, xformQuery);
|
||||||
|
|
||||||
foreach (var bound in bounds)
|
foreach (var bound in bounds)
|
||||||
{
|
{
|
||||||
if (!bound.Contains(position)) continue;
|
if (!bound.Contains(position))
|
||||||
|
continue;
|
||||||
|
|
||||||
filter.AddPlayer(session);
|
filter.AddPlayer(session);
|
||||||
break;
|
break;
|
||||||
@@ -355,6 +385,7 @@ public sealed class StationSystem : EntitySystem
|
|||||||
/// <param name="station">Station to attach the grid to.</param>
|
/// <param name="station">Station to attach the grid to.</param>
|
||||||
/// <param name="gridComponent">Resolve pattern, grid component of mapGrid.</param>
|
/// <param name="gridComponent">Resolve pattern, grid component of mapGrid.</param>
|
||||||
/// <param name="stationData">Resolve pattern, station data component of station.</param>
|
/// <param name="stationData">Resolve pattern, station data component of station.</param>
|
||||||
|
/// <param name="name">The name to assign to the grid if any.</param>
|
||||||
/// <exception cref="ArgumentException">Thrown when mapGrid or station are not a grid or station, respectively.</exception>
|
/// <exception cref="ArgumentException">Thrown when mapGrid or station are not a grid or station, respectively.</exception>
|
||||||
public void AddGridToStation(EntityUid station, EntityUid mapGrid, IMapGridComponent? gridComponent = null, StationDataComponent? stationData = null, string? name = null)
|
public void AddGridToStation(EntityUid station, EntityUid mapGrid, IMapGridComponent? gridComponent = null, StationDataComponent? stationData = null, string? name = null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user