Overall Phase/inital purchase handling. First purchase handled

master
j 2024-03-30 00:15:43 -04:00
parent fde47b0025
commit 5e2e9a7d15
1 changed files with 171 additions and 8 deletions

View File

@ -1,31 +1,194 @@
import GameState, { PHASE_ENUM } from './gameState' import GameState, { PHASE_ENUM } from './gameState';
class GameFlow { class GameFlow {
gameState: GameState gameState: GameState;
constructor(gameState: GameState) { constructor(gameState: GameState) {
this.gameState = gameState; this.gameState = gameState;
} }
async executeCurrentPhase(userInput?: any) { async executeCurrentPhase(userInput?: string) {
switch (this.gameState.phase) { switch (this.gameState.phase) {
case PHASE_ENUM.SETUP: case PHASE_ENUM.SETUP:
// Handle the setup phase, e.g., initial purchases // Handle the setup phase, e.g., initial purchases
await this.handleSetupPhase(userInput);
break; break;
case PHASE_ENUM.RIDERS_ATTACK: case PHASE_ENUM.RIDERS_ATTACK:
// Handle a riders attack phase
await this.handleRidersAttack(userInput);
break; break;
// Additional cases for other phases...
case PHASE_ENUM.TRAVEL: case PHASE_ENUM.TRAVEL:
// Handle travel logic // Handle travel logic
await this.handleTravel();
break; break;
case PHASE_ENUM.FORT: 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; break;
// Include other phases as necessary
} }
} }
// Other methods as needed private async handleSetupPhase(userInput?: string): Promise<string> {
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<void> {
// Logic for handling a riders attack, may involve checking userInput for response to attack
}
private async handleTravel(): Promise<void> {
// Logic for handling the travel phase
}
private async handleFort(): Promise<void> {
// Logic for interacting at the fort, such as purchasing supplies
}
private async handleHunt(): Promise<void> {
// Logic for the hunt phase, possibly determining success based on gameState attributes
}
private async handleEncounter(): Promise<void> {
// Logic for handling encounters
}
private async handleRandomEvent(): Promise<void> {
// Logic for determining and handling a random event
}
private async handleMountain(): Promise<void> {
// Logic for traversing the mountains, may affect gameState
}
private async handleDeathCheck(): Promise<void> {
// Check gameState conditions and determine if the player has died
}
// Other methods as needed, such as advancing to the next phase
} }
export default GameFlow; export default GameFlow;
interface WeaponOption {
name: string;
cost: number;
}
const weaponOptions: Record<string, WeaponOption> = {
"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 }
};