Skip to content

Commit

Permalink
fix "teach person a lesson" (#2412)
Browse files Browse the repository at this point in the history
* "when you code it" but i already fucking did

* FUCK

* ok thats a thing apparently
  • Loading branch information
MilonPL authored Dec 12, 2024
1 parent 77f96e7 commit dd6675d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Requires that a target dies once and only once.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/// <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 SharedMindSystem _mind = default!;
[Dependency] private readonly TargetObjectiveSystem _target = default!;

private readonly List<EntityUid> _wasKilled = [];

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<TeachLessonConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundEnd);
SubscribeLocalEvent<MobStateChangedEvent>(OnMobStateChanged);
}

private void OnGetProgress(Entity<TeachLessonConditionComponent> 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<MindComponent>(target, out var mind) && mind.OwnedEntity != null && !_mind.IsCharacterDeadIc(mind))
return _wasKilled.Contains(target) ? 1f : 0f;
// Get all TeachLessonConditionComponent entities
var query = EntityQueryEnumerator<TeachLessonConditionComponent, TargetObjectiveComponent>();

_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);
}
}
}
1 change: 1 addition & 0 deletions Resources/Prototypes/DeltaV/Objectives/traitor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
sprite: Objects/Weapons/Guns/Pistols/viper.rsi
state: icon
- type: TeachLessonCondition
- type: CodeCondition
- type: ObjectiveBlacklistRequirement
blacklist:
components:
Expand Down

0 comments on commit dd6675d

Please sign in to comment.