mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* 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
48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using Content.Server.Objectives.Components;
|
|
using Content.Shared.Objectives.Components;
|
|
using JetBrains.Annotations;
|
|
|
|
namespace Content.Server.Objectives.Systems;
|
|
|
|
/// <summary>
|
|
/// This system handles returning the progress for CounterConditionComponents,
|
|
/// which simple increment for traitor NumberObjectives, e.g. cut into 12 envelopes.
|
|
/// </summary>
|
|
public sealed partial class CounterConditionSystem : EntitySystem
|
|
{
|
|
[Dependency] private NumberObjectiveSystem _number = default!;
|
|
[Dependency] private EntityQuery<CounterConditionComponent> _compQuery = default!;
|
|
|
|
/// <inheritdoc/>
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<CounterConditionComponent, ObjectiveGetProgressEvent>(OnCounterGetProgress);
|
|
}
|
|
|
|
private void OnCounterGetProgress(Entity<CounterConditionComponent> ent, ref ObjectiveGetProgressEvent args)
|
|
{
|
|
args.Progress = GetProgress(ent, _number.GetTarget(ent.Owner));
|
|
}
|
|
|
|
private float GetProgress(Entity<CounterConditionComponent> ent, int target)
|
|
{
|
|
// prevent divide-by-zero
|
|
if (target == 0)
|
|
return 1f;
|
|
|
|
if (ent.Comp.Count >= target)
|
|
return 1f;
|
|
|
|
return (float)ent.Comp.Count / target;
|
|
}
|
|
|
|
[PublicAPI]
|
|
public void IncreaseCount(Entity<CounterConditionComponent?> objective)
|
|
{
|
|
if (_compQuery.Resolve(objective, ref objective.Comp))
|
|
{
|
|
objective.Comp.Count++;
|
|
}
|
|
}
|
|
}
|