forked from new-frontiers-14/frontier-station-14
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make APCs explode (when turned on) after a random delay during a powe…
…r grid check. (new-frontiers-14#24) * Make APCs explode after a random delay during a power grid check. * Change buzz message according to review * Make message hidden in chat * Increase delay between buzzes * Named parameters --------- Co-authored-by: TsjipTsjip <[email protected]>
- Loading branch information
Showing
5 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
Content.Server/Power/Components/ElectricalOverloadComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Content.Shared.Explosion; | ||
|
||
namespace Content.Server.Power.Components; | ||
|
||
[RegisterComponent] | ||
public sealed partial class ElectricalOverloadComponent : Component | ||
{ | ||
[ValidatePrototypeId<ExplosionPrototype>] | ||
[DataField] | ||
public string ExplosionOnOverload = "Default"; | ||
|
||
[ViewVariables] | ||
public DateTime ExplodeAt = DateTime.MaxValue; | ||
|
||
[ViewVariables] | ||
public DateTime NextBuzz = DateTime.MaxValue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
Content.Server/Power/EntitySystems/ElectricalOverloadSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Content.Server.Chat.Systems; | ||
using Content.Server.Explosion.EntitySystems; | ||
using Content.Server.Power.Components; | ||
using Robust.Shared.Random; | ||
|
||
namespace Content.Server.Power.EntitySystems; | ||
|
||
public sealed class ElectricalOverloadSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly ExplosionSystem _explosionSystem = default!; | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
[Dependency] private readonly ChatSystem _chatSystem = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<ElectricalOverloadComponent, ApcToggledMainBreakerEvent>(OnApcToggleMainBreaker); | ||
} | ||
|
||
private void OnApcToggleMainBreaker(EntityUid uid, ElectricalOverloadComponent component, ApcToggledMainBreakerEvent args) | ||
{ | ||
if (args.Enabled) | ||
{ | ||
// Toggled on, means explode! | ||
component.ExplodeAt = DateTime.Now + TimeSpan.FromSeconds(_random.NextDouble(25, 35)); | ||
component.NextBuzz = DateTime.Now + TimeSpan.FromSeconds(_random.NextDouble(3, 5)); | ||
} | ||
else | ||
{ | ||
// Toggled off, means cancel explosion. | ||
component.ExplodeAt = DateTime.MaxValue; | ||
component.NextBuzz = DateTime.MaxValue; | ||
} | ||
} | ||
|
||
public override void Update(float frameTime) | ||
{ | ||
base.Update(frameTime); | ||
|
||
var enumerator = EntityQueryEnumerator<ElectricalOverloadComponent>(); | ||
while (enumerator.MoveNext(out var entity, out var component)) | ||
{ | ||
if (component.ExplodeAt > DateTime.Now) | ||
{ | ||
if (component.NextBuzz > DateTime.Now) | ||
continue; | ||
|
||
component.NextBuzz = DateTime.Now + TimeSpan.FromSeconds(_random.NextDouble(7, 15)); | ||
_chatSystem.TrySendInGameICMessage( | ||
entity, | ||
Loc.GetString("electrical-overload-system-buzz"), | ||
InGameICChatType.Emote, | ||
hideChat: true, | ||
ignoreActionBlocker: true | ||
); | ||
continue; | ||
} | ||
|
||
_explosionSystem.QueueExplosion(entity, component.ExplosionOnOverload, 2f, 0.5f, 2f, 1f, int.MaxValue, false, null, true); | ||
// if the device survives, we add a bit of randomness to the next explosion time | ||
component.ExplodeAt = DateTime.Now + TimeSpan.FromSeconds(_random.NextDouble(3, 10)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
electrical-overload-system-buzz = buzzes |