status update logic added

master
j 2024-03-31 23:24:38 -04:00
parent 78c36d1b77
commit 94cb64f37a
1 changed files with 54 additions and 8 deletions

View File

@ -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<string> {
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> {
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 } {