new getCharacter2 plugin
This commit is contained in:
parent
4babc165f8
commit
a6ad04074c
|
@ -14,10 +14,12 @@ Irkkibotti kulmapaikkalaisille. Sisältää seuraavat huimat ominaisuudet:
|
|||
* Hakee youtubesta hakusanalla
|
||||
- .luohahmo
|
||||
* Luo D&D-hahmon
|
||||
- .luohahmo2
|
||||
* Luo D&D-hahmon
|
||||
|
||||
|
||||
##Automaattiset toiminnot
|
||||
- Youtube-linkeille tulee automaattisesti youtube-tiedot
|
||||
- Linkeistä näytetään automaattisesti otsikko (Testauksessa)
|
||||
|
||||
|
||||
|
||||
|
|
8
app.js
8
app.js
|
@ -32,6 +32,7 @@ var googletin = require('./googleapi.js')(config);
|
|||
var owmapi = require('./owmapi')(config);
|
||||
var getTemperatureString = require('./plugins/getWeather')(config);
|
||||
var getDnDCharacter = require('./plugins/getCharacter')();
|
||||
var getDnDCharacter2 = require('./plugins/getCharacter2')();
|
||||
var getDiceString = require('./plugins/getDice')();
|
||||
var getUrlString = require('./plugins/getUrl')();
|
||||
var getTweet = require('./plugins/getTweet')(config);
|
||||
|
@ -113,7 +114,12 @@ var handleMessage = function(from, to, message) {
|
|||
var character = getDnDCharacter();
|
||||
client.say(to, ''+character);
|
||||
}
|
||||
|
||||
|
||||
// Create Character
|
||||
if (res = message.match(/^\.luohahmo2$/i)) {
|
||||
var character = getDnDCharacter2();
|
||||
client.say(to, ''+character);
|
||||
}
|
||||
// Instant Answer
|
||||
if (res = message.match(/^\.wtf (.+)$/i)) {
|
||||
getInstantAnswer(res[1]).then(function(answer) {
|
||||
|
|
|
@ -76,7 +76,12 @@ module.exports = function(config) {
|
|||
//console.log(resp.items[0].snippet.channelTitle);
|
||||
|
||||
//console.log(resp, videoId);
|
||||
if(resp.items.length <= 0) {
|
||||
if(resp === null || resp.items === null) {
|
||||
reject('No results (null)');
|
||||
return;
|
||||
}
|
||||
|
||||
if(resp.items.length <= 0) {
|
||||
reject('No results');
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
"irc": "latest",
|
||||
"googleapis": "latest",
|
||||
"node-ddg-api": "latest",
|
||||
"twitter": "latest"
|
||||
"twitter": "latest",
|
||||
"chance": "=1.0.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^1.2.1"
|
||||
|
|
107
plugins/getCharacter2.js
Normal file
107
plugins/getCharacter2.js
Normal file
|
@ -0,0 +1,107 @@
|
|||
var Chance = require('chance');
|
||||
module.exports = function(config) {
|
||||
var chance = new Chance();
|
||||
var method = function() {
|
||||
var result = '';
|
||||
Character = function() {
|
||||
this.gender = null;
|
||||
this.name = null;
|
||||
this.class = null;
|
||||
this.alignment = null;
|
||||
this.stats = [];
|
||||
this.statSum = -1;
|
||||
};
|
||||
|
||||
Character.prototype.create = function() {
|
||||
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]];
|
||||
|
||||
};
|
||||
|
||||
Character.prototype.toString = function() {
|
||||
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;
|
||||
};
|
||||
|
||||
var newChar = new Character();
|
||||
newChar.create();
|
||||
result = newChar.toString();
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
return method;
|
||||
}; // export
|
Loading…
Reference in New Issue
Block a user