forked from zero-to-mastery/ZTM-Quest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpuff.interaction.js
More file actions
44 lines (42 loc) · 1.58 KB
/
Copy pathpuff.interaction.js
File metadata and controls
44 lines (42 loc) · 1.58 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
import { time } from '../../kplayCtx';
import { displayDialogue, showCustomPrompt } from '../../utils';
import { updateEnergyState } from '../../utils/energyUpdate';
let abort;
export const interactionWithPuff = (player, k, map) => {
player.onCollide('puff', () => {
time.paused = true;
player.state.isInDialog = true;
abort = new AbortController();
showCustomPrompt(
'Would you like to sit and rest on the puff? (Time advances 15s)',
['Sit', 'Leave'],
(selectedOption) => {
const texts = {
Sit: ['Wow, I feel fresh and energetic!'],
Leave: ['No way! I want to keep exploring!'],
};
if (texts[selectedOption]) {
displayDialogue({
k,
player,
text: texts[selectedOption],
onDisplayEnd: () => {
if (selectedOption === 'Sit') {
updateEnergyState(player.state, 15);
if (time.seconds + 15 >= 60) {
time.minutes += 1;
time.seconds = (time.seconds + 15) % 60;
} else {
time.seconds += 15;
}
}
},
});
}
},
player,
k,
abort
);
});
};