New source found from dndbeyond.com
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import sortBy from 'lodash/sortBy';
|
||||
import { AbilityAccessors } from '../Ability';
|
||||
import { FormatUtils } from '../Format';
|
||||
import { getEntityId, getFriendlySubtypeName, getPrerequisites, getSubType, getType, getValue, getShouldExclude, } from './accessors';
|
||||
@@ -207,3 +208,46 @@ export function getPrerequisiteGroupingFailures(prerequisiteGrouping, prerequisi
|
||||
}
|
||||
return groupingFailures.filter((group) => group.length);
|
||||
}
|
||||
// Creates a string that summarizes the prerequisite failures for feats and multiclassing
|
||||
export function getPrerequisiteFailuresText(prereqFailures) {
|
||||
//get all the prerequisite failures, sorted so that if every group failure is a missing prereq, they come first
|
||||
const failures = sortBy(prereqFailures, (failureGroup) => (failureGroup.every((f) => !f.shouldExclude) ? 0 : 1));
|
||||
// Create an intro string for the summary
|
||||
let intro = '';
|
||||
// Check if all failures are either missing or prohibited
|
||||
const hasOnlyMissingFailures = failures.every((failureGroup) => failureGroup.every((f) => !f.shouldExclude));
|
||||
const hasOnlyProhibitedFailures = failures.every((failureGroup) => failureGroup.every((f) => f.shouldExclude));
|
||||
// Determine the intro text based on the type of failures
|
||||
if (hasOnlyMissingFailures) {
|
||||
intro = 'Missing: ';
|
||||
}
|
||||
else if (hasOnlyProhibitedFailures) {
|
||||
intro = 'Prohibited by: ';
|
||||
}
|
||||
else {
|
||||
intro = 'Requires: ';
|
||||
}
|
||||
// Each failure is sorted so that prohibited failures come last, and then combined into a single string
|
||||
const combinedStrings = failures
|
||||
.map((failure) => sortBy(failure, (f) => (f.shouldExclude ? 1 : 0))
|
||||
.map((failureAnd) => {
|
||||
if (failureAnd.shouldExclude && !hasOnlyProhibitedFailures && !hasOnlyMissingFailures) {
|
||||
return `Prohibited by: ${failureAnd.data.requiredDescription}`;
|
||||
}
|
||||
return `${failureAnd.data.requiredDescription}`;
|
||||
})
|
||||
.reduce((acc, desc, idx) => {
|
||||
let connector = '';
|
||||
if (idx < failure.length - 2) {
|
||||
connector = ', ';
|
||||
}
|
||||
else if (idx < failure.length - 1) {
|
||||
connector = ' and ';
|
||||
}
|
||||
acc += `${desc}${connector}`;
|
||||
return acc;
|
||||
}, ''))
|
||||
.join(' or ');
|
||||
// return the intro text followed by the combined strings
|
||||
return `${intro}${combinedStrings}`;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import sortBy from 'lodash/sortBy';
|
||||
import { characterActions } from "../actions";
|
||||
import { ChoiceUtils } from "../engine/Choice";
|
||||
import { DisplayConfigurationTypeEnum } from "../engine/Core";
|
||||
@@ -77,48 +76,7 @@ export class FeatManager extends BaseManager {
|
||||
return PrerequisiteUtils.getPrerequisiteGroupingFailures(this.getPrerequisites(), prerequisiteData);
|
||||
};
|
||||
// Creates a string that summarizes the prerequisite failures for this feat
|
||||
this.getPrerequisiteFailuresText = () => {
|
||||
//get all the prerequisite failures, sorted so that if every group failure is a missing prereq, they come first
|
||||
const failures = sortBy(this.getPrerequisiteFailures(), (failureGroup) => failureGroup.every((f) => !f.shouldExclude) ? 0 : 1);
|
||||
// Create an intro string for the summary
|
||||
let intro = '';
|
||||
// Check if all failures are either missing or prohibited
|
||||
const hasOnlyMissingFailures = failures.every((failureGroup) => failureGroup.every((f) => !f.shouldExclude));
|
||||
const hasOnlyProhibitedFailures = failures.every((failureGroup) => failureGroup.every((f) => f.shouldExclude));
|
||||
// Determine the intro text based on the type of failures
|
||||
if (hasOnlyMissingFailures) {
|
||||
intro = 'Missing: ';
|
||||
}
|
||||
else if (hasOnlyProhibitedFailures) {
|
||||
intro = 'Prohibits: ';
|
||||
}
|
||||
else {
|
||||
intro = 'Requires: ';
|
||||
}
|
||||
// Each failure is sorted so that prohibited failures come last, and then combined into a single string
|
||||
const combinedStrings = failures
|
||||
.map((failure) => sortBy(failure, (f) => (f.shouldExclude ? 1 : 0))
|
||||
.map((failureAnd) => {
|
||||
if (failureAnd.shouldExclude && !hasOnlyProhibitedFailures && !hasOnlyMissingFailures) {
|
||||
return `Prohibits ${failureAnd.data.requiredDescription}`;
|
||||
}
|
||||
return `${failureAnd.data.requiredDescription}`;
|
||||
})
|
||||
.reduce((acc, desc, idx) => {
|
||||
let connector = '';
|
||||
if (idx < failure.length - 2) {
|
||||
connector = ', ';
|
||||
}
|
||||
else if (idx < failure.length - 1) {
|
||||
connector = ' and ';
|
||||
}
|
||||
acc += `${desc}${connector}`;
|
||||
return acc;
|
||||
}, ''))
|
||||
.join(' or ');
|
||||
// return the intro text followed by the combined strings
|
||||
return `${intro}${combinedStrings}`;
|
||||
};
|
||||
this.getPrerequisiteFailuresText = () => PrerequisiteUtils.getPrerequisiteFailuresText(this.getPrerequisiteFailures());
|
||||
this.getRepeatableGroupId = () => FeatUtils.getRepeatableGroupId(this.feat);
|
||||
this.isRepeatableFeatParent = () => this.isRepeatable() && this.getRepeatableParentId() === null;
|
||||
this.getDefinitionKey = () => {
|
||||
|
||||
Reference in New Issue
Block a user