From b437d518c92eaa72f73858e63e3f0cf548c7e1ec Mon Sep 17 00:00:00 2001 From: j Date: Fri, 26 Apr 2024 01:46:14 -0400 Subject: [PATCH] Hunting Logic to Own class --- src/game/phases/hunt.ts | 75 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/game/phases/hunt.ts diff --git a/src/game/phases/hunt.ts b/src/game/phases/hunt.ts new file mode 100644 index 0000000..af2ef4e --- /dev/null +++ b/src/game/phases/hunt.ts @@ -0,0 +1,75 @@ +import GameState, { PHASE_ENUM } from '../gameState'; +import GameFlow from '../gameFlow'; + +export class HuntPhase { + static async handleHunt(gameState: GameState, gameFlow: GameFlow, userInput?: string): Promise { + switch (gameState.subPhase) { + case 0: // Initial Logic + await HuntPhase.initialLogic(gameState, gameFlow); + break; + case 1: // Shooting Logic + await HuntPhase.shootingLogic(gameState, gameFlow, userInput); + break; + case 2: // Outcome Logic + await HuntPhase.outcomeLogic(gameState, gameFlow); + break; + default: + console.error("Unknown subphase in HuntPhase"); + break; + } + } + + + static async initialLogic(gameState: GameState, gameFlow: GameFlow,): Promise { + let responseMessage = ''; + responseMessage += gameFlow.handleShooting(); + gameState.subPhase = 1; + gameState.lastPrompt = responseMessage; + await gameFlow.statusUpdate(responseMessage); + await gameState.save(); + } + + static async shootingLogic(gameState: GameState, gameFlow: GameFlow, userInput?: string): Promise { + let responseMessage = ''; + if (!userInput) { + responseMessage = "Invalid input.\n\n"; + responseMessage += gameState.lastPrompt; + await gameFlow.statusUpdate(responseMessage); + return; + } + if (userInput.toLowerCase() === "start") { + responseMessage += gameState.lastPrompt; + await gameFlow.statusUpdate(responseMessage); + return; + } + responseMessage += gameFlow.handleShooting(userInput.toString()); + gameState.lastPrompt = responseMessage; + gameState.subPhase = 2; + await gameState.save(); + await gameFlow.executeCurrentPhase(); + return; + } + + static async outcomeLogic(gameState: GameState, gameFlow: GameFlow): Promise { + let responseMessage = gameState.lastPrompt; + if (gameState.shootResponseTime <= 1) { + responseMessage += `RIGHT BETWEEN THE EYES---YOU GOT A BIG ONE!!!!\n\n`; + responseMessage += `FULL BELLIES TONIGHT!\n\n`; + gameState.amountSpentOnFood += 52 + (Math.random() * 6); + gameState.amountSpentOnAmmunition -= 10 - (Math.random() * 4); + } else if (100 * Math.random() > (13 * gameState.shootResponseTime)) { + responseMessage += `NICE SHOT--RIGHT ON TARGET--GOOD EATIN' TONIGHT!!\n\n`; + gameState.amountSpentOnFood += 48 - (2 * gameState.shootResponseTime); + gameState.amountSpentOnAmmunition -= 10 - (3 * gameState.shootResponseTime); + } else { + responseMessage += `Better luck next time! Maybe practice your aim some more.\n\n`; + gameState.amountSpentOnAmmunition -= 50; + } + gameState.lastPrompt = responseMessage; + gameState.phase = PHASE_ENUM.ACTION_CHOICE; + gameState.subPhase = 0; + await gameState.save(); + await gameFlow.executeCurrentPhase(); + return; + } +}