Advertisement
chainsol

Untitled

Jun 12th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.54 KB | None | 0 0
  1. from evennia.commands.default.muxcommand import MuxCommand
  2. from evennia.utils.evmenu import EvMenu
  3.  
  4. # Following this are the menu nodes. EvMenu
  5. # imports all these as nodes, so be careful
  6. # what functions you put here
  7. def node_get_1(caller):
  8.     # This is the first node called by EvMenu.
  9.     # It just sets a prompt, and since the only
  10.     # command is _default, it just passes that
  11.     # to the next node.
  12.     text = "Please enter first description:\n"
  13.     options = ({'key': '_default',
  14.         'goto': 'node_get_2'},) # goto tells EvMenu where to go next
  15.  
  16.     return text, options # call signature - every function for an
  17.                          # evmenu has to return text, options
  18.  
  19. def node_get_2(caller, raw_string):
  20.     # each node is passed the text entered
  21.     # via raw_string. technically we should use
  22.     # raw_string.strip()
  23.     # _menutree is set by EvMenu on the caller.
  24.     # use it to store info you need through the menu
  25.     # it deletes itself after
  26.     caller.ndb._menutree.desc1 = raw_string
  27.     text = "Please enter second description:\n"
  28.     options = ({'key': '_default',
  29.         'goto': 'node_get_3'},)
  30.     return text, options
  31.  
  32. def node_get_3(caller, raw_string):
  33.     caller.ndb._menutree.desc2 = raw_string
  34.     text = "Please enter third description:\n"
  35.     options = ({'key': '_default',
  36.         'goto': 'node_final'},)
  37.     return text, options
  38.  
  39. def node_final(caller, raw_string):
  40.     # final node, lots going on here
  41.  
  42.     # first we pull our descriptions out of the _menutree
  43.     desc1 = caller.ndb._menutree.desc1
  44.     desc2 = caller.ndb._menutree.desc2
  45.     # we're passed a final string from the last node
  46.     desc3 = raw_string
  47.  
  48.     # in our initialization of EvMenu, we added these arguments.
  49.     # EvMenu stores this info in _menutree automagically.
  50.     player_a = caller.ndb._menutree.player_a
  51.     player_b = caller.ndb._menutree.player_b
  52.  
  53.     # past here, do as you will with the data. this is an example
  54.     player_a.msg(desc1)
  55.     player_b.msg(desc2)
  56.  
  57.     # so here, we could just use caller.location.msg, or you could uncomment the confusing generator.
  58.     # up to you
  59.     """
  60.    players = [con for con in caller.location.contents if con.has_player]
  61.    for player in players:
  62.        player.msg(desc3)
  63.    """
  64.     caller.location.msg_contents(desc3, exclude=[player_a, player_b])
  65.  
  66.     text = "Successfully completed spell!"
  67.     return text, None
  68.  
  69. class CmdSpell(MuxCommand):
  70.     """
  71.    Cast a Spell
  72.  
  73.    Usage:
  74.         +spell [target-1] [target-2]
  75.    """
  76.     key = "+spell"
  77.     locks = "cmd:all()"
  78.  
  79.     def func(self):
  80.         if not self.args:
  81.             self.msg("You must provide a target for your spell.")
  82.             return
  83.         if ' ' in self.args:
  84.             arg1, arg2 = self.args.split(' ', 1)
  85.             playerA = self.caller.search(arg1)
  86.             playerB = self.caller.search(arg2)
  87.  
  88.             # just in case we don't get a player target, we return if so
  89.             if not playerA or not playerB:
  90.                 self.caller.msg("Couldn't find those players")
  91.                 return
  92.             # this calls EvMenu with our menu. It imports from the
  93.             # module we give it, in this case, our own module.
  94.             # in practice you should store your menus somewhere else.
  95.             EvMenu(self.caller, 'commands.spells',
  96.                    startnode='node_get_1', # this is the initial node
  97.                    player_a=playerA, # any data we give as kwargs is passed
  98.                    player_b=playerB) # to the menu in caller.ndb._menutree
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement