kulmapaikka-ircbot/plugins/getCharacter.js

40 lines
809 B
JavaScript
Raw Normal View History

2015-09-01 22:44:55 +03:00
/**
* Based on Cb's get character code
*/
module.exports = function(config) {
var throwStat = function() {
// Heittää 4 kertaa d6:n, tiputtaa heikoimman tuloksen ja laskee
// loput yhteen
var throws = [];
var sum = 0;
for( var i = 0; i < 4; i++ ) {
var t = Math.floor(Math.random()*6)+1;
throws.push(t);
}
throws.sort();
throws.reverse();
var sum = 0;
for(var i = 0; i < 3; i++) {
sum += throws[i];
}
return sum;
};
var getDnDCharacter = function() {
var statPoints = 'DnD-statsit:';
var total = 0;
for( var i = 0; i < 6; i++) {
var newStat = throwStat();
statPoints += ' '; // erotetaan sanat toisistaan
statPoints += newStat;
total += Number(newStat);
}
statPoints += ' ('+total+')';
return statPoints;
};
return getDnDCharacter;
};