From 5e2e9a7d15b38a6e626796170e8e548c6125db1f Mon Sep 17 00:00:00 2001 From: j Date: Sat, 30 Mar 2024 00:15:43 -0400 Subject: [PATCH] Overall Phase/inital purchase handling. First purchase handled --- src/game/gameFlow.ts | 179 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 171 insertions(+), 8 deletions(-) diff --git a/src/game/gameFlow.ts b/src/game/gameFlow.ts index 849d3a0..40eb57b 100644 --- a/src/game/gameFlow.ts +++ b/src/game/gameFlow.ts @@ -1,31 +1,194 @@ -import GameState, { PHASE_ENUM } from './gameState' +import GameState, { PHASE_ENUM } from './gameState'; class GameFlow { - gameState: GameState + gameState: GameState; constructor(gameState: GameState) { this.gameState = gameState; } - async executeCurrentPhase(userInput?: any) { + async executeCurrentPhase(userInput?: string) { switch (this.gameState.phase) { case PHASE_ENUM.SETUP: // Handle the setup phase, e.g., initial purchases + await this.handleSetupPhase(userInput); break; case PHASE_ENUM.RIDERS_ATTACK: + // Handle a riders attack phase + await this.handleRidersAttack(userInput); break; - // Additional cases for other phases... case PHASE_ENUM.TRAVEL: // Handle travel logic + await this.handleTravel(); break; case PHASE_ENUM.FORT: - // Handle fort or hunt choices + // Handle interactions at the fort + await this.handleFort(); + break; + case PHASE_ENUM.HUNT: + // Handle hunting logic + await this.handleHunt(); + break; + case PHASE_ENUM.ENCOUNTER: + // Handle encounters, which might include interactions with NPCs or obstacles + await this.handleEncounter(); + break; + case PHASE_ENUM.EVENT: + // Handle random events that can occur + await this.handleRandomEvent(); + break; + case PHASE_ENUM.MOUNTAIN: + // Handle mountain traversal challenges + await this.handleMountain(); + break; + case PHASE_ENUM.DEATH_CHECK: + // Check if conditions leading to the player's death have been met + await this.handleDeathCheck(); + break; + default: + console.error("Unknown game phase:", this.gameState.phase); break; - // Include other phases as necessary } } - // Other methods as needed + private async handleSetupPhase(userInput?: string): Promise { + let responseMessage = ""; + // Logic to handle initial setup + switch (this.gameState.subPhase) { + case 0: + // Weapons Purchase Subphase + if (!userInput) { + // Send instructions to the user for the current subphase + responseMessage = ` +🔫 **Choose Your Weapon for the Journey** 🔫 + +Please select from the following options by replying with **!!Oregon [choice]**: + +1. **Frontiersman's Sharpshooter Rifle** - $200 (Best accuracy and range) +2. **Pioneer's Long Rifle** - $150 (Improved accuracy and range) +3. **Settler's Carbine** - $100 (Good balance of cost and performance) +4. **Homesteader's Musket** - $75 (Reliable but not as accurate) +5. **Grandpa's Rusty Shotgun** - Free (Least accurate but no cost) + +**Note:** Your choice of weapon can greatly affect your hunting success and defense against threats on the trail. Choose wisely! + +Reply with the choice number, for example: **!!Oregon 3** to select the Settler's Carbine. +`; + // The lack of userInput argument triggers a request for input. + } else { + // Process user input here and decide whether to advance subphase or send an error message + const purchaseResult = this.handleWeaponPurchase(userInput); + if (purchaseResult.success) { + // If the purchase was successful, advance to the next subphase and recursively call handleSetupPhase without userInput to get the next set of instructions + this.gameState.subPhase++; + return this.handleSetupPhase(); + } else { + // If there was an error, include the error message in responseMessage + responseMessage = `${purchaseResult.errorMessage}`; + // Do not advance subphase; possibly prompt the same instructions with an error message + } + } + break; + case 1: + //OXEN TEAM Purchase + break; + case 2: + //FOOD Purchase + break; + case 3: + //AMMUNITION Purchase + break; + case 4: + //CLOTHING Purchase + break; + case 5: + //MISCELLANEOUS SUPPLIES Purchase + break; + default: + //Advance Phase + break; + } + return responseMessage; + } + + handleWeaponPurchase(userInput: string): { success: boolean; errorMessage?: string } { + + // Check if the userInput is one of the valid choices + if (!Object.keys(weaponOptions).includes(userInput)) { + // If the input is not valid, return an error message + return { + success: false, + errorMessage: "⚠️ Invalid choice. Please select a valid weapon option by replying with !!Oregon [choice]." + }; + } + + // Check if the user has enough money for the selected weapon + const selectedWeapon = weaponOptions[userInput]; + if (this.gameState.cashLeftAfterInitialPurchases < selectedWeapon.cost) { + // If not enough money, return an error message + return { + success: false, + errorMessage: `⚠️ You do not have enough money for ${selectedWeapon.name}. You have $${this.gameState.cashLeftAfterInitialPurchases} remaining.` + }; + } + + // Update gameState with the selected weapon and deduct the cost + this.gameState.shootingExpertiseLevelChoice = parseInt(userInput); + this.gameState.cashLeftAfterInitialPurchases -= selectedWeapon.cost; + + // Return a success object, indicating the purchase was successful + return { + success: true + }; + } + + + private async handleRidersAttack(userInput?: string | number): Promise { + // Logic for handling a riders attack, may involve checking userInput for response to attack + } + + private async handleTravel(): Promise { + // Logic for handling the travel phase + } + + private async handleFort(): Promise { + // Logic for interacting at the fort, such as purchasing supplies + } + + private async handleHunt(): Promise { + // Logic for the hunt phase, possibly determining success based on gameState attributes + } + + private async handleEncounter(): Promise { + // Logic for handling encounters + } + + private async handleRandomEvent(): Promise { + // Logic for determining and handling a random event + } + + private async handleMountain(): Promise { + // Logic for traversing the mountains, may affect gameState + } + + private async handleDeathCheck(): Promise { + // Check gameState conditions and determine if the player has died + } + + // Other methods as needed, such as advancing to the next phase } -export default GameFlow; \ No newline at end of file +export default GameFlow; + +interface WeaponOption { + name: string; + cost: number; +} + +const weaponOptions: Record = { + "1": { name: "Frontiersman's Sharpshooter Rifle", cost: 200 }, + "2": { name: "Pioneer's Long Rifle", cost: 150 }, + "3": { name: "Settler's Carbine", cost: 100 }, + "4": { name: "Homesteader's Musket", cost: 75 }, + "5": { name: "Grandpa's Rusty Shotgun", cost: 0 } +}; \ No newline at end of file