mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
better for MRP this code is originally by me anyway, they just made it better 🆑 - tweak: Kill random person objective has been replaced by teaching them a lesson, removing the need to RR a random person. --------- Signed-off-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> Co-authored-by: Lyndomen <49795619+Lyndomen@users.noreply.github.com> Co-authored-by: Milon <milonpl.git@proton.me> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: VMSolidus <evilexecutive@gmail.com> (cherry picked from commit f592d4cd890bc14c70153182a400d273ffb113b9)
56 lines
2.0 KiB
C#
56 lines
2.0 KiB
C#
using Content.Server.DeltaV.Objectives.Components;
|
|
using Content.Server.Objectives.Components;
|
|
using Content.Server.Objectives.Systems;
|
|
using Content.Shared.Mind.Components;
|
|
using Content.Shared.Mobs;
|
|
|
|
namespace Content.Server.DeltaV.Objectives.Systems;
|
|
|
|
/// <summary>
|
|
/// Handles teach a lesson condition logic, does not assign target.
|
|
/// </summary>
|
|
public sealed class TeachLessonConditionSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly CodeConditionSystem _codeCondition = default!;
|
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<MobStateChangedEvent>(OnMobStateChanged);
|
|
}
|
|
|
|
// TODO: subscribe by ref at some point in the future
|
|
private void OnMobStateChanged(MobStateChangedEvent args)
|
|
{
|
|
if (args.NewMobState != MobState.Dead)
|
|
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)
|
|
return;
|
|
|
|
// Get all TeachLessonConditionComponent entities
|
|
var query = EntityQueryEnumerator<TeachLessonConditionComponent, TargetObjectiveComponent>();
|
|
|
|
while (query.MoveNext(out var uid, 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 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);
|
|
}
|
|
}
|
|
}
|