* Station event system Adds 2 basic events: (Power) GridCheck and RadiationStorm (based on the goonstation version). The system itself to choose events is based on tgstation's implementation. This also adds the event command that can be run to force specific events. There's still some other TODO items for these to be complete, to my knowledge: 1. There's no worldspace DrawCircle method (though the radstorm could look a lot nicer with a shader). 2. The PlayGlobal power_off / power_on audio seems to cut out halfway-through 3. (I think this is a known issue) lights still emit light until you get closer in a gridcheck so PVS range might need bumping. * Invariants for event names * Fix random event shutdown * Mix stereo announcements to mono * Address feedback * Remove redundant client system and use the overlay component instead * Drop the server prefix * Fix radiation overlay enum * use entityquery instead * zum's feedback * Use EntityQuery Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
89 lines
2.9 KiB
C#
89 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Content.Server.GameObjects.Components.Power;
|
|
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
|
using Content.Server.GameObjects.Components.Power.PowerNetComponents;
|
|
using JetBrains.Annotations;
|
|
using Robust.Server.GameObjects.EntitySystems;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.GameObjects.Systems;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
using Robust.Shared.Interfaces.Random;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Localization;
|
|
|
|
namespace Content.Server.StationEvents
|
|
{
|
|
[UsedImplicitly]
|
|
public sealed class PowerGridCheck : StationEvent
|
|
{
|
|
public override string Name => "PowerGridCheck";
|
|
|
|
public override StationEventWeight Weight => StationEventWeight.Normal;
|
|
|
|
public override int? MaxOccurrences => 3;
|
|
|
|
protected override string StartAnnouncement => Loc.GetString(
|
|
"Abnormal activity detected in the station's powernet. As a precautionary measure, the station's power will be shut off for an indeterminate duration.");
|
|
|
|
protected override string EndAnnouncement => Loc.GetString(
|
|
"Power has been restored to the station. We apologize for the inconvenience.");
|
|
|
|
private float _elapsedTime;
|
|
private int _failDuration;
|
|
|
|
private Dictionary<IEntity, bool> _powered = new Dictionary<IEntity, bool>();
|
|
|
|
private readonly List<PowerReceiverComponent> _toPowerDown = new List<PowerReceiverComponent>();
|
|
|
|
public override void Startup()
|
|
{
|
|
base.Startup();
|
|
EntitySystem.Get<AudioSystem>().PlayGlobal("/Audio/Announcements/power_off.ogg");
|
|
|
|
_elapsedTime = 0.0f;
|
|
_failDuration = IoCManager.Resolve<IRobustRandom>().Next(30, 120);
|
|
var componentManager = IoCManager.Resolve<IComponentManager>();
|
|
|
|
foreach (var component in componentManager.EntityQuery<PowerReceiverComponent>())
|
|
{
|
|
component.PowerDisabled = true;
|
|
}
|
|
}
|
|
|
|
public override void Shutdown()
|
|
{
|
|
base.Shutdown();
|
|
EntitySystem.Get<AudioSystem>().PlayGlobal("/Audio/Announcements/power_on.ogg");
|
|
|
|
foreach (var (entity, powered) in _powered)
|
|
{
|
|
if (entity.Deleted) continue;
|
|
|
|
if (entity.TryGetComponent(out PowerReceiverComponent powerReceiverComponent))
|
|
{
|
|
powerReceiverComponent.PowerDisabled = powered;
|
|
}
|
|
}
|
|
|
|
_powered.Clear();
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
if (!Running)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_elapsedTime += frameTime;
|
|
|
|
if (_elapsedTime < _failDuration)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Running = false;
|
|
}
|
|
}
|
|
} |