Hunting Logic to Own class

master
j 2024-04-26 01:46:14 -04:00
parent 203cba4a3e
commit b437d518c9
1 changed files with 75 additions and 0 deletions

View File

@ -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<void> {
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<void> {
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<void> {
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<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();
return;
}
}