added return list of spells. Moved them into seperate json

This commit is contained in:
2021-04-24 09:53:05 +02:00
parent 8e4f4eedb8
commit e65715cce6
10 changed files with 787 additions and 66 deletions

30
functions/getSpell.js Normal file
View File

@ -0,0 +1,30 @@
const globals = require('../globals');
const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
const getSpell = ({ Character: Character = [], spell_name: spell_name = '' } = {}) => {
let spell_entry =
globals.Spells.find(spell => spell.id.toLowerCase() === spell_name.toLowerCase()) ||
globals.Spells.find(spell => spell.name.toLowerCase() === spell_name.toLowerCase());
if (!spell_entry) {
console.log(`getSpell did not find entry for ${spell_name}`);
return;
}
let Level = 0; // This is the minimum attributes value.
let Spell = Character.spells.find(spell => spell.id === spell_entry.id) || {};
if (Spell) {
Level = Spell.level || 0;
}
let Name = globals.Spells.find(spell => spell.id === spell_entry.id).name;
let ModifiedBy = globals.Spells.find(spell => spell.id === spell_entry.id).modified_by;
let Attributes = getAttributeLevels(spell_entry.attributes, Character);
return {
Name: Name,
Level: Level,
Attributes: Attributes,
ModifiedBy: ModifiedBy,
};
};
module.exports = { getSpell };