forked from zero-to-mastery/ZTM-Quest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjessica.interation.js
More file actions
100 lines (98 loc) · 3.72 KB
/
jessica.interation.js
File metadata and controls
100 lines (98 loc) · 3.72 KB
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
import { interactionHandler } from '../handler.interactions';
import { displayDialogue } from '../../utils';
import {
completeQuestObjective,
playerHasQuest,
receiveQuest,
completeQuest,
isObjectiveComplete,
} from '../../utils/questHandler';
import { jessicaQuests } from '../quests/constants.quests';
import { updateEnergyState } from '../../utils/energyUpdate';
import { addCoins } from '../../utils/coinsUpdate';
const generateJessicaDialogue = (player) => {
if (!playerHasQuest(player, 'Find the Flash Drive')) {
return "Hi, I'm Jessica! Would you please help me find my flash drive? I think I lost it up north in the forest, but I haven't had any luck finding it!";
} else if (
// Player has the quest but hasn't found the flash drive yet
playerHasQuest(player, 'Find the Flash Drive') &&
!isObjectiveComplete(
player,
'Find the Flash Drive',
'Found the Flash Drive'
)
) {
return 'Any luck finding my flash drive? I think I lost it up north in the forest.';
} else if (
// Player has found the flash drive but hasn't returned it yet
playerHasQuest(player, 'Find the Flash Drive') &&
isObjectiveComplete(
player,
'Find the Flash Drive',
'Found the Flash Drive'
)
) {
return "You found it! Thank you so much for finding my flash drive! I was really worried I'd lost all my work on my Javascript project! You're the best! Let me pay you for your help!";
} else {
return 'Have a great day!';
}
};
export const jessicaInteraction = async (player, k) => {
interactionHandler(player, 'jessica', k, async () => {
await displayDialogue({
k,
player,
characterName: 'Jessica',
text: [generateJessicaDialogue(player)],
onDisplayEnd: async () => {
if (!playerHasQuest(player, 'Find the Flash Drive')) {
await receiveQuest(
player,
jessicaQuests.findTheFlashDriveQuest
);
await completeQuestObjective(
player,
'Find the Flash Drive',
'Has Talked to Jessica'
);
}
if (
playerHasQuest(player, 'Find the Flash Drive') &&
!isObjectiveComplete(
player,
'Find the Flash Drive',
'Has Talked to Jessica'
)
) {
await completeQuestObjective(
player,
'Find the Flash Drive',
'Has Talked to Jessica'
);
}
if (
isObjectiveComplete(
player,
'Find the Flash Drive',
'Found the Flash Drive'
) &&
!isObjectiveComplete(
player,
'Find the Flash Drive',
'Returned the Flash Drive'
)
) {
updateEnergyState(player.state, 99);
addCoins(50);
await completeQuestObjective(
player,
'Find the Flash Drive',
'Returned the Flash Drive'
);
}
// Check if all objectives are complete
await completeQuest(player, 'Find the Flash Drive');
},
});
});
};