New source found from dndbeyond.com
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
export function getItemDefinitionKey(itemPlan) {
|
||||
return itemPlan.itemDefinitionKey;
|
||||
}
|
||||
export function getDataOrigin(itemPlan) {
|
||||
return itemPlan.dataOrigin;
|
||||
}
|
||||
export function getItemName(itemPlan) {
|
||||
return itemPlan.itemName;
|
||||
}
|
||||
export function getChoice(itemPlan) {
|
||||
return itemPlan.choice;
|
||||
}
|
||||
export function getOriginDefinitionKey(itemPlan) {
|
||||
return itemPlan.originDefinitionKey;
|
||||
}
|
||||
export function getDescription(itemPlan) {
|
||||
return itemPlan.description;
|
||||
}
|
||||
export function getItem(itemPlan) {
|
||||
return itemPlan.item;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import { sortBy } from 'lodash';
|
||||
import { ChoiceAccessors } from '../Choice';
|
||||
import { ClassAccessors, ClassDerivers } from '../Class';
|
||||
import { ClassFeatureAccessors } from '../ClassFeature';
|
||||
import { ContainerAccessors } from '../Container';
|
||||
import { DataOriginGenerators } from '../DataOrigin';
|
||||
import { DefinitionHacks } from '../Definition';
|
||||
import { HelperUtils } from '../Helper';
|
||||
import { ItemAccessors } from '../Item';
|
||||
import { OptionAccessors } from '../Option';
|
||||
import { getItemDefinitionKey, getItemName, getOriginDefinitionKey } from './accessors';
|
||||
export function generateItemPlans(choices, options, dataOriginType, primary, parent) {
|
||||
return choices.map((choice) => {
|
||||
return generateItemPlan(choice, options, DataOriginGenerators.generateDataOrigin(dataOriginType, primary, parent));
|
||||
});
|
||||
}
|
||||
export function generateItemPlan(choice, options, dataOrigin) {
|
||||
const optionValue = ChoiceAccessors.getOptionValue(choice);
|
||||
const chosenOption = options.find((option) => OptionAccessors.getId(option) === optionValue);
|
||||
const itemName = chosenOption ? `Plan: ${OptionAccessors.getName(chosenOption)}` : 'Plan: Unknown';
|
||||
let originDefinitionKey = null;
|
||||
if (chosenOption && optionValue) {
|
||||
originDefinitionKey = DefinitionHacks.hack__generateDefinitionKey(OptionAccessors.getDefinitionEntityTypeId(chosenOption), optionValue);
|
||||
}
|
||||
return {
|
||||
originDefinitionKey,
|
||||
choice,
|
||||
dataOrigin,
|
||||
itemName,
|
||||
itemDefinitionKey: choice.itemDefinitionKey,
|
||||
};
|
||||
}
|
||||
export function generateAggregatedItemPlans(classes, inventoryLookupByOrigin, containerLookup) {
|
||||
const availablePlans = [];
|
||||
classes.forEach((charClass) => {
|
||||
ClassAccessors.getClassFeatures(charClass).forEach((feature) => {
|
||||
const itemPlans = ClassFeatureAccessors.getItemPlans(feature).filter((plan) => getOriginDefinitionKey(plan) !== null && getItemDefinitionKey(plan) !== null);
|
||||
availablePlans.push(...itemPlans);
|
||||
});
|
||||
});
|
||||
//add inventory mappings to the item plans if they exist in the lookup
|
||||
const updatedPlans = availablePlans.map((plan) => {
|
||||
const planOriginDefinitionKey = getOriginDefinitionKey(plan);
|
||||
const item = planOriginDefinitionKey
|
||||
? HelperUtils.lookupDataOrFallback(inventoryLookupByOrigin, planOriginDefinitionKey)
|
||||
: null;
|
||||
const container = item
|
||||
? HelperUtils.lookupDataOrFallback(containerLookup, ItemAccessors.getContainerDefinitionKey(item))
|
||||
: null;
|
||||
// if there is a container, use its name, otherwise default to 'In Equipment'
|
||||
let containerName = 'In Equipment';
|
||||
if (item && container) {
|
||||
containerName = !ItemAccessors.isContainer(item)
|
||||
? `In ${ContainerAccessors.getName(container)}`
|
||||
: `In ${ContainerAccessors.isShared(container) ? 'Party ' : ''}Inventory`;
|
||||
}
|
||||
return Object.assign(Object.assign({}, plan), { item, description: item ? containerName : 'No item replicated.' });
|
||||
});
|
||||
return sortBy(updatedPlans, (plan) => getItemName(plan));
|
||||
}
|
||||
export function generateMaxReplicatedItemCount(classes) {
|
||||
let totalMaxReplicatedItemsCount = 0;
|
||||
classes.forEach((charClass) => {
|
||||
const classMaxCount = ClassDerivers.deriveMaxReplicatedMagicItems(charClass);
|
||||
if (classMaxCount) {
|
||||
totalMaxReplicatedItemsCount += classMaxCount;
|
||||
}
|
||||
});
|
||||
return totalMaxReplicatedItemsCount > 0 ? totalMaxReplicatedItemsCount : null;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import * as ItemPlanAccessors from './accessors';
|
||||
import * as ItemPlanGenerators from './generators';
|
||||
import * as ItemPlanTypings from './typings';
|
||||
export * from './typings';
|
||||
export { ItemPlanAccessors, ItemPlanGenerators };
|
||||
export default Object.assign(Object.assign(Object.assign({}, ItemPlanAccessors), ItemPlanGenerators), ItemPlanTypings);
|
||||
Reference in New Issue
Block a user