Compare commits

...

5 Commits

Author SHA1 Message Date
j 04335c5b41 Better Regex and Start functionality 2024-04-05 01:56:34 -04:00
j bf113e845c Better Formatting 2024-04-05 01:56:11 -04:00
j a39819814c Fixed Spelling Error 2024-04-05 01:55:58 -04:00
j a8e823f593 Allowed for start command and nicer error messages 2024-04-05 01:55:34 -04:00
j b3a0a026cb Reset Command Added 2024-04-05 01:54:34 -04:00
5 changed files with 44 additions and 9 deletions

View File

@ -114,12 +114,13 @@ class GameFlow {
} }
private async handleSetupPhase(userInput?: string): Promise<void> { private async handleSetupPhase(userInput?: string): Promise<void> {
userInput = userInput?.toLowerCase()
let responseMessage = ""; let responseMessage = "";
// Logic to handle initial setup // Logic to handle initial setup
switch (this.gameState.subPhase) { switch (this.gameState.subPhase) {
case 0: case 0:
// Weapons Purchase Subphase // Weapons Purchase Subphase
if (!userInput) { if (!userInput || userInput === 'start') {
// Send instructions to the user for the current subphase // Send instructions to the user for the current subphase
responseMessage = `${MessageService.getRandomMessage( responseMessage = `${MessageService.getRandomMessage(
MessageFileName.Oregon_WeaponPurchase, MessageFileName.Oregon_WeaponPurchase,
@ -136,6 +137,10 @@ class GameFlow {
} else { } else {
// If there was an error, include the error message in responseMessage // If there was an error, include the error message in responseMessage
responseMessage = `${purchaseResult.errorMessage}`; responseMessage = `${purchaseResult.errorMessage}`;
responseMessage += `\n\n${MessageService.getRandomMessage(
MessageFileName.Oregon_WeaponPurchase,
{}
)}`
// Do not advance subphase; possibly prompt the same instructions with an error message // Do not advance subphase; possibly prompt the same instructions with an error message
} }
} }
@ -154,6 +159,10 @@ class GameFlow {
return this.handleSetupPhase(); // Call setup phase again for next subphase return this.handleSetupPhase(); // Call setup phase again for next subphase
} else { } else {
responseMessage = purchaseResult.errorMessage || ''; responseMessage = purchaseResult.errorMessage || '';
responseMessage += `\n\n${MessageService.getRandomMessage(
MessageFileName.Oregon_OxenPurchase,
{}
)}`
} }
} }
break; break;
@ -171,6 +180,10 @@ class GameFlow {
return this.handleSetupPhase(); // Call setup phase again for next subphase return this.handleSetupPhase(); // Call setup phase again for next subphase
} else { } else {
responseMessage = purchaseResult.errorMessage || ''; responseMessage = purchaseResult.errorMessage || '';
responseMessage += `\n\n${MessageService.getRandomMessage(
MessageFileName.Oregon_FoodPurchase,
{}
)}`
} }
} }
break; break;
@ -188,6 +201,10 @@ class GameFlow {
return this.handleSetupPhase(); // Call setup phase again for next subphase return this.handleSetupPhase(); // Call setup phase again for next subphase
} else { } else {
responseMessage = purchaseResult.errorMessage || ''; responseMessage = purchaseResult.errorMessage || '';
responseMessage += `\n\n${MessageService.getRandomMessage(
MessageFileName.Oregon_AmmoPurchase,
{}
)}`
} }
} }
break; break;
@ -205,6 +222,10 @@ class GameFlow {
return this.handleSetupPhase(); // Call setup phase again for next subphase return this.handleSetupPhase(); // Call setup phase again for next subphase
} else { } else {
responseMessage = purchaseResult.errorMessage || ''; responseMessage = purchaseResult.errorMessage || '';
responseMessage += `\n\n${MessageService.getRandomMessage(
MessageFileName.Oregon_ClothingPurchase,
{}
)}`
} }
} }
break; break;
@ -222,6 +243,10 @@ class GameFlow {
return this.handleSetupPhase(); // Call setup phase again for next subphase return this.handleSetupPhase(); // Call setup phase again for next subphase
} else { } else {
responseMessage = purchaseResult.errorMessage || ''; responseMessage = purchaseResult.errorMessage || '';
responseMessage += `\n\n${MessageService.getRandomMessage(
MessageFileName.Oregon_MiscSuppliesPurchase,
{}
)}`
} }
} }
break; break;

View File

@ -77,6 +77,14 @@ class GameState {
} }
} }
/**
* Resets the current game state by saving the current state and then resetting the game state in the database.
*/
public async reset() {
await DatabaseService.saveGameState(this.authorId, this);
await DatabaseService.resetGameState(this.authorId)
}
} }
export default GameState export default GameState

View File

@ -4,7 +4,7 @@
📅 **Date:** {date} 📅 **Date:** {date}
💰 **Available Funds:** ${money} 💰 **Available Funds:** ${money}
🧭 **Distance Travelled:** {totalMilage} 🧭 **Distance Travelled:** {totalMileage}
<details> <details>
<summary>🛒 Current Supplies</summary> <summary>🛒 Current Supplies</summary>

View File

@ -2,11 +2,11 @@
Please select from the following options by replying with **!!Oregon [choice]**: Please select from the following options by replying with **!!Oregon [choice]**:
1. **Frontiersman's Sharpshooter Rifle** - $200 (Best accuracy and range) - 1. **Frontiersman's Sharpshooter Rifle** - $200 (Best accuracy and range)
2. **Pioneer's Long Rifle** - $150 (Improved accuracy and range) - 2. **Pioneer's Long Rifle** - $150 (Improved accuracy and range)
3. **Settler's Carbine** - $100 (Good balance of cost and performance) - 3. **Settler's Carbine** - $100 (Good balance of cost and performance)
4. **Homesteader's Musket** - $75 (Reliable but not as accurate) - 4. **Homesteader's Musket** - $75 (Reliable but not as accurate)
5. **Grandpa's Rusty Shotgun** - Free (Least accurate but no cost) - 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! **Note:** Your choice of weapon can greatly affect your hunting success and defense against threats on the trail. Choose wisely!

View File

@ -3,17 +3,19 @@ import { Comment } from '../models/Comment';
export class CommentParser { export class CommentParser {
/** /**
* Parses commands from the body of a single comment triggered by !!Oregon. * Parses commands from the body of a single comment triggered by !!Oregon.
* If the comment contains only "!!Oregon", it treats it as a "start" command.
* @param comment A single Comment object to be processed. * @param comment A single Comment object to be processed.
* @returns An object containing the command and its arguments, if any. * @returns An object containing the command and its arguments, if any.
*/ */
public static parseCommand(comment: Comment): { command: string, args: string[] } { public static parseCommand(comment: Comment): { command: string, args: string[] } {
if (comment.is_bot) return { command: '', args: [] }; if (comment.is_bot) return { command: '', args: [] };
const commandTrigger: RegExp = /!!Oregon\s+(\w+)(?:\s+(.*))?/i; const commandTrigger: RegExp = /!!Oregon\s*(\w+)?(?:\s+(.*))?/i;
const match = comment.body.match(commandTrigger); const match = comment.body.match(commandTrigger);
if (match) { if (match) {
const command = match[1].toLowerCase(); // If the command is exactly "!!Oregon" with no additional command word, set command to "start"
const command = match[1] ? match[1].toLowerCase() : "start";
const args = match[2] ? match[2].split(' ').map(arg => arg.trim()) : []; const args = match[2] ? match[2].split(' ').map(arg => arg.trim()) : [];
return { command, args }; return { command, args };
} }