Purchasing Phase updates and enum
parent
76a5710ae6
commit
eff594379a
|
@ -1,4 +1,5 @@
|
||||||
import GameState, { PHASE_ENUM } from './gameState';
|
import GameState, { PHASE_ENUM } from './gameState';
|
||||||
|
import { MessageService, MessageFileName } from '../utils/MessageService'
|
||||||
|
|
||||||
class GameFlow {
|
class GameFlow {
|
||||||
gameState: GameState;
|
gameState: GameState;
|
||||||
|
@ -59,21 +60,10 @@ class GameFlow {
|
||||||
// Weapons Purchase Subphase
|
// Weapons Purchase Subphase
|
||||||
if (!userInput) {
|
if (!userInput) {
|
||||||
// Send instructions to the user for the current subphase
|
// Send instructions to the user for the current subphase
|
||||||
responseMessage = `
|
responseMessage = `${MessageService.getRandomMessage(
|
||||||
🔫 **Choose Your Weapon for the Journey** 🔫
|
MessageFileName.Oregon_WeaponPurchase,
|
||||||
|
{}
|
||||||
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.
|
// The lack of userInput argument triggers a request for input.
|
||||||
} else {
|
} else {
|
||||||
// Process user input here and decide whether to advance subphase or send an error message
|
// Process user input here and decide whether to advance subphase or send an error message
|
||||||
|
@ -81,6 +71,7 @@ Reply with the choice number, for example: **!!Oregon 3** to select the Settler'
|
||||||
if (purchaseResult.success) {
|
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
|
// 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++;
|
this.gameState.subPhase++;
|
||||||
|
//TODO next we will need to add a wrapper methood that will dump the game object and the message back to the player
|
||||||
return this.handleSetupPhase();
|
return this.handleSetupPhase();
|
||||||
} else {
|
} else {
|
||||||
// If there was an error, include the error message in responseMessage
|
// If there was an error, include the error message in responseMessage
|
||||||
|
@ -91,18 +82,93 @@ Reply with the choice number, for example: **!!Oregon 3** to select the Settler'
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
//OXEN TEAM Purchase
|
//OXEN TEAM Purchase
|
||||||
|
if (!userInput) {
|
||||||
|
responseMessage = `${MessageService.getRandomMessage(
|
||||||
|
MessageFileName.Oregon_OxenPurchase,
|
||||||
|
{}
|
||||||
|
)}`;
|
||||||
|
} else {
|
||||||
|
const purchaseResult = this.handleGenericPurchase(PurchaseOption.OXEN, userInput, 200, 300);
|
||||||
|
if (purchaseResult.success) {
|
||||||
|
this.gameState.subPhase++;
|
||||||
|
//TODO next we will need to add a wrapper methood that will dump the game object and the message back to the player
|
||||||
|
return this.handleSetupPhase(); // Call setup phase again for next subphase
|
||||||
|
} else {
|
||||||
|
responseMessage = purchaseResult.errorMessage || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
//FOOD Purchase
|
//FOOD Purchase
|
||||||
|
if (!userInput) {
|
||||||
|
responseMessage = `${MessageService.getRandomMessage(
|
||||||
|
MessageFileName.Oregon_FoodPurchase,
|
||||||
|
{}
|
||||||
|
)}`;
|
||||||
|
} else {
|
||||||
|
const purchaseResult = this.handleGenericPurchase(PurchaseOption.FOOD, userInput);
|
||||||
|
if (purchaseResult.success) {
|
||||||
|
this.gameState.subPhase++;
|
||||||
|
//TODO next we will need to add a wrapper methood that will dump the game object and the message back to the player
|
||||||
|
return this.handleSetupPhase(); // Call setup phase again for next subphase
|
||||||
|
} else {
|
||||||
|
responseMessage = purchaseResult.errorMessage || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
//AMMUNITION Purchase
|
//AMMUNITION Purchase
|
||||||
|
if (!userInput) {
|
||||||
|
responseMessage = `${MessageService.getRandomMessage(
|
||||||
|
MessageFileName.Oregon_AmmoPurchase,
|
||||||
|
{}
|
||||||
|
)}`;
|
||||||
|
} else {
|
||||||
|
const purchaseResult = this.handleGenericPurchase(PurchaseOption.AMMO, userInput);
|
||||||
|
if (purchaseResult.success) {
|
||||||
|
this.gameState.subPhase++;
|
||||||
|
//TODO next we will need to add a wrapper methood that will dump the game object and the message back to the player
|
||||||
|
return this.handleSetupPhase(); // Call setup phase again for next subphase
|
||||||
|
} else {
|
||||||
|
responseMessage = purchaseResult.errorMessage || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
//CLOTHING Purchase
|
//CLOTHING Purchase
|
||||||
|
if (!userInput) {
|
||||||
|
responseMessage = `${MessageService.getRandomMessage(
|
||||||
|
MessageFileName.Oregon_ClothingPurchase,
|
||||||
|
{}
|
||||||
|
)}`;
|
||||||
|
} else {
|
||||||
|
const purchaseResult = this.handleGenericPurchase(PurchaseOption.CLOTHING, userInput);
|
||||||
|
if (purchaseResult.success) {
|
||||||
|
this.gameState.subPhase++;
|
||||||
|
//TODO next we will need to add a wrapper methood that will dump the game object and the message back to the player
|
||||||
|
return this.handleSetupPhase(); // Call setup phase again for next subphase
|
||||||
|
} else {
|
||||||
|
responseMessage = purchaseResult.errorMessage || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
//MISCELLANEOUS SUPPLIES Purchase
|
//MISCELLANEOUS SUPPLIES Purchase
|
||||||
|
if (!userInput) {
|
||||||
|
responseMessage = `${MessageService.getRandomMessage(
|
||||||
|
MessageFileName.Oregon_MiscSuppliesPurchase,
|
||||||
|
{}
|
||||||
|
)}`;
|
||||||
|
} else {
|
||||||
|
const purchaseResult = this.handleGenericPurchase(PurchaseOption.MISC, userInput);
|
||||||
|
if (purchaseResult.success) {
|
||||||
|
this.gameState.subPhase++;
|
||||||
|
//TODO next we will need to add a wrapper methood that will dump the game object and the message back to the player
|
||||||
|
return this.handleSetupPhase(); // Call setup phase again for next subphase
|
||||||
|
} else {
|
||||||
|
responseMessage = purchaseResult.errorMessage || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//Advance Phase
|
//Advance Phase
|
||||||
|
@ -142,6 +208,59 @@ Reply with the choice number, for example: **!!Oregon 3** to select the Settler'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleGenericPurchase(itemType: PurchaseOption, userInput: string, minAmount?: number, maxAmount?: number): { success: boolean; errorMessage?: string; responseMessage?: string } {
|
||||||
|
const amount = parseInt(userInput);
|
||||||
|
if (isNaN(amount) || amount < 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
errorMessage: "⚠️ Invalid input. Please enter a positive number."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((maxAmount && amount > maxAmount) || (minAmount && amount < minAmount)) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
errorMessage: `⚠️ Invalid input. Please enter a number between ${minAmount} and ${maxAmount}.`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const totalCost = amount
|
||||||
|
if (this.gameState.cashLeftAfterInitialPurchases < totalCost) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
errorMessage: `⚠️ You do not have enough money to purchase ${amount} units of ${itemType}. You have $${this.gameState.cashLeftAfterInitialPurchases} remaining.`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update gameState based on itemType
|
||||||
|
switch (itemType) {
|
||||||
|
case PurchaseOption.OXEN:
|
||||||
|
this.gameState.amountSpentOnAnimals += totalCost;
|
||||||
|
break;
|
||||||
|
case PurchaseOption.FOOD:
|
||||||
|
this.gameState.amountSpentOnFood += totalCost;
|
||||||
|
break;
|
||||||
|
case PurchaseOption.AMMO:
|
||||||
|
this.gameState.amountSpentOnAmmunition += totalCost * 50;
|
||||||
|
break;
|
||||||
|
case PurchaseOption.CLOTHING:
|
||||||
|
this.gameState.amountSpentOnClothing += totalCost;
|
||||||
|
break;
|
||||||
|
case PurchaseOption.MISC:
|
||||||
|
this.gameState.amountSpentOnMiscellaneousSupplies += totalCost;
|
||||||
|
break;
|
||||||
|
// Add cases for other item types
|
||||||
|
}
|
||||||
|
|
||||||
|
this.gameState.cashLeftAfterInitialPurchases -= totalCost;
|
||||||
|
|
||||||
|
// Optionally, return a success message
|
||||||
|
return {
|
||||||
|
success: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private async handleRidersAttack(userInput?: string | number): Promise<void> {
|
private async handleRidersAttack(userInput?: string | number): Promise<void> {
|
||||||
// Logic for handling a riders attack, may involve checking userInput for response to attack
|
// Logic for handling a riders attack, may involve checking userInput for response to attack
|
||||||
|
@ -192,3 +311,11 @@ const weaponOptions: Record<string, WeaponOption> = {
|
||||||
"4": { name: "Homesteader's Musket", cost: 75 },
|
"4": { name: "Homesteader's Musket", cost: 75 },
|
||||||
"5": { name: "Grandpa's Rusty Shotgun", cost: 0 }
|
"5": { name: "Grandpa's Rusty Shotgun", cost: 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum PurchaseOption {
|
||||||
|
OXEN = 'oxen',
|
||||||
|
FOOD = 'food',
|
||||||
|
AMMO = 'ammo',
|
||||||
|
CLOTHING = 'clothing',
|
||||||
|
MISC = 'misc',
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue