Add Skillchecks for Magical Talents (#25)

* initial implementation of spells

* added return list of spells. Moved them into seperate json

* added _some_ chants, restructuring data from spells

* added more chants, added command for getting info

* added related messages, added skillcheck for spells (cast)

* better error handling, added chant command

* (fix) Chants were referring to spells

* cleanup testing variables and code

* updated README

* fixed storage location issues and minor bugs

* removed db storage location

* rc1

* (fix) chants_title

* (fix) Uncaught ReferenceError: Discord is not defined

* (fix) more reference errors

Co-authored-by: Marcus Netz <marcus.netz@godyo.com>
This commit is contained in:
2021-04-28 19:33:30 +02:00
committed by GitHub
parent b49873e1d4
commit 23418bbc60
22 changed files with 656 additions and 193 deletions

View File

@ -1,35 +1,51 @@
const CompareResults = (Throws = [], AttributeLevels = [8, 8, 8], Bonus = 0, PointsRemaining = 0) => {
/**
* 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
) => {
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,28 @@
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, f };

28
functions/getChant.js Normal file
View File

@ -0,0 +1,28 @@
const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
const Chants = require('@Lib/Chants.json');
const getChant = ({ Character: Character = [], chant_name: chant_name = '' } = {}) => {
//if (!Character.hasOwnProperty('chants')) return;
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}`);
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;
}
let Attributes = getAttributeLevels(chant_entry.attributes, Character);
return {
Name: chant_entry.name,
Level: Level,
Attributes: Attributes,
};
};
module.exports = { getChant };

View File

@ -1,24 +1,27 @@
const globals = require('../globals');
const { getAttributeLevels } = require("@dsabot/getAttributeLevels");
const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
const getSkill = ({ Character: Character = [], args: args = [] } = {}) => {
let skill_entry = globals.Talente.find(skill => skill.id.toLowerCase() === args[0].toLowerCase()) ||
globals.Talente.find(skill => skill.name.toLowerCase() === args[0].toLowerCase());
let skill_entry =
globals.Talente.find(skill => skill.id.toLowerCase() === args[0].toLowerCase()) ||
globals.Talente.find(skill => skill.name.toLowerCase() === args[0].toLowerCase());
if (!skill_entry) { return; }
if (!skill_entry) {
return;
}
let Level = 0; // This is the minimum attributes value.
let cSkill = Character.skills.find(skill => skill.id === skill_entry.id) || {};
if (cSkill) {
Level = cSkill.level || 0;
}
let Name = globals.Talente.find(skill => skill.id === skill_entry.id).name;
let Attributes = getAttributeLevels(skill_entry.values, Character);
let Level = 0; // This is the minimum attributes value.
let cSkill = Character.skills.find(skill => skill.id === skill_entry.id) || {};
if (cSkill) {
Level = cSkill.level || 0;
}
let Name = globals.Talente.find(skill => skill.id === skill_entry.id).name;
let Attributes = getAttributeLevels(skill_entry.values, Character);
return {
Name: Name,
Level: Level,
Attributes: Attributes
};
return {
Name: Name,
Level: Level,
Attributes: Attributes,
};
};
module.exports = { getSkill };

30
functions/getSpell.js Normal file
View File

@ -0,0 +1,30 @@
const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
const Spells = require('@Lib/Spells.json');
const getSpell = ({ Character: Character = [], spell_name: spell_name = '' } = {}) => {
const spell_entry =
Spells.find(spell => spell.id.toLowerCase() === spell_name.toLowerCase()) ||
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.
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;
}
let ModifiedBy = spell_entry.modified_by;
let Attributes = getAttributeLevels(spell_entry.attributes, Character);
return {
Name: spell_entry.name,
Level: Level,
Attributes: Attributes,
ModifiedBy: ModifiedBy,
};
};
module.exports = { getSpell };