OregonTrail/src/phases/action.ts

81 lines
3.6 KiB
TypeScript

import GameState, { PHASE_ENUM } from '../game/gameState';
import GameFlow from '../game/gameFlow';
import { MessageService } from '../utils/MessageService';
export class ActionPhase {
static async actionChoice(gameState: GameState, userInput?: string): Promise<void> {
let responseMessage = "";
userInput = userInput?.toLowerCase()
console.log("userInput", userInput);
switch (userInput) {
case "1": // Hunt
if (gameState.amountSpentOnAmmunition < 40) {
responseMessage = `You do not have enough ammunition to hunt. Purchase more ammunition first.\n\n`;
if (gameState.fortOptionFlag) {
responseMessage += `Do you want to:\n2. Continue\n3. Stop at the Next Fort\n\n`
} else {
responseMessage += `Do you want to:\n2. Continue\n\n`
}
await MessageService.statusUpdate(gameState, responseMessage)
} else {
gameState.phase = PHASE_ENUM.HUNT;
gameState.totalMileageWholeTrip -= 45;
await gameState.save()
GameFlow.executeCurrentPhase(gameState)
}
return;
break;
case "2": // Continue
gameState.phase = PHASE_ENUM.TRAVEL;
await gameState.save()
GameFlow.executeCurrentPhase(gameState)
return;
break;
case "3": // Stop at the Next Fort (if applicable)
if (gameState.fortOptionFlag) {
gameState.subPhase = 2
gameState.totalMileageWholeTrip -= 45;
gameState.phase = PHASE_ENUM.FORT;
await gameState.save()
GameFlow.executeCurrentPhase(gameState)
return;
} else {
responseMessage += "⚠️ There is no fort option available at this time.\n\n"
responseMessage += `Do you want to:\n1. Hunt\n2. Continue\n\n`
await MessageService.statusUpdate(gameState, responseMessage)
return;
}
break;
default:
console.log("Starting turn...");
if (userInput !== undefined || userInput === "" || userInput === "start") {
responseMessage += "⚠️ Invalid Selection.\n\n"
}
//check for illness or injury
if (gameState.illnessFlag || gameState.injuryFlag) {
responseMessage += GameFlow.handleDoctor(gameState);
if (gameState.phase === PHASE_ENUM.DEATH) {
GameFlow.executeCurrentPhase(gameState)
return;
}
}
// Warn the player if food is low
if (gameState.amountSpentOnFood < 13) {
responseMessage += `You only have ${gameState.amountSpentOnFood} pounds of food.\n\n YOU'D BETTER DO SOME HUNTING OR BUY FOOD AND SOON!!!!\n\n`;
}
if (gameState.fortOptionFlag) {
responseMessage += `Do you want to:\n1. Hunt\n2. Continue\n3. Stop at the Next Fort\n\n`
} else {
responseMessage += `Do you want to:\n1. Hunt\n2. Continue\n\n`
}
await MessageService.statusUpdate(gameState, gameState.lastPrompt + responseMessage)
gameState.lastPrompt = responseMessage;
break;
}
return;
}
}