Skip to content

Commit

Permalink
Fix Logic Requirements Not Checking Inversion (#891)
Browse files Browse the repository at this point in the history
  • Loading branch information
DEATHB4DEFEAT authored and Mnemotechnician committed Sep 9, 2024
1 parent cb7aeab commit 37b9a31
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile,
{
var succeeded = false;
var reasons = new List<FormattedMessage>();
var characterRequirements = entityManager.EntitySysManager.GetEntitySystem<CharacterRequirementsSystem>();

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;
Expand Down Expand Up @@ -110,11 +112,12 @@ public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile,
{
var reasons = new List<FormattedMessage>();
var succeeded = false;
var characterRequirements = entityManager.EntitySysManager.GetEntitySystem<CharacterRequirementsSystem>();

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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, TimeSpan> 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<CharacterRequirement> requirements, JobPrototype job,
HumanoidCharacterProfile profile, Dictionary<string, TimeSpan> playTimes, bool whitelisted, IPrototype prototype,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
Expand Down

0 comments on commit 37b9a31

Please sign in to comment.