def send_intro_message(character, combatant=True): """ Displays intro message of combat to character """ if not combatant: msg = fill("{mYou are now in observer mode for a fight. {n" + "Most combat commands will not function. To " + "join the fight, use the {w+fight{n command.") else: msg = "{rEntering combat mode.{n\n" msg += "\n\n" + fill(COMBAT_INTRO) character.msg(msg) return
def format_help_entry(title, help_text, aliases=None, suggested=None): """ This visually formats the help entry. This method can be overriden to customize the way a help entry is displayed. Args: title (str): the title of the help entry. help_text (str): the text of the help entry. aliases (list of str or None): the list of aliases. suggested (list of str or None): suggested reading. Returns the formatted string, ready to be sent. """ string = _SEP + "\n" if title: string += "|CHelp for |w%s|n" % title if aliases: string += " |C(aliases: %s|C)|n" % ("|C,|n ".join("|w%s|n" % ali for ali in aliases)) if help_text: string += "\n%s" % dedent(help_text.rstrip()) if suggested: string += "\n\n|CSuggested:|n " string += "%s" % fill("|C,|n ".join("|w%s|n" % sug for sug in suggested)) string.strip() string += "\n" + _SEP return string
def render_examine_commands(self, viewer, avail_cmdset, styling): if not (len(self.obj.cmdset.all()) == 1 and self.obj.cmdset.current.key == "_EMPTY_CMDSET"): # all() returns a 'stack', so make a copy to sort. stored_cmdsets = sorted(self.obj.cmdset.all(), key=lambda x: x.priority, reverse=True) string = "|wStored Cmdset(s)|n:\n %s" % ("\n ".join( "%s [%s] (%s, prio %s)" % (cmdset.path, cmdset.key, cmdset.mergetype, cmdset.priority) for cmdset in stored_cmdsets if cmdset.key != "_EMPTY_CMDSET")) # this gets all components of the currently merged set all_cmdsets = [(cmdset.key, cmdset) for cmdset in avail_cmdset.merged_from] # we always at least try to add account- and session sets since these are ignored # if we merge on the object level. if hasattr(self, "account") and self.obj.account: all_cmdsets.extend([ (cmdset.key, cmdset) for cmdset in self.obj.account.cmdset.all() ]) if self.obj.sessions.count(): # if there are more sessions than one on objdb it's because of multisession mode 3. # we only show the first session's cmdset here (it is -in principle- possible that # different sessions have different cmdsets but for admins who want such madness # it is better that they overload with their own CmdExamine to handle it). all_cmdsets.extend([ (cmdset.key, cmdset) for cmdset in self.obj.account.sessions.all()[0].cmdset.all() ]) else: try: # we have to protect this since many objdb don't have sessions. all_cmdsets.extend([ (cmdset.key, cmdset) for cmdset in self.obj.get_session( self.obj.sessions.get()).cmdset.all() ]) except (TypeError, AttributeError): # an error means we are merging an object without a session pass all_cmdsets = [cmdset for cmdset in dict(all_cmdsets).values()] all_cmdsets.sort(key=lambda x: x.priority, reverse=True) string += "\n|wMerged Cmdset(s)|n:\n %s" % ("\n ".join( "%s [%s] (%s, prio %s)" % (cmdset.path, cmdset.key, cmdset.mergetype, cmdset.priority) for cmdset in all_cmdsets)) # list the commands available to this object avail_cmdset = sorted( [cmd.key for cmd in avail_cmdset if cmd.access(self, "cmd")]) cmdsetstr = utils.fill(", ".join(avail_cmdset), indent=2) string += "\n|wCommands available to %s (result of Merged CmdSets)|n:\n %s" % ( self.obj.key, cmdsetstr, ) return [styling.styled_separator("Commands"), string ] if string else []
def func(self): """ This is the hook function that actually does all the work. It is called by the cmdhandler right after self.parser() finishes, and so has access to all the variables defined therein. """ # a simple test command to show the available properties string = "-" * 50 string += "\n{w%s{n - Command variables from evennia:\n" % self.key string += "-" * 50 string += "\nname of cmd (self.key): {w%s{n\n" % self.key string += "cmd aliases (self.aliases): {w%s{n\n" % self.aliases string += "cmd locks (self.locks): {w%s{n\n" % self.locks string += "help category (self.help_category): {w%s{n\n" % self.help_category string += "object calling (self.caller): {w%s{n\n" % self.caller string += "object storing cmdset (self.obj): {w%s{n\n" % self.obj string += "command string given (self.cmdstring): {w%s{n\n" % self.cmdstring # show cmdset.key instead of cmdset to shorten output string += utils.fill("current cmdset (self.cmdset): {w%s{n\n" % self.cmdset) string += "\n" + "-" * 50 string += "\nVariables from MuxCommand baseclass\n" string += "-" * 50 string += "\nraw argument (self.raw): {w%s{n \n" % self.raw string += "cmd args (self.args): {w%s{n\n" % self.args string += "cmd switches (self.switches): {w%s{n\n" % self.switches string += "space-separated arg list (self.arglist): {w%s{n\n" % self.arglist string += "lhs, left-hand side of '=' (self.lhs): {w%s{n\n" % self.lhs string += "lhs, comma separated (self.lhslist): {w%s{n\n" % self.lhslist string += "rhs, right-hand side of '=' (self.rhs): {w%s{n\n" % self.rhs string += "rhs, comma separated (self.rhslist): {w%s{n\n" % self.rhslist string += "-" * 50 self.caller.msg(string)
def func(self): """ This is the actual executing part of the command. It is called directly after self.parse(). See the docstring of this module for which object properties are available (beyond those set in self.parse()) """ variables = '\n'.join(" |w{}|n ({}): {}".format(key, type(val), val) for key, val in self.__dict__.items()) string = f""" Command {self} has no defined `func()` - showing on-command variables: {variables} """ self.caller.msg(string) return # a simple test command to show the available properties string = "-" * 50 string += "\n|w%s|n - Command variables from evennia:\n" % self.key string += "-" * 50 string += "\nname of cmd (self.key): |w%s|n\n" % self.key string += "cmd aliases (self.aliases): |w%s|n\n" % self.aliases string += "cmd locks (self.locks): |w%s|n\n" % self.locks string += "help category (self.help_category): |w%s|n\n" % self.help_category.capitalize() string += "object calling (self.caller): |w%s|n\n" % self.caller string += "object storing cmdset (self.obj): |w%s|n\n" % self.obj string += "command string given (self.cmdstring): |w%s|n\n" % self.cmdstring # show cmdset.key instead of cmdset to shorten output string += fill("current cmdset (self.cmdset): |w%s|n\n" % (self.cmdset.key if self.cmdset.key else self.cmdset.__class__)) self.caller.msg(string)
def func(self): """ This is the actual executing part of the command. It is called directly after self.parse(). See the docstring of this module for which object properties are available (beyond those set in self.parse()) """ # a simple test command to show the available properties string = "-" * 50 string += "\n{w%s{n - Command variables from evennia:\n" % self.key string += "-" * 50 string += "\nname of cmd (self.key): {w%s{n\n" % self.key string += "cmd aliases (self.aliases): {w%s{n\n" % self.aliases string += "cmd locks (self.locks): {w%s{n\n" % self.locks string += "help category (self.help_category): {w%s{n\n" % self.help_category.capitalize() string += "object calling (self.caller): {w%s{n\n" % self.caller string += "object storing cmdset (self.obj): {w%s{n\n" % self.obj string += "command string given (self.cmdstring): {w%s{n\n" % self.cmdstring # show cmdset.key instead of cmdset to shorten output string += fill( "current cmdset (self.cmdset): {w%s{n\n" % (self.cmdset.key if self.cmdset.key else self.cmdset.__class__) ) self.caller.msg(string)
def format_help_entry(title, help_text, aliases=None, suggested=None, unavailable=False, related_tags=None): """ This visually formats the help entry. """ string = SEP + "\n" if title: string += "{CHelp topic for {w%s{n" % title if aliases: string += " {C(aliases: {w%s{n{C){n" % (", ".join(aliases)) if unavailable: string += "\n{rThis command is not presently available to you.{n" if help_text: string += "\n%s" % dedent(help_text.rstrip()) if related_tags: entries = (HelpEntry.objects.exclude(db_key=title).filter( db_tags__db_key__in=related_tags).distinct().values_list( 'db_key', flat=True)) string += "\n\n{CRelated help entries: {w%s" % ", ".join(entries) if suggested: string += "\n\n{CSuggested:{n " string += "{w%s{n" % fill(", ".join(suggested)) string.strip() string += "\n" + SEP return string
def format_help_entry(title, help_text, aliases=None, suggested=None): """ This visually formats the help entry. This method can be overriden to customize the way a help entry is displayed. Args: title (str): the title of the help entry. help_text (str): the text of the help entry. aliases (list of str or None): the list of aliases. suggested (list of str or None): suggested reading. Returns the formatted string, ready to be sent. """ string = _SEP + "\n" if title: string += "|CHelp for |w%s|n" % title if aliases: string += " |C(aliases: %s|C)|n" % ("|C,|n ".join( "|w%s|n" % ali for ali in aliases)) if help_text: string += "\n%s" % dedent(help_text.rstrip()) if suggested: string += "\n\n|CSuggested:|n " string += "%s" % fill("|C,|n ".join("|w%s|n" % sug for sug in suggested)) string.strip() string += "\n" + _SEP return string
def get_command_info(self): """ This is the default output of func() if no func() overload is done. Provided here as a separate method so that it can be called for debugging purposes when making commands. """ variables = "\n".join( " |w{}|n ({}): {}".format(key, type(val), val) for key, val in self.__dict__.items() ) string = f""" Command {self} has no defined `func()` - showing on-command variables: {variables} """ # a simple test command to show the available properties string += "-" * 50 string += "\n|w%s|n - Command variables from evennia:\n" % self.key string += "-" * 50 string += "\nname of cmd (self.key): |w%s|n\n" % self.key string += "cmd aliases (self.aliases): |w%s|n\n" % self.aliases string += "cmd locks (self.locks): |w%s|n\n" % self.locks string += "help category (self.help_category): |w%s|n\n" % self.help_category.capitalize() string += "object calling (self.caller): |w%s|n\n" % self.caller string += "object storing cmdset (self.obj): |w%s|n\n" % self.obj string += "command string given (self.cmdstring): |w%s|n\n" % self.cmdstring # show cmdset.key instead of cmdset to shorten output string += fill( "current cmdset (self.cmdset): |w%s|n\n" % (self.cmdset.key if self.cmdset.key else self.cmdset.__class__) ) self.caller.msg(string)
def func(self): """ This is the actual executing part of the command. It is called directly after self.parse(). See the docstring of this module for which object properties are available (beyond those set in self.parse()) """ # a simple test command to show the available properties string = "-" * 50 string += "\n|w%s|n - Command variables from evennia:\n" % self.key string += "-" * 50 string += "\nname of cmd (self.key): |w%s|n\n" % self.key string += "cmd aliases (self.aliases): |w%s|n\n" % self.aliases string += "cmd locks (self.locks): |w%s|n\n" % self.locks string += "help category (self.help_category): |w%s|n\n" % self.help_category.capitalize( ) string += "object calling (self.caller): |w%s|n\n" % self.caller string += "object storing cmdset (self.obj): |w%s|n\n" % self.obj string += "command string given (self.cmdstring): |w%s|n\n" % self.cmdstring # show cmdset.key instead of cmdset to shorten output string += fill( "current cmdset (self.cmdset): |w%s|n\n" % (self.cmdset.key if self.cmdset.key else self.cmdset.__class__)) self.caller.msg(string)
def format_help_list(hdict_cmds, hdict_db): """ Output a category-ordered list. The input are the pre-loaded help files for commands and database-helpfiles resectively. """ string = "" if hdict_cmds and any(hdict_cmds.values()): string += "\n" + _SEP + "\n {CCommand help entries{n\n" + _SEP for category in sorted(hdict_cmds.keys()): string += "\n {w%s{n:\n" % (str(category).title()) string += "{G" + fill(", ".join(sorted(hdict_cmds[category]))) + "{n" if hdict_db and any(hdict_db.values()): string += "\n\n" + _SEP + "\n\r {COther help entries{n\n" + _SEP for category in sorted(hdict_db.keys()): string += "\n\r {w%s{n:\n" % (str(category).title()) string += "{G" + fill(", ".join(sorted([str(topic) for topic in hdict_db[category]]))) + "{n" return string
def render_examine_tags(self, viewer, cmdset, styling): tags_string = utils.fill( ", ".join("%s[%s]" % (tag, category) for tag, category in self.obj.tags.all( return_key_and_category=True)), indent=5, ) if tags_string: return [f"|wTags[category]|n: {tags_string.strip()}"] return list()
def format_help_list(hdict_cmds, hdict_db): """ Output a category-ordered list. The input are the pre-loaded help files for commands and database-helpfiles respectively. You can override this method to return a custom display of the list of commands and topics. """ string = "" if hdict_cmds and any(hdict_cmds.values()): string += "\n" + _SEP + "\n |CCommand help entries|n\n" + _SEP for category in sorted(hdict_cmds.keys()): string += "\n |w%s|n:\n" % (str(category).title()) string += "|G" + fill("|C, |G".join(sorted(hdict_cmds[category]))) + "|n" if hdict_db and any(hdict_db.values()): string += "\n\n" + _SEP + "\n\r |COther help entries|n\n" + _SEP for category in sorted(hdict_db.keys()): string += "\n\r |w%s|n:\n" % (str(category).title()) string += "|G" + fill(", ".join(sorted([str(topic) for topic in hdict_db[category]]))) + "|n" return string
def render_examine_access(self, viewer, cmdset, styling): locks = str(self.obj.locks) if locks: locks_string = utils.fill("; ".join( [lock for lock in locks.split(";")]), indent=6) else: locks_string = " Default" message = [ styling.styled_separator("Access"), f"|wPermissions|n: {', '.join(perms) if (perms := self.obj.permissions.all()) else '<None>'}", f"|wLocks|n:{locks_string}" ] return message
def format_help_entry(title, help_text, aliases=None, suggested=None): """ This visually formats the help entry. """ string = _SEP + "\n" if title: string += "{CHelp for {w%s{n" % title if aliases: string += " {C(aliases: %s{C){n" % ("{C,{n ".join("{w%s{n" % ali for ali in aliases)) if help_text: string += "\n%s" % dedent(help_text.rstrip()) if suggested: string += "\n\n{CSuggested:{n " string += "%s" % fill("{C,{n ".join("{w%s{n" % sug for sug in suggested)) string.strip() string += "\n" + _SEP return string
def func(self): """ This is the hook function that actually does all the work. It is called by the cmdhandler right after self.parser() finishes, and so has access to all the variables defined therein. """ variables = "\n".join( " |w{}|n ({}): {}".format(key, type(val), val) for key, val in self.__dict__.items() ) string = f""" Command {self} has no defined `func()` - showing on-command variables: No child func() defined for {self} - available variables: {variables} """ self.caller.msg(string) # a simple test command to show the available properties string = "-" * 50 string += "\n|w%s|n - Command variables from evennia:\n" % self.key string += "-" * 50 string += "\nname of cmd (self.key): |w%s|n\n" % self.key string += "cmd aliases (self.aliases): |w%s|n\n" % self.aliases string += "cmd locks (self.locks): |w%s|n\n" % self.locks string += "help category (self.help_category): |w%s|n\n" % self.help_category string += "object calling (self.caller): |w%s|n\n" % self.caller string += "object storing cmdset (self.obj): |w%s|n\n" % self.obj string += "command string given (self.cmdstring): |w%s|n\n" % self.cmdstring # show cmdset.key instead of cmdset to shorten output string += utils.fill("current cmdset (self.cmdset): |w%s|n\n" % self.cmdset) string += "\n" + "-" * 50 string += "\nVariables from MuxCommand baseclass\n" string += "-" * 50 string += "\nraw argument (self.raw): |w%s|n \n" % self.raw string += "cmd args (self.args): |w%s|n\n" % self.args string += "cmd switches (self.switches): |w%s|n\n" % self.switches string += "cmd options (self.switch_options): |w%s|n\n" % self.switch_options string += "cmd parse left/right using (self.rhs_split): |w%s|n\n" % self.rhs_split string += "space-separated arg list (self.arglist): |w%s|n\n" % self.arglist string += "lhs, left-hand side of '=' (self.lhs): |w%s|n\n" % self.lhs string += "lhs, comma separated (self.lhslist): |w%s|n\n" % self.lhslist string += "rhs, right-hand side of '=' (self.rhs): |w%s|n\n" % self.rhs string += "rhs, comma separated (self.rhslist): |w%s|n\n" % self.rhslist string += "-" * 50 self.caller.msg(string)
def format_help_list(hdict_cmds, hdict_db, viewer): """ Output a category-ordered list. The input are the pre-loaded help files for commands and database-helpfiles resectively. """ string = list() if hdict_cmds and any(hdict_cmds.values()): string.append(viewer.player.render.header('Command Help Entries')) help_table = viewer.player.render.make_table(["Category", "Files"], width=[16, 62], border='cells') for category in sorted(hdict_cmds.keys()): help_table.add_row('|w' + str(category).title() + '|n', ", ".join(sorted(hdict_cmds[category]))) string.append(help_table) if hdict_db and any(hdict_db.values()): string.append(viewer.player.render.header('Other Help Entries')) other_table = viewer.player.render.make_table(["Category", "Files"], width=[16, 62], border='cells') for category in sorted(hdict_db.keys()): other_table.add('|w' + str(category).title() + '|n', "{G" + fill(", ".join(sorted([str(topic) for topic in hdict_db[category]]))) + "{n") string.append(other_table) return '\n'.join(unicode(line) for line in string)
def format_help_entry(title, help_text, aliases=None, suggested=None, unavailable=False): """ This visually formats the help entry. """ string = SEP + "\n" if title: string += "{CHelp topic for {w%s{n" % title if aliases: string += " {C(aliases: {w%s{n{C){n" % (", ".join(aliases)) if unavailable: string += "\n{rThis command is not presently available to you.{n" if help_text: string += "\n%s" % dedent(help_text.rstrip()) if suggested: string += "\n\n{CSuggested:{n " string += "{w%s{n" % fill(", ".join(suggested)) string.strip() string += "\n" + SEP return string