-
Notifications
You must be signed in to change notification settings - Fork 1
/
dialogFunc.js
96 lines (89 loc) · 3.58 KB
/
dialogFunc.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function Dialog() {
this.messages = {};
}
Dialog.prototype.setNextQuestionBatch = function() {
var nextBatch = String(Number(this.messages["currentBatchKey"]) + 1);
if (this.messages[nextBatch]) {
this.messages["currentBatchKey"] = nextBatch;
}
}
Dialog.prototype.getNextQuestionBatch = function() {
return this.messages[this.messages["currentBatchKey"]];
}
Dialog.prototype.lastBatch = function() {
var totalBatches = Object.keys(this.messages).length - 2;
return Number(this.messages["currentBatchKey"]) == totalBatches;
}
var gaurdianCreatures = {
"crab": {
"island": "earth",
"direction": "north"
},
"tortoise": {
"island": "water",
"direction": "south"
},
"eagle": {
"island": "fire",
"direction": "east"
},
"owl": {
"island": "air",
"direction": "west"
}
};
var initNPCDialog = function(creatureName) {
var commonDialogue = {
"0": {
"welcomeMessage": "Glad to see you have not yet given up on your quest to rescue your lost friend.",
"0": {
"question": "Do you know me? I have lost all memory and do not remember.",
"answer": "You are the brave adventurer, who is risking his life to save his lost friend.",
"askedStatus": 0
},
"1": {
"question": " Do you know what happened to my lost friend?",
"answer": "Yes, a portal opened. Your friend and many people got lost.",
"askedStatus": 0
}
}, // end of batch 0
"1": {
"welcomeMessage": "Rescue your friend.",
"0": {
"question": "Who are you.?",
"answer": "I am the gaurdian of the " + gaurdianCreatures[creatureName].island + " island.",
"askedStatus": 0
},
"1": {
"question": "What do I need to do to rescue my friend?",
"answer": "Retrieve the " + gaurdianCreatures[creatureName].island + " gem from the " + gaurdianCreatures[creatureName].island + " island.",
"askedStatus": 0
},
"2": {
"question": " How do I get the gem?",
"answer": "Take the key from me to enter the island in the " + gaurdianCreatures[creatureName].direction + " to get the gem.",
"askedStatus": 0
},
"3": {
"question": "Where should I go next?",
"answer": "To one of the islands",
"askedStatus": 0
}
},
"2": { // when he has key but no gem and gem not returned to central island.
"welcomeMessage": "Go to the " + gaurdianCreatures[creatureName].island + " island in the " + gaurdianCreatures[creatureName].direction + " to get the gem."
},
"3": { // Got gem but not all.
"welcomeMessage": "Great! you got the " + gaurdianCreatures[creatureName].island + " island gem. Get gems from other islands."
},
"4": { // Got all gems. Yet to return them to central island.
"welcomeMessage": "Save your friend by placing the gems in central island and opening the portal."
},
"currentBatchKey": "0"
};
return Object.create(commonDialogue);
}
var crabDialogue = initNPCDialog("crab");
var tortoiseDialogue = initNPCDialog("tortoise");
var eagleDialogue = initNPCDialog("eagle");
var owlDialogue = initNPCDialog("owl");