From 94cb64f37aa4f5cf7dca1fc6ad91a4a4150a8b81 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 31 Mar 2024 23:24:38 -0400 Subject: [PATCH] status update logic added --- src/game/gameFlow.ts | 62 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/src/game/gameFlow.ts b/src/game/gameFlow.ts index ccfeff3..069a29c 100644 --- a/src/game/gameFlow.ts +++ b/src/game/gameFlow.ts @@ -1,5 +1,6 @@ import GameState, { PHASE_ENUM } from './gameState'; import { MessageService, MessageFileName } from '../utils/MessageService' +import { CommentPoster } from '../rdrama/services/CommentPoster'; class GameFlow { gameState: GameState; @@ -52,7 +53,56 @@ class GameFlow { } } - private async handleSetupPhase(userInput?: string): Promise { + formatDate(date: Date): string { + return date.toLocaleDateString("en-US", { + weekday: 'long', + year: 'numeric', + month: 'long', + day: 'numeric', + }).toUpperCase(); + } + + async statusUpdate(message: string): Promise { + 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 { let responseMessage = ""; // Logic to handle initial setup switch (this.gameState.subPhase) { @@ -71,7 +121,6 @@ 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 @@ -91,7 +140,6 @@ 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 || ''; @@ -109,7 +157,6 @@ 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 || ''; @@ -127,7 +174,6 @@ 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 || ''; @@ -145,7 +191,6 @@ 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 || ''; @@ -163,7 +208,6 @@ 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 || ''; @@ -174,7 +218,9 @@ class GameFlow { //Advance Phase break; } - return responseMessage; + + await this.statusUpdate(responseMessage) + return; } handleWeaponPurchase(userInput: string): { success: boolean; errorMessage?: string } {