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; } /// /// 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); } }