Technical Specification: Player Entity for Labyrinth MUD - wwestlake/Labyrinth GitHub Wiki
Technical Specification: Managing Player and Character Entities in a MUD
Overview
This technical specification outlines the architecture and data management strategy for handling Player and Character entities in a MUD (Multi-User Dungeon) game. The proposed model distinguishes between the Character entity as a static template and the Player entity as a dynamic, mutable record that tracks the gameplay state for a specific user-character combination.
Key Entities
-
Character Entity:
- Acts as a template or reference point.
- Stores immutable or rarely changing attributes of a character, such as:
- Character Class (e.g., Warrior, Mage)
- Race (e.g., Elf, Human)
- Base Stats (e.g., Strength, Dexterity)
- Permanent Attributes (e.g., special skills or abilities)
- Represents the character's initial state upon creation and can be used for resetting the game or starting new sessions.
-
Player Entity:
- Represents the active, mutable state of a character being played by a specific user.
- Identified by a combination of
UserIdandCharacterId. - Stores dynamic gameplay data, including:
- Current Room ID: Where the player is currently located.
- Health, Mana, and Other Stats: Current values that fluctuate during gameplay.
- Experience Points: Tracks experience and level progression.
- Inventory and Equipment: Lists current items and gear.
- Quest Progress: Active, completed, and failed quests.
- Status Effects: Temporary buffs, debuffs, and conditions.
- IsOnline: Indicates if the player is currently in-game.
Data Model
Character Document (Stored in the Characters collection):
{
"_id": "CharacterId123",
"Owner": "UserId456",
"CharacterClass": "Mage",
"Name": "Merlin",
"Description": "A wise mage.",
"Race": "Elf",
"Level": 1,
"BaseStats": {
"Strength": 10,
"Dexterity": 15,
"Intelligence": 20,
"Constitution": 12
},
"Abilities": ["Fireball", "Teleport"],
"BaseEquipment": ["Staff", "Robe"],
// Other static attributes...
}
Player Document (Stored in the Players collection):
{
"_id": "PlayerId789",
"UserId": "UserId456",
"CharacterId": "CharacterId123",
"Name": "Merlin",
"CharacterClass": "Mage",
"Race": "Elf",
"Level": 1,
"CurrentRoomId": "RoomId001",
"Health": 80,
"Mana": 50,
"ExperiencePoints": 1200,
"Inventory": ["Potion", "Magic Scroll"],
"ActiveQuests": ["QuestId001", "QuestId002"],
"CompletedQuests": ["QuestId003"],
"FailedQuests": [],
"IsOnline": true,
"StatusEffects": ["Blessing", "Curse"],
// Other dynamic attributes...
}
Processes
-
Creating a New Character and Entering the Game:
- Step 1: User creates a new character. A
Characterdocument is created in theCharacterscollection. - Step 2: A new
Playerdocument is created in thePlayerscollection. This document references theCharacterIdand initializes other fields likeCurrentRoomId,Health, etc. - Step 3: The game session is initialized using the
Playerdocument, and the player enters the game world.
- Step 1: User creates a new character. A
-
Selecting an Existing Character:
- Step 1: User selects an existing character. The game fetches the corresponding
CharacterandPlayerdocuments. - Step 2: The
Playerdocument is updated with any relevant session-specific data (if necessary). - Step 3: The player enters the game, and the game state is initialized from the
Playerdocument.
- Step 1: User selects an existing character. The game fetches the corresponding
-
Switching Characters During Play:
- Step 1: User decides to switch characters. The game saves the current state of the active
Playerdocument. - Step 2: The game fetches the new
CharacterandPlayerdocuments. - Step 3: If a
Playerdocument does not exist for the new character, a new one is created using theCharactertemplate. - Step 4: The game session is transitioned to the new character's state based on the
Playerdocument.
- Step 1: User decides to switch characters. The game saves the current state of the active
Benefits of the Proposed Model
-
Separation of Concerns:
- By distinguishing between
CharacterandPlayerentities, the model allows for clearer management of game state versus character templates. The immutableCharactertemplate remains unaffected by gameplay, while thePlayerdocument captures all in-game changes.
- By distinguishing between
-
Flexibility in Gameplay Management:
- Players can have multiple
Playerrecords tied to different characters or sessions, allowing for complex game mechanics such as permadeath, different gameplay modes, or simultaneous multi-character play.
- Players can have multiple
-
Efficient Data Management:
- Using multiple
Playerdocuments reduces the need to constantly update theCharacterdocument, keeping it as a clean reference. It also minimizes data conflicts when switching between characters or managing multiple sessions.
- Using multiple
-
Enhanced Game Features and Flexibility:
- The proposed model supports various advanced game features, such as detailed tracking of quest progress, room states, and dynamic game interactions.
Conclusion
Adopting this model provides a robust framework for managing player and character data in a MUD game, aligning with best practices observed in other MUDs and RPGs. It allows for dynamic gameplay while maintaining the integrity and flexibility of the underlying data model.
By treating Character documents as templates and Player documents as mutable states, the game can efficiently manage multiple characters, dynamic game sessions, and complex gameplay features. This approach ensures both scalability and ease of management for future game expansions and modifications.