switched nedb to nedb-promises (#37)
* breaking change: switched to nedb-promises * Linting * some dev dependencies * more tests * updated package version * bug fixing * changed isNaN to isString * (fix) args[0]
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
const CalculateQuality = (PointsAvailable = 0) => {
|
||||
if (PointsAvailable <= 3) return 1;
|
||||
else if (PointsAvailable > 3 && PointsAvailable <= 6) return 2;
|
||||
else if (PointsAvailable > 6 && PointsAvailable <= 9) return 3;
|
||||
else if (PointsAvailable > 9 && PointsAvailable <= 12) return 4;
|
||||
else if (PointsAvailable > 12 && PointsAvailable <= 15) return 5;
|
||||
else return 6;
|
||||
if (PointsAvailable > 3 && PointsAvailable <= 6) return 2;
|
||||
if (PointsAvailable > 6 && PointsAvailable <= 9) return 3;
|
||||
if (PointsAvailable > 9 && PointsAvailable <= 12) return 4;
|
||||
if (PointsAvailable > 12 && PointsAvailable <= 15) return 5;
|
||||
return 6;
|
||||
};
|
||||
module.exports = { CalculateQuality };
|
||||
|
@ -7,24 +7,20 @@
|
||||
* @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, Points = 0) => {
|
||||
let Passed = 0;
|
||||
let Fumbles = 0;
|
||||
let CriticalHit = 0;
|
||||
let AllPointsUsed = [];
|
||||
let PointsRemaining = Points;
|
||||
const AllPointsUsed = [];
|
||||
|
||||
Throws.forEach((Throw, key) => {
|
||||
let PointsUsed = 0;
|
||||
let AttributeLevel = AttributeLevels.find((v, k) => key === k);
|
||||
const AttributeLevel = AttributeLevels.find((v, k) => key === k);
|
||||
if (Math.floor(AttributeLevel + Bonus) >= Throw) {
|
||||
Passed++;
|
||||
Passed += 1;
|
||||
} else if (Math.floor(AttributeLevel + PointsRemaining + Bonus) >= Throw) {
|
||||
Passed++;
|
||||
Passed += 1;
|
||||
PointsUsed = Throw - Bonus - AttributeLevel;
|
||||
PointsRemaining -= PointsUsed;
|
||||
} else {
|
||||
@ -32,10 +28,10 @@ const CompareResults = (
|
||||
PointsRemaining -= PointsUsed;
|
||||
}
|
||||
if (Throw === 1) {
|
||||
CriticalHit++;
|
||||
CriticalHit += 1;
|
||||
}
|
||||
if (Throw === 20) {
|
||||
Fumbles++;
|
||||
Fumbles += 1;
|
||||
}
|
||||
AllPointsUsed.push(PointsUsed);
|
||||
});
|
||||
|
@ -1,3 +1,7 @@
|
||||
function f(n) {
|
||||
return (n > 0 ? '+' : '') + n;
|
||||
}
|
||||
|
||||
const CreateResultTable = ({
|
||||
Attributes: Attributes,
|
||||
Throws: Throws,
|
||||
@ -21,8 +25,4 @@ const CreateResultTable = ({
|
||||
`;
|
||||
};
|
||||
|
||||
const f = n => {
|
||||
return (n > 0 ? '+' : '') + n;
|
||||
};
|
||||
|
||||
module.exports = { CreateResultTable, f };
|
||||
|
@ -1,14 +1,12 @@
|
||||
const Random = { int, use };
|
||||
|
||||
function int(min, max) {
|
||||
if (!min || !max) {
|
||||
return;
|
||||
return undefined;
|
||||
}
|
||||
return Math.floor(Math.random() * (Math.floor(max) - Math.ceil(min) + 1)) + min;
|
||||
}
|
||||
|
||||
function use(str) {
|
||||
function use() {
|
||||
return true;
|
||||
}
|
||||
|
||||
const Random = { int, use };
|
||||
module.exports = { Random };
|
||||
|
@ -1,18 +1,17 @@
|
||||
const { Random } = require("@dsabot/Random");
|
||||
const { Random } = require('@dsabot/Random');
|
||||
//const Random = require('random');
|
||||
|
||||
const roll = (numberOfDice, numberOfEyes, tag) => {
|
||||
let dice = [];
|
||||
const dice = [];
|
||||
let sum = 0;
|
||||
if(tag) {
|
||||
if (tag) {
|
||||
Random.use(tag);
|
||||
}
|
||||
for (let i = 0; i<numberOfDice; i++ ) {
|
||||
let result = Random.int(1,numberOfEyes);
|
||||
for (let i = 0; i < numberOfDice; i += 1) {
|
||||
const result = Random.int(1, numberOfEyes);
|
||||
dice.push(result);
|
||||
sum += result;
|
||||
}
|
||||
return { dice, sum };
|
||||
};
|
||||
module.exports = { roll };
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
const globals = require('../globals');
|
||||
const { Replies } = require('../globals');
|
||||
|
||||
const findMessage = (value) => {
|
||||
return globals.Replies.find(r => r.id === value).string;
|
||||
const findMessage = value => {
|
||||
return Replies.find(r => r.id === value).string;
|
||||
};
|
||||
|
||||
module.exports = { findMessage };
|
||||
module.exports = { findMessage };
|
||||
|
@ -1,14 +1,13 @@
|
||||
const globals = require('../globals');
|
||||
const { Werte } = require('../globals');
|
||||
|
||||
const getAttributeLevels = (Attributes = [], Character = {}) => {
|
||||
let AttributeId;
|
||||
let AttributeLevel;
|
||||
let AttributeList = [];
|
||||
for (let Attribute of Attributes) {
|
||||
AttributeId = globals.Werte.find(att => att.kuerzel === Attribute).id;
|
||||
AttributeLevel = Character.attributes.find(att => att.id === AttributeId).level;
|
||||
AttributeList.push({ Name: Attribute, Level: AttributeLevel });
|
||||
}
|
||||
const AttributeList = [];
|
||||
Attributes.forEach(Attribute => {
|
||||
const { id } = Werte.find(att => att.kuerzel === Attribute);
|
||||
const { level } = Character.attributes.find(att => att.id === id);
|
||||
AttributeList.push({ Name: Attribute, Level: level });
|
||||
});
|
||||
|
||||
return AttributeList;
|
||||
};
|
||||
module.exports = { getAttributeLevels };
|
||||
|
@ -1,28 +1,24 @@
|
||||
const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
|
||||
const Chants = require('@Lib/Chants.json');
|
||||
|
||||
const getChant = ({ Character: Character = [], chant_name: chant_name = '' } = {}) => {
|
||||
const getChant = ({ Character: Character = [], chant_name: chantName = '' } = {}) => {
|
||||
//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());
|
||||
const chantEntry =
|
||||
Chants.find(chant => chant.id.toLowerCase() === chantName.toLowerCase()) ||
|
||||
Chants.find(chant => chant.name.toLowerCase() === chantName.toLowerCase());
|
||||
|
||||
if (!chant_entry) {
|
||||
console.log(`getChant() Did not find entry for ${chant_name}`);
|
||||
return;
|
||||
if (!chantEntry) {
|
||||
console.log(`getChant() Did not find entry for ${chantName}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
let Level = 0; // This is the minimum attributes value.
|
||||
let Chant = Character.chants.find(chant => chant.id === chant_entry.id) || {};
|
||||
const Chant = Character.chants.find(chant => chant.id === chantEntry.id) || null;
|
||||
if (Chant && Chant.hasOwnProperty('level')) {
|
||||
Level = Chant.level || 0;
|
||||
}
|
||||
let Attributes = getAttributeLevels(chant_entry.attributes, Character);
|
||||
const Attributes = getAttributeLevels(chantEntry.attributes, Character);
|
||||
|
||||
return {
|
||||
Name: chant_entry.name,
|
||||
Level: Level,
|
||||
Attributes: Attributes,
|
||||
};
|
||||
return { Name: chantEntry.name, Level: Level, Attributes: Attributes };
|
||||
};
|
||||
module.exports = { getChant };
|
||||
|
@ -1,22 +1,22 @@
|
||||
const globals = require('../globals');
|
||||
const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
|
||||
const { Talente } = require('../globals');
|
||||
|
||||
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());
|
||||
const skillEntry =
|
||||
Talente.find(skill => skill.id.toLowerCase() === args[0].toLowerCase()) ||
|
||||
Talente.find(skill => skill.name.toLowerCase() === args[0].toLowerCase());
|
||||
|
||||
if (!skill_entry) {
|
||||
return;
|
||||
if (!skillEntry) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let Level = 0; // This is the minimum attributes value.
|
||||
let cSkill = Character.skills.find(skill => skill.id === skill_entry.id) || {};
|
||||
const cSkill = Character.skills.find(skill => skill.id === skillEntry.id) || null;
|
||||
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);
|
||||
const Name = Talente.find(skill => skill.id === skillEntry.id).name;
|
||||
const Attributes = getAttributeLevels(skillEntry.values, Character);
|
||||
|
||||
return {
|
||||
Name: Name,
|
||||
|
@ -1,27 +1,27 @@
|
||||
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());
|
||||
const getSpell = ({ Character: Character = [], spell_name: spellName = '' } = {}) => {
|
||||
const spellEntry =
|
||||
Spells.find(spell => spell.id.toLowerCase() === spellName.toLowerCase()) ||
|
||||
Spells.find(spell => spell.name.toLowerCase() === spellName.toLowerCase());
|
||||
|
||||
if (!spell_entry) {
|
||||
console.log(`getSpell() did not find entry for ${spell_name}`);
|
||||
return;
|
||||
if (!spellEntry) {
|
||||
console.log(`getSpell() did not find entry for ${spellName}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
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 (!Character.hasOwnProperty('spells')) return null;
|
||||
const Spell = Character.spells.find(spell => spell.id === spellEntry.id) || null; //?+
|
||||
if (Spell && Spell.hasOwnProperty('level')) {
|
||||
Level = Spell.level || 0;
|
||||
}
|
||||
let ModifiedBy = spell_entry.modified_by;
|
||||
let Attributes = getAttributeLevels(spell_entry.attributes, Character);
|
||||
const ModifiedBy = spellEntry.modified_by;
|
||||
const Attributes = getAttributeLevels(spellEntry.attributes, Character);
|
||||
|
||||
return {
|
||||
Name: spell_entry.name,
|
||||
Name: spellEntry.name,
|
||||
Level: Level,
|
||||
Attributes: Attributes,
|
||||
ModifiedBy: ModifiedBy,
|
||||
|
6
functions/isEmpty.js
Normal file
6
functions/isEmpty.js
Normal file
@ -0,0 +1,6 @@
|
||||
function isEmpty(document = {}) {
|
||||
if (!document) return true;
|
||||
if (document.length === 0) return true;
|
||||
return Object.keys(document).length === 0 ? true : false;
|
||||
}
|
||||
module.exports = { isEmpty };
|
4
functions/isString.js
Normal file
4
functions/isString.js
Normal file
@ -0,0 +1,4 @@
|
||||
function isString(str) {
|
||||
return typeof str === 'string' || str instanceof String ? true : false;
|
||||
}
|
||||
module.exports = { isString };
|
Reference in New Issue
Block a user