Compare commits

..

No commits in common. "5b97b4b219218e1b31e3ab555257f1bf122eb3c9" and "375fb9bd18e5e1a28c0fae337d65c3179223205c" have entirely different histories.

4 changed files with 26 additions and 79 deletions

View File

@ -1,6 +1,5 @@
import GameState, { PHASE_ENUM } from './gameState';
import { MessageService, MessageFileName } from '../utils/MessageService'
import { CommentPoster } from '../rdrama/services/CommentPoster';
class GameFlow {
gameState: GameState;
@ -53,56 +52,7 @@ class GameFlow {
}
}
formatDate(date: Date): string {
return date.toLocaleDateString("en-US", {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
}).toUpperCase();
}
async statusUpdate(message: string): Promise<void> {
const placeholders: { [key: string]: string } = {
playerName: this.gameState.authorName,
message: message,
date: this.gameState.currentDate,
money: this.gameState.cashLeftAfterInitialPurchases.toString(),
totalMileage: this.gameState.totalMileageWholeTrip.toString(),
oxen: this.describeOxenQuality(),
food: this.gameState.amountSpentOnFood.toString(),
ammo: this.gameState.amountSpentOnAmmunition.toString(),
clothing: this.gameState.amountSpentOnClothing.toString(),
supplies: this.gameState.amountSpentOnMiscellaneousSupplies.toString(),
};
const parsedMessage = `${MessageService.getRandomMessage(MessageFileName.Oregon_Template, placeholders)}`
await CommentPoster.postComment(`c_${this.gameState.comment.id}`, parsedMessage)
}
describeOxenQuality(): string {
const spent = this.gameState.amountSpentOnAnimals;
const qualityLevels = [
{ max: 220, description: 'Basic Quality' },
{ max: 240, description: 'Moderate Quality' },
{ max: 260, description: 'Good Quality' },
{ max: 280, description: 'High Quality' },
{ max: 300, description: 'Exceptional Quality' }
];
for (const level of qualityLevels) {
if (spent <= level.max) {
return level.description;
}
}
// Default to the lowest quality if for some reason the amount doesn't fit the expected range
return 'Unknown Quality';
}
private async handleSetupPhase(userInput?: string): Promise<void> {
private async handleSetupPhase(userInput?: string): Promise<string> {
let responseMessage = "";
// Logic to handle initial setup
switch (this.gameState.subPhase) {
@ -121,6 +71,7 @@ class GameFlow {
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++;
//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();
} else {
// If there was an error, include the error message in responseMessage
@ -140,6 +91,7 @@ class GameFlow {
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 || '';
@ -157,6 +109,7 @@ class GameFlow {
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 || '';
@ -174,6 +127,7 @@ class GameFlow {
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 || '';
@ -191,6 +145,7 @@ class GameFlow {
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 || '';
@ -208,6 +163,7 @@ class GameFlow {
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 || '';
@ -218,9 +174,7 @@ class GameFlow {
//Advance Phase
break;
}
await this.statusUpdate(responseMessage)
return;
return responseMessage;
}
handleWeaponPurchase(userInput: string): { success: boolean; errorMessage?: string } {

View File

@ -1,5 +1,4 @@
import { DatabaseService } from "../db/services/Database";
import { Comment } from "../rdrama/models/Comment";
/**
* Represents the state of a game session for an Oregon Trail-style game.
@ -7,9 +6,7 @@ import { Comment } from "../rdrama/models/Comment";
* to load from and save to a database.
*/
class GameState {
comment: Comment;
authorId: number;
authorName: string;
authorId: number = 0;
amountSpentOnAnimals: number = 0;
amountSpentOnAmmunition: number = 0;
actualResponseTimeForBang: number = 0;
@ -19,7 +16,7 @@ class GameState {
yesNoResponseToQuestions: string = '';
eventCounter: number = 0;
turnNumberForSettingDate: number = 0;
currentDate: string = 'MONDAY MARCH 29 1847';
currentDate: string = '';
shootingExpertiseLevelChoice: number = 0;
eatingChoice: number = 0;
amountSpentOnFood: number = 0;
@ -46,10 +43,8 @@ class GameState {
phase: PHASE_ENUM = PHASE_ENUM.SETUP;
subPhase: number = 0;
private constructor(comment: Comment, state?: Partial<GameState>) {
this.comment = comment
this.authorId = comment.author_id;
this.authorName = comment.author_name;
private constructor(authorId: number, state?: Partial<GameState>) {
this.authorId = authorId;
Object.assign(this, state); // Initialize with loaded state or undefined
}
@ -62,21 +57,20 @@ class GameState {
/**
* Loads an existing game state from the database or creates a new one if it doesn't exist.
* @param {Comment} comment - The invoking comment of the author/player.
* @param {number} authorId - The ID of the author/player.
* @returns {Promise<GameState>} - The loaded or newly created game state.
*/
public static async load(comment: Comment): Promise<GameState> {
const loadedState = await DatabaseService.loadGameState(comment.author_id);
public static async load(authorId: number): Promise<GameState> {
const loadedState = await DatabaseService.loadGameState(authorId);
if (loadedState) {
return new GameState(comment, loadedState);
return new GameState(authorId, loadedState);
} else {
// Create a new GameState with default values
const newState = new GameState(comment);
const newState = new GameState(authorId);
await newState.save(); // Optionally save the new state to the database
return newState;
}
}
}
export default GameState

View File

@ -9,22 +9,22 @@
<details>
<summary>๐Ÿ›’ Current Supplies</summary>
- **Oxen:** {oxen} (Essential for travel speed; higher quality means faster travel)
- **Food:** {food} lbs (Vital for sustaining health and energy)
- **Ammunition:** {ammo} bullets (Critical for hunting and defense against threats)
- **Clothing Supplies:** {clothing} (Important for protection against the elements)
- **Misc. Supplies:** {supplies} lbs (Useful for various challenges along the way)
- **Oxen:** {oxen} teams (Essential for travel speed)
- **Food:** {food} lbs (Vital for health)
- **Ammunition:** {ammo} boxes (Needed for hunting)
- **Clothing:** {clothing} set(s) (Important for health in bad weather)
- **Misc. Supplies:** {supplies} items (Useful for various challenges along the way)
</details>
<details>
<summary>โœจ Actions Available</summary>
- **Restart:** Begin a new game.
- **Start Over:** Begin a new game.
- **Status:** Get the current game state.
- **Help:** Show game instructions and tips.
- **Fort:** Make purchases at the current location (Available at forts).
- **Continue:** Move forward with your journey.
- **Buy Supplies:** Make purchases at the current location (Available at forts).
- **Continue on Trail:** Move forward with your journey.
- **Hunt:** Spend a day hunting for food.
- **Rest:** Rest for a day to improve health.
@ -33,7 +33,7 @@
### ๐Ÿ”„ To Make a Choice
Please reply with **!!Oregon** followed by one of the actions above. For example:
```
!!Oregon Fort
!!Oregon Buy Supplies
```
Remember, wise choices and preparation are key to a successful journey on the Oregon Trail. Good luck, traveler! ๐Ÿš—๐Ÿ’จ

View File

@ -9,7 +9,6 @@ export enum MessageFileName {
Oregon_AmmoPurchase = 'oregon_AmmoPurchase.txt',
Oregon_ClothingPurchase = 'oregon_ClothingPurchase.txt',
Oregon_MiscSuppliesPurchase = 'oregon_MiscSuppliesPurchase.txt',
Oregon_Template = 'oregon_Template.txt',
}
export class MessageService {