2019-08-13 19:37:22 +03:00
|
|
|
var BasePlugin = require('./base.js')
|
2018-04-29 17:37:07 +03:00
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
var Chance = require('chance')
|
|
|
|
var chance = new Chance()
|
2018-04-29 17:37:07 +03:00
|
|
|
class Character {
|
2019-08-13 19:37:22 +03:00
|
|
|
constructor () {
|
|
|
|
this.gender = null
|
|
|
|
this.name = null
|
|
|
|
this.class = null
|
|
|
|
this.alignment = null
|
|
|
|
this.stats = []
|
|
|
|
this.statSum = -1
|
2018-04-29 17:37:07 +03:00
|
|
|
}
|
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
create () {
|
|
|
|
this.gender = chance.gender()
|
|
|
|
this.name = chance.first({gender: this.gender})
|
2018-04-29 17:37:07 +03:00
|
|
|
|
|
|
|
// Throw stats
|
2019-08-13 19:37:22 +03:00
|
|
|
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)
|
2018-04-29 17:37:07 +03:00
|
|
|
}
|
2019-08-13 19:37:22 +03:00
|
|
|
this.statSum = this.stats.reduce(function (a, b) { return a + b }, 0)
|
2018-04-29 17:37:07 +03:00
|
|
|
|
|
|
|
// Select race
|
|
|
|
var races = {
|
|
|
|
'Human': '',
|
|
|
|
'Dwarf': 'Fighter',
|
|
|
|
'Elf': 'Wizard',
|
|
|
|
'Gnome': 'Bard',
|
|
|
|
'Half-Elf': '',
|
|
|
|
'Half-Orc': 'Barbarian',
|
2019-08-13 19:37:22 +03:00
|
|
|
'Halfling': 'Rogue'
|
|
|
|
}
|
2018-04-29 17:37:07 +03:00
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
this.race = Object.keys(races)[chance.natural({min: 0, max: Object.keys(races).length - 1})]
|
2018-04-29 17:37:07 +03:00
|
|
|
|
|
|
|
// Select alignment
|
2019-08-13 19:37:22 +03:00
|
|
|
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)
|
2018-04-29 17:37:07 +03:00
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
this.alignment = (alignmentY[0] === 'Neutral' && alignmentX[0] === 'Neutral') ? 'True Neutral' : alignmentX[0] + ' ' + alignmentY[0]
|
2018-04-29 17:37:07 +03:00
|
|
|
|
|
|
|
// Select class
|
|
|
|
var classes = {
|
2019-08-13 19:37:22 +03:00
|
|
|
'Barbarian': '',
|
2018-04-29 17:37:07 +03:00
|
|
|
'Bard': '',
|
|
|
|
'Cleric': '',
|
|
|
|
'Druid': '',
|
|
|
|
'Fighter': '',
|
|
|
|
'Monk': '',
|
|
|
|
'Paladin': '',
|
|
|
|
'Ranger': '',
|
|
|
|
'Rogue': '',
|
2019-08-13 19:37:22 +03:00
|
|
|
'Sorcerer': ''
|
2018-04-29 17:37:07 +03:00
|
|
|
}
|
2019-08-13 19:37:22 +03:00
|
|
|
this.class = Object.keys(classes)[chance.natural({min: 0, max: Object.keys(classes).length - 1})]
|
2018-04-29 17:37:07 +03:00
|
|
|
|
|
|
|
// Select age
|
2019-08-13 19:37:22 +03:00
|
|
|
var roll = function (times, func) {
|
|
|
|
var sum = 0
|
|
|
|
for (var i = 0; i < times; i++) {
|
|
|
|
sum += chance[func]()
|
2018-04-29 17:37:07 +03:00
|
|
|
}
|
2019-08-13 19:37:22 +03:00
|
|
|
return sum
|
2018-04-29 17:37:07 +03:00
|
|
|
}
|
|
|
|
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')] },
|
2019-08-13 19:37:22 +03:00
|
|
|
'Elf': { start: 110, classes: [roll(4, 'd6'), roll(6, 'd6'), roll(10, 'd6')] },
|
2018-04-29 17:37:07 +03:00
|
|
|
'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')] },
|
2019-08-13 19:37:22 +03:00
|
|
|
'Halfling': { start: 20, classes: [roll(2, 'd4'), roll(3, 'd6'), roll(4, 'd6')] }
|
|
|
|
}
|
2018-04-29 17:37:07 +03:00
|
|
|
var ageClasses = {
|
2019-08-13 19:37:22 +03:00
|
|
|
'Barbarian': 0,
|
|
|
|
'Rogue': 0,
|
|
|
|
'Sorcerer': 0,
|
|
|
|
'Bard': 1,
|
|
|
|
'Fighter': 1,
|
|
|
|
'Paladin': 1,
|
|
|
|
'Ranger': 1,
|
|
|
|
'Cleric': 2,
|
|
|
|
'Druid': 2,
|
|
|
|
'Monk': 2,
|
|
|
|
'Wizard': 2
|
|
|
|
}
|
2018-04-29 17:37:07 +03:00
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
this.age = ages[this.race].start + ages[this.race].classes[ageClasses[this.class]]
|
2018-04-29 17:37:07 +03:00
|
|
|
}
|
2019-08-13 19:37:22 +03:00
|
|
|
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
|
2018-04-29 17:37:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Character2 extends BasePlugin {
|
2019-08-13 19:37:22 +03:00
|
|
|
constructor (config) {
|
|
|
|
super(config)
|
|
|
|
this.name = 'Character2'
|
2018-04-29 17:37:07 +03:00
|
|
|
}
|
|
|
|
|
2019-11-20 20:28:11 +02:00
|
|
|
help () {
|
|
|
|
// | Command | Description
|
|
|
|
return '.luohahmo2 Luo D&D-hahmon statsit nimellä ja luokalla'
|
|
|
|
}
|
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
test (input) {
|
|
|
|
if (input.match(/^\.luohahmo2$/i)) {
|
|
|
|
return true
|
2018-04-29 17:37:07 +03:00
|
|
|
}
|
2019-08-13 19:37:22 +03:00
|
|
|
return false
|
2018-04-29 17:37:07 +03:00
|
|
|
}
|
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
result (input) {
|
2018-04-29 17:37:07 +03:00
|
|
|
// Different cases
|
2019-08-13 19:37:22 +03:00
|
|
|
let newChar = new Character()
|
|
|
|
newChar.create()
|
|
|
|
let result = newChar.toString()
|
|
|
|
return result
|
2018-04-29 17:37:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
module.exports = Character2
|