|
@@ -1,5 +1,4 @@ |
|
|
var Alexa = require('alexa-sdk') |
|
|
var Alexa = require('alexa-sdk') |
|
|
var askingConditions = [3, 3, false, false, false, false, false, false, false, false, false] |
|
|
|
|
|
|
|
|
|
|
|
exports.handler = function (event, context, callback) { |
|
|
exports.handler = function (event, context, callback) { |
|
|
var alexa = Alexa.handler(event, context) |
|
|
var alexa = Alexa.handler(event, context) |
|
@@ -12,95 +11,40 @@ var handlers = { |
|
|
this.emit(':ask', 'Welcome to Dota 2 Random. Say help for help.') |
|
|
this.emit(':ask', 'Welcome to Dota 2 Random. Say help for help.') |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
'RequestMeleeCarry': function () { |
|
|
|
|
|
reset() |
|
|
|
|
|
askingConditions[1] = 0 |
|
|
|
|
|
askingConditions[2] = true |
|
|
|
|
|
getHero(askingConditions, (name) => { |
|
|
|
|
|
this.emit(':tell', name) |
|
|
|
|
|
// this.emit(':ask', 'RequestMeleeCarry') |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
'RequestIntent': function () { |
|
|
|
|
|
var given = [] |
|
|
|
|
|
var category = this.event.request.intent.slots.Category |
|
|
|
|
|
given.push(category) |
|
|
|
|
|
|
|
|
'RequestMeleeSupport': function () { |
|
|
|
|
|
reset() |
|
|
|
|
|
askingConditions[1] = 0 |
|
|
|
|
|
askingConditions[3] = true |
|
|
|
|
|
getHero(askingConditions, (name) => { |
|
|
|
|
|
|
|
|
randomHero(given, (name) => { |
|
|
this.emit(':tell', name) |
|
|
this.emit(':tell', name) |
|
|
// this.emit(':ask', 'RequestMeleeSupport') |
|
|
|
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
'RequestRangedCarry': function () { |
|
|
|
|
|
reset() |
|
|
|
|
|
askingConditions[1] = 1 |
|
|
|
|
|
askingConditions[2] = true |
|
|
|
|
|
getHero(askingConditions, (name) => { |
|
|
|
|
|
this.emit(':tell', name) |
|
|
|
|
|
// this.emit(':ask', 'RequestRangedCarry') |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
'RequestTwoIntent': function () { |
|
|
|
|
|
var given = [] |
|
|
|
|
|
var category1 = this.event.request.intent.slots.Category1 |
|
|
|
|
|
var category2 = this.event.request.intent.slots.Category2 |
|
|
|
|
|
given.push(category1) |
|
|
|
|
|
given.push(category2) |
|
|
|
|
|
|
|
|
'RequestRangedSupport': function () { |
|
|
|
|
|
reset() |
|
|
|
|
|
askingConditions[1] = 1 |
|
|
|
|
|
askingConditions[3] = true |
|
|
|
|
|
getHero(askingConditions, (name) => { |
|
|
|
|
|
|
|
|
randomHero(given, (name) => { |
|
|
this.emit(':tell', name) |
|
|
this.emit(':tell', name) |
|
|
// this.emit(':ask', 'RequestRangedSupport') |
|
|
|
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
'RequestCarry': function () { |
|
|
|
|
|
reset() |
|
|
|
|
|
askingConditions[2] = true |
|
|
|
|
|
getHero(askingConditions, (name) => { |
|
|
|
|
|
this.emit(':tell', name) |
|
|
|
|
|
// this.emit(':ask', 'RequestCarry') |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
'RequestSupport': function () { |
|
|
|
|
|
reset() |
|
|
|
|
|
askingConditions[3] = true |
|
|
|
|
|
getHero(askingConditions, (name) => { |
|
|
|
|
|
this.emit(':tell', name) |
|
|
|
|
|
// this.emit(':ask', 'RequestSupport') |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
'RequestMelee': function () { |
|
|
|
|
|
reset() |
|
|
|
|
|
askingConditions[1] = 0 |
|
|
|
|
|
getHero(askingConditions, (name) => { |
|
|
|
|
|
this.emit(':tell', name) |
|
|
|
|
|
// this.emit(':ask', 'RequestMelee') |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
'RequestRanged': function () { |
|
|
|
|
|
reset() |
|
|
|
|
|
askingConditions[1] = 1 |
|
|
|
|
|
getHero(askingConditions, (name) => { |
|
|
|
|
|
|
|
|
'AnyRequest': function () { |
|
|
|
|
|
var given = [] |
|
|
|
|
|
randomHero(given, (name) => { |
|
|
this.emit(':tell', name) |
|
|
this.emit(':tell', name) |
|
|
// this.emit(':ask', 'RequestRanged') |
|
|
|
|
|
|
|
|
// this.emit(':ask', 'AnyRequest triggered') |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
'AMAZON.HelpIntent': function () { |
|
|
'AMAZON.HelpIntent': function () { |
|
|
reset() |
|
|
|
|
|
this.emit(':ask', 'You can try saying random any hero, random melee carry or random ranged support for more specific randoming.') |
|
|
this.emit(':ask', 'You can try saying random any hero, random melee carry or random ranged support for more specific randoming.') |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
'AnyRequest': function () { |
|
|
|
|
|
reset() |
|
|
|
|
|
getHero(askingConditions, (name) => { |
|
|
|
|
|
this.emit(':tell', name) |
|
|
|
|
|
// this.emit(':ask', 'AnyRequest triggered') |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
'Stop': function () { |
|
|
'Stop': function () { |
|
|
this.emit(':tell', 'Enjoy the game!') |
|
|
this.emit(':tell', 'Enjoy the game!') |
|
|
} |
|
|
} |
|
@@ -108,18 +52,16 @@ var handlers = { |
|
|
|
|
|
|
|
|
var https = require('https') |
|
|
var https = require('https') |
|
|
|
|
|
|
|
|
function getHero (conditions, callback) { |
|
|
|
|
|
|
|
|
function randomHero (categories, callback) { |
|
|
var location |
|
|
var location |
|
|
|
|
|
|
|
|
httpsGet((heroes) => { |
|
|
httpsGet((heroes) => { |
|
|
do { |
|
|
do { |
|
|
location = random(heroes.length) |
|
|
location = random(heroes.length) |
|
|
} while (!checkConditions(conditions, heroes[location])) |
|
|
|
|
|
|
|
|
} while (!checkCategory(categories, heroes[location])) |
|
|
|
|
|
|
|
|
callback(heroes[location].localized_name) |
|
|
callback(heroes[location].localized_name) |
|
|
// callback(heroes[location].attack_type + ': ' + heroes[location].localized_name) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function httpsGet (callback) { |
|
|
function httpsGet (callback) { |
|
@@ -149,105 +91,30 @@ function random (size) { |
|
|
return Math.floor(Math.random() * (size)) |
|
|
return Math.floor(Math.random() * (size)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function checkConditions (conditions, hero) { |
|
|
|
|
|
if (!checkType(conditions[0], hero.primary_attr)) { |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function checkCategory (categories, hero) { |
|
|
|
|
|
var i = 0 |
|
|
|
|
|
|
|
|
if (!checkAttackType(conditions[1], hero.attack_type)) { |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var allConditions = [] |
|
|
|
|
|
|
|
|
|
|
|
// carry |
|
|
|
|
|
if (conditions[2]) { |
|
|
|
|
|
allConditions.push('Carry') |
|
|
|
|
|
} |
|
|
|
|
|
// support |
|
|
|
|
|
if (conditions[3]) { |
|
|
|
|
|
allConditions.push('Support') |
|
|
|
|
|
} |
|
|
|
|
|
// jungler |
|
|
|
|
|
if (conditions[4]) { |
|
|
|
|
|
allConditions.push('Jungler') |
|
|
|
|
|
} |
|
|
|
|
|
// escape |
|
|
|
|
|
if (conditions[5]) { |
|
|
|
|
|
allConditions.push('Escape') |
|
|
|
|
|
} |
|
|
|
|
|
// nuker |
|
|
|
|
|
if (conditions[6]) { |
|
|
|
|
|
allConditions.push('Nuker') |
|
|
|
|
|
} |
|
|
|
|
|
// durable |
|
|
|
|
|
if (conditions[7]) { |
|
|
|
|
|
allConditions.push('Durable') |
|
|
|
|
|
} |
|
|
|
|
|
// disabler |
|
|
|
|
|
if (conditions[8]) { |
|
|
|
|
|
allConditions.push('Disabler') |
|
|
|
|
|
} |
|
|
|
|
|
// initiator |
|
|
|
|
|
if (conditions[9]) { |
|
|
|
|
|
allConditions.push('Initiator') |
|
|
|
|
|
} |
|
|
|
|
|
// pusher |
|
|
|
|
|
if (conditions[10]) { |
|
|
|
|
|
allConditions.push('Pusher') |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (allConditions.length > 0 && !checkRoles(allConditions, hero.roles)) { |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var hits = false |
|
|
|
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function checkType (type, toCheck) { |
|
|
|
|
|
switch (type) { |
|
|
|
|
|
case 0: |
|
|
|
|
|
return (toCheck === 'str') |
|
|
|
|
|
case 1: |
|
|
|
|
|
return (toCheck === 'agi') |
|
|
|
|
|
case 2: |
|
|
|
|
|
return (toCheck === 'int') |
|
|
|
|
|
default: |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function checkAttackType (atype, toCheck) { |
|
|
|
|
|
switch (atype) { |
|
|
|
|
|
case 0: |
|
|
|
|
|
return (toCheck.localeCompare('Melee') === 0) |
|
|
|
|
|
case 1: |
|
|
|
|
|
return (toCheck.localeCompare('Ranged') === 0) |
|
|
|
|
|
default: |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function checkRoles (roles, toCheck) { |
|
|
|
|
|
var match = true |
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < roles.length; i++) { |
|
|
|
|
|
var thisCondition = false |
|
|
|
|
|
|
|
|
|
|
|
for (var j = 0; j < toCheck.length; j++) { |
|
|
|
|
|
if (roles[i].localeCompare(toCheck[j]) === 0) { |
|
|
|
|
|
thisCondition = true |
|
|
|
|
|
|
|
|
while (i < categories.length) { |
|
|
|
|
|
if (categories[i] === hero.primary_attr || categories[i] === hero.attack_type) { |
|
|
|
|
|
hits = true |
|
|
|
|
|
} else { |
|
|
|
|
|
for (var j = 0; j < hero.roles.length; j++) { |
|
|
|
|
|
if (categories[i] === hero.roles[j]) { |
|
|
|
|
|
hits = true |
|
|
|
|
|
break |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!thisCondition) { |
|
|
|
|
|
match = false |
|
|
|
|
|
|
|
|
if (hits) { |
|
|
|
|
|
i++ |
|
|
|
|
|
hits = false |
|
|
|
|
|
} else { |
|
|
|
|
|
return false |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return match |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function reset () { |
|
|
|
|
|
askingConditions = [3, 3, false, false, false, false, false, false, false, false, false] |
|
|
|
|
|
|
|
|
return true |
|
|
} |
|
|
} |