Creating a marriage system for characters in Evennia would involve defining a set of mechanics and commands to establish, manage, and dissolve marriages. Below is a step-by-step guide to implement such a system, leveraging the Evennia framework and its capabilities, such as Attributes and Commands.
1. Define the Marriage System Requirements
The marriage system could include the following features:
Proposals: One character proposes to another.
Acceptance/Refusal: The proposal can be accepted or refused.
Marriage Record: The relationship is stored persistently.
Divorce: Marriages can be dissolved.
Roleplaying Integration: Optional enhancements like emotes or ceremony events.
2. Use Evennia’s Attribute System for Marriage Data
You can store marriage information as Attributes on character objects. Each character can have an attribute called spouse (or a list of spouses for polygamous systems).
For example:
python
# Add marriage attributes to characters
character.db.spouse = None # or [] for multiple spouses
3. Create Marriage Commands
Define commands to handle marriage-related actions. Use Evennia's Command system to create commands such as propose, accept, refuse, and divorce.
Example: propose Command
python
from evennia.commands.command import Command
class CmdPropose(Command):
"""
Propose marriage to another character.
Usage:
propose <character>
Example:
propose [Redacted Person]
This will initiate a marriage proposal.
"""
key = "propose"
def func(self):
caller = self.caller
if not self.args:
caller.msg("Who do you want to propose to?")
return
target = caller.search(self.args.strip())
if not target:
return # Error message already handled by `search`
if target == [Redacted Person]:
[Redacted Person]("You can't propose to yourself!")
return
if target.db.spouse == [Redacted Person]:
caller.msg("You are already married to this person!")
return
target.msg(f"{caller.key} proposes to you! Type 'accept' to marry or 'refuse' to decline.")
caller.msg(f"You propose to {target.key}. Now waiting for their response...")
# Store the proposal temporarily
target.ndb.marriage_proposal = caller
Example: accept Command
python
class CmdAccept(Command):
"""
Accept a marriage proposal.
Usage:
accept
This accepts a pending marriage proposal.
"""
key = "accept"
def func(self):
caller = self.caller
proposer = caller.ndb.marriage_proposal
if not proposer:
caller.msg("You have no marriage proposal to accept.")
return
if caller.db.spouse and proposer in caller.db.spouse:
caller.msg("You are already married to this person!")
return
# Update marriage records
if not isinstance(caller.db.spouse, list):
caller.db.spouse = []
if not isinstance(proposer.db.spouse, list):
proposer.db.spouse = []
caller.db.spouse.append(proposer)
proposer.db.spouse.append(caller)
# Clear the proposal
del caller.ndb.marriage_proposal
# Notify the participants
caller.msg(f"You are now married to {proposer.key}!")
proposer.msg(f"{caller.key} has accepted your proposal. Congratulations, you are now married!")
Example: refuse Command
python
class CmdRefuse(Command):
"""
Refuse a marriage proposal.
Usage:
refuse
This declines a pending marriage proposal.
"""
key = "refuse"
def func(self):
caller = self.caller
proposer = caller.ndb.marriage_proposal
if not proposer:
caller.msg("You have no marriage proposal to refuse.")
return
# Clear the proposal
del caller.ndb.marriage_proposal
# Notify the participants
caller.msg(f"You have refused {proposer.key}'s proposal.")
proposer.msg(f"{caller.key} has refused your marriage proposal.")
Example: divorce Command
python
class CmdDivorce(Command):
"""
Divorce your current spouse.
Usage:
divorce <character>
Example:
divorce [Redacted Person]
"""
key = "divorce"
def func(self):
caller = self.caller
if not self.args:
caller.msg("Who do you want to divorce?")
return
target = caller.search(self.args.strip())
if not target:
return # Error message already handled by `search`
if target not in caller.db.spouse:
caller.msg(f"You are not married to {target.key}.")
return
# Remove the marriage
caller.db.spouse.remove(target)
target.db.spouse.remove(caller)
# Notify the participants
caller.msg(f"You are now divorced from {target.key}.")
target.msg(f"{caller.key} has divorced you.")
4. Add Commands to a Command Set
Create a MarriageCmdSet and add it to your character typeclass.
python
from evennia.commands.cmdset import CmdSet
class MarriageCmdSet(CmdSet):
"""
Command set for marriage commands.
"""
key = "MarriageCmdSet"
def at_cmdset_creation(self):
self.add(CmdPropose())
self.add(CmdAccept())
self.add(CmdRefuse())
self.add(CmdDivorce())
5. Integrate Marriage into Character Typeclass
Ensure your character typeclass includes the MarriageCmdSet and initializes the spouse attribute.
python
from evennia.contrib.rpg.rpsystem.rpsystem import ContribRPCharacter
from typeclasses.commands import MarriageCmdSet
class Character(ContribRPCharacter):
"""
Custom character class with marriage support.
"""
def at_object_creation(self):
super().at_object_creation()
self.db.spouse = []
def at_cmdset_get(self, **kwargs):
super().at_cmdset_get(**kwargs)
self.cmdset.add(MarriageCmdSet)
6. Optional Enhancements
Ceremony Command
Create a command or scripted event for marriage ceremonies. For example, a room description might change to reflect the event, or NPCs could react.
Roleplaying Integration
Leverage the rpsystem contrib to let players emote during proposals and ceremonies:
python
emote /me kneels before /target and says, "Will you marry me?"
Divorce Costs
Add game mechanics such as in-game costs for divorce or penalties for breaking a marriage.
Webclient Integration
Display marriage information on a character’s web profile.
7. Test the System
Test all commands to ensure proper functionality:
Proposals trigger notifications.
Marriages are recorded.
Divorces cleanly remove relationships.
Edge cases (e.g., proposing to yourself or duplicate marriages) are handled.
8. Documentation
Explain the system to players, including how to use commands and any in-game implications of marriage.
By following these steps, you will have implemented a fully functional marriage system for your Evennia game.