-
Notifications
You must be signed in to change notification settings - Fork 2
/
questGenerator.js
49 lines (44 loc) · 1.11 KB
/
questGenerator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict'
const chance = require('chance').Chance()
const db = require('./db')
const Quest = db.quest
const quests = require('./questLoader').load()
const questsMap = {}
quests.forEach(function (quest) {
questsMap[quest.name] = quest
})
function generateDailies () {
const dailies = chance.pickset(quests, 5)
dailies.forEach(function (daily, index) {
const dbQuest = new Quest({
name: daily.name
})
dbQuest.save().catch(function (err) {
console.log('ERROR - Unable to save generated daily - ', err)
})
dailies[index].id = dbQuest.id
})
return dailies
}
function inflateQuest (dbQuest) {
let quest = {}
if (dbQuest && dbQuest.name) {
quest = JSON.parse(JSON.stringify(questsMap[dbQuest.name]))
}
quest.id = dbQuest.id
quest.progress = dbQuest.progress
quest.status = dbQuest.status
return quest
}
function inflateQuests (dbQuests) {
const quests = []
dbQuests.forEach(function (dbQuest) {
quests.push(inflateQuest(dbQuest))
})
return quests
}
module.exports = {
generateDailies: generateDailies,
inflateQuest: inflateQuest,
inflateQuests: inflateQuests
}