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

Graytide Virus Event #1293

Merged
merged 5 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Content.Server.StationEvents.Events;

namespace Content.Server.StationEvents.Components;

[RegisterComponent]
public sealed partial class AirlockVirusRuleComponent : Component
{
/// <summary>
/// The minimum amount of time in seconds before each infected door is self-emagged.
/// </summary>
[DataField]
public int MinimumTimeToEmag = 30;

/// <summary>
/// The maximum amount of time in seconds before each infected door is self-emagged.
/// </summary>
[DataField]
public int MaximumTimeToEmag = 120;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Content.Server.StationEvents.Components;

[RegisterComponent]
public sealed partial class AirlockVirusTargetComponent : Component { }
61 changes: 61 additions & 0 deletions Content.Server/StationEvents/Events/AirlockVirusRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Content.Server.StationEvents.Components;
using Content.Shared.GameTicking.Components;
using JetBrains.Annotations;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Content.Server.Announcements.Systems;
using Content.Server.GameTicking;
using Content.Shared.Emag.Systems;
using Robust.Shared.Timing;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;

namespace Content.Server.StationEvents.Events;

[UsedImplicitly]
public sealed class AirlockVirusRule : StationEventSystem<AirlockVirusRuleComponent>
{
[Dependency] private readonly AnnouncerSystem _announcer = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly EmagSystem _emag = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly StationSystem _station = default!;

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

var station = _gameTicker.GetSpawnableStations();
if (station is null)
return;
var stationGrids = new HashSet<EntityUid>();
foreach (var stations in station)
{
if (TryComp<StationDataComponent>(stations, out var data) && _station.GetLargestGrid(data) is { } grid)
stationGrids.Add(grid);
}

var query = EntityManager.EntityQueryEnumerator<AirlockVirusTargetComponent>();
List<EntityUid> airlocks = new();
while (query.MoveNext(out var airlockUid, out var _))
{
var parent = Transform(airlockUid).GridUid;
if (parent is null
|| !stationGrids.Contains(parent!.Value))
continue;

airlocks.Add(airlockUid);
}
foreach (var target in airlocks)
Timer.Spawn(TimeSpan.FromSeconds(_random.NextDouble(component.MinimumTimeToEmag, component.MaximumTimeToEmag)), () =>
_emag.DoEmagEffect(uid, target));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can probably remove the whole airlocks list and do it inside the while block

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fatally allergic to while loops lmao. I'm horribly foreachpilled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're iterating over the airlocks twice basically. First time you're gathering them in while querry, next time you're applying effects to them. This is simply redundant

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh. Actually I see how you're right. gimme a few minutes to drop the PR I'm about to drop and I'll do this right away.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! There is now no longer a second loop. If an airlock passes the check, it targets that airlock with the emag timer.


_announcer.SendAnnouncement(
_announcer.GetAnnouncementId(args.RuleId),
Filter.Broadcast(),
"airlock-virus-event-announcement",
null,
Color.FromHex("#18abf5"),
null, null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
airlock-virus-event-announcement = We have detected a GR4YT1D3 virus in the station's systems. Engineering staff are to inspect all station equipment for malfunctions and affect repairs if necessary.
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@
- type: ContainerFill
containers:
board: [ DoorElectronicsSecurity ]
- type: AirlockVirusTarget

- type: entity
parent: AirlockSecurity
Expand All @@ -369,6 +370,7 @@
- type: ContainerFill
containers:
board: [ DoorElectronicsDetective ]
- type: AirlockVirusTarget

#Delta V: Removed Brig Access
#- type: entity
Expand All @@ -388,6 +390,7 @@
- type: ContainerFill
containers:
board: [ DoorElectronicsSecurityLawyer ]
- type: AirlockVirusTarget

- type: entity
parent: AirlockSecurity
Expand Down Expand Up @@ -734,6 +737,7 @@
- type: ContainerFill
containers:
board: [ DoorElectronicsSecurity ]
- type: AirlockVirusTarget

- type: entity
parent: AirlockSecurityGlass
Expand All @@ -743,6 +747,7 @@
- type: ContainerFill
containers:
board: [ DoorElectronicsDetective ]
- type: AirlockVirusTarget

#- type: entity
# parent: AirlockSecurityGlass
Expand All @@ -761,6 +766,7 @@
- type: ContainerFill
containers:
board: [ DoorElectronicsSecurityLawyer ]
- type: AirlockVirusTarget

- type: entity
parent: AirlockSecurityGlass
Expand Down Expand Up @@ -1004,6 +1010,7 @@
board: [ DoorElectronicsSecurity ]
- type: Wires
layoutId: AirlockSecurity
- type: AirlockVirusTarget

- type: entity
parent: AirlockMaintSecLocked
Expand Down
12 changes: 12 additions & 0 deletions Resources/Prototypes/GameRules/events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,15 @@
maxOccurrences: 1 # this event has diminishing returns on interesting-ness, so we cap it
weight: 5
- type: MobReplacementRule

- type: entity
id: AirlockVirusRule
parent: BaseGameRule
categories: [ HideSpawnMenu ]
components:
- type: StationEvent
earliestStart: 15
minimumPlayers: 5
maxOccurrences: 1
weight: 3
- type: AirlockVirusRule
Loading