Creating a marriage system for characters would involve several steps:
Database Setup: The first step is to set up your database to store information about the marriages. You can add a new model to your database that stores information about each marriage, such as the two characters involved, the date of the marriage, and any other relevant details.
python
from django.db import models
from evennia.typeclasses.models import TypedObject
class Marriage(TypedObject):
partner1 = models.ForeignKey('objects.ObjectDB', on_delete=models.CASCADE, related_name='partner1')
partner2 = models.ForeignKey('objects.ObjectDB', on_delete=models.CASCADE, related_name='partner2')
date = models.DateTimeField(auto_now_add=True)
code
2. **Commands:** Next, you'll need to create commands that allow characters to propose, accept proposals, and divorce. These commands would check the status of the characters involved and update the database accordingly.
```python
from evennia import Command
class CmdPropose(Command):
key = "propose"
def func(self):
# Get the target of the proposal
target = self.caller.search(self.args)
if not target:
self.caller.msg("You must specify a target.")
return
# Check if the target is already married
if Marriage.objects.filter(partner1=target).exists() or Marriage.objects.filter(partner2=target).exists():
self.caller.msg("They are already married.")
return
# Check if the caller is already married
if Marriage.objects.filter(partner1=self.caller).exists() or Marriage.objects.filter(partner2=self.caller).exists():
self.caller.msg("You are already married.")
return
# Create a proposal
self.caller.msg("You propose to %s." % target)
target.msg("%s has proposed to you. Type 'accept' to accept or 'decline' to decline." % self.caller)
class CmdAccept(Command):
key = "accept"
def func(self):
# Get the caller's current proposal
proposal = self.caller.ndb.proposal
if not proposal:
self.caller.msg("You have no proposal to accept.")
return
# Create a new marriage
Marriage.objects.create(partner1=self.caller, partner2=proposal)
self.caller.msg("You have accepted the proposal and are now married.")
proposal.msg("They have accepted your proposal and you are now married.")
class CmdDivorce(Command):
key = "divorce"
def func(self):
# Get the caller's current marriage
marriage = Marriage.objects.filter(partner1=self.caller).first() or Marriage.objects.filter(partner2=self.caller).first()
if not marriage:
self.caller.msg("You are not married.")
return
# Remove the marriage
marriage.delete()
self.caller.msg("You are now divorced.")
Checks: You'll also want to add checks to prevent characters from marrying themselves, marrying someone who is already married, or divorcing someone they are not married to.
Messages: Finally, you'll want to add messages to let the characters know what is happening. For example, when a character proposes, the other character should receive a message asking them to accept or decline. When a character accepts a proposal, both characters should receive a message letting them know that they are now married.
Here's an example of how you could implement this system:
python
from evennia import Command, DefaultCharacter
from evennia.utils import create
class MarriageHandler:
def __init__(self, obj):
self.obj = obj
def propose(self, target):
# Check if the target is already married
if Marriage.objects.filter(partner1=target).exists() or Marriage.objects.filter(partner2=target).exists():
self.obj.msg("They are already married.")
return
# Check if the caller is already married
if Marriage.objects.filter(partner1=self.obj).exists() or Marriage.objects.filter(partner2=self.obj).exists():
self.obj.msg("You are already married.")
return
# Create a proposal
self.obj.msg("You propose to %s." % target)
target.msg("%s has proposed to you. Type 'accept' to accept or 'decline' to decline." % self.obj)
target.ndb.proposal = self.obj
def accept_proposal(self):
# Get the caller's current proposal
proposal = self.obj.ndb.proposal
if not proposal:
self.obj.msg("You have no proposal to accept.")
return
# Create a new marriage
Marriage.objects.create(partner1=self.obj, partner2=proposal)
self.obj.msg("You have accepted the proposal and are now married.")
proposal.msg("They have accepted your proposal and you are now married.")
def divorce(self):
# Get the caller's current marriage
marriage = Marriage.objects.filter(partner1=self.obj).first() or Marriage.objects.filter(partner2=self.obj).first()
if not marriage:
self.obj.msg("You are not married.")
return
# Remove the marriage
marriage.delete()
self.obj.msg("You are now divorced.")
class Character(DefaultCharacter):
@[Redacted Person]
def marriage(self):
return MarriageHandler(self)
class CmdPropose(Command):
key = "propose"
def func(self):
# Get the target of the proposal
target = self.caller.search(self.args)
if not target:
self.caller.msg("You must specify a target.")
return
self.caller.marriage.propose(target)
class CmdAccept(Command):
key = "accept"
def func(self):
self.caller.marriage.accept_proposal()
class CmdDivorce(Command):
key = "divorce"
def func(self):
self.caller.marriage.divorce()