CatStation/Content.Server/Objectives/Systems/HelpProgressConditionSystem.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

58 lines
1.8 KiB
C#

using Content.Server.Objectives.Components;
using Content.Shared.Mind;
using Content.Shared.Objectives.Components;
using Content.Shared.Objectives.Systems;
namespace Content.Server.Objectives.Systems;
/// <summary>
/// Handles help progress condition logic.
/// </summary>
public sealed partial class HelpProgressConditionSystem : EntitySystem
{
[Dependency] private SharedObjectivesSystem _objectives = default!;
[Dependency] private TargetObjectiveSystem _target = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<HelpProgressConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
}
private void OnGetProgress(EntityUid uid, HelpProgressConditionComponent comp, ref ObjectiveGetProgressEvent args)
{
if (!_target.GetTarget(uid, out var target))
return;
args.Progress = GetProgress(target.Value);
}
private float GetProgress(EntityUid target)
{
var total = 0f; // how much progress they have
var max = 0f; // how much progress is needed for 100%
if (TryComp<MindComponent>(target, out var mind))
{
foreach (var objective in mind.Objectives)
{
// this has the potential to loop forever, anything setting target has to check that there is no HelpProgressCondition.
var info = _objectives.GetInfo(objective, target, mind);
if (info == null)
continue;
max++; // things can only be up to 100% complete yeah
total += info.Value.Progress;
}
}
// no objectives that can be helped with...
if (max == 0f)
return 1f;
// require 50% completion for this one to be complete
var completion = total / max;
return completion;
}
}