forked from zero-to-mastery/ZTM-Quest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounterClerkInteraction.interactions.js
More file actions
114 lines (111 loc) · 4.24 KB
/
counterClerkInteraction.interactions.js
File metadata and controls
114 lines (111 loc) · 4.24 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { time } from '../../kplayCtx';
import { interactionHandler } from '../handler.interactions';
import {
displayDialogue,
displayPermissionBox,
showCustomPrompt,
} from '../../utils';
import {
completeQuest,
completeQuestObjective,
receiveQuest,
} from '../../utils/questHandler';
import { takeAwayCoins } from '../../utils/coinsUpdate';
import { map_realtor } from '../quests/constants.quests';
let abort;
export const counterClerkInteraction = (player, k) => {
interactionHandler(player, 'counter_clerk', k, async () => {
await displayDialogue({
k,
player,
characterName: 'Realtor Clerk',
text: [
'Hello, we are a firm that gives out houses to residents attending Zero To Mastery.',
'Would you like to purchase a house?',
],
});
await receiveQuest(player, map_realtor['Buy a house!']);
await completeQuestObjective(
player,
'Buy a house!',
'hasTalkedToRealtorClerk'
);
const answer = await displayPermissionBox({ k, player, text: [''] });
if (answer) {
const possibleHouses = ['Orange House', 'Red House'];
const choices = [
...possibleHouses.filter(
(el) => !player.state.housesOwned.includes(el.split(' ')[0])
),
"Neither, I've changed my mind",
];
time.paused = true;
player.state.isInDialog = true;
abort = new AbortController();
showCustomPrompt(
'Which house would you like to buy?',
choices,
(selectedOption) => {
const selectedOptionArr = selectedOption.split(' ');
if (!selectedOptionArr.includes('House')) {
displayDialogue({
k,
player,
characterName: 'Realtor Clerk',
text: [
"Okay, well let me know if you change your mind and we'll see if we can set you up!",
],
});
return;
}
if (player.state.coinsCollected >= 100) {
displayDialogue({
k,
player,
characterName: 'Realtor Clerk',
text: [
'Congratulations!',
`You now own the ${selectedOption}!`,
],
onDisplayEnd: async () => {
player.state.housesOwned = [
...player.state.housesOwned,
selectedOptionArr[0],
];
takeAwayCoins(100);
await completeQuestObjective(
player,
'Buy a house!',
'hasBoughtHouse'
);
await completeQuest(player, 'Buy a house!');
},
});
} else {
displayDialogue({
k,
player,
characterName: 'Realtor Clerk',
text: [
"Oooooof, I'm sorry.",
"It looks like you don't have enough coins for the house...",
],
});
}
},
player,
k,
abort
);
} else {
await displayDialogue({
k,
player,
characterName: 'Realtor Clerk',
text: [
"Okay, well let me know if you change your mind and we'll see if we can set you up!",
],
});
}
});
};