2021-01-18 18:14:53 +08:00
|
|
|
using System.Collections.Generic;
|
2020-09-21 09:14:40 +10:00
|
|
|
using System.Threading;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Power.Components;
|
2020-08-14 06:52:17 +10:00
|
|
|
using JetBrains.Annotations;
|
2021-03-01 20:42:54 -08:00
|
|
|
using Robust.Shared.Audio;
|
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;
|
2021-03-01 20:42:54 -08:00
|
|
|
using Robust.Shared.Player;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Random;
|
2021-02-18 20:45:45 -08:00
|
|
|
using Timer = Robust.Shared.Timing.Timer;
|
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 PowerGridCheck : StationEvent
|
|
|
|
|
{
|
|
|
|
|
public override string Name => "PowerGridCheck";
|
2021-01-18 18:14:53 +08:00
|
|
|
public override float Weight => WeightNormal;
|
|
|
|
|
public override int? MaxOccurrences => 3;
|
2021-06-21 02:13:54 +02:00
|
|
|
public override string StartAnnouncement => Loc.GetString("station-event-power-grid-check-start-announcement");
|
|
|
|
|
protected override string EndAnnouncement => Loc.GetString("station-event-power-grid-check-end-announcement");
|
2021-01-18 18:14:53 +08:00
|
|
|
public override string? StartAudio => "/Audio/Announcements/power_off.ogg";
|
2020-08-14 06:52:17 +10:00
|
|
|
|
2021-01-18 18:14:53 +08:00
|
|
|
// If you need EndAudio it's down below. Not set here because we can't play it at the normal time without spamming sounds.
|
2020-11-21 14:02:00 +01:00
|
|
|
|
2021-01-18 18:14:53 +08:00
|
|
|
protected override float StartAfter => 12.0f;
|
2020-09-21 09:14:40 +10:00
|
|
|
|
2021-01-18 18:14:53 +08:00
|
|
|
private CancellationTokenSource? _announceCancelToken;
|
2020-09-03 21:21:16 -05:00
|
|
|
|
2020-11-27 11:00:49 +01:00
|
|
|
private readonly List<IEntity> _powered = new();
|
2020-11-21 14:02:00 +01:00
|
|
|
|
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 = IoCManager.Resolve<IRobustRandom>().Next(60, 120);
|
|
|
|
|
}
|
2020-08-14 06:52:17 +10:00
|
|
|
|
2021-01-18 18:14:53 +08:00
|
|
|
public override void Startup()
|
|
|
|
|
{
|
2021-09-28 13:35:29 +02:00
|
|
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
2020-11-21 14:02:00 +01:00
|
|
|
|
2021-09-28 13:35:29 +02:00
|
|
|
foreach (var component in entityManager.EntityQuery<ApcPowerReceiverComponent>(true))
|
2020-08-14 06:52:17 +10:00
|
|
|
{
|
|
|
|
|
component.PowerDisabled = true;
|
2020-09-03 21:21:16 -05:00
|
|
|
_powered.Add(component.Owner);
|
2020-08-14 06:52:17 +10:00
|
|
|
}
|
2021-01-18 18:14:53 +08:00
|
|
|
|
|
|
|
|
base.Startup();
|
2020-08-14 06:52:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
2020-09-03 21:21:16 -05:00
|
|
|
foreach (var entity in _powered)
|
2020-08-14 06:52:17 +10:00
|
|
|
{
|
|
|
|
|
if (entity.Deleted) continue;
|
2020-11-21 14:02:00 +01:00
|
|
|
|
2021-07-04 18:11:52 +02:00
|
|
|
if (entity.TryGetComponent(out ApcPowerReceiverComponent? powerReceiverComponent))
|
2020-08-14 06:52:17 +10:00
|
|
|
{
|
2020-09-03 21:21:16 -05:00
|
|
|
powerReceiverComponent.PowerDisabled = false;
|
2020-08-14 06:52:17 +10:00
|
|
|
}
|
|
|
|
|
}
|
2020-11-21 14:02:00 +01:00
|
|
|
|
2021-01-18 18:14:53 +08:00
|
|
|
// Can't use the default EndAudio
|
2020-09-21 09:14:40 +10:00
|
|
|
_announceCancelToken?.Cancel();
|
|
|
|
|
_announceCancelToken = new CancellationTokenSource();
|
|
|
|
|
Timer.Spawn(3000, () =>
|
|
|
|
|
{
|
2021-03-01 20:42:54 -08:00
|
|
|
SoundSystem.Play(Filter.Broadcast(), "/Audio/Announcements/power_on.ogg");
|
2020-09-21 09:14:40 +10:00
|
|
|
}, _announceCancelToken.Token);
|
2020-08-14 06:52:17 +10:00
|
|
|
_powered.Clear();
|
|
|
|
|
|
2021-01-18 18:14:53 +08:00
|
|
|
base.Shutdown();
|
2020-08-14 06:52:17 +10:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-03 21:21:16 -05:00
|
|
|
}
|