Solar flare better effects (#14400)

This commit is contained in:
Slava0135
2023-03-07 02:35:59 +03:00
committed by GitHub
parent cb8909ce17
commit 32f316218e
3 changed files with 32 additions and 22 deletions

View File

@@ -33,8 +33,14 @@ public sealed class SolarFlareEventRuleConfiguration : StationEventRuleConfigura
public readonly HashSet<string> AffectedChannels = new(); public readonly HashSet<string> AffectedChannels = new();
/// <summary> /// <summary>
/// Chance any given light bulb breaks due to event /// Chance light bulb breaks per second during event
/// </summary> /// </summary>
[DataField("lightBreakChance")] [DataField("lightBreakChancePerSecond")]
public float LightBreakChance; public float LightBreakChancePerSecond;
/// <summary>
/// Chance door toggles per second during event
/// </summary>
[DataField("doorToggleChancePerSecond")]
public float DoorToggleChancePerSecond;
} }

View File

@@ -5,16 +5,20 @@ using Robust.Shared.Random;
using Content.Server.Light.EntitySystems; using Content.Server.Light.EntitySystems;
using Content.Server.Light.Components; using Content.Server.Light.Components;
using Content.Shared.Radio.Components; using Content.Shared.Radio.Components;
using Content.Shared.Doors.Components;
using Content.Shared.Doors.Systems;
namespace Content.Server.StationEvents.Events; namespace Content.Server.StationEvents.Events;
public sealed class SolarFlare : StationEventSystem public sealed class SolarFlare : StationEventSystem
{ {
[Dependency] private readonly PoweredLightSystem _poweredLight = default!; [Dependency] private readonly PoweredLightSystem _poweredLight = default!;
[Dependency] private readonly SharedDoorSystem _door = default!;
public override string Prototype => "SolarFlare"; public override string Prototype => "SolarFlare";
private SolarFlareEventRuleConfiguration _event = default!; private SolarFlareEventRuleConfiguration _event = default!;
private float _effectTimer = 0;
public override void Initialize() public override void Initialize()
{ {
@@ -33,24 +37,6 @@ public sealed class SolarFlare : StationEventSystem
_event.EndAfter = RobustRandom.Next(ev.MinEndAfter, ev.MaxEndAfter); _event.EndAfter = RobustRandom.Next(ev.MinEndAfter, ev.MaxEndAfter);
} }
public override void Started()
{
base.Started();
MessLights();
}
private void MessLights()
{
foreach (var comp in EntityQuery<PoweredLightComponent>())
{
if (RobustRandom.Prob(_event.LightBreakChance))
{
var uid = comp.Owner;
_poweredLight.TryDestroyBulb(uid, comp);
}
}
}
public override void Update(float frameTime) public override void Update(float frameTime)
{ {
base.Update(frameTime); base.Update(frameTime);
@@ -58,6 +44,23 @@ public sealed class SolarFlare : StationEventSystem
if (!RuleStarted) if (!RuleStarted)
return; return;
_effectTimer -= frameTime;
if (_effectTimer < 0)
{
_effectTimer += 1;
foreach (var comp in EntityQuery<PoweredLightComponent>())
{
if (RobustRandom.Prob(_event.LightBreakChancePerSecond))
_poweredLight.TryDestroyBulb(comp.Owner, comp);
}
foreach (var comp in EntityQuery<DoorComponent>())
{
if (RobustRandom.Prob(_event.DoorToggleChancePerSecond))
_door.TryToggleDoor(comp.Owner, comp);
}
}
if (Elapsed > _event.EndAfter) if (Elapsed > _event.EndAfter)
{ {
ForceEndSelf(); ForceEndSelf();

View File

@@ -177,7 +177,8 @@
affectedChannels: affectedChannels:
- Common - Common
- Service - Service
lightBreakChance: 0.05 lightBreakChancePerSecond: 0.0003
doorToggleChancePerSecond: 0.001
- type: gameRule - type: gameRule
id: VentClog id: VentClog