diff --git a/Content.Server/DeltaV/Objectives/Systems/TeachLessonConditionSystem.cs b/Content.Server/DeltaV/Objectives/Systems/TeachLessonConditionSystem.cs index 929a361a3fe..4beff20fef3 100644 --- a/Content.Server/DeltaV/Objectives/Systems/TeachLessonConditionSystem.cs +++ b/Content.Server/DeltaV/Objectives/Systems/TeachLessonConditionSystem.cs @@ -21,35 +21,40 @@ public override void Initialize() SubscribeLocalEvent(OnMobStateChanged); } - // TODO: subscribe by ref at some point in the future private void OnMobStateChanged(MobStateChangedEvent args) { - if (args.NewMobState != MobState.Dead) + if (args.NewMobState != MobState.Critical || args.OldMobState >= args.NewMobState + || !TryComp(args.Target, out var mc) || mc.OriginalMind is not { } mindId) return; - // Get the mind of the entity that just died (if it had one) - // Uses OriginalMind so if someone ghosts or otherwise loses control of a mob, you can still greentext - if (!TryComp(args.Target, out var mc) || mc.OriginalMind is not {} mindId) + // If the attacker actually has the objective, we can just skip any enumeration outright. + if (args.Origin is not null + && HasComp(args.Origin) + && TryComp(args.Origin, out var targetComp) + && targetComp.Target == mindId) + { + _codeCondition.SetCompleted(args.Origin!.Value); return; + } // Get all TeachLessonConditionComponent entities var query = EntityQueryEnumerator(); - while (query.MoveNext(out var uid, out var conditionComp, out var targetObjective)) + while (query.MoveNext(out var ent, out var conditionComp, out var targetObjective)) { // Check if this objective's target matches the entity that died if (targetObjective.Target != mindId) continue; - var userWorldPos = _transform.GetWorldPosition(uid); + var userWorldPos = _transform.GetWorldPosition(ent); var targetWorldPos = _transform.GetWorldPosition(args.Target); - + var distance = (userWorldPos - targetWorldPos).Length(); if (distance > conditionComp.MaxDistance - || Transform(uid).MapID != Transform(args.Target).MapID) + || Transform(ent).MapID != Transform(args.Target).MapID) continue; - _codeCondition.SetCompleted(uid); + _codeCondition.SetCompleted(ent); } } }