import GameState from '../game/gameState'; export class HandleShooting { private static shootingWordVariations: string[] = [ "BANG", "BLAM", "POW", "WHAM", "BOOM", "ZAP", "PEW", "BAM", "CRACK", "POP", "BOFF", "SMACK", "KABOOM", "ZOOM", "WHOOSH", "BLOOP", "SPLAT", "SPLASH", "CRASH", "BANG!" ]; static async handleShooting(gameState: GameState, userInput?: string): Promise { if (!gameState.shootingWordSelector) { return await HandleShooting.initialLogic(gameState); } else { return await HandleShooting.shootingLogic(gameState, userInput); } } private static async initialLogic(gameState: GameState): Promise { const shootingWordSelector = Math.floor(Math.random() * HandleShooting.shootingWordVariations.length); gameState.shootingWordSelector = HandleShooting.shootingWordVariations[shootingWordSelector]; gameState.clockTimeAtStartOfBang = Math.floor(new Date().getTime() / 1000); const responseMessage = `\nQuick! TYPE !!Oregon ${gameState.shootingWordSelector} within the next few minutes. Hurry, time is ticking!\n\n`; await gameState.save(); return responseMessage; } private static async shootingLogic(gameState: GameState, userInput?: string): Promise { let responseMessage = ''; if (!userInput) { responseMessage = "Invalid input.\n\n"; responseMessage += `Quick! TYPE !!Oregon ${gameState.shootingWordSelector} within the next few minutes. Hurry, time is ticking!\n\n`; return responseMessage; } if (userInput.toUpperCase() === gameState.shootingWordSelector.toUpperCase()) { const clockTimeAtEndOfBang = gameState.comment.created_utc; let actualResponseTimeForBang = ((clockTimeAtEndOfBang - gameState.clockTimeAtStartOfBang) / 60000); actualResponseTimeForBang += (gameState.shootingExpertiseLevelChoice - 1); if (actualResponseTimeForBang < 0) { actualResponseTimeForBang = 0; } gameState.shootResponseTime = actualResponseTimeForBang; } else { responseMessage += `Your Word was ${gameState.shootingWordSelector}. Better luck next time!\n\n`; gameState.shootResponseTime = 9; // Set a high time to indicate a miss } gameState.shootingWordSelector = ''; // Reset the shooting word selector await gameState.save(); return responseMessage; } }