Compare commits

...

4 Commits

Author SHA1 Message Date
j fde47b0025 session thoughts 2024-03-29 00:26:48 -04:00
j 0f73d3520c further enum on phases 2024-03-29 00:26:36 -04:00
j 0165d9212b phaseManagement Skeleton 2024-03-29 00:26:14 -04:00
j a95240a1b0 !!Oregon Logic 2024-03-29 00:25:47 -04:00
4 changed files with 81 additions and 84 deletions

View File

@ -1,4 +1,4 @@
import GameState from './gameState'
import GameState, { PHASE_ENUM } from './gameState'
class GameFlow {
gameState: GameState
@ -7,19 +7,22 @@ class GameFlow {
this.gameState = gameState;
}
executeCurrentPhase() {
switch (this.gameState.currentPhase) {
case 'initialChoice':
// Handle initial choice
async executeCurrentPhase(userInput?: any) {
switch (this.gameState.phase) {
case PHASE_ENUM.SETUP:
// Handle the setup phase, e.g., initial purchases
break;
case 'fort':
// Handle fort logic
case PHASE_ENUM.RIDERS_ATTACK:
break;
// Other cases for each phase
// Additional cases for other phases...
case PHASE_ENUM.TRAVEL:
// Handle travel logic
break;
case PHASE_ENUM.FORT:
// Handle fort or hunt choices
break;
// Include other phases as necessary
}
// After phase logic, advance to next phase
this.gameState.advancePhase();
}
// Other methods as needed

View File

@ -1,74 +1,72 @@
import GameState from './gameState';
import GameFlow from './gameFlow';
import { Comment } from '../rdrama/models/Comment';
import { CommentParser } from '../rdrama/services/CommentParser';
class GameSession {
private gameState: GameState;
private gameManager: GameFlow;
private authorId: string;
private gameFlow: GameFlow;
private authorId: number;
constructor(authorId: string) {
private constructor(authorId: number, gameState: GameState) {
this.authorId = authorId;
// Initialize GameState. If there's saved data for this authorId, load it; otherwise, start with default values.
this.gameState = new GameState(authorId);
// Initialize the GameManager with the current game state.
this.gameManager = new GameFlow(this.gameState);
this.gameState = gameState;
this.gameFlow = new GameFlow(gameState);
}
async handleUserInput(userId: string, input: string): Promise<void> {
const gameState = await this.loadGameState(userId);
/**
* Loads an existing game session for the given author or creates a new one if none exists.
* @param authorId The ID of the author for whom to load or create the game session.
* @returns A GameSession instance for the given author.
*/
public static async loadSession(authorId: number): Promise<GameSession> {
const gameState = await GameState.load(authorId);
return new GameSession(authorId, gameState);
}
switch (input.split(' ')[0].toLowerCase()) {
case "!!oregon":
await this.processCommand(gameState, input);
/**
* Handles user input by parsing the command and executing the corresponding action.
* @param comment The comment containing the user input.
*/
public async handleUserInput(comment: Comment): Promise<void> {
const { command, args } = CommentParser.parseCommand(comment);
// Process the command
switch (command) {
case 'startover':
// Example of resetting the game
this.gameState.reset();
break;
case 'buysupplies':
// Example of handling a purchase command
// Logic to handle buying supplies
break;
// Add additional cases for other commands
default:
console.error('Unrecognized command:', command);
break;
// Additional commands as necessary
}
await this.saveGameState(gameState);
}
private async processCommand(gameState: GameState, command: string): Promise<void> {
const args = command.split(' ');
// Process different game setup commands (e.g., "start over", "buy supplies")
if (args[1].toLowerCase() === "startover") {
gameState.reset(); // Resets game state to initial values
} else if (args[1].toLowerCase() === "buysupplies") {
// Transition to handling purchases
// This would involve setting the next expected action in the game state
// And possibly sending a prompt for the first purchase
}
// Handle other commands and shopping logic
// After processing the command, save any changes to the game state
await this.gameState.save();
}
/**
* Saves the current game state.
* This method would serialize the GameState object and save it to a database or file system.
*/
private saveGameState(): void {
// Implementation for saving the game state.
console.log('Saving game state...');
// Serialize and save the GameState object here.
}
/**
* Loads a saved game state.
* This method would deserialize a saved GameState object and update the current game state with it.
*/
private loadGameState(): void {
// Implementation for loading a saved game state.
console.log('Loading game state...');
// Deserialize and load the GameState object here.
// Update this.gameState with the loaded state.
}
/**
* Retrieves the current game status update for the player.
* This could include information about the player's progress, inventory, and available actions.
* @returns A string representing the current game status.
* Generates a status update message based on the current state of the game.
* @returns A string representing the current game status, formatted for display.
*/
public getStatusUpdate(): string {
// Generate a status update message based on the current game state.
// This message could be formatted with Markdown for better presentation.
return this.gameManager.generateStatusMessage();
// Use the GameFlow instance to generate a status message
return this.gameFlow.generateStatusMessage();
}
/**
* Resets the game to its initial state and saves the updated state.
*/
private async reset(): Promise<void> {
this.gameState.reset();
await this.gameState.save();
}
}
export { GameSession };

View File

@ -76,12 +76,14 @@ class GameState {
export default GameState
// Enumeration for different phases of the game.
enum PHASE_ENUM {
export enum PHASE_ENUM {
SETUP = 'SETUP',
TRAVEL = 'TRAVEL',
FORT_HUNT = 'FORT_HUNT',
FORT = 'FORT',
HUNT = 'HUNT',
ENCOUNTER = 'ENCOUNTER',
EVENT = 'EVENT',
MOUNTAIN = 'MOUNTAIN',
DEATH_CHECK = 'DEATH_CHECK',
RIDERS_ATTACK = 'RIDERS_ATTACK',
}

View File

@ -2,27 +2,21 @@ import { Comment } from '../models/Comment';
export class CommentParser {
/**
* Extracts Reddit usernames from the body of a single comment.
* Parses commands from the body of a single comment triggered by !!Oregon.
* @param comment A single Comment object to be processed.
* @returns An array of unique Reddit usernames found in the comment.
* @returns An object containing the command and its arguments, if any.
*/
public static extractUsernames(comment: Comment): string[] {
const regexPattern: RegExp = /(^|\s|\\r\\n|\\t|[".,;(){}\[\]!?@#])(\/?u\/[a-zA-Z0-9_]+)/g;
const foundUsernames: Set<string> = new Set();
public static parseCommand(comment: Comment): { command: string, args: string[] } {
const commandTrigger: RegExp = /!!Oregon\s+(\w+)(?:\s+(.*))?/i;
const match = comment.body.match(commandTrigger);
const matches = comment.body.match(regexPattern);
if (matches) {
matches.forEach(match => {
// Ensure the username is captured in a standardized format
const usernameMatch = match.trim().match(/\/?u\/([a-zA-Z0-9_]+)/);
if (usernameMatch) {
// Standardize to "username" format
const username = `${usernameMatch[1].toLowerCase()}`;
foundUsernames.add(username);
}
});
if (match) {
const command = match[1].toLowerCase();
const args = match[2] ? match[2].split(' ').map(arg => arg.trim()) : [];
return { command, args };
}
return Array.from(foundUsernames);
// No command found
return { command: '', args: [] };
}
}