Cleanup Objective files, add PickSpecificPersonComponent (#35802)
* cleanup objectives * remove unrelated access restriction * review
This commit is contained in:
parent
dc37bc6830
commit
37914e3fb7
|
|
@ -18,7 +18,6 @@ using Content.Server.Storage.Components;
|
|||
using Content.Server.Storage.EntitySystems;
|
||||
using Content.Server.Tabletop;
|
||||
using Content.Server.Tabletop.Components;
|
||||
using Content.Server.Terminator.Systems;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Administration.Components;
|
||||
using Content.Shared.Body.Components;
|
||||
|
|
@ -76,7 +75,6 @@ public sealed partial class AdminVerbSystem
|
|||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly TabletopSystem _tabletopSystem = default!;
|
||||
[Dependency] private readonly TerminatorSystem _terminator = default!;
|
||||
[Dependency] private readonly VomitSystem _vomitSystem = default!;
|
||||
[Dependency] private readonly WeldableSystem _weldableSystem = default!;
|
||||
[Dependency] private readonly SharedContentEyeSystem _eyeSystem = default!;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
using Content.Server.Objectives.Systems;
|
||||
|
||||
namespace Content.Server.Objectives.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the target for <see cref="TargetObjectiveComponent"/> to a random head.
|
||||
/// If there are no heads it will fallback to any person.
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(KillPersonConditionSystem))]
|
||||
public sealed partial class PickRandomHeadComponent : Component
|
||||
{
|
||||
}
|
||||
[RegisterComponent]
|
||||
public sealed partial class PickRandomHeadComponent : Component;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
using Content.Server.Objectives.Systems;
|
||||
|
||||
namespace Content.Server.Objectives.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the target for <see cref="TargetObjectiveComponent"/> to a random person.
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(KillPersonConditionSystem))]
|
||||
[RegisterComponent]
|
||||
public sealed partial class PickRandomPersonComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
namespace Content.Server.Objectives.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Sets this objective's target to the one given in <see cref="TargetOverrideComponent"/>, if the entity has it.
|
||||
/// This component needs to be added to objective entity itself.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class PickSpecificPersonComponent : Component;
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
using Content.Server.Objectives.Systems;
|
||||
|
||||
namespace Content.Server.Objectives.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the target for <see cref="KeepAliveConditionComponent"/> to a random traitor.
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(KeepAliveConditionSystem))]
|
||||
public sealed partial class RandomTraitorAliveComponent : Component
|
||||
{
|
||||
}
|
||||
[RegisterComponent]
|
||||
public sealed partial class RandomTraitorAliveComponent : Component;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
using Content.Server.Objectives.Systems;
|
||||
|
||||
namespace Content.Server.Objectives.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the target for <see cref="HelpProgressConditionComponent"/> to a random traitor.
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(HelpProgressConditionSystem))]
|
||||
public sealed partial class RandomTraitorProgressComponent : Component
|
||||
{
|
||||
}
|
||||
[RegisterComponent]
|
||||
public sealed partial class RandomTraitorProgressComponent : Component;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
namespace Content.Server.Objectives.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Sets a target objective to a specific target when receiving it.
|
||||
/// The objective entity needs to have <see cref="PickSpecificPersonComponent"/>.
|
||||
/// This component needs to be added to entity receiving the objective.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class TargetOverrideComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The entity that should be targeted.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public EntityUid? Target;
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
using Content.Server.Objectives.Systems;
|
||||
|
||||
namespace Content.Server.Objectives.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Sets this objective's target to the exterminator's target override, if it has one.
|
||||
/// If not it will be random.
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(TerminatorTargetOverrideSystem))]
|
||||
public sealed partial class TerminatorTargetOverrideComponent : Component
|
||||
{
|
||||
}
|
||||
|
|
@ -1,31 +1,23 @@
|
|||
using Content.Server.GameTicking.Rules;
|
||||
using Content.Server.Objectives.Components;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Components;
|
||||
using Content.Shared.Objectives.Systems;
|
||||
using Content.Shared.Roles.Jobs;
|
||||
using Robust.Shared.Random;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Server.Objectives.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// Handles help progress condition logic and picking random help targets.
|
||||
/// Handles help progress condition logic.
|
||||
/// </summary>
|
||||
public sealed class HelpProgressConditionSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly SharedObjectivesSystem _objectives = default!;
|
||||
[Dependency] private readonly TargetObjectiveSystem _target = default!;
|
||||
[Dependency] private readonly TraitorRuleSystem _traitorRule = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<HelpProgressConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
|
||||
|
||||
SubscribeLocalEvent<RandomTraitorProgressComponent, ObjectiveAssignedEvent>(OnTraitorAssigned);
|
||||
}
|
||||
|
||||
private void OnGetProgress(EntityUid uid, HelpProgressConditionComponent comp, ref ObjectiveGetProgressEvent args)
|
||||
|
|
@ -36,55 +28,6 @@ public sealed class HelpProgressConditionSystem : EntitySystem
|
|||
args.Progress = GetProgress(target.Value);
|
||||
}
|
||||
|
||||
private void OnTraitorAssigned(EntityUid uid, RandomTraitorProgressComponent comp, ref ObjectiveAssignedEvent args)
|
||||
{
|
||||
// invalid prototype
|
||||
if (!TryComp<TargetObjectiveComponent>(uid, out var target))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var traitors = _traitorRule.GetOtherTraitorMindsAliveAndConnected(args.Mind).ToHashSet();
|
||||
|
||||
// cant help anyone who is tasked with helping:
|
||||
// 1. thats boring
|
||||
// 2. no cyclic progress dependencies!!!
|
||||
foreach (var traitor in traitors)
|
||||
{
|
||||
// TODO: replace this with TryComp<ObjectivesComponent>(traitor) or something when objectives are moved out of mind
|
||||
if (!TryComp<MindComponent>(traitor.Id, out var mind))
|
||||
continue;
|
||||
|
||||
foreach (var objective in mind.Objectives)
|
||||
{
|
||||
if (HasComp<HelpProgressConditionComponent>(objective))
|
||||
traitors.RemoveWhere(x => x.Mind == mind);
|
||||
}
|
||||
}
|
||||
|
||||
// Can't have multiple objectives to help/save the same person
|
||||
foreach (var objective in args.Mind.Objectives)
|
||||
{
|
||||
if (HasComp<RandomTraitorAliveComponent>(objective) || HasComp<RandomTraitorProgressComponent>(objective))
|
||||
{
|
||||
if (TryComp<TargetObjectiveComponent>(objective, out var help))
|
||||
{
|
||||
traitors.RemoveWhere(x => x.Id == help.Target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// no more helpable traitors
|
||||
if (traitors.Count == 0)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_target.SetTarget(uid, _random.Pick(traitors).Id, target);
|
||||
}
|
||||
|
||||
private float GetProgress(EntityUid target)
|
||||
{
|
||||
var total = 0f; // how much progress they have
|
||||
|
|
|
|||
|
|
@ -1,30 +1,22 @@
|
|||
using Content.Server.Objectives.Components;
|
||||
using Content.Server.GameTicking.Rules;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Components;
|
||||
using Content.Shared.Roles.Jobs;
|
||||
using Robust.Shared.Random;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Server.Objectives.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// Handles keep alive condition logic and picking random traitors to keep alive.
|
||||
/// Handles keep alive condition logic.
|
||||
/// </summary>
|
||||
public sealed class KeepAliveConditionSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly SharedMindSystem _mind = default!;
|
||||
[Dependency] private readonly TargetObjectiveSystem _target = default!;
|
||||
[Dependency] private readonly TraitorRuleSystem _traitorRule = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<KeepAliveConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
|
||||
|
||||
SubscribeLocalEvent<RandomTraitorAliveComponent, ObjectiveAssignedEvent>(OnAssigned);
|
||||
}
|
||||
|
||||
private void OnGetProgress(EntityUid uid, KeepAliveConditionComponent comp, ref ObjectiveGetProgressEvent args)
|
||||
|
|
@ -35,39 +27,6 @@ public sealed class KeepAliveConditionSystem : EntitySystem
|
|||
args.Progress = GetProgress(target.Value);
|
||||
}
|
||||
|
||||
private void OnAssigned(EntityUid uid, RandomTraitorAliveComponent comp, ref ObjectiveAssignedEvent args)
|
||||
{
|
||||
// invalid prototype
|
||||
if (!TryComp<TargetObjectiveComponent>(uid, out var target))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var traitors = _traitorRule.GetOtherTraitorMindsAliveAndConnected(args.Mind).ToHashSet();
|
||||
|
||||
// Can't have multiple objectives to help/save the same person
|
||||
foreach (var objective in args.Mind.Objectives)
|
||||
{
|
||||
if (HasComp<RandomTraitorAliveComponent>(objective) || HasComp<RandomTraitorProgressComponent>(objective))
|
||||
{
|
||||
if (TryComp<TargetObjectiveComponent>(objective, out var help))
|
||||
{
|
||||
traitors.RemoveWhere(x => x.Id == help.Target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// You are the first/only traitor.
|
||||
if (traitors.Count == 0)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_target.SetTarget(uid, _random.Pick(traitors).Id, target);
|
||||
}
|
||||
|
||||
private float GetProgress(EntityUid target)
|
||||
{
|
||||
if (!TryComp<MindComponent>(target, out var mind))
|
||||
|
|
|
|||
|
|
@ -1,16 +1,9 @@
|
|||
using System.Linq;
|
||||
using Content.Server.Objectives.Components;
|
||||
using Content.Server.Revolutionary.Components;
|
||||
using Content.Server.Shuttles.Systems;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Components;
|
||||
using Content.Shared.Roles; // DeltaV
|
||||
using Content.Shared.Roles.Jobs; // DeltaV
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Prototypes; // DeltaV
|
||||
using Robust.Shared.Random;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Server.Objectives.Systems;
|
||||
|
||||
|
|
@ -21,10 +14,7 @@ public sealed class KillPersonConditionSystem : EntitySystem
|
|||
{
|
||||
[Dependency] private readonly EmergencyShuttleSystem _emergencyShuttle = default!;
|
||||
[Dependency] private readonly IConfigurationManager _config = default!;
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!; // DeltaV
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly SharedMindSystem _mind = default!;
|
||||
[Dependency] private readonly SharedRoleSystem _role = default!; // DeltaV
|
||||
[Dependency] private readonly TargetObjectiveSystem _target = default!;
|
||||
|
||||
public override void Initialize()
|
||||
|
|
@ -32,8 +22,6 @@ public sealed class KillPersonConditionSystem : EntitySystem
|
|||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<KillPersonConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
|
||||
SubscribeLocalEvent<PickRandomPersonComponent, ObjectiveAssignedEvent>(OnPersonAssigned);
|
||||
SubscribeLocalEvent<PickRandomHeadComponent, ObjectiveAssignedEvent>(OnHeadAssigned);
|
||||
}
|
||||
|
||||
private void OnGetProgress(EntityUid uid, KillPersonConditionComponent comp, ref ObjectiveGetProgressEvent args)
|
||||
|
|
@ -44,85 +32,6 @@ public sealed class KillPersonConditionSystem : EntitySystem
|
|||
args.Progress = GetProgress(target.Value, comp.RequireDead);
|
||||
}
|
||||
|
||||
private void OnPersonAssigned(Entity<PickRandomPersonComponent> ent, ref ObjectiveAssignedEvent args)
|
||||
{
|
||||
AssignRandomTarget(ent, ref args, _ => true, ent.Comp.OnlyChoosableJobs); // DeltaV: pass onlyJobs
|
||||
}
|
||||
|
||||
private void OnHeadAssigned(Entity<PickRandomHeadComponent> ent, ref ObjectiveAssignedEvent args)
|
||||
{
|
||||
AssignRandomTarget(ent, ref args, mindId =>
|
||||
TryComp<MindComponent>(mindId, out var mind) &&
|
||||
mind.OwnedEntity is { } ownedEnt &&
|
||||
HasComp<CommandStaffComponent>(ownedEnt));
|
||||
}
|
||||
|
||||
// DeltaV: added onlyJobs
|
||||
private void AssignRandomTarget(EntityUid uid, ref ObjectiveAssignedEvent args, Predicate<EntityUid> filter, bool onlyJobs = true, bool fallbackToAny = true)
|
||||
{
|
||||
// invalid prototype
|
||||
if (!TryComp<TargetObjectiveComponent>(uid, out var target))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// target already assigned
|
||||
if (target.Target != null)
|
||||
return;
|
||||
|
||||
// Get all alive humans, filter out any with TargetObjectiveImmuneComponent
|
||||
var allHumans = _mind.GetAliveHumans(args.MindId)
|
||||
.Where(mindId =>
|
||||
{
|
||||
if (!TryComp<MindComponent>(mindId, out var mindComp) || mindComp.OwnedEntity == null)
|
||||
return false;
|
||||
return !HasComp<TargetObjectiveImmuneComponent>(mindComp.OwnedEntity.Value);
|
||||
})
|
||||
.ToList();
|
||||
|
||||
// Begin DeltaV Additions: Only target people with jobs
|
||||
if (onlyJobs)
|
||||
{
|
||||
allHumans.RemoveAll(mindId => !(
|
||||
_role.MindHasRole<JobRoleComponent>((mindId.Owner, mindId.Comp), out var role) &&
|
||||
role?.Comp1.JobPrototype is {} jobId &&
|
||||
_proto.Index(jobId).SetPreference));
|
||||
}
|
||||
// End DeltaV Additions
|
||||
|
||||
// Can't have multiple objectives to kill the same person
|
||||
foreach (var objective in args.Mind.Objectives)
|
||||
{
|
||||
if (HasComp<KillPersonConditionComponent>(objective) && TryComp<TargetObjectiveComponent>(objective, out var kill))
|
||||
{
|
||||
allHumans.RemoveAll(x => x.Owner == kill.Target);
|
||||
}
|
||||
}
|
||||
|
||||
// Filter out targets based on the filter
|
||||
var filteredHumans = allHumans.Where(mind => filter(mind)).ToList();
|
||||
|
||||
// There's no humans and we can't fall back to any other target
|
||||
if (filteredHumans.Count == 0 && !fallbackToAny)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Pick between humans matching our filter or fall back to all humans alive
|
||||
var selectedHumans = filteredHumans.Count > 0 ? filteredHumans : allHumans;
|
||||
|
||||
// Still no valid targets even after the fallback
|
||||
if (selectedHumans.Count == 0)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_target.SetTarget(uid, _random.Pick(selectedHumans), target);
|
||||
}
|
||||
|
||||
private float GetProgress(EntityUid target, bool requireDead)
|
||||
{
|
||||
// deleted or gibbed or something, counts as dead
|
||||
|
|
|
|||
|
|
@ -0,0 +1,231 @@
|
|||
using Content.Server.Objectives.Components;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Components;
|
||||
using Content.Shared.Roles; // DeltaV
|
||||
using Content.Shared.Roles.Jobs; // DeltaV
|
||||
using Content.Server.GameTicking.Rules;
|
||||
using Content.Server.Revolutionary.Components;
|
||||
using Robust.Shared.Prototypes; // DeltaV
|
||||
using Robust.Shared.Random;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Server.Objectives.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// Handles assinging a target to an objective entity with <see cref="TargetObjectiveComponent"/> using different components.
|
||||
/// These can be combined with condition components for objective completions in order to create a variety of objectives.
|
||||
/// </summary>
|
||||
public sealed class PickObjectiveTargetSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly TargetObjectiveSystem _target = default!;
|
||||
[Dependency] private readonly SharedMindSystem _mind = default!;
|
||||
[Dependency] private readonly SharedRoleSystem _role = default!; // DeltaV
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!; // DeltaV
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly TraitorRuleSystem _traitorRule = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<PickSpecificPersonComponent, ObjectiveAssignedEvent>(OnSpecificPersonAssigned);
|
||||
SubscribeLocalEvent<PickRandomPersonComponent, ObjectiveAssignedEvent>(OnRandomPersonAssigned);
|
||||
SubscribeLocalEvent<PickRandomHeadComponent, ObjectiveAssignedEvent>(OnRandomHeadAssigned);
|
||||
|
||||
SubscribeLocalEvent<RandomTraitorProgressComponent, ObjectiveAssignedEvent>(OnRandomTraitorProgressAssigned);
|
||||
SubscribeLocalEvent<RandomTraitorAliveComponent, ObjectiveAssignedEvent>(OnRandomTraitorAliveAssigned);
|
||||
}
|
||||
|
||||
private void OnSpecificPersonAssigned(Entity<PickSpecificPersonComponent> ent, ref ObjectiveAssignedEvent args)
|
||||
{
|
||||
// invalid objective prototype
|
||||
if (!TryComp<TargetObjectiveComponent>(ent.Owner, out var target))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// target already assigned
|
||||
if (target.Target != null)
|
||||
return;
|
||||
|
||||
if (args.Mind.OwnedEntity == null)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var user = args.Mind.OwnedEntity.Value;
|
||||
if (!TryComp<TargetOverrideComponent>(user, out var targetComp) || targetComp.Target == null)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_target.SetTarget(ent.Owner, targetComp.Target.Value);
|
||||
}
|
||||
|
||||
private void OnRandomPersonAssigned(Entity<PickRandomPersonComponent> ent, ref ObjectiveAssignedEvent args)
|
||||
{
|
||||
// Begin DeltaV Changes - replaced copy pasta with this
|
||||
Predicate<EntityUid> pred = ent.Comp.OnlyChoosableJobs
|
||||
? mindId =>
|
||||
_role.MindHasRole<JobRoleComponent>(mindId, out var role) &&
|
||||
role?.Comp1.JobPrototype is {} jobId &&
|
||||
_proto.Index(jobId).SetPreference
|
||||
: _ => true;
|
||||
AssignRandomTarget(ent, ref args, pred);
|
||||
// End DeltaV Changes - replaced copy pasta with this
|
||||
}
|
||||
|
||||
private void OnRandomHeadAssigned(Entity<PickRandomHeadComponent> ent, ref ObjectiveAssignedEvent args)
|
||||
{
|
||||
// Begin DeltaV Changes - replaced copy pasta with this
|
||||
AssignRandomTarget(ent, ref args, mindId =>
|
||||
TryComp<MindComponent>(mindId, out var mind) &&
|
||||
mind.OwnedEntity is { } ownedEnt &&
|
||||
HasComp<CommandStaffComponent>(ownedEnt));
|
||||
// End DeltaV Changes - replaced copy pasta with this
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DeltaV - Common code deduplicated from above functions.
|
||||
/// Filters all alive humans and picks a target from them.
|
||||
/// </summary>
|
||||
private void AssignRandomTarget(EntityUid uid, ref ObjectiveAssignedEvent args, Predicate<EntityUid> filter, bool fallbackToAny = true)
|
||||
{
|
||||
// invalid prototype
|
||||
if (!TryComp<TargetObjectiveComponent>(uid, out var target))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// target already assigned
|
||||
if (target.Target != null)
|
||||
return;
|
||||
|
||||
// Get all alive humans, filter out any with TargetObjectiveImmuneComponent
|
||||
var allHumans = _mind.GetAliveHumans(args.MindId)
|
||||
.Where(mindId =>
|
||||
{
|
||||
if (!TryComp<MindComponent>(mindId, out var mindComp) || mindComp.OwnedEntity == null)
|
||||
return false;
|
||||
return !HasComp<TargetObjectiveImmuneComponent>(mindComp.OwnedEntity.Value);
|
||||
})
|
||||
.ToList();
|
||||
|
||||
// Can't have multiple objectives to kill the same person
|
||||
foreach (var objective in args.Mind.Objectives)
|
||||
{
|
||||
if (HasComp<KillPersonConditionComponent>(objective) && TryComp<TargetObjectiveComponent>(objective, out var kill))
|
||||
{
|
||||
allHumans.RemoveAll(x => x.Owner == kill.Target);
|
||||
}
|
||||
}
|
||||
|
||||
// Filter out targets based on the filter
|
||||
var filteredHumans = allHumans.Where(mind => filter(mind)).ToList();
|
||||
|
||||
// There's no humans and we can't fall back to any other target
|
||||
if (filteredHumans.Count == 0 && !fallbackToAny)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Pick between humans matching our filter or fall back to all humans alive
|
||||
var selectedHumans = filteredHumans.Count > 0 ? filteredHumans : allHumans;
|
||||
|
||||
// Still no valid targets even after the fallback
|
||||
if (selectedHumans.Count == 0)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_target.SetTarget(uid, _random.Pick(selectedHumans), target);
|
||||
}
|
||||
|
||||
private void OnRandomTraitorProgressAssigned(Entity<RandomTraitorProgressComponent> ent, ref ObjectiveAssignedEvent args)
|
||||
{
|
||||
// invalid prototype
|
||||
if (!TryComp<TargetObjectiveComponent>(ent.Owner, out var target))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var traitors = _traitorRule.GetOtherTraitorMindsAliveAndConnected(args.Mind).ToHashSet();
|
||||
|
||||
// cant help anyone who is tasked with helping:
|
||||
// 1. thats boring
|
||||
// 2. no cyclic progress dependencies!!!
|
||||
foreach (var traitor in traitors)
|
||||
{
|
||||
// TODO: replace this with TryComp<ObjectivesComponent>(traitor) or something when objectives are moved out of mind
|
||||
if (!TryComp<MindComponent>(traitor.Id, out var mind))
|
||||
continue;
|
||||
|
||||
foreach (var objective in mind.Objectives)
|
||||
{
|
||||
if (HasComp<HelpProgressConditionComponent>(objective))
|
||||
traitors.RemoveWhere(x => x.Mind == mind);
|
||||
}
|
||||
}
|
||||
|
||||
// Can't have multiple objectives to help/save the same person
|
||||
foreach (var objective in args.Mind.Objectives)
|
||||
{
|
||||
if (HasComp<RandomTraitorAliveComponent>(objective) || HasComp<RandomTraitorProgressComponent>(objective))
|
||||
{
|
||||
if (TryComp<TargetObjectiveComponent>(objective, out var help))
|
||||
{
|
||||
traitors.RemoveWhere(x => x.Id == help.Target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// no more helpable traitors
|
||||
if (traitors.Count == 0)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_target.SetTarget(ent.Owner, _random.Pick(traitors).Id, target);
|
||||
}
|
||||
|
||||
private void OnRandomTraitorAliveAssigned(Entity<RandomTraitorAliveComponent> ent, ref ObjectiveAssignedEvent args)
|
||||
{
|
||||
// invalid prototype
|
||||
if (!TryComp<TargetObjectiveComponent>(ent.Owner, out var target))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var traitors = _traitorRule.GetOtherTraitorMindsAliveAndConnected(args.Mind).ToHashSet();
|
||||
|
||||
// Can't have multiple objectives to help/save the same person
|
||||
foreach (var objective in args.Mind.Objectives)
|
||||
{
|
||||
if (HasComp<RandomTraitorAliveComponent>(objective) || HasComp<RandomTraitorProgressComponent>(objective))
|
||||
{
|
||||
if (TryComp<TargetObjectiveComponent>(objective, out var help))
|
||||
{
|
||||
traitors.RemoveWhere(x => x.Id == help.Target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// You are the first/only traitor.
|
||||
if (traitors.Count == 0)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_target.SetTarget(ent.Owner, _random.Pick(traitors).Id, target);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
using Content.Server.Objectives.Components;
|
||||
using Content.Server.Terminator.Components;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Components;
|
||||
|
||||
namespace Content.Server.Objectives.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// Handles copying the exterminator's target override to this objective.
|
||||
/// </summary>
|
||||
public sealed class TerminatorTargetOverrideSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly TargetObjectiveSystem _target = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<TerminatorTargetOverrideComponent, ObjectiveAssignedEvent>(OnAssigned);
|
||||
}
|
||||
|
||||
private void OnAssigned(EntityUid uid, TerminatorTargetOverrideComponent comp, ref ObjectiveAssignedEvent args)
|
||||
{
|
||||
if (args.Mind.OwnedEntity == null)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var user = args.Mind.OwnedEntity.Value;
|
||||
if (!TryComp<TerminatorComponent>(user, out var terminator))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// this exterminator has a target override so set its objective target accordingly
|
||||
if (terminator.Target != null)
|
||||
_target.SetTarget(uid, terminator.Target.Value);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
using Content.Server.Terminator.Systems;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
|
||||
namespace Content.Server.Terminator.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Main terminator component, handles the target, if any, and objectives.
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(TerminatorSystem))]
|
||||
public sealed partial class TerminatorComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to force the terminate objective's target.
|
||||
/// If null it will be a random person.
|
||||
/// </summary>
|
||||
[DataField("target")]
|
||||
public EntityUid? Target;
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
using Content.Server.Body.Components;
|
||||
using Content.Server.Ghost.Roles.Events;
|
||||
using Content.Server.Roles;
|
||||
using Content.Server.Terminator.Components;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.Terminator.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// DeltaV - this is just used for paradox anomaly upstream doesnt use it anymore.
|
||||
/// </summary>
|
||||
public sealed class TerminatorSystem : EntitySystem
|
||||
{
|
||||
public void SetTarget(Entity<TerminatorComponent?> ent, EntityUid mindId)
|
||||
{
|
||||
ent.Comp ??= EnsureComp<TerminatorComponent>(ent);
|
||||
ent.Comp.Target = mindId;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ using Content.Server.Psionics;
|
|||
using Content.Server.Station.Systems;
|
||||
using Content.Server.StationEvents.Components;
|
||||
using Content.Server.StationEvents.Events;
|
||||
using Content.Server.Terminator.Systems;
|
||||
using Content.Server.Objectives.Components;
|
||||
using Content.Shared.Cloning;
|
||||
using Content.Shared.Humanoid;
|
||||
using Content.Shared.Humanoid.Prototypes;
|
||||
|
|
@ -23,7 +23,7 @@ namespace Content.Server.StationEvents.Events;
|
|||
|
||||
/// <summary>
|
||||
/// Creates clones of random players to make into selected antags.
|
||||
/// 90% of the actual antag's work is done by exterminator (rip) since its a reskin.
|
||||
/// 90% of the actual antag's work is done by TargetOverrideComponent.
|
||||
/// </summary>
|
||||
public sealed class ParadoxClonerRule : StationEventSystem<ParadoxClonerRuleComponent>
|
||||
{
|
||||
|
|
@ -36,7 +36,6 @@ public sealed class ParadoxClonerRule : StationEventSystem<ParadoxClonerRuleComp
|
|||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly StationSystem _station = default!;
|
||||
[Dependency] private readonly StationSpawningSystem _stationSpawning = default!;
|
||||
[Dependency] private readonly TerminatorSystem _terminator = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
|
|
@ -108,7 +107,7 @@ public sealed class ParadoxClonerRule : StationEventSystem<ParadoxClonerRuleComp
|
|||
|
||||
// Set the kill target to the chosen player
|
||||
var spawned = mob.Value;
|
||||
_terminator.SetTarget(spawned, mindId);
|
||||
EnsureComp<TargetOverrideComponent>(spawned).Target = mindId;
|
||||
|
||||
// guaranteed psionic power
|
||||
var psi = EnsureComp<PotentialPsionicComponent>(spawned);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
state: icon
|
||||
- type: TargetObjective
|
||||
title: objective-paradox-anomaly-kill-title
|
||||
- type: TerminatorTargetOverride
|
||||
- type: PickSpecificPerson
|
||||
- type: KillPersonCondition
|
||||
requireDead: true
|
||||
|
||||
|
|
@ -38,7 +38,7 @@
|
|||
state: folder-white
|
||||
- type: TargetObjective
|
||||
title: objective-paradox-anomaly-friend-title
|
||||
- type: TerminatorTargetOverride
|
||||
- type: PickSpecificPerson
|
||||
- type: KeepAliveCondition
|
||||
|
||||
- type: entity
|
||||
|
|
|
|||
Loading…
Reference in New Issue