forked from zero-to-mastery/ZTM-Quest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrink_machine.interaction.js
More file actions
65 lines (62 loc) · 2.45 KB
/
Copy pathdrink_machine.interaction.js
File metadata and controls
65 lines (62 loc) · 2.45 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
import { time } from '../../kplayCtx';
import { displayDialogue, showCustomPrompt } from '../../utils';
import { updateAchievements } from '../../utils/achievementsUpdate';
import { purchaseItem } from '../../utils/coinsUpdate';
let abort;
// List of drinks and possible fun surprises
export const interactionWithDrinksMachine = (player, k, map) => {
player.onCollide('drinks_machine', () => {
time.paused = true;
player.state.isInDialog = true;
abort = new AbortController();
// Trigger the custom prompt when the player collides with the drinks machine
showCustomPrompt(
'What would you like to drink?', // Prompt message
[
'Coke (8 coins)',
'Soda (8 coins)',
'Water (5 coins)',
'Sprite (8 coins)',
], // Options
(selectedOption) => {
// Callback when an option is selected
// Logic based on the selected option
const texts = {
'Coke (8 coins)': [
'Coke - "Taste the Feeling!" A cold refreshment is coming your way!',
],
'Soda (8 coins)': [
'Soda - "Fizz up your life!" Time for some sparkling fun!',
],
'Water (5 coins)': [
'Water - "Pure as the mountain stream." Stay hydrated and fresh!',
],
'Sprite (8 coins)': [
'Sprite - "Obey Your Thirst!" Crisp and refreshing as ever!',
],
};
displayDialogue({
k,
player,
text: texts[selectedOption],
onDisplayEnd: () => {
if (selectedOption == 'Water') {
const purchaseStatus = purchaseItem(k, 5, 20);
if (purchaseStatus === 'purchased') {
updateAchievements(
'Stay hydrated and healthy',
null
);
}
} else {
purchaseItem(k, 8, 15);
}
},
});
},
player,
k,
abort
);
});
};