added related messages, added skillcheck for spells (cast)

This commit is contained in:
2021-04-27 18:11:47 +02:00
parent 1b67dcb4e6
commit f5c485fdcc
12 changed files with 798 additions and 1184 deletions

View File

@ -1,44 +1,51 @@
/**
* Compares each item inside an array Throws
* Compares each item inside an array Throws
* with corresponding AttributeLevels (With added bonus)
*
*
* @param {Array} Throws=[]
* @param {Array} AttributeLevels=[8,8,8]
* @param {BigInt} Bonus=0
* @param {BigInt} PointsRemaining=0
*/
const CompareResults = (Throws = [], AttributeLevels = [8, 8, 8], Bonus = 0, PointsRemaining = 0) => {
const CompareResults = (
Throws = [],
AttributeLevels = [8, 8, 8],
Bonus = 0,
PointsRemaining = 0
) => {
let Passed = 0;
let Fumbles = 0;
let CriticalHit = 0;
let AllPointsUsed = [];
let Passed = 0;
let Fumbles = 0;
let CriticalHit = 0;
let AllPointsUsed = [];
for (let i = 0; i < Throws.length; i++) {
let PointsUsed = 0;
if (Math.floor(AttributeLevels[i] + Bonus) >= Throws[i]) {
Passed++;
} else if (Math.floor(AttributeLevels[i] + PointsRemaining + Bonus) >= Throws[i]) {
Passed++;
PointsUsed = (Throws[i] - Bonus - AttributeLevels[i]);
PointsRemaining -= PointsUsed;
}
else {
// We need to use all our points, so that next die/dice
// would not return a 'Passed'.
PointsUsed = PointsRemaining;
PointsRemaining -= PointsUsed;
}
if (Throws[i] == 1) { CriticalHit++; }
if (Throws[i] == 20) { Fumbles++; }
AllPointsUsed.push(PointsUsed);
}
return {
Passed: Passed,
CriticalHit: CriticalHit,
Fumbles: Fumbles,
PointsUsed: AllPointsUsed,
PointsRemaining: PointsRemaining
};
for (let i = 0; i < Throws.length; i++) {
let PointsUsed = 0;
if (Math.floor(AttributeLevels[i] + Bonus) >= Throws[i]) {
Passed++;
} else if (Math.floor(AttributeLevels[i] + PointsRemaining + Bonus) >= Throws[i]) {
Passed++;
PointsUsed = Throws[i] - Bonus - AttributeLevels[i];
PointsRemaining -= PointsUsed;
} else {
// We need to use all our points, so that next die/dice
// would not return a 'Passed'.
PointsUsed = PointsRemaining;
PointsRemaining -= PointsUsed;
}
if (Throws[i] == 1) {
CriticalHit++;
}
if (Throws[i] == 20) {
Fumbles++;
}
AllPointsUsed.push(PointsUsed);
}
return {
Passed: Passed,
CriticalHit: CriticalHit,
Fumbles: Fumbles,
PointsUsed: AllPointsUsed,
PointsRemaining: PointsRemaining,
};
};
module.exports = { CompareResults };

View File

@ -0,0 +1,21 @@
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(
'\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)}
\`\`\`
`;
};
const f = n => {
return (n > 0 ? '+' : '') + n;
};
module.exports = { CreateResultTable };

View File

@ -1,50 +1,28 @@
const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
//JSON.parse(require('fs').readFileSync('../data/Spells.json'))
const Chants = require('../data/Chants');
/* definition of attributes in chant database
{
id: 'adlerauge', // the id of the chant inside characters database.
name: 'Adlerauge', // the well-known name of the chant.
attributes: [ 'KL', 'IN', 'FF' ], // needed attribute checks when casting the chant
chantduration: 2, // the player needs this many actions to cast the chant.
modified_by: [], // the chant is modified by this character's attribute
cost: null, // how many units does the chant 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 chant?
effectduration: '' // How long does the effect last?
talent: null //
},
*/
const getChant = ({ Character: Character = [], chant_name: chant_name = '' } = {}) => {
let chant_entry =
Chants.find(chant => chant.id.toLowerCase() === chant_name.toLowerCase()) ||
Chants.find(chant => chant.name.toLowerCase() === chant_name.toLowerCase());
if (!chant_entry) {
console.log(`getchant did not find entry for ${chant_name}`);
console.log(`getChant() Did not find entry for ${chant_name}`);
return;
}
let Level = 0; // This is the minimum attributes value.
let Chant = Character.chants.find(chant => chant.id === chant_entry.id) || {};
if (Chant) {
if (Chant && Chant.hasOwnProperty('level')) {
Level = Chant.level || 0;
}
let Name = Chant.name;
//let ModifiedBy = Chant.modified_by;
let Attributes = getAttributeLevels(chant_entry.attributes, Character);
return {
Name: Name,
Name: chant_entry.name,
Level: Level,
Attributes: Attributes,
//ModifiedBy: ModifiedBy,
};
};
module.exports = { getChant };

View File

@ -30,15 +30,14 @@ const getSpell = ({ Character: Character = [], spell_name: spell_name = '' } = {
let Level = 0; // This is the minimum attributes value.
let Spell = Character.spells.find(spell => spell.id === spell_entry.id) || {}; //?+
if (Spell) {
if (Spell && Spell.hasOwnProperty('level')) {
Level = Spell.level || 0;
}
let Name = spell_entry.name;
let ModifiedBy = spell_entry.modified_by;
let Attributes = getAttributeLevels(spell_entry.attributes, Character);
return {
Name: Name,
Name: spell_entry.name,
Level: Level,
Attributes: Attributes,
ModifiedBy: ModifiedBy,