2021-02-18 20:45:45 -08:00
|
|
|
#nullable enable
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.GameTicking;
|
|
|
|
|
using Content.Server.Radiation;
|
|
|
|
|
using Content.Shared.Coordinates;
|
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-01-18 18:14:53 +08:00
|
|
|
public override string StartAnnouncement => Loc.GetString(
|
2020-08-14 06:52:17 +10:00
|
|
|
"High levels of radiation detected near the station. Evacuate any areas containing abnormal green energy fields.");
|
|
|
|
|
protected override string EndAnnouncement => Loc.GetString(
|
|
|
|
|
"The radiation threat has passed. Please return to your workplaces.");
|
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;
|
|
|
|
|
|
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-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-06-20 10:09:24 +02:00
|
|
|
var defaultGrid = IoCManager.Resolve<IMapManager>().GetGrid(EntitySystem.Get<GameTicker>().DefaultGridId);
|
2020-10-09 23:47:56 +11:00
|
|
|
|
|
|
|
|
if (pauseManager.IsGridPaused(defaultGrid))
|
|
|
|
|
return;
|
2020-10-12 00:48:43 +02:00
|
|
|
|
2020-10-09 23:47:56 +11:00
|
|
|
SpawnPulse(defaultGrid);
|
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
|
|
|
|
|
|
|
|
var randomX = _robustRandom.Next((int) mapGrid.WorldBounds.Left, (int) mapGrid.WorldBounds.Right);
|
|
|
|
|
var randomY = _robustRandom.Next((int) mapGrid.WorldBounds.Bottom, (int) mapGrid.WorldBounds.Top);
|
|
|
|
|
|
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
|
|
|
}
|