CatStation/Content.Shared/EntityConditions/Conditions/Mind/DifferentDepartmentConditionSystem.cs
KeTuFaisPiKiNut 5a6bf259d6
Changeling Escape as Department Objective (#44220)
* insanity

* changeling real pliz

* the wizard

* no conflict plz :3

* Update Content.Server/Objectives/Systems/ChangelingEscapeDepartmentConditionSystem.cs

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* linq is hell

* Update Content.Server/Objectives/Systems/ChangelingEscapeDepartmentConditionSystem.cs

Co-authored-by: Pok <113675512+Pok27@users.noreply.github.com>

* comment & API

* wokism is real and is coming for you in this pride month

* i am stoopid and dont know how to code :3

* cleanup, self review, usual stuff

* oops

* comments and difficulty

* fuck everything

* add to rolls

* FFS

* self ontag

* filters? you should kill your mom, here's why women never fuck you here's how you could build a bomb.

* ncat

* Update Content.Shared/Roles/Jobs/SharedJobSystem.cs

eqweqwewqe

Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>

* address slam,s reviews idfk this will be squashed anyway

* from captain sprite (apparently removed on master) to atmosian sprite

* Minor cleanup changes

---------

Co-authored-by: nomdéraisonnablementlong <you@example.com>
Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Co-authored-by: Pok <113675512+Pok27@users.noreply.github.com>
Co-authored-by: ScarKy0 <scarky0@onet.eu>
Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>
Co-authored-by: SlamBamActionman <slambamactionman@gmail.com>
2026-08-13 13:03:37 +00:00

58 lines
2.1 KiB
C#

using System.Linq;
using Content.Shared.Mind;
using Content.Shared.Roles;
using Content.Shared.Roles.Jobs;
using Content.Shared.Throwing;
using Robust.Shared.Prototypes;
namespace Content.Shared.EntityConditions.Conditions.Mind;
public sealed partial class DifferentDepartmentConditionSystem : EntityConditionSystem<MindComponent, DifferentDepartmentCondition>
{
[Dependency] private SharedRoleSystem _roleSystem = default!;
[Dependency] private SharedJobSystem _jobSystem = default!;
protected override void Condition(Entity<MindComponent> entity, ref EntityConditionEvent<DifferentDepartmentCondition> args)
{
args.Result = !IsInvalid(entity, args.SourceEnt);
}
private bool IsInvalid(Entity<MindComponent> mind, EntityUid? exclude)
{
// no entity to exclude depts, so all depts are valid
if (!exclude.HasValue)
return false;
if (!_jobSystem.MindTryGetJobId(exclude.Value, out var objJob))
return false; // in no department, so all departments are valid
if (!_jobSystem.MindTryGetJobId(mind.Owner, out var job))
return false; // target in no department, so all depts are valid
if (!objJob.HasValue || !job.HasValue)
throw new Exception("Unreachable statement after getting job proto from mind.");
// get all departments
if (!_jobSystem.TryGetAllDepartments(objJob.Value, out var deptsA) || !_jobSystem.TryGetAllDepartments(job.Value, out var deptsB))
throw new Exception("Job didn't have any department assigned.");
// perform the department check
if (deptsA.Select(dept => dept.ID).Intersect(deptsB.Select(dept => dept.ID)).Any())
return true;
return false;
}
}
/// <summary>
/// A condition that requires minds to have a job with a different department from the excluded entity's.
/// This uses mind roles, not ID cards.
/// </summary>
public sealed partial class DifferentDepartmentCondition : EntityConditionBase<DifferentDepartmentCondition>
{
public override string EntityConditionGuidebookText(IPrototypeManager prototype)
{
return string.Empty;
}
}