From ff3ae5ccfc662403dcb3a2b588126f3f5fb91580 Mon Sep 17 00:00:00 2001 From: InspectorCaracal <51038201+InspectorCaracal@users.noreply.github.com> Date: Sun, 2 Jun 2024 16:31:20 -0600 Subject: [PATCH 1/2] add session to account execute_cmd --- evennia/contrib/rpg/character_creator/character_creator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/evennia/contrib/rpg/character_creator/character_creator.py b/evennia/contrib/rpg/character_creator/character_creator.py index 7fae70332d..a51b3273f2 100644 --- a/evennia/contrib/rpg/character_creator/character_creator.py +++ b/evennia/contrib/rpg/character_creator/character_creator.py @@ -87,11 +87,11 @@ class ContribCmdCharCreate(MuxAccountCommand): char = session.new_char if char.db.chargen_step: # this means the character creation process was exited in the middle - account.execute_cmd("look") + account.execute_cmd("look", session=session) else: # this means character creation was completed - start playing! # 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) From ee92c3fd86d2ea89f27f1fb0455831b656f7e781 Mon Sep 17 00:00:00 2001 From: Cal Date: Sun, 2 Jun 2024 17:06:09 -0600 Subject: [PATCH 2/2] catch WIP characters in IC command --- .../contrib/rpg/character_creator/README.md | 6 ++--- .../character_creator/character_creator.py | 24 ++++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/evennia/contrib/rpg/character_creator/README.md b/evennia/contrib/rpg/character_creator/README.md index 1d7b4d3739..e3249281bd 100644 --- a/evennia/contrib/rpg/character_creator/README.md +++ b/evennia/contrib/rpg/character_creator/README.md @@ -7,17 +7,17 @@ Commands for managing and initiating an in-game character-creation menu. ## Installation In your game folder `commands/default_cmdsets.py`, import and add -`ContribCmdCharCreate` to your `AccountCmdSet`. +`ContribChargenCmdSet` to your `AccountCmdSet`. Example: ```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): def at_cmdset_creation(self): super().at_cmdset_creation() - self.add(ContribCmdCharCreate) + self.add(ContribChargenCmdSet) ``` In your game folder `typeclasses/accounts.py`, import and inherit from `ContribChargenAccount` diff --git a/evennia/contrib/rpg/character_creator/character_creator.py b/evennia/contrib/rpg/character_creator/character_creator.py index a51b3273f2..189c5d4a47 100644 --- a/evennia/contrib/rpg/character_creator/character_creator.py +++ b/evennia/contrib/rpg/character_creator/character_creator.py @@ -23,9 +23,11 @@ from django.conf import settings from evennia import DefaultAccount 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.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 @@ -35,6 +37,17 @@ except AttributeError: _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): """ create a new character @@ -96,6 +109,15 @@ class ContribCmdCharCreate(MuxAccountCommand): 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): """ A modified Account class that makes minor changes to the OOC look