Compare commits

..

No commits in common. "398465db02509365d2acf1d40a6dd4138f600ce7" and "2ba372f6fd12e0ecffb2f52af68d6957f4070713" have entirely different histories.

3 changed files with 4 additions and 6 deletions

View File

@ -12,6 +12,8 @@ class GameFlow {
async executeCurrentPhase(userInput?: string) { async executeCurrentPhase(userInput?: string) {
this.cleanupGameState(); this.cleanupGameState();
if (userInput && userInput?.toLowerCase().indexOf('restart') >= 0) this.gameState = await this.gameState.reset();
switch (this.gameState.phase) { switch (this.gameState.phase) {
case PHASE_ENUM.SETUP: case PHASE_ENUM.SETUP:
// Handle the setup phase, e.g., initial purchases // Handle the setup phase, e.g., initial purchases
@ -127,7 +129,7 @@ class GameFlow {
switch (this.gameState.subPhase) { switch (this.gameState.subPhase) {
case 0: case 0:
// Weapons Purchase Subphase // Weapons Purchase Subphase
if (!userInput || userInput === 'start' || userInput === 'restart') { 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,

View File

@ -58,7 +58,6 @@ class GameState {
* Saves the current game state to the database. * Saves the current game state to the database.
*/ */
public async save() { public async save() {
console.log(`Saving game state to database... Phase: ${this.phase} SubPhase: ${this.subPhase} Cash: ${this.cashLeftAfterInitialPurchases}`);
await DatabaseService.saveGameState(this.authorId, this); await DatabaseService.saveGameState(this.authorId, this);
} }

View File

@ -14,10 +14,7 @@ class WorkflowOrchestrator {
try { try {
const parsedComment = CommentParser.parseCommand(comment) const parsedComment = CommentParser.parseCommand(comment)
if (parsedComment.command === "") return if (parsedComment.command === "") return
const gameState = await GameState.load(comment)
let gameState = await GameState.load(comment)
if (parsedComment.command === 'restart') gameState = await gameState.reset();
const gameFlow = new GameFlow(gameState) const gameFlow = new GameFlow(gameState)
await gameFlow.executeCurrentPhase(parsedComment.command) await gameFlow.executeCurrentPhase(parsedComment.command)
await gameState.save() await gameState.save()