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

51 lines
1.7 KiB
C#

using Content.Server.Objectives.Components;
using Content.Shared.Changeling.Components;
using Content.Shared.Mind;
using Content.Shared.Objectives.Components;
namespace Content.Server.Objectives.Systems;
public sealed partial class ChangelingObjectiveSystem : EntitySystem
{
[Dependency] private NumberObjectiveSystem _number = default!;
[Dependency] private SharedMindSystem _mind = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ChangelingUniqueIdentityConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
SubscribeLocalEvent<ChangelingDevouredEvent>(OnChangelingDevoured);
}
private void OnChangelingDevoured(ref ChangelingDevouredEvent args)
{
// We check if the devour granted us Dna.
// We do this because we could already have gotten the identity by other means before, such as the Dna sting.
// Dna grant basically ensures this is the first time valid devour has happened on a target.
if (!args.GrantedDna)
return;
if (!_mind.TryGetObjectiveComp<ChangelingUniqueIdentityConditionComponent>(args.Changeling, out var obj))
return;
obj.UniqueIdentities++;
}
private void OnGetProgress(Entity<ChangelingUniqueIdentityConditionComponent> ent, ref ObjectiveGetProgressEvent args)
{
args.Progress = GetProgress(ent.Comp, _number.GetTarget(ent));
}
private float GetProgress(ChangelingUniqueIdentityConditionComponent comp, int target)
{
// prevent divide-by-zero
if (target == 0)
return 1f;
if (comp.UniqueIdentities >= target)
return 1f;
return (float)comp.UniqueIdentities / (float)target;
}
}