Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-Pick "Fix Logic Requirements Not Checking Inversion" #181

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading