make objectives use yml defined mind filters (#36030)
* add MindHasRole whitelist overload * add mind filters framework * add different mind filters and pools * update traitor stuff to use mind filters * line * don't duplicate kill objectives * g * gs --------- Co-authored-by: deltanedas <@deltanedas:kde.org> Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com> Co-authored-by: ScarKy0 <scarky0@onet.eu> Co-authored-by: SlamBamActionman <slambamactionman@gmail.com>
This commit is contained in:
@@ -25,10 +25,6 @@ public sealed class PickObjectiveTargetSystem : EntitySystem
|
||||
|
||||
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)
|
||||
@@ -63,7 +59,7 @@ public sealed class PickObjectiveTargetSystem : EntitySystem
|
||||
private void OnRandomPersonAssigned(Entity<PickRandomPersonComponent> ent, ref ObjectiveAssignedEvent args)
|
||||
{
|
||||
// invalid objective prototype
|
||||
if (!TryComp<TargetObjectiveComponent>(ent.Owner, out var target))
|
||||
if (!TryComp<TargetObjectiveComponent>(ent, out var target))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
@@ -73,140 +69,13 @@ public sealed class PickObjectiveTargetSystem : EntitySystem
|
||||
if (target.Target != null)
|
||||
return;
|
||||
|
||||
var allHumans = _mind.GetAliveHumans(args.MindId);
|
||||
|
||||
// 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.RemoveWhere(x => x.Owner == kill.Target);
|
||||
}
|
||||
}
|
||||
|
||||
// no other humans to kill
|
||||
if (allHumans.Count == 0)
|
||||
// couldn't find a target :(
|
||||
if (_mind.PickFromPool(ent.Comp.Pool, ent.Comp.Filters, args.MindId) is not {} picked)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_target.SetTarget(ent.Owner, _random.Pick(allHumans), target);
|
||||
}
|
||||
|
||||
private void OnRandomHeadAssigned(Entity<PickRandomHeadComponent> ent, ref ObjectiveAssignedEvent args)
|
||||
{
|
||||
// invalid prototype
|
||||
if (!TryComp<TargetObjectiveComponent>(ent.Owner, out var target))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// target already assigned
|
||||
if (target.Target != null)
|
||||
return;
|
||||
|
||||
// no other humans to kill
|
||||
var allHumans = _mind.GetAliveHumans(args.MindId);
|
||||
if (allHumans.Count == 0)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var allHeads = new HashSet<Entity<MindComponent>>();
|
||||
foreach (var person in allHumans)
|
||||
{
|
||||
if (TryComp<MindComponent>(person, out var mind) && mind.OwnedEntity is { } owned && HasComp<CommandStaffComponent>(owned))
|
||||
allHeads.Add(person);
|
||||
}
|
||||
|
||||
if (allHeads.Count == 0)
|
||||
allHeads = allHumans; // fallback to non-head target
|
||||
|
||||
_target.SetTarget(ent.Owner, _random.Pick(allHeads), 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);
|
||||
_target.SetTarget(ent, picked, target);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user