|
1 | 1 | import { interactionHandler } from '../handler.interactions'; |
2 | 2 | import { displayDialogue } from '../../utils'; |
| 3 | +import { completeQuestObjective, playerHasQuest, recieveQuest, completeQuest, isObjectiveComplete } from '../../utils/questHandler'; |
| 4 | +import { jessicaQuests } from '../quests/constants.quests'; |
| 5 | +import { updateEnergyState } from '../../utils/energyUpdate'; |
| 6 | +import { addCoins } from '../../utils/coinsUpdate'; |
3 | 7 |
|
4 | | -export const jessicaInteraction = (player, k) => { |
| 8 | +const generateJessicaDialogue = (player) => { |
| 9 | + if ( |
| 10 | + !playerHasQuest(player, 'Find the Flash Drive') |
| 11 | + ) { |
| 12 | + 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!" |
| 13 | + } else if ( |
| 14 | + // Player has the quest but hasn't found the flash drive yet |
| 15 | + playerHasQuest(player, 'Find the Flash Drive') |
| 16 | + && |
| 17 | + !isObjectiveComplete(player, 'Find the Flash Drive', 'Found the Flash Drive') |
| 18 | + ) { |
| 19 | + return "Any luck finding my flash drive? I think I lost it up north in the forest." |
| 20 | + } else if ( |
| 21 | + // Player has found the flash drive but hasn't returned it yet |
| 22 | + playerHasQuest(player, 'Find the Flash Drive') |
| 23 | + && |
| 24 | + isObjectiveComplete(player, 'Find the Flash Drive', 'Found the Flash Drive') |
| 25 | + ) { |
| 26 | + 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!" |
| 27 | + } else { |
| 28 | + return "Have a great day!" |
| 29 | + } |
| 30 | + |
| 31 | +} |
| 32 | + |
| 33 | +export const jessicaInteraction = async (player, k) => { |
5 | 34 | interactionHandler(player, 'jessica', k, async () => { |
6 | 35 | await displayDialogue({ |
7 | 36 | k, |
8 | 37 | player, |
9 | 38 | characterName: 'Jessica', |
10 | 39 | text: [ |
11 | | - "Hi, I'm Jessica! I'm learning Javascript! It's a lot of work, but I'm excited to get better at it.", |
| 40 | + generateJessicaDialogue(player) |
12 | 41 | ], |
| 42 | + onDisplayEnd: async () => { |
| 43 | + if (!playerHasQuest(player, 'Find the Flash Drive')) { |
| 44 | + await recieveQuest( |
| 45 | + player, |
| 46 | + jessicaQuests.findTheFlashDriveQuest |
| 47 | + ) |
| 48 | + await completeQuestObjective( |
| 49 | + player, |
| 50 | + 'Find the Flash Drive', |
| 51 | + 'Has Talked to Jessica' |
| 52 | + ) |
| 53 | + } |
| 54 | + if ( |
| 55 | + playerHasQuest(player, 'Find the Flash Drive') |
| 56 | + && |
| 57 | + !isObjectiveComplete(player, 'Find the Flash Drive', 'Has Talked to Jessica') |
| 58 | + ) { |
| 59 | + await completeQuestObjective( |
| 60 | + player, |
| 61 | + 'Find the Flash Drive', |
| 62 | + 'Has Talked to Jessica' |
| 63 | + ) |
| 64 | + } |
| 65 | + if ( |
| 66 | + isObjectiveComplete(player, 'Find the Flash Drive', 'Found the Flash Drive') |
| 67 | + && |
| 68 | + !isObjectiveComplete(player, 'Find the Flash Drive', 'Returned the Flash Drive') |
| 69 | + ) { |
| 70 | + updateEnergyState(player.state, 99); |
| 71 | + addCoins(50); |
| 72 | + await completeQuestObjective( |
| 73 | + player, |
| 74 | + 'Find the Flash Drive', |
| 75 | + 'Returned the Flash Drive' |
| 76 | + ) |
| 77 | + } |
| 78 | + // Check if all objectives are complete |
| 79 | + await completeQuest(player, 'Find the Flash Drive'); |
| 80 | + } |
13 | 81 | }); |
14 | 82 | }); |
15 | 83 | }; |
0 commit comments