Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Teach Lesson Code #1657

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server.DeltaV.Objectives.Components;
using Content.Server.KillTracking;
using Content.Server.Objectives.Components;
using Content.Server.Objectives.Systems;
using Content.Shared.Mind.Components;
Expand All @@ -18,38 +19,42 @@ public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<MobStateChangedEvent>(OnMobStateChanged);
SubscribeLocalEvent<KillTrackerComponent, MobStateChangedEvent>(OnMobStateChanged);
}

// TODO: subscribe by ref at some point in the future
private void OnMobStateChanged(MobStateChangedEvent args)
private void OnMobStateChanged(EntityUid uid, KillTrackerComponent trackerComponent, MobStateChangedEvent args)
{
if (args.NewMobState != MobState.Dead)
if (args.NewMobState != trackerComponent.KillState || args.OldMobState >= args.NewMobState
|| !TryComp<MindContainerComponent>(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<MindContainerComponent>(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
&& TryComp<TargetObjectiveComponent>(args.Origin, out var targetComp)
&& targetComp.Target == mindId)
{
_codeCondition.SetCompleted(args.Origin!.Value);
return;
}

// Get all TeachLessonConditionComponent entities
var query = EntityQueryEnumerator<TeachLessonConditionComponent, TargetObjectiveComponent>();

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)
continue;

_codeCondition.SetCompleted(uid);
_codeCondition.SetCompleted(ent);
}
}
}
Loading