CatStation/Content.Server/Objectives/Systems/ConditionCounterSystem.cs
themias c32d52502b
Mail Fraud [Traitor Objective] (#43560)
* save

* cutting open your own letter check

* typo

* update and use API method

* tweak text

* generic counter system

* update requires

* review comments

* api method

* Update Content.Server/Objectives/Systems/ConditionCounterSystem.cs

Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>

* Update Content.Server/Objectives/Systems/ConditionCounterSystem.cs

Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>

* Update Content.Server/Objectives/Systems/ConditionCounterSystem.cs

Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>

* remove break

---------

Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>
2026-04-22 00:44:10 +00:00

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 class CounterConditionSystem : EntitySystem
{
[Dependency] private readonly 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++;
}
}
}