2021-11-26 03:02:46 -06:00
|
|
|
using System.Linq;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Radiation;
|
2021-11-26 03:02:46 -06:00
|
|
|
using Content.Server.Station;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Coordinates;
|
2021-11-26 03:02:46 -06:00
|
|
|
using Content.Shared.Station;
|
2021-01-18 18:14:53 +08:00
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-08-14 06:52:17 +10:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
using Robust.Shared.Random;
|
2021-02-18 20:45:45 -08:00
|
|
|
using Robust.Shared.Timing;
|
2020-08-14 06:52:17 +10:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.StationEvents.Events
|
2020-08-14 06:52:17 +10:00
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
public sealed class RadiationStorm : StationEvent
|
|
|
|
|
{
|
|
|
|
|
// Based on Goonstation style radiation storm with some TG elements (announcer, etc.)
|
2020-09-06 16:11:53 +02:00
|
|
|
|
2020-08-14 06:52:17 +10:00
|
|
|
[Dependency] private IEntityManager _entityManager = default!;
|
|
|
|
|
[Dependency] private IRobustRandom _robustRandom = default!;
|
|
|
|
|
|
|
|
|
|
public override string Name => "RadiationStorm";
|
2021-06-21 02:13:54 +02:00
|
|
|
public override string StartAnnouncement => Loc.GetString("station-event-radiation-storm-start-announcement");
|
|
|
|
|
protected override string EndAnnouncement => Loc.GetString("station-event-radiation-storm-end-announcement");
|
2021-01-18 18:14:53 +08:00
|
|
|
public override string StartAudio => "/Audio/Announcements/radiation.ogg";
|
|
|
|
|
protected override float StartAfter => 10.0f;
|
2020-08-14 06:52:17 +10:00
|
|
|
|
2021-01-18 18:14:53 +08:00
|
|
|
// Event specific details
|
2020-08-14 06:52:17 +10:00
|
|
|
private float _timeUntilPulse;
|
|
|
|
|
private const float MinPulseDelay = 0.2f;
|
|
|
|
|
private const float MaxPulseDelay = 0.8f;
|
2021-11-26 03:02:46 -06:00
|
|
|
private StationId _target = StationId.Invalid;
|
2020-08-14 06:52:17 +10:00
|
|
|
|
2020-10-12 00:48:43 +02:00
|
|
|
private void ResetTimeUntilPulse()
|
|
|
|
|
{
|
|
|
|
|
_timeUntilPulse = _robustRandom.NextFloat() * (MaxPulseDelay - MinPulseDelay) + MinPulseDelay;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 18:14:53 +08:00
|
|
|
public override void Announce()
|
2020-08-14 06:52:17 +10:00
|
|
|
{
|
2021-01-18 18:14:53 +08:00
|
|
|
base.Announce();
|
|
|
|
|
EndAfter = _robustRandom.Next(30, 80) + StartAfter; // We want to be forgiving about the radstorm.
|
|
|
|
|
}
|
2020-08-14 06:52:17 +10:00
|
|
|
|
2021-01-18 18:14:53 +08:00
|
|
|
public override void Startup()
|
|
|
|
|
{
|
2020-10-12 00:48:43 +02:00
|
|
|
ResetTimeUntilPulse();
|
2021-11-26 03:02:46 -06:00
|
|
|
_target = _robustRandom.Pick(_entityManager.EntityQuery<StationComponent>().ToArray()).Station;
|
2021-01-18 18:14:53 +08:00
|
|
|
base.Startup();
|
2020-08-14 06:52:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
2021-01-18 18:14:53 +08:00
|
|
|
base.Shutdown();
|
2020-08-14 06:52:17 +10:00
|
|
|
}
|
2020-09-06 16:11:53 +02:00
|
|
|
|
2020-08-14 06:52:17 +10:00
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
2021-01-18 18:14:53 +08:00
|
|
|
base.Update(frameTime);
|
2020-08-14 06:52:17 +10:00
|
|
|
|
2021-01-18 18:14:53 +08:00
|
|
|
if (!Started || !Running) return;
|
2020-08-14 06:52:17 +10:00
|
|
|
|
|
|
|
|
_timeUntilPulse -= frameTime;
|
|
|
|
|
|
|
|
|
|
if (_timeUntilPulse <= 0.0f)
|
|
|
|
|
{
|
2020-10-09 23:47:56 +11:00
|
|
|
var pauseManager = IoCManager.Resolve<IPauseManager>();
|
2021-11-26 03:02:46 -06:00
|
|
|
// Account for split stations by just randomly picking a piece of it.
|
|
|
|
|
var possibleTargets = _entityManager.EntityQuery<StationComponent>()
|
|
|
|
|
.Where(x => x.Station == _target).ToArray();
|
|
|
|
|
var stationEnt = _robustRandom.Pick(possibleTargets).OwnerUid;
|
2020-10-09 23:47:56 +11:00
|
|
|
|
2021-11-26 03:02:46 -06:00
|
|
|
if (!_entityManager.TryGetComponent<IMapGridComponent>(stationEnt, out var grid))
|
2020-10-09 23:47:56 +11:00
|
|
|
return;
|
2020-10-12 00:48:43 +02:00
|
|
|
|
2021-11-26 03:02:46 -06:00
|
|
|
if (pauseManager.IsGridPaused(grid.GridIndex))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
SpawnPulse(grid.Grid);
|
2020-08-14 06:52:17 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SpawnPulse(IMapGrid mapGrid)
|
2020-09-06 16:11:53 +02:00
|
|
|
{
|
2020-10-12 00:48:43 +02:00
|
|
|
if (!TryFindRandomGrid(mapGrid, out var coordinates))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var pulse = _entityManager.SpawnEntity("RadiationPulse", coordinates);
|
2020-09-21 01:49:40 +02:00
|
|
|
pulse.GetComponent<RadiationPulseComponent>().DoPulse();
|
2020-10-12 00:48:43 +02:00
|
|
|
ResetTimeUntilPulse();
|
2020-08-14 06:52:17 +10:00
|
|
|
}
|
|
|
|
|
|
2020-10-12 00:48:43 +02:00
|
|
|
private bool TryFindRandomGrid(IMapGrid mapGrid, out EntityCoordinates coordinates)
|
2020-08-14 06:52:17 +10:00
|
|
|
{
|
2020-10-12 00:48:43 +02:00
|
|
|
if (!mapGrid.Index.IsValid())
|
|
|
|
|
{
|
|
|
|
|
coordinates = default;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-08-14 06:52:17 +10:00
|
|
|
|
2021-10-04 02:26:45 +01:00
|
|
|
var bounds = mapGrid.LocalBounds;
|
|
|
|
|
var randomX = _robustRandom.Next((int) bounds.Left, (int) bounds.Right);
|
|
|
|
|
var randomY = _robustRandom.Next((int) bounds.Bottom, (int) bounds.Top);
|
2020-08-14 06:52:17 +10:00
|
|
|
|
2020-10-12 00:48:43 +02:00
|
|
|
coordinates = mapGrid.ToCoordinates(randomX, randomY);
|
|
|
|
|
|
|
|
|
|
// TODO: Need to get valid tiles? (maybe just move right if the tile we chose is invalid?)
|
|
|
|
|
if (!coordinates.IsValid(_entityManager))
|
|
|
|
|
{
|
|
|
|
|
coordinates = default;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2020-08-14 06:52:17 +10:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-06 16:11:53 +02:00
|
|
|
}
|