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

ElectricStorm Event #2142

Closed
wants to merge 14 commits into from
20 changes: 19 additions & 1 deletion Content.Server/StationEvents/Components/StationEventComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,25 @@ public sealed partial class StationEventComponent : Component
/// Frontier - How many players need to be present on station for the event to not run, to avoid running safe events with high-pop
/// </remarks>
[DataField]
public int MaximumPlayers = 999;
public int MaximumPlayers = 9999;

/// <summary>
/// Frontier -
/// </remarks>
[DataField]
public int MinimumStations = 1;

/// <summary>
/// Frontier -
/// </remarks>
[DataField]
public int MaximumStations = 1;

/// <summary>
/// Frontier -
/// </summary>
[DataField]
public int PlayersPerEvent = 10;

/// <summary>
/// How many times this even can occur in a single round
Expand Down
7 changes: 7 additions & 0 deletions Content.Server/StationEvents/EventManagerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,11 @@ private bool CanRun(EntityPrototype prototype, StationEventComponent stationEven

return true;
}

public void GetEventStations(StationEventComponent stationEvent)
{
var numStations = Math.Clamp(_playerManager.PlayerCount / stationEvent.PlayersPerEvent, stationEvent.MinimumStations, stationEvent.MaximumStations);


}
}
29 changes: 29 additions & 0 deletions Content.Server/_NF/Power/Components/ElectricalOverloadComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Content.Server._NF.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;
}
84 changes: 84 additions & 0 deletions Content.Server/_NF/Power/EntitySystems/ElectricalOverloadSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using Content.Server._NF.Power.Components;
using Content.Server._NF.Tools.Components;
using Content.Server.Chat.Systems;
using Content.Server.Emp;
using Content.Server.Power.Components;
using Robust.Shared.Random;

namespace Content.Server._NF.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, ElectricalOverloadEvent>(OnElectricalOverload);
}

private void OnElectricalOverload(EntityUid uid, ElectricalOverloadComponent component, ElectricalOverloadEvent args)
{
if (args.Enabled)
{
// Toggled on, means EMP pulse!
component.EmpAt = DateTime.Now + TimeSpan.FromSeconds(_random.NextDouble(25, 35));
component.NextBuzz = DateTime.Now + TimeSpan.FromSeconds(_random.NextDouble(3, 5));
if (!HasComp<DisableToolUseComponent>(uid))
{
EnsureComp<DisableToolUseComponent>(uid, out var disableToolUse);
disableToolUse.Anchoring = true;
disableToolUse.Cutting = true;
disableToolUse.Prying = true;
disableToolUse.Screwing = true;
disableToolUse.Welding = true;

disableToolUse.TemporarilyDisabled = true; // Event
}
}
else
{
// Toggled off, means cancel EMP pulse.
component.EmpAt = DateTime.MaxValue;
component.NextBuzz = DateTime.MaxValue;
if (TryComp<DisableToolUseComponent>(uid, out var disableToolUse) && disableToolUse.TemporarilyDisabled)
{
RemComp<DisableToolUseComponent>(uid);
}
}
}

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);
_emp.EmpPulse(coords, component.EmpRange, component.EmpConsumption, component.EmpDuration);
// We add a bit of randomness to the next EMP pulse time
component.EmpAt = DateTime.Now + TimeSpan.FromSeconds(_random.NextDouble(3, 10));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Threading;
using Content.Server.StationEvents.Events;

namespace Content.Server.StationEvents.Components;

/// <summary>
/// Solar Flare event specific configuration
/// </summary>
[RegisterComponent, Access(typeof(ElectricStormRule))]
public sealed partial class ElectricStormRuleComponent : Component
{
/// <summary>
/// Chance light bulb breaks per second during event
/// </summary>
[DataField]
public float ComputerChance;

/// <summary>
/// Chance door toggles per second during event
/// </summary>
[DataField]
public float MachineChance;

/// <summary>
/// Minimum faxes to send
/// </summary>
[DataField]
public int PlayersPerTargets { get; private set; } = 5;

/// <summary>
/// Minimum faxes to send
/// </summary>
[DataField]
public int MinTargets { get; private set; } = 1;

/// <summary>
/// Maximum faxes to send
/// </summary>
[DataField]
public int MaxTargets { get; private set; } = 10;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public sealed partial class RandomFaxRuleComponent : Component
[DataField]
public List<IRecipientFaxAction>? PerRecipientActions { get; private set; }

/// <summary>
///
/// </summary>
[DataField]
public int PlayersPerFaxes { get; private set; } = 15;

/// <summary>
/// Minimum faxes to send
/// </summary>
Expand All @@ -62,7 +68,7 @@ public sealed partial class RandomFaxRuleComponent : Component
/// Maximum faxes to send
/// </summary>
[DataField]
public int MaxFaxes { get; private set; } = 1;
public int MaxFaxes { get; private set; } = 3;
}

