fix nuke when arming off station (#16702)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -24,7 +24,7 @@ namespace Content.Server.Nuke
|
|||||||
[Dependency] private readonly PopupSystem _popups = default!;
|
[Dependency] private readonly PopupSystem _popups = default!;
|
||||||
[Dependency] private readonly ExplosionSystem _explosions = default!;
|
[Dependency] private readonly ExplosionSystem _explosions = default!;
|
||||||
[Dependency] private readonly AlertLevelSystem _alertLevel = default!;
|
[Dependency] private readonly AlertLevelSystem _alertLevel = default!;
|
||||||
[Dependency] private readonly StationSystem _stationSystem = default!;
|
[Dependency] private readonly StationSystem _station = default!;
|
||||||
[Dependency] private readonly ServerGlobalSoundSystem _soundSystem = default!;
|
[Dependency] private readonly ServerGlobalSoundSystem _soundSystem = default!;
|
||||||
[Dependency] private readonly ChatSystem _chatSystem = default!;
|
[Dependency] private readonly ChatSystem _chatSystem = default!;
|
||||||
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
||||||
@@ -99,7 +99,7 @@ namespace Content.Server.Nuke
|
|||||||
|
|
||||||
private void OnMapInit(EntityUid uid, NukeComponent nuke, MapInitEvent args)
|
private void OnMapInit(EntityUid uid, NukeComponent nuke, MapInitEvent args)
|
||||||
{
|
{
|
||||||
var originStation = _stationSystem.GetOwningStation(uid);
|
var originStation = _station.GetOwningStation(uid);
|
||||||
|
|
||||||
if (originStation != null)
|
if (originStation != null)
|
||||||
nuke.OriginStation = originStation;
|
nuke.OriginStation = originStation;
|
||||||
@@ -436,14 +436,14 @@ namespace Content.Server.Nuke
|
|||||||
if (component.Status == NukeStatus.ARMED)
|
if (component.Status == NukeStatus.ARMED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var stationUid = _stationSystem.GetOwningStation(uid);
|
var nukeXform = Transform(uid);
|
||||||
|
var stationUid = _station.GetStationInMap(nukeXform.MapID);
|
||||||
// The nuke may not be on a station, so it's more important to just
|
// The nuke may not be on a station, so it's more important to just
|
||||||
// let people know that a nuclear bomb was armed in their vicinity instead.
|
// let people know that a nuclear bomb was armed in their vicinity instead.
|
||||||
// Otherwise, you could set every station to whatever AlertLevelOnActivate is.
|
// Otherwise, you could set every station to whatever AlertLevelOnActivate is.
|
||||||
if (stationUid != null)
|
if (stationUid != null)
|
||||||
_alertLevel.SetLevel(stationUid.Value, component.AlertLevelOnActivate, true, true, true, true);
|
_alertLevel.SetLevel(stationUid.Value, component.AlertLevelOnActivate, true, true, true, true);
|
||||||
|
|
||||||
var nukeXform = Transform(uid);
|
|
||||||
var pos = nukeXform.MapPosition;
|
var pos = nukeXform.MapPosition;
|
||||||
var x = (int) pos.X;
|
var x = (int) pos.X;
|
||||||
var y = (int) pos.Y;
|
var y = (int) pos.Y;
|
||||||
@@ -453,7 +453,7 @@ namespace Content.Server.Nuke
|
|||||||
var announcement = Loc.GetString("nuke-component-announcement-armed",
|
var announcement = Loc.GetString("nuke-component-announcement-armed",
|
||||||
("time", (int) component.RemainingTime), ("position", posText));
|
("time", (int) component.RemainingTime), ("position", posText));
|
||||||
var sender = Loc.GetString("nuke-component-announcement-sender");
|
var sender = Loc.GetString("nuke-component-announcement-sender");
|
||||||
_chatSystem.DispatchStationAnnouncement(uid, announcement, sender, false, null, Color.Red);
|
_chatSystem.DispatchStationAnnouncement(stationUid ?? uid, announcement, sender, false, null, Color.Red);
|
||||||
|
|
||||||
_soundSystem.PlayGlobalOnStation(uid, _audio.GetSound(component.ArmSound));
|
_soundSystem.PlayGlobalOnStation(uid, _audio.GetSound(component.ArmSound));
|
||||||
|
|
||||||
@@ -474,7 +474,7 @@ namespace Content.Server.Nuke
|
|||||||
if (component.Status != NukeStatus.ARMED)
|
if (component.Status != NukeStatus.ARMED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var stationUid = _stationSystem.GetOwningStation(uid);
|
var stationUid = _station.GetOwningStation(uid);
|
||||||
if (stationUid != null)
|
if (stationUid != null)
|
||||||
_alertLevel.SetLevel(stationUid.Value, component.AlertLevelOnDeactivate, true, true, true);
|
_alertLevel.SetLevel(stationUid.Value, component.AlertLevelOnDeactivate, true, true, true);
|
||||||
|
|
||||||
|
|||||||
@@ -440,6 +440,30 @@ public sealed class StationSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
return EntityQuery<StationDataComponent>().Select(x => x.Owner).ToHashSet();
|
return EntityQuery<StationDataComponent>().Select(x => x.Owner).ToHashSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the first station that has a grid in a certain map.
|
||||||
|
/// If the map has no stations, null is returned instead.
|
||||||
|
/// </summary>
|
||||||
|
/// </remarks
|
||||||
|
/// If there are multiple stations on a map it is probably arbitrary which one is returned.
|
||||||
|
/// </remarks>
|
||||||
|
public EntityUid? GetStationInMap(MapId map)
|
||||||
|
{
|
||||||
|
var query = EntityQueryEnumerator<StationDataComponent>();
|
||||||
|
while (query.MoveNext(out var uid, out var data))
|
||||||
|
{
|
||||||
|
foreach (var gridUid in data.Grids)
|
||||||
|
{
|
||||||
|
if (Transform(gridUid).MapID == map)
|
||||||
|
{
|
||||||
|
return uid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user