131 lines
3.6 KiB
JavaScript
131 lines
3.6 KiB
JavaScript
var Promise = require('promise');
|
|
var requestPromise = require('./helpers/requestPromise.js');
|
|
var BasePlugin = require('./base.js');
|
|
var logger = require('winston');
|
|
|
|
var Chance = require('chance');
|
|
var chance = new Chance();
|
|
class Character {
|
|
constructor() {
|
|
|
|
this.gender = null;
|
|
this.name = null;
|
|
this.class = null;
|
|
this.alignment = null;
|
|
this.stats = [];
|
|
this.statSum = -1;
|
|
}
|
|
|
|
create() {
|
|
this.gender = chance.gender();
|
|
this.name = chance.first({gender: this.gender});
|
|
|
|
// Throw stats
|
|
for(var i = 0; i < 6; i++) {
|
|
var throws = [chance.d6(), chance.d6(), chance.d6(), chance.d6()].sort();
|
|
throws.splice(0, 1);
|
|
var stat = throws.reduce(function(a, b) { return a + b; }, 0);
|
|
this.stats.push(stat);
|
|
}
|
|
this.statSum = this.stats.reduce(function(a, b) { return a + b; }, 0);
|
|
|
|
// Select race
|
|
var races = {
|
|
'Human': '',
|
|
'Dwarf': 'Fighter',
|
|
'Elf': 'Wizard',
|
|
'Gnome': 'Bard',
|
|
'Half-Elf': '',
|
|
'Half-Orc': 'Barbarian',
|
|
'Halfling': 'Rogue',
|
|
};
|
|
|
|
this.race = Object.keys(races)[chance.natural({min: 0, max: Object.keys(races).length-1})];
|
|
|
|
// Select alignment
|
|
var alignmentY = ['Good', 'Neutral', 'Evil'].splice(chance.natural({min: 0, max: 2}), 1);
|
|
var alignmentX = ['Lawful', 'Neutral', 'Chaotic'].splice(chance.natural({min: 0, max: 2}), 1);
|
|
|
|
this.alignment = (alignmentY[0] === 'Neutral' && alignmentX[0] === 'Neutral') ? 'True Neutral' : alignmentX[0] + ' ' + alignmentY[0];
|
|
|
|
// Select class
|
|
var classes = {
|
|
'Barbarian' : '',
|
|
'Bard': '',
|
|
'Cleric': '',
|
|
'Druid': '',
|
|
'Fighter': '',
|
|
'Monk': '',
|
|
'Paladin': '',
|
|
'Ranger': '',
|
|
'Rogue': '',
|
|
'Sorcerer': '',
|
|
}
|
|
this.class = Object.keys(classes)[chance.natural({min: 0, max: Object.keys(classes).length-1})];
|
|
|
|
// Select age
|
|
var roll = function(times, func) {
|
|
var sum = 0;
|
|
for(var i = 0; i < times; i++) {
|
|
sum += chance[func]();
|
|
}
|
|
return sum;
|
|
}
|
|
var ages = {
|
|
'Human': { start: 15, classes: [roll(1, 'd4'), roll(1, 'd6'), roll(2, 'd6')] },
|
|
'Dwarf': { start: 40, classes: [roll(3, 'd6'), roll(5, 'd6'), roll(6, 'd6')] },
|
|
'Elf': { start: 110, classes: [roll(4, 'd6'), roll(6, 'd6'), roll(10, 'd6')] },
|
|
'Gnome': { start: 40, classes: [roll(4, 'd6'), roll(6, 'd6'), roll(9, 'd6')] },
|
|
'Half-Elf': { start: 20, classes: [roll(1, 'd6'), roll(2, 'd6'), roll(3, 'd6')] },
|
|
'Half-Orc': { start: 14, classes: [roll(1, 'd4'), roll(1, 'd6'), roll(2, 'd6')] },
|
|
'Halfling': { start: 20, classes: [roll(2, 'd4'), roll(3, 'd6'), roll(4, 'd6')] },
|
|
};
|
|
var ageClasses = {
|
|
'Barbarian': 0, 'Rogue': 0, 'Sorcerer': 0,
|
|
'Bard': 1, 'Fighter': 1, 'Paladin': 1, 'Ranger': 1,
|
|
'Cleric': 2, 'Druid': 2, 'Monk': 2, 'Wizard': 2,
|
|
};
|
|
|
|
this.age = ages[this.race].start + ages[this.race].classes[ageClasses[this.class]];
|
|
|
|
|
|
|
|
}
|
|
toString() {
|
|
var str = this.age + " years old " + this.alignment + " " + this.gender + " " + this.race + " " + this.class + " named " + this.name;
|
|
str += " with stats ";
|
|
this.stats.forEach(function(val) {
|
|
str += val + " ";
|
|
});
|
|
str += " ("+this.statSum+")";
|
|
return str;
|
|
}
|
|
}
|
|
|
|
class Character2 extends BasePlugin {
|
|
constructor(config) {
|
|
super(config);
|
|
this.name = 'Character2';
|
|
|
|
}
|
|
|
|
test(input) {
|
|
var res = null;
|
|
if (res = input.match(/^\.luohahmo2$/i)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
result(input) {
|
|
// Different cases
|
|
let newChar = new Character();
|
|
newChar.create();
|
|
let result = newChar.toString();
|
|
return result;
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = Character2;
|