using Content.Server.Objectives.Components;
using Content.Shared.Objectives.Components;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
namespace Content.Server.Objectives.Systems;
///
/// Handles progress and provides API for systems to use.
///
public sealed class CodeConditionSystem : EntitySystem
{
[Dependency] private readonly SharedMindSystem _mind = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent(OnGetProgress);
}
private void OnGetProgress(Entity ent, ref ObjectiveGetProgressEvent args)
{
args.Progress = ent.Comp.Completed ? 1f : 0f;
}
///
/// Returns whether an objective is completed.
///
public bool IsCompleted(Entity ent)
{
if (!Resolve(ent, ref ent.Comp))
return false;
return ent.Comp.Completed;
}
///
/// Returns true if a mob's objective with a certain prototype is completed.
///
public bool IsCompleted(Entity mob, string prototype)
{
if (_mind.GetMind(mob, mob.Comp) is not {} mindId)
return false;
if (!_mind.TryFindObjective(mindId, prototype, out var obj))
return false;
return IsCompleted(obj.Value);
}
///
/// Sets an objective's completed field.
///
public void SetCompleted(Entity ent, bool completed = true)
{
if (!Resolve(ent, ref ent.Comp))
return;
ent.Comp.Completed = completed;
}
///
/// Sets a mob's objective to complete.
///
public void SetCompleted(Entity mob, string prototype, bool completed = true)
{
if (_mind.GetMind(mob, mob.Comp) is not {} mindId)
return;
if (!_mind.TryFindObjective(mindId, prototype, out var obj))
return;
SetCompleted(obj.Value, completed);
}
}