CatStation/Content.Server/Objectives/Systems/SupercriticalAnomaliesConditionSystem.cs
Pieter-Jan Briers 5168b5f3d4
IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

41 lines
1.3 KiB
C#

using Content.Server.Objectives.Components;
using Content.Shared.Anomaly.Components;
using Content.Shared.Objectives.Components;
namespace Content.Server.Objectives.Systems;
public sealed partial class SupercriticalAnomaliesConditionSystem : EntitySystem
{
[Dependency] private NumberObjectiveSystem _numberObjective = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AnomalyShutdownEvent>(OnAnomalySupercrit);
SubscribeLocalEvent<SupercriticalAnomaliesConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
}
private void OnAnomalySupercrit(ref AnomalyShutdownEvent args)
{
if (!args.Supercritical)
return;
var query = EntityQueryEnumerator<SupercriticalAnomaliesConditionComponent>();
while (query.MoveNext(out var comp))
{
comp.SupercriticalAnomalies += 1;
}
}
private void OnGetProgress(Entity<SupercriticalAnomaliesConditionComponent> ent, ref ObjectiveGetProgressEvent args)
{
var target = _numberObjective.GetTarget(ent);
if (target == 0)
{
args.Progress = 0f;
return;
}
args.Progress = MathF.Min((float)ent.Comp.SupercriticalAnomalies / target, 1f);
}
}