Skip to content

Commit

Permalink
Events Stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
dvir001 committed Oct 3, 2024
1 parent de95241 commit 8a45c17
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 19 deletions.
4 changes: 0 additions & 4 deletions Content.Server/Power/EntitySystems/ApcSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ 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 @@ -243,5 +241,3 @@ private void OnToolUseAttempt(EntityUid uid, ApcComponent component, ToolUseAtte

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

public record struct ApcToggledMainBreakerEvent(bool Enabled); // Umbra - ElectricalOverload
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);


}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Content.Server.Power.Components;
namespace Content.Server._NF.Power.Components;

[RegisterComponent]
public sealed partial class ElectricalOverloadComponent : Component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
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.Power.EntitySystems;
namespace Content.Server._NF.Power.EntitySystems;

public sealed class ElectricalOverloadSystem : EntitySystem
{
Expand All @@ -17,29 +18,37 @@ public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ElectricalOverloadComponent, ApcToggledMainBreakerEvent>(OnApcToggleMainBreaker);
SubscribeLocalEvent<ElectricalOverloadComponent, ElectricalOverloadEvent>(OnElectricalOverload);
}

private void OnApcToggleMainBreaker(EntityUid uid, ElectricalOverloadComponent component, ApcToggledMainBreakerEvent args)
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));
EnsureComp<DisableToolUseComponent>(uid, out var disableToolUse); // Frontier
disableToolUse.Anchoring = true;
disableToolUse.Cutting = true;
disableToolUse.Prying = true;
disableToolUse.Screwing = true;
disableToolUse.Welding = true;
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;
RemComp<DisableToolUseComponent>(uid); // Frontier
if (TryComp<DisableToolUseComponent>(uid, out var disableToolUse) && disableToolUse.TemporarilyDisabled)
{
RemComp<DisableToolUseComponent>(uid);
}
}
}

Expand All @@ -66,8 +75,8 @@ public override void Update(float frameTime)
continue;
}

var coords = _transform.GetMapCoordinates(entity); // Frontier - EMP
_emp.EmpPulse(coords, component.EmpRange, component.EmpConsumption, component.EmpDuration); // Frontier - EMP
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));
}
Expand Down
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 @@ -53,7 +53,7 @@ public sealed partial class RandomFaxRuleComponent : Component
public List<IRecipientFaxAction>? PerRecipientActions { get; private set; }

/// <summary>
/// Minimum faxes to send
///
/// </summary>
[DataField]
public int PlayersPerFaxes { get; private set; } = 15;
Expand Down
71 changes: 71 additions & 0 deletions Content.Server/_NF/StationEvents/Events/ElectricStormRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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>
{
[Dependency] private readonly ElectricalOverloadSystem _electricalOverload = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

private const int MaxRetries = 10;
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>(entity); // Umbra - ElectricalOverload
}

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);
}

0 comments on commit 8a45c17

Please sign in to comment.