Skip to content

Commit 7bc8973

Browse files
RyanCodeDevr4pt0s
andauthored
New quest for Jessica: Find the Flash Drive (#256)
Co-authored-by: Wolfgang Kreminger <r4pt0s@protonmail.com>
1 parent 2e8cee5 commit 7bc8973

5 files changed

Lines changed: 98 additions & 6 deletions

File tree

src/gameObjects/map_forest/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ import { flashDrive } from './flashdrive.gameObject';
33

44
const gameObjects = [butterfly, flashDrive];
55

6+
67
export default gameObjects;
Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,83 @@
11
import { interactionHandler } from '../handler.interactions';
22
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';
37

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) => {
534
interactionHandler(player, 'jessica', k, async () => {
635
await displayDialogue({
736
k,
837
player,
938
characterName: 'Jessica',
1039
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)
1241
],
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+
}
1381
});
1482
});
1583
};
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
import { displayDialogue } from '../../utils';
2+
import { playerHasQuest, completeQuestObjective } from '../../utils/questHandler';
23
import { interactionHandler } from '../handler.interactions';
34

45
export const interactionWithFlashDrive = (player, k, map) => {
6+
7+
const messageToPlayer = "You found a flash drive! " + (playerHasQuest(player, 'Find the Flash Drive')
8+
? "This might be Jessica's flash drive! Better return it to her in the city!"
9+
: "You wonder who it might belong to? You leave it be in case someone comes looking for it.");
10+
511
interactionHandler(player, 'flashDrive', k, () => {
612
displayDialogue({
713
k,
814
player,
9-
characterName: 'flashDrive',
15+
characterName: 'Flash Drive',
1016
text: [
11-
'You found a flash drive in the the forest. You wonder who it might belong to?',
17+
messageToPlayer
1218
],
19+
onDisplayEnd: async () => {
20+
if (playerHasQuest(player, 'Find the Flash Drive')) {
21+
await completeQuestObjective(
22+
player,
23+
'Find the Flash Drive',
24+
'Found the Flash Drive'
25+
)
26+
}
27+
}
1328
});
1429
});
1530
};

src/interactions/quests/constants.quests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export const map_realtor = {
3333
),
3434
};
3535

36-
export const findFlashDriveQuest = {
37-
'Find the Flash Drive': makeQuest(
36+
export const jessicaQuests = {
37+
findTheFlashDriveQuest: makeQuest(
3838
'Find the Flash Drive',
3939
'Find the flash drive that Jessica has lost.',
4040
{

src/utils/questHandler.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export const completeQuestObjective = async (player, questName, objective) => {
107107
characterName: 'Quest System',
108108
text: [`✅ Objective Completed!`, `"${objective}"`],
109109
});
110+
return true;
110111
};
111112

112113
export const retrieveQuestObjectiveStatus = (player, questName, objective) => {
@@ -144,5 +145,12 @@ const playerHasObjective = (player, questName, objective) => {
144145
return objective in player.state.quests[questName].objectives;
145146
};
146147

148+
export const isObjectiveComplete = (player, questName, objective) => {
149+
if (!playerHasQuest(player, questName) || !playerHasObjective(player, questName, objective)) {
150+
return false;
151+
}
152+
return player.state.quests[questName].objectives[objective];
153+
}
154+
147155
// If you want to add quests, you can recieve them through interactions.
148156
// Use recieveQuest to get the quest via the player's state object.

0 commit comments

Comments
 (0)