Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make APCs emp (when turned on) after a random delay during a power grid check #1906

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Content.Server/Power/EntitySystems/ApcSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public void ApcToggleBreaker(EntityUid uid, ApcComponent? apc = null, PowerNetwo
apc.MainBreakerEnabled = !apc.MainBreakerEnabled;
battery.CanDischarge = apc.MainBreakerEnabled;

RaiseLocalEvent(uid, new ApcToggledMainBreakerEvent(apc.MainBreakerEnabled)); // Umbra - ElectricalOverload

UpdateUIState(uid, apc);
_audio.PlayPvs(apc.OnReceiveMessageSound, uid, AudioParams.Default.WithVolume(-2f));
}
Expand Down Expand Up @@ -241,3 +243,5 @@ private void OnToolUseAttempt(EntityUid uid, ApcComponent component, ToolUseAtte

[ByRefEvent]
public record struct ApcToggleMainBreakerAttemptEvent(bool Cancelled);

public record struct ApcToggledMainBreakerEvent(bool Enabled); // Umbra - ElectricalOverload
10 changes: 10 additions & 0 deletions Content.Server/StationEvents/Events/PowerGridCheckRule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Threading;
using Content.Server._NF.Tools.Components; // Frontier
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.StationEvents.Components;
Expand Down Expand Up @@ -52,6 +54,9 @@
if(!apcComponent.MainBreakerEnabled)
_apcSystem.ApcToggleBreaker(entity, apcComponent);
}

RemComp<ElectricalOverloadComponent>(entity); // Umbra - ElectricalOverload
RemComp<OnToolsUseComponent>(entity); // Umbra - ElectricalOverload

Check failure on line 59 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)
}

// Can't use the default EndAudio
Expand Down Expand Up @@ -87,7 +92,12 @@
if (TryComp<ApcComponent>(selected, out var apcComponent))
{
if (apcComponent.MainBreakerEnabled)
{
_apcSystem.ApcToggleBreaker(selected, apcComponent);
EnsureComp<ElectricalOverloadComponent>(selected); // Umbra - ElectricalOverload
var onToolUse = EnsureComp<OnToolsUseComponent>(selected); // Umbra - ElectricalOverload

Check failure on line 98 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 98 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 98 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 98 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 98 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 98 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 98 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 98 in Content.Server/StationEvents/Events/PowerGridCheckRule.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'OnToolsUseComponent' could not be found (are you missing a using directive or an assembly reference?)
onToolUse.Disabled = true; // Umbra - ElectricalOverload
}
}
component.Unpowered.Add(selected);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Content.Server.Power.Components;

[RegisterComponent]
public sealed partial class ElectricalOverloadComponent : Component
{
[ViewVariables]
public DateTime EmpAt = DateTime.MaxValue;

[ViewVariables]
public DateTime NextBuzz = DateTime.MaxValue;

/// <summary>
/// Range of the EMP in tiles.
/// </summary>
[DataField]
public float EmpRange = 1f;

/// <summary>
/// Power consumed from batteries by the EMP
/// </summary>
[DataField]
public float EmpConsumption = 100000f;

/// <summary>
/// How long the EMP effects last for, in seconds
/// </summary>
[DataField]
public float EmpDuration = 15f;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Content.Server.Chat.Systems;
using Content.Server.Emp;
using Content.Server.Power.Components;
using Robust.Shared.Random;

namespace Content.Server.Power.EntitySystems;

public sealed class ElectricalOverloadSystem : EntitySystem
{
[Dependency] private readonly EmpSystem _emp = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly SharedTransformSystem _transform = 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 Emp!
component.EmpAt = DateTime.Now + TimeSpan.FromSeconds(_random.NextDouble(25, 35));
component.NextBuzz = DateTime.Now + TimeSpan.FromSeconds(_random.NextDouble(3, 5));
}
else
{
// Toggled off, means cancel emp.
component.EmpAt = 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.EmpAt > 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;
}

var coords = _transform.GetMapCoordinates(entity); // Frontier - EMP
_emp.EmpPulse(coords, component.EmpRange, component.EmpConsumption, component.EmpDuration); // Frontier - EMP
// if the device survives, we add a bit of randomness to the next emp time
component.EmpAt = DateTime.Now + TimeSpan.FromSeconds(_random.NextDouble(3, 10));
}
}
}
1 change: 1 addition & 0 deletions Resources/Locale/en-US/_Umbra/power/overload.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
electrical-overload-system-buzz = buzzes
Loading