Compare commits
2 Commits
2ba372f6fd
...
398465db02
Author | SHA1 | Date |
---|---|---|
j | 398465db02 | |
j | 51a9aa3ee6 |
|
@ -12,8 +12,6 @@ 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
|
||||||
|
@ -129,7 +127,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') {
|
if (!userInput || userInput === 'start' || userInput === 'restart') {
|
||||||
// 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,
|
||||||
|
|
|
@ -58,6 +58,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,10 @@ 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()
|
||||||
|
|
Loading…
Reference in New Issue