OregonTrail/src/phases/hunt.ts

78 lines
3.2 KiB
TypeScript

import GameState, { PHASE_ENUM } from '../game/gameState';
import GameFlow from '../game/gameFlow';
import { HandleShooting } from './shooting';
import { MessageService } from '../utils/MessageService';
export class HuntPhase {
static async handleHunt(gameState: GameState, userInput?: string): Promise<void> {
switch (gameState.subPhase) {
case 0: // Initial Logic
await HuntPhase.initialLogic(gameState);
break;
case 1: // Shooting Logic
await HuntPhase.shootingLogic(gameState, userInput);
break;
case 2: // Outcome Logic
await HuntPhase.outcomeLogic(gameState);
break;
default:
console.error("Unknown subphase in HuntPhase");
break;
}
}
static async initialLogic(gameState: GameState): Promise<void> {
let responseMessage = '';
responseMessage += HandleShooting.handleShooting(gameState);
gameState.subPhase = 1;
gameState.lastPrompt = responseMessage;
await MessageService.statusUpdate(gameState, responseMessage);
await gameState.save();
}
static async shootingLogic(gameState: GameState, userInput?: string): Promise<void> {
let responseMessage = '';
if (!userInput) {
responseMessage = "Invalid input.\n\n";
responseMessage += gameState.lastPrompt;
await MessageService.statusUpdate(gameState, responseMessage);
return;
}
if (userInput.toLowerCase() === "start") {
responseMessage += gameState.lastPrompt;
await MessageService.statusUpdate(gameState, responseMessage);
return;
}
responseMessage += HandleShooting.handleShooting(gameState, userInput.toString());
gameState.lastPrompt = responseMessage;
gameState.subPhase = 2;
await gameState.save();
await GameFlow.executeCurrentPhase(gameState);
return;
}
static async outcomeLogic(gameState: GameState): Promise<void> {
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(gameState);
return;
}
}