Merge pull request #3554 from InspectorCaracal/chargen-bugfix

Fix character creator contrib commands
This commit is contained in:
Griatch 2024-06-14 12:31:50 +02:00 committed by GitHub
commit 9a92c20204
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 6 deletions

View file

@ -7,17 +7,17 @@ Commands for managing and initiating an in-game character-creation menu.
## Installation ## Installation
In your game folder `commands/default_cmdsets.py`, import and add In your game folder `commands/default_cmdsets.py`, import and add
`ContribCmdCharCreate` to your `AccountCmdSet`. `ContribChargenCmdSet` to your `AccountCmdSet`.
Example: Example:
```python ```python
from evennia.contrib.rpg.character_creator.character_creator import ContribCmdCharCreate from evennia.contrib.rpg.character_creator.character_creator import ContribChargenCmdSet
class AccountCmdSet(default_cmds.AccountCmdSet): class AccountCmdSet(default_cmds.AccountCmdSet):
def at_cmdset_creation(self): def at_cmdset_creation(self):
super().at_cmdset_creation() super().at_cmdset_creation()
self.add(ContribCmdCharCreate) self.add(ContribChargenCmdSet)
``` ```
In your game folder `typeclasses/accounts.py`, import and inherit from `ContribChargenAccount` In your game folder `typeclasses/accounts.py`, import and inherit from `ContribChargenAccount`

View file

@ -23,9 +23,11 @@ from django.conf import settings
from evennia import DefaultAccount from evennia import DefaultAccount
from evennia.commands.default.muxcommand import MuxAccountCommand from evennia.commands.default.muxcommand import MuxAccountCommand
from evennia.commands.default.account import CmdIC
from evennia.commands.cmdset import CmdSet
from evennia.objects.models import ObjectDB from evennia.objects.models import ObjectDB
from evennia.utils.evmenu import EvMenu from evennia.utils.evmenu import EvMenu
from evennia.utils.utils import is_iter from evennia.utils.utils import is_iter, string_partial_matching
_MAX_NR_CHARACTERS = settings.MAX_NR_CHARACTERS _MAX_NR_CHARACTERS = settings.MAX_NR_CHARACTERS
@ -35,6 +37,17 @@ except AttributeError:
_CHARGEN_MENU = "evennia.contrib.rpg.character_creator.example_menu" _CHARGEN_MENU = "evennia.contrib.rpg.character_creator.example_menu"
class ContribCmdIC(CmdIC):
def func(self):
if self.args:
# check if the args match an in-progress character
wips = [chara for chara in self.account.characters if chara.db.chargen_step]
if matches := string_partial_matching([c.key for c in wips], self.args):
# the character is in progress, resume creation
return self.execute_cmd("charcreate")
super().func()
class ContribCmdCharCreate(MuxAccountCommand): class ContribCmdCharCreate(MuxAccountCommand):
""" """
create a new character create a new character
@ -87,15 +100,24 @@ class ContribCmdCharCreate(MuxAccountCommand):
char = session.new_char char = session.new_char
if char.db.chargen_step: if char.db.chargen_step:
# this means the character creation process was exited in the middle # this means the character creation process was exited in the middle
account.execute_cmd("look") account.execute_cmd("look", session=session)
else: else:
# this means character creation was completed - start playing! # this means character creation was completed - start playing!
# execute the ic command to start puppeting the character # execute the ic command to start puppeting the character
account.execute_cmd("ic {}".format(char.key)) account.execute_cmd("ic {}".format(char.key), session=session)
EvMenu(session, _CHARGEN_MENU, startnode=startnode, cmd_on_exit=finish_char_callback) EvMenu(session, _CHARGEN_MENU, startnode=startnode, cmd_on_exit=finish_char_callback)
class ContribChargenCmdSet(CmdSet):
key = "Contrib Chargen CmdSet"
def at_cmdset_creation(self):
super().at_cmdset_creation()
self.add(ContribCmdIC)
self.add(ContribCmdCharCreate)
class ContribChargenAccount(DefaultAccount): class ContribChargenAccount(DefaultAccount):
""" """
A modified Account class that changes the OOC look output to better match the contrib and A modified Account class that changes the OOC look output to better match the contrib and