From ab2bbab26a117199774c9c8d029805460be484d2 Mon Sep 17 00:00:00 2001 From: pleomorph Date: Fri, 11 Oct 2024 18:57:33 +0000 Subject: [PATCH 1/2] Add kitchen_fridge and mage interaction to map_campus_house_1 --- src/interactions/map_campus_house_1/index.js | 2 + .../kitchenFridge.interaction.js | 36 ++++++++++ .../map_campus_house_1/mage.interaction.js | 68 ++++++++++++++++--- 3 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 src/interactions/map_campus_house_1/kitchenFridge.interaction.js diff --git a/src/interactions/map_campus_house_1/index.js b/src/interactions/map_campus_house_1/index.js index 5468fb2f..109ef79a 100644 --- a/src/interactions/map_campus_house_1/index.js +++ b/src/interactions/map_campus_house_1/index.js @@ -3,6 +3,7 @@ import { bedInteractions } from './bed.interaction'; import { computerInteractions } from './computer.interaction'; import { mageInteractions } from './mage.interaction'; import { bedroomVanityInteractions } from './bedroomVanity.interaction'; +import { kitchenFridgeInteractions } from './kitchenFridge.interaction'; const interactions = [ // Add more interactions here @@ -11,6 +12,7 @@ const interactions = [ computerInteractions, mageInteractions, bedroomVanityInteractions, + kitchenFridgeInteractions, ]; export default interactions; diff --git a/src/interactions/map_campus_house_1/kitchenFridge.interaction.js b/src/interactions/map_campus_house_1/kitchenFridge.interaction.js new file mode 100644 index 00000000..25e00d05 --- /dev/null +++ b/src/interactions/map_campus_house_1/kitchenFridge.interaction.js @@ -0,0 +1,36 @@ +import { displayDialogue, displayPermissionBox } from '../../utils'; +import { updateEnergyState } from '../../utils/energyUpdate'; + +const butterBeerDialog = [ + "You see a fresh mug of butterbeer in the fridge and take it. You're not thirsty at the moment, but perhaps someone else in the house might enjoy it.", +]; + +const emptyFridge = ['The refrigerator is now empty.']; + +export const kitchenFridgeInteractions = (player, k, map) => { + player.onCollide('kitchen_fridge', async () => { + player.isInDialog = true; + + if (player?.state?.hasButterBeer) { + await displayDialogue({ + k, + player, + text: emptyFridge, + onDisplayEnd: () => { + player.isInDialog = false; + }, + }); + return; + } + + displayDialogue({ + k, + player, + text: butterBeerDialog, + onDisplayEnd: () => { + player.state.hasButterBeer = true; + player.isInDialog = false; + }, + }); + }); +}; diff --git a/src/interactions/map_campus_house_1/mage.interaction.js b/src/interactions/map_campus_house_1/mage.interaction.js index 48e4f350..aafb8ab3 100644 --- a/src/interactions/map_campus_house_1/mage.interaction.js +++ b/src/interactions/map_campus_house_1/mage.interaction.js @@ -1,4 +1,5 @@ import { displayDialogue, displayPermissionBox } from '../../utils'; +import { updateEnergyState } from '../../utils/energyUpdate'; const alredyUnlockText = ['The challenge is waiting for you!']; @@ -23,6 +24,16 @@ const noSpell = [ 'It does not seem like thou art yet prepared for the challenge...', ]; +const butterBeerDialog = { + ask: [ + "Hey, is that a butterbeer you're carrying? That's my favorite drink! If you're not going to drink it, may I have it?", + ], + thank: [ + 'Thank you so much! "Since this dev has been so great, his energy is now top rate!"', + ], + denied: ['Oh, ok. I understand...'], +}; + export const mageInteractions = async (player, k, map) => { const [computer] = map.query({ include: 'computer' }); let mageInteractionCounter = 0; @@ -89,17 +100,56 @@ export const mageInteractions = async (player, k, map) => { } } } else { - player.isInDialog = true; computer.play('on'); - await displayDialogue({ - k, - player, - text: alredyUnlockText, - onDisplayEnd: () => { - player.isInDialog = false; - }, - }); + if (player?.state?.hasButterBeer) { + // Mage asks if he can have the butterbeer + let giveButterBeer = await displayPermissionBox({ + k, + player, + text: butterBeerDialog.ask, + characterName: 'Mage', + onDisplayEnd: () => { + player.isInDialog = false; + }, + }); + + if (giveButterBeer) { + player.isInDialog = true; + await displayDialogue({ + k, + player, + text: butterBeerDialog.thank, + characterName: 'Mage', + onDisplayEnd: () => { + player.isInDialog = false; + player.state.hasButterBeer = false; + updateEnergyState(player.state, 99); + }, + }); + } else { + player.isInDialog = true; + await displayDialogue({ + k, + player, + text: butterBeerDialog.denied, + characterName: 'Mage', + onDisplayEnd: () => { + player.isInDialog = false; + }, + }); + } + } else { + player.isInDialog = true; + await displayDialogue({ + k, + player, + text: alredyUnlockText, + onDisplayEnd: () => { + player.isInDialog = false; + }, + }); + } } }); From 2026e9b4c61774dd61c86060207e6d687851da96 Mon Sep 17 00:00:00 2001 From: pleomorph Date: Fri, 11 Oct 2024 19:05:34 +0000 Subject: [PATCH 2/2] Removed unused imports --- .../kitchenFridge.interaction.js | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/interactions/map_campus_house_1/kitchenFridge.interaction.js b/src/interactions/map_campus_house_1/kitchenFridge.interaction.js index 25e00d05..04e7418f 100644 --- a/src/interactions/map_campus_house_1/kitchenFridge.interaction.js +++ b/src/interactions/map_campus_house_1/kitchenFridge.interaction.js @@ -1,36 +1,35 @@ -import { displayDialogue, displayPermissionBox } from '../../utils'; -import { updateEnergyState } from '../../utils/energyUpdate'; +import { displayDialogue } from '../../utils'; const butterBeerDialog = [ - "You see a fresh mug of butterbeer in the fridge and take it. You're not thirsty at the moment, but perhaps someone else in the house might enjoy it.", + "You see a fresh mug of butterbeer in the fridge and take it. You're not thirsty at the moment, but perhaps someone else in the house might enjoy it.", ]; const emptyFridge = ['The refrigerator is now empty.']; export const kitchenFridgeInteractions = (player, k, map) => { - player.onCollide('kitchen_fridge', async () => { - player.isInDialog = true; + player.onCollide('kitchen_fridge', async () => { + player.isInDialog = true; - if (player?.state?.hasButterBeer) { - await displayDialogue({ - k, - player, - text: emptyFridge, - onDisplayEnd: () => { - player.isInDialog = false; - }, - }); - return; - } + if (player?.state?.hasButterBeer) { + await displayDialogue({ + k, + player, + text: emptyFridge, + onDisplayEnd: () => { + player.isInDialog = false; + }, + }); + return; + } - displayDialogue({ - k, - player, - text: butterBeerDialog, - onDisplayEnd: () => { - player.state.hasButterBeer = true; - player.isInDialog = false; - }, - }); + displayDialogue({ + k, + player, + text: butterBeerDialog, + onDisplayEnd: () => { + player.state.hasButterBeer = true; + player.isInDialog = false; + }, }); + }); };