better error handling, added chant command

This commit is contained in:
Marcus Netz
2021-04-28 15:50:02 +02:00
parent f5c485fdcc
commit d29e04a103
11 changed files with 228 additions and 44 deletions

View File

@ -1,12 +1,19 @@
const CreateResultTable = ({ Attributes: Attributes, Throws: Throws, PointsUsed: PointsUsed, Bonus: Bonus = 0 }) => {
const CreateResultTable = ({
Attributes: Attributes,
Throws: Throws,
PointsUsed: PointsUsed,
Bonus: Bonus = 0,
}) => {
return `
\`\`\`
${''.padEnd(15)} ${Attributes.map(attr => `${attr.Name}`.padStart(6)).join('\t|\t')}\t|
${'Dein Wert'.padEnd(15)} ${Attributes.map(attr => `${attr.Level}${Bonus ? `(${f(Bonus)})` : ``}`.padStart(6)).join(
${'Dein Wert'.padEnd(15)} ${Attributes.map(attr =>
`${attr.Level}${Bonus ? `(${f(Bonus)})` : ``}`.padStart(6)
).join('\t|\t')}\t|
${'Dein Wurf'.padEnd(15)} ${Throws.map(Throw => `${Throw}`.padStart(6)).join('\t|\t')}\t|
${'Abzüge'.padEnd(15)} ${PointsUsed.map(Points => `${Points}`.replace(0, '--').padStart(6)).join(
'\t|\t'
)}\t|
${'Dein Wurf'.padEnd(15)} ${Throws.map(Throw => `${Throw}`.padStart(6)).join('\t|\t')}\t|
${'Abzüge'.padEnd(15)} ${PointsUsed.map(Points => `${Points}`.replace(0, '--').padStart(6)).join('\t|\t')}\t|
${'Gesamt'.padEnd(15)} ${PointsUsed.reduce((acc, cur) => acc + cur)
.toString()
.padStart(6)}
@ -18,4 +25,4 @@ const f = n => {
return (n > 0 ? '+' : '') + n;
};
module.exports = { CreateResultTable };
module.exports = { CreateResultTable, f };

View File

@ -1,6 +1,6 @@
const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
const Chants = require('../data/Chants.json');
const Chants = require('../data/Chants');
const getChant = ({ Character: Character = [], chant_name: chant_name = '' } = {}) => {
let chant_entry =
Chants.find(chant => chant.id.toLowerCase() === chant_name.toLowerCase()) ||
@ -10,13 +10,13 @@ const getChant = ({ Character: Character = [], chant_name: chant_name = '' } = {
console.log(`getChant() Did not find entry for ${chant_name}`);
return;
}
if (!Character.hasOwnProperty('chants')) return;
let Level = 0; // This is the minimum attributes value.
let Chant = Character.chants.find(chant => chant.id === chant_entry.id) || {};
if (Chant && Chant.hasOwnProperty('level')) {
Level = Chant.level || 0;
}
console.log(chant_entry);
let Attributes = getAttributeLevels(chant_entry.attributes, Character);
return {

View File

@ -1,22 +1,5 @@
const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
const Spells = require('../data/Spells');
/* definition of attributes in spell database
{
id: 'adlerauge', // the id of the spell inside characters database.
name: 'Adlerauge', // the well-known name of the spell.
attributes: [ 'KL', 'IN', 'FF' ], // needed attribute checks when casting the spell
spellduration: 2, // the player needs this many actions to cast the spell.
modified_by: [], // the spell is modified by this character's attribute
cost: null, // how many units does the spell cost? (when activated)
cost_type: 'asp', // what kind of points does the character need?
// AsP = Astral Points, KaP = Karmal Points
effect: '', // What is the desired effect of this spell?
effectduration: '' // How long does the effect last?
talent: null //
},
*/
const Spells = require('../data/Spells.json');
const getSpell = ({ Character: Character = [], spell_name: spell_name = '' } = {}) => {
const spell_entry =
@ -24,11 +7,12 @@ const getSpell = ({ Character: Character = [], spell_name: spell_name = '' } = {
Spells.find(spell => spell.name.toLowerCase() === spell_name.toLowerCase());
if (!spell_entry) {
console.log(`getSpell did not find entry for ${spell_name}`);
console.log(`getSpell() did not find entry for ${spell_name}`);
return;
}
let Level = 0; // This is the minimum attributes value.
if (!Character.hasOwnProperty('spells')) return;
let Spell = Character.spells.find(spell => spell.id === spell_entry.id) || {}; //?+
if (Spell && Spell.hasOwnProperty('level')) {
Level = Spell.level || 0;