From 37b9a31ab815dd91ca3fa13da15e88f0a498c6f2 Mon Sep 17 00:00:00 2001 From: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com> Date: Sun, 8 Sep 2024 22:19:47 -0700 Subject: [PATCH] Fix Logic Requirements Not Checking Inversion (#891) --- .../Systems/CharacterRequirements.Logic.cs | 11 +++++++---- .../Systems/CharacterRequirementsSystem.cs | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Content.Shared/Customization/Systems/CharacterRequirements.Logic.cs b/Content.Shared/Customization/Systems/CharacterRequirements.Logic.cs index 1cd3618fda..397e74bc8b 100644 --- a/Content.Shared/Customization/Systems/CharacterRequirements.Logic.cs +++ b/Content.Shared/Customization/Systems/CharacterRequirements.Logic.cs @@ -63,10 +63,12 @@ public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile, { var succeeded = false; var reasons = new List(); + var characterRequirements = entityManager.EntitySysManager.GetEntitySystem(); + foreach (var requirement in Requirements) { - if (requirement.IsValid(job, profile, playTimes, whitelisted, prototype, entityManager, prototypeManager, - configManager, out var raisin, depth + 1)) + if (characterRequirements.CheckRequirementValid(requirement, job, profile, playTimes, whitelisted, prototype, + entityManager, prototypeManager, configManager, out var raisin, depth + 1)) { succeeded = true; break; @@ -110,11 +112,12 @@ public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile, { var reasons = new List(); var succeeded = false; + var characterRequirements = entityManager.EntitySysManager.GetEntitySystem(); foreach (var requirement in Requirements) { - if (requirement.IsValid(job, profile, playTimes, whitelisted, prototype, entityManager, prototypeManager, - configManager, out var raisin, depth + 1)) + if (characterRequirements.CheckRequirementValid(requirement, job, profile, playTimes, whitelisted, prototype, + entityManager, prototypeManager, configManager, out var raisin, depth + 1)) { if (succeeded) { diff --git a/Content.Shared/Customization/Systems/CharacterRequirementsSystem.cs b/Content.Shared/Customization/Systems/CharacterRequirementsSystem.cs index 74c2c26cf8..9becb640d1 100644 --- a/Content.Shared/Customization/Systems/CharacterRequirementsSystem.cs +++ b/Content.Shared/Customization/Systems/CharacterRequirementsSystem.cs @@ -15,6 +15,21 @@ public sealed class CharacterRequirementsSystem : EntitySystem [Dependency] private readonly InventorySystem _inventory = default!; + public bool CheckRequirementValid(CharacterRequirement requirement, JobPrototype job, + HumanoidCharacterProfile profile, Dictionary playTimes, bool whitelisted, IPrototype prototype, + IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager, + out FormattedMessage? reason, int depth = 0) + { + // Return false if the requirement is invalid and not inverted + // If it's inverted return false when it's valid + return + !requirement.IsValid(job, profile, playTimes, whitelisted, prototype, + entityManager, prototypeManager, configManager, + out reason, depth) + ? requirement.Inverted + : !requirement.Inverted; + } + public bool CheckRequirementsValid(List requirements, JobPrototype job, HumanoidCharacterProfile profile, Dictionary playTimes, bool whitelisted, IPrototype prototype, IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,