diff --git a/Content.Server/DeltaV/Objectives/Components/TeachLessonConditionComponent.cs b/Content.Server/DeltaV/Objectives/Components/TeachLessonConditionComponent.cs index ee86f4851b3..e8592c3d73e 100644 --- a/Content.Server/DeltaV/Objectives/Components/TeachLessonConditionComponent.cs +++ b/Content.Server/DeltaV/Objectives/Components/TeachLessonConditionComponent.cs @@ -1,6 +1,7 @@ -using Content.Server.Objectives.Systems; +using Content.Server.DeltaV.Objectives.Systems; +using Content.Server.Objectives.Components; -namespace Content.Server.Objectives.Components; +namespace Content.Server.DeltaV.Objectives.Components; /// /// Requires that a target dies once and only once. diff --git a/Content.Server/DeltaV/Objectives/Systems/TeachLessonConditionSystem.cs b/Content.Server/DeltaV/Objectives/Systems/TeachLessonConditionSystem.cs index 8e3ca19f885..660380ba80b 100644 --- a/Content.Server/DeltaV/Objectives/Systems/TeachLessonConditionSystem.cs +++ b/Content.Server/DeltaV/Objectives/Systems/TeachLessonConditionSystem.cs @@ -1,48 +1,46 @@ -using Content.Server.Objectives.Components; -using Content.Shared.GameTicking; +using Content.Server.DeltaV.Objectives.Components; +using Content.Server.Objectives.Components; +using Content.Server.Objectives.Systems; using Content.Shared.Mind; -using Content.Shared.Objectives.Components; +using Content.Shared.Mobs; -namespace Content.Server.Objectives.Systems; +namespace Content.Server.DeltaV.Objectives.Systems; /// /// Handles teach a lesson condition logic, does not assign target. /// public sealed class TeachLessonConditionSystem : EntitySystem { + [Dependency] private readonly CodeConditionSystem _codeCondition = default!; [Dependency] private readonly SharedMindSystem _mind = default!; - [Dependency] private readonly TargetObjectiveSystem _target = default!; - - private readonly List _wasKilled = []; public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnGetProgress); - SubscribeLocalEvent(OnRoundEnd); + SubscribeLocalEvent(OnMobStateChanged); } - private void OnGetProgress(Entity ent, ref ObjectiveGetProgressEvent args) + // TODO: subscribe by ref at some point in the future + private void OnMobStateChanged(MobStateChangedEvent args) { - if (!_target.GetTarget(ent, out var target)) + if (args.NewMobState != MobState.Dead) return; - args.Progress = GetProgress(target.Value); - } + // Get the mind of the entity that just died (if it has one) + if (!_mind.TryGetMind(args.Target, out var mindId, out _)) + return; - private float GetProgress(EntityUid target) - { - if (TryComp(target, out var mind) && mind.OwnedEntity != null && !_mind.IsCharacterDeadIc(mind)) - return _wasKilled.Contains(target) ? 1f : 0f; + // Get all TeachLessonConditionComponent entities + var query = EntityQueryEnumerator(); - _wasKilled.Add(target); - return 1f; - } + while (query.MoveNext(out var uid, out _, out var targetObjective)) + { + // Check if this objective's target matches the entity that died + if (targetObjective.Target != mindId) + continue; - // Clear the wasKilled list on round end - private void OnRoundEnd(RoundRestartCleanupEvent ev) - { - _wasKilled.Clear(); + _codeCondition.SetCompleted(uid); + } } } diff --git a/Resources/Prototypes/DeltaV/Objectives/traitor.yml b/Resources/Prototypes/DeltaV/Objectives/traitor.yml index 2083abff62f..371dbba0a71 100644 --- a/Resources/Prototypes/DeltaV/Objectives/traitor.yml +++ b/Resources/Prototypes/DeltaV/Objectives/traitor.yml @@ -63,6 +63,7 @@ sprite: Objects/Weapons/Guns/Pistols/viper.rsi state: icon - type: TeachLessonCondition + - type: CodeCondition - type: ObjectiveBlacklistRequirement blacklist: components: