ソースを参照

Added random for carry/support

tags/v1.0
BinHong Lee 7年前
コミット
154e524a48
3個のファイルの変更221行の追加24行の削除
  1. +19
    -1
      speechAssets/IntentSchema.json
  2. +20
    -2
      speechAssets/Utterances.txt
  3. +182
    -21
      src/index.js

+ 19
- 1
speechAssets/IntentSchema.json ファイルの表示

@@ -1,7 +1,22 @@
{
"intents": [
{
"intent": "AnyRequest"
"intent": "RequestMeleeCarry"
},
{
"intent": "RequestMeleeSupport"
},
{
"intent": "RequestRangedCarry"
},
{
"intent": "RequestRangedSupport"
},
{
"intent": "RequestCarry"
},
{
"intent": "RequestSupport"
},
{
"intent": "RequestMelee"
@@ -9,6 +24,9 @@
{
"intent": "RequestRanged"
},
{
"intent": "AnyRequest"
},
{
"intent": "Stop"
}


+ 20
- 2
speechAssets/Utterances.txt ファイルの表示

@@ -1,9 +1,27 @@
AnyRequest random any hero
AnyRequest random any other hero
RequestMeleeCarry random melee carry
RequestMeleeCarry random another melee carry
RequestMeleeCarry random melee carry again
RequestRangedCarry random ranged carry
RequestRangedCarry random another ranged carry
RequestRangedCarry random ranged carry again
RequestMeleeSupport random melee support
RequestMeleeSupport random another melee support
RequestMeleeSupport random melee support again
RequestRangedSupport random ranged support
RequestRangedSupport random another ranged support
RequestRangedSupport random ranged support again
RequestCarry random carry
RequestCarry random another carry
RequestCarry random carry again
RequestSupport random support
RequestSupport random another support
RequestSupport random support again
RequestMelee random melee
RequestMelee random another melee
RequestMelee random melee again
RequestRanged random ranged
RequestRanged random another ranged
RequestRanged random ranged again
AnyRequest random any hero
AnyRequest random any other hero
Stop stop

+ 182
- 21
src/index.js ファイルの表示

@@ -1,4 +1,5 @@
var Alexa = require('alexa-sdk')
var askingConditions = [3, 3, false, false, false, false, false, false, false, false, false]

exports.handler = function (event, context, callback) {
var alexa = Alexa.handler(event, context)
@@ -8,24 +9,90 @@ exports.handler = function (event, context, callback) {

var handlers = {
'LaunchRequest': function () {
this.emit('RequestMelee')
this.emit(':ask', 'Welcome to Dota 2 Random.')
},

'AnyRequest': function () {
getHero(0, (name) => {
'RequestMeleeCarry': function () {
reset()
askingConditions[1] = 0
askingConditions[2] = true
getHero(askingConditions, (name) => {
this.emit(':ask', name)
// this.emit(':ask', 'RequestMeleeCarry')
})
},

'RequestMeleeSupport': function () {
reset()
askingConditions[1] = 0
askingConditions[3] = true
getHero(askingConditions, (name) => {
this.emit(':ask', name)
// this.emit(':ask', 'RequestMeleeSupport')
})
},

'RequestRangedCarry': function () {
reset()
askingConditions[1] = 1
askingConditions[2] = true
getHero(askingConditions, (name) => {
this.emit(':ask', name)
// this.emit(':ask', 'RequestRangedCarry')
})
},

'RequestRangedSupport': function () {
reset()
askingConditions[1] = 1
askingConditions[3] = true
getHero(askingConditions, (name) => {
this.emit(':ask', name)
// this.emit(':ask', 'RequestRangedSupport')
})
},

'RequestCarry': function () {
reset()
askingConditions[2] = true
getHero(askingConditions, (name) => {
this.emit(':ask', name)
// this.emit(':ask', 'RequestCarry')
})
},

'RequestSupport': function () {
reset()
askingConditions[3] = true
getHero(askingConditions, (name) => {
this.emit(':ask', name)
// this.emit(':ask', 'RequestSupport')
})
},

'RequestMelee': function () {
getHero(1, (name) => {
reset()
askingConditions[1] = 0
getHero(askingConditions, (name) => {
this.emit(':ask', name)
// this.emit(':ask', 'RequestMelee')
})
},

'RequestRanged': function () {
getHero(2, (name) => {
reset()
askingConditions[1] = 1
getHero(askingConditions, (name) => {
this.emit(':ask', name)
// this.emit(':ask', 'RequestRanged')
})
},

'AnyRequest': function () {
reset()
getHero(askingConditions, (name) => {
this.emit(':ask', name)
// this.emit(':ask', 'AnyRequest triggered')
})
},

@@ -36,25 +103,16 @@ var handlers = {

var https = require('https')

function getHero (type, callback) {
httpsGet((heroes) => {
var position = -1
var toCompare = ''

if (type === 1) {
toCompare = 'Melee'
} else if (type === 2) {
toCompare = 'Ranged'
} else {
callback(heroes[random(heroes.length)].localized_name)
return
}
function getHero (conditions, callback) {
var location

httpsGet((heroes) => {
do {
position = random(heroes.length)
} while (heroes[position].attack_type.localeCompare(toCompare) !== 0)
location = random(heroes.length)
} while (!checkConditions(conditions, heroes[location]))

callback(heroes[position].localized_name)
callback(heroes[location].localized_name)
// callback(heroes[location].attack_type + ': ' + heroes[location].localized_name)
}
)
}
@@ -85,3 +143,106 @@ function httpsGet (callback) {
function random (size) {
return Math.floor(Math.random() * (size))
}

function checkConditions (conditions, hero) {
if (!checkType(conditions[0], hero.primary_attr)) {
return false
}

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
}

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
}
}

if (!thisCondition) {
match = false
}
}

return match
}

function reset () {
askingConditions = [3, 3, false, false, false, false, false, false, false, false, false]
}

読み込み中…
キャンセル
保存