-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNPC.js
123 lines (107 loc) · 2.18 KB
/
NPC.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
class NPC
{
constructor(name, object, dialogue)
{
this.name = name;
this.object = object;
this.dialogue = dialogue;
}
interact()
{
//console.log("hi");
}
}
class QuestNPC extends NPC
{
constructor(name, object, dialogue, quest)
{
super(name, object, dialogue);
this.quest = quest;
this.counter = 0;
this.defaultDisplay = null;
this.completedDisplay = null;
this.currentSprite = null;
this.in_world = null;
}
changeDisplaySprite(NEW_DISPLAY)
{
if (this.currentSprite != null)
{
g.remove(this.currentSprite);
}
this.currentSprite = replaceWithAnimatedSprite(this.object, NEW_DISPLAY);
this.in_world.add(this.currentSprite);
}
dispDialogue()
{
var state = this.quest.questState;
this.counter++;
if (this.counter === 3)
{
this.quest.changeState(QUEST_ACTIVE);
}
if (state === QUEST_AVAILABLE)
{
//this.quest.changeState(QUEST_ACTIVE);
return this.dialogue.greeting + "\n" + this.dialogue.needExp;
}
else if (state === QUEST_ACTIVE)
{
return this.dialogue.needExp;
}
else if (state === QUEST_COMPLETE)
{
return this.dialogue.thanks;
}
return "";
}
interact()
{
var display = this.dispDialogue();
console.log(display);
if (this.quest.questState === QUEST_AVAILABLE)
{
console.log("quest added");
return this.quest;
}
}
receive()
{
var i, currentItem;
for (i = 0; i < inventory.length; i++)
{
currentItem = inventory[i];
if (this.quest.checkMatchingItem(currentItem))
{
inventory.splice(i, 1);
this.changeDisplaySprite(this.completedDisplay);
};
}
}
setDisplays(ARRAY_1, ARRAY_2)
{
this.defaultDisplay = ARRAY_1;
this.completedDisplay = ARRAY_2;
this.changeDisplaySprite(this.defaultDisplay);
}
setWorld(WORLD)
{
this.in_world = WORLD;
}
}
class RegNPC extends NPC
{
constructor(name, object, dialogue)
{
super(name, object, dialogue);
}
interact()
{
this.dialogue.playSound();
console.log(this.dialogue.greeting);
}
dispDialogue()
{
return this.dialogue.greeting;
}
}