// TODO: relocate these definitions.
Expand Down Expand Up @@ -101,4 +107,4 @@ public sealed partial class EditableFaxPrintout
public string? StampState;
public List<StampDisplayInfo> StampedBy = new();
public bool Locked;
}
}
68 changes: 68 additions & 0 deletions Content.Server/_NF/StationEvents/Events/ElectricStormRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Content.Server.GameTicking.Rules.Components;
using Robust.Shared.Random;
using Content.Server.StationEvents.Components;
using Content.Shared.GameTicking.Components;
using Content.Server.Construction.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Power.Components;
using Content.Shared.Station.Components;
using Robust.Server.Player;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Server._NF.Power.EntitySystems;
using Content.Server._NF.Power.Components;

namespace Content.Server.StationEvents.Events;

public sealed class ElectricStormRule : StationEventSystem<ElectricStormRuleComponent>
{
private float _effectTimer = 0;

public override void Initialize()
{
base.Initialize();
}

protected override void Started(EntityUid uid, ElectricStormRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);

RaiseLocalEvent(uid, new ElectricalOverloadEvent(true));
}

protected override void Ended(EntityUid uid, ElectricStormRuleComponent component, GameRuleComponent gameRule, GameRuleEndedEvent args)
{
base.Ended(uid, component, gameRule, args);

RemComp<ElectricalOverloadComponent>(uid);
}

protected override void ActiveTick(EntityUid uid, ElectricStormRuleComponent component, GameRuleComponent gameRule, float frameTime)
{
base.ActiveTick(uid, component, gameRule, frameTime);

_effectTimer -= frameTime;
if (_effectTimer < 0)
{
_effectTimer += 1;
var computerQuery = EntityQueryEnumerator<ComputerComponent>();
while (computerQuery.MoveNext(out var computerEnt, out var computer))
{
if (RobustRandom.Prob(component.ComputerChance))
{
EnsureComp<ElectricalOverloadComponent>(computerEnt);
}
}
var lightQuery = EntityQueryEnumerator<MachineComponent>();
while (lightQuery.MoveNext(out var machineEnt, out var machine))
{
if (RobustRandom.Prob(component.MachineChance))
{
EnsureComp<ElectricalOverloadComponent>(machineEnt);
}
}
}
}

public record struct ElectricalOverloadEvent(bool Enabled);
}
6 changes: 3 additions & 3 deletions Content.Server/_NF/StationEvents/Events/RandomFaxRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Content.Shared.Fax.Components;
using Content.Server.Fax;
using Content.Server.Station.Systems;
using Robust.Shared.Random;
using Robust.Server.Player;

namespace Content.Server.StationEvents.Events;

Expand All @@ -13,7 +13,7 @@ public sealed class RandomFaxRule : StationEventSystem<RandomFaxRuleComponent>
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly FaxSystem _faxSystem = default!;
[Dependency] private readonly StationSystem _stationSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

private const int MaxRetries = 10;
protected override void Added(EntityUid uid, RandomFaxRuleComponent component, GameRuleComponent gameRule, GameRuleAddedEvent args)
Expand Down Expand Up @@ -41,7 +41,7 @@ protected override void Started(EntityUid uid, RandomFaxRuleComponent component,
{
base.Started(uid, component, gameRule, args);

var numFaxes = _random.Next(component.MinFaxes, component.MaxFaxes);
var numFaxes = Math.Clamp(_playerManager.PlayerCount / component.PlayersPerFaxes, component.MinFaxes, component.MaxFaxes);

List<EntityUid> stations = new();
int retries = 0;
Expand Down
7 changes: 3 additions & 4 deletions Content.Server/_NF/Tools/Component/DisableToolUseComponent.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using Content.Shared.Tools;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

namespace Content.Server._NF.Tools.Components
{
[RegisterComponent]
Expand Down Expand Up @@ -30,5 +26,8 @@ public sealed partial class DisableToolUseComponent : Component
public bool Rolling;
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool Digging;

[DataField, ViewVariables(VVAccess.ReadWrite)] // Used by events
public bool TemporarilyDisabled;
}
}
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