Beispiel #1
0
def basePrompt(player, room):
    """
    Desc: Main game prompt.
    Called by: main game loop
    Notes:
    returns either a room or None. If returning None, all necessary actions are taken within the called function.
    """
    command = None
    while not command:
        commandFull = raw_input(player.showHP() + ">")
        parts = commandFull.lower().split(" ")
        command = parts[0]
        args = parts[1:]
    if command in ("1","2","3","4","enter"):
        if command in ("1","2","3","4"):
            command = int(command)
            return actions.enter(command, room, player)
        elif command == "enter":
            try:
                args = int(args)
                return actions.enter(args, room, player)
            except:
                print "That is not a valid door."
    elif command == "help":
        #need to extend this to look at other commands
        if len(args) == 0:
            actions.ghelp()
        else:
            actions.ghelp(args[0])
        return
    elif command in ("l", "look"):
        if len(args) == 0:
            actions.look(room)
        else:
            actions.examine(player, args[0])
        return
    elif command in ("quit", "exit"):
        actions.quit(player)
        return
    elif command in ("stat","stats","status"):
        actions.status(player)
        return
    elif command == "use":
        if len(args) == 0:
            print "That command requires a target.\n"
        else:
            actions.use(player, args[0])
        return
    elif command in ("i", "inv", "inven", "inventory"):
        actions.inventory(player)
        return
    elif command in ("e", "eq", "equip"):
        if len(args) == 0:
            actions.worn(player)
        else:
            actions.equipCommand(player, args[0])
        return
    elif command == "worn":
        actions.worn(player)
        return
    elif command in ("un", "une", "uneq", "unequip"):
        if len(args) == 0:
            print "That command requires a target.\n"
        else:
            actions.unequipCommand(player, args[0])
        return
    elif command == "get":
        if len(args) == 0:
            print "That command requires a target.\n"
        else:
            actions.get(player, room, args[0])
    elif command == "drop":
        if len(args) == 0:
            print "That command requires a target.\n"
        else:
            actions.drop(player, room, args[0])
    elif command in ("ex", "exam", "examine"):
        if len(args) == 0:
            print "That command requires a target.\n"
        else:
            actions.examine(player, args[0])
    elif command == "set":
        if len(args) == 0:
            actions.set(player)
        elif len(args) == 1:
            print "Set command requires a hotkey and a skill.\n"
        elif len(args) == 2:
            actions.set(player, args[0], args[1])
        else:
            actions.set(player, args[0], args[1], args[2])
    else:
        return
Beispiel #2
0
def main():

    #print ''

    log.setDebug(util.argv(_cmds['Debug']))
    actions.supress(util.argv(_cmds['Supress']))

    args = sys.argv

    if len(args) == 1:
        log.comment(
            "No arguments specified, listing your Gists. Try '%s help' if you need help."
            % util.fileName)
        print('')

    del args[0]  # Delete the filename
    cmd = None

    log.debug("Arguments " + str(args))

    #--------------------------------------------
    # If args[0] is a command. We remove it from the list. args now contains only the  command arguments
    # else we keep as is and try to evaluate the command
    #--------------------------------------------
    if _hasCmd(args):
        cmd = args[0]
        del args[
            0]  # Delete the command. Arguments remaining are the options for each command
    else:
        cmd = _deriveCmd(args)

    log.debug("Adjusted cmd: " + str(cmd))
    log.debug("Adjusted arguments " + str(args))
    #--------------------------------------------
    # Handle commands
    #--------------------------------------------
    if cmd == None:
        _printNoMatch()
    elif cmd in (_cmds['Help']):
        actions.help()
    elif cmd in (_cmds['List']):
        actions.list()
    elif cmd in (_cmds['Token']):
        actions.updateCredentials()
    elif cmd in (_cmds['Open']):
        if len(args) == 1:
            actions.open(args[0])
        else:
            _printNoMatch()
    elif cmd in (_cmds['View']):
        if len(args) == 1:
            actions.view(args[0])
        elif len(args) == 2:
            actions.view(args[0], fileName=args[1])
    elif cmd in (_cmds['Download']):
        if len(args) == 2:
            actions.get(args[0], path=args[1])
        elif len(args) == 3:
            actions.get(args[0], fileName=args[1], path=args[2])
    elif cmd in (_cmds['New']):
        # Each option will prompt for public/pvt and description. In silent mode, assumes private and no description.
        if len(args) == 0:
            actions.new()
        elif len(args) == 1:
            # create File
            # create Content
            if util.isFileOrDir(args[0]) == True:
                actions.new(filename=args[0])
            else:
                actions.new(content=args[0])
        elif len(args) == 2:
            # create Boolean and File
            # create Boolean and Content
            # create Description and File
            # create Description and Content
            if util.parseBool(args[0]) != None:
                if util.isFileOrDir(args[1]) == True:
                    actions.new(public=util.parseBool(args[0]),
                                filename=args[1])
                else:
                    actions.new(public=util.parseBool(args[0]),
                                content=args[1])
            else:
                if util.isFileOrDir(args[1]) == True:
                    actions.new(description=args[0], filename=args[1])
                else:
                    actions.new(description=args[0], content=args[1])
        elif len(args) == 3 and util.parseBool(args[0]) != None:
            # create Boolean, Description and File
            # create Boolean, Description and Content
            if util.isFileOrDir(args[2]) == True:
                actions.new(public=util.parseBool(args[0]),
                            description=args[1],
                            filename=args[2])
            else:
                actions.new(public=util.parseBool(args[0]),
                            description=args[1],
                            content=args[2])
        else:
            _printNoMatch()
    elif cmd in (_cmds['Append']):
        # Each option will prompt for public/pvt and description.
        if len(args) == 0:
            _printNoMatch()
        elif len(args) == 2:
            # append: id File
            # append: id Content
            if util.isFileOrDir(args[1]) == True:
                actions.append(args[0], filename=args[1])
            else:
                actions.append(args[0], content=args[1])
        elif len(args) == 3:
            # append: id Description File
            # append: id Description Content
            if util.isFileOrDir(args[2]) == True:
                actions.append(args[0], description=args[1], filename=args[2])
            else:
                actions.append(args[0], description=args[1], content=args[2])
        else:
            actions.append(args[0])
    elif cmd in (_cmds['Update']):
        # Each option will prompt for public/pvt and description.
        if len(args) == 0:
            _printNoMatch()
        elif len(args) == 2:
            # append: id File
            # append: id Content
            if util.isFileOrDir(args[1]) == True:
                actions.update(args[0], filename=args[1])
            else:
                actions.update(args[0], content=args[1])
        elif len(args) == 3:
            # append: id Description File
            # append: id Description Content
            if util.isFileOrDir(args[2]) == True:
                actions.update(args[0], description=args[1], filename=args[2])
            else:
                actions.update(args[0], description=args[1], content=args[2])
        else:
            actions.update(args[0])
    elif cmd in (_cmds['Delete']):
        actions.delete(args[0])
    elif cmd in (_cmds['Backup']):
        _printNoImpl()
        actions.backup()
    elif cmd in (_cmds['Search']):
        _printNoImpl()
        actions.search()
    else:
        _printNoMatch()

    log.debug("Done.")
    print('')
Beispiel #3
0
def main ( ):

  #print ''

  log.setDebug( util.argv( _cmds['Debug'] ) )
  actions.supress( util.argv( _cmds['Supress']) )

  args = sys.argv
  
  if len(args) == 1:
    log.comment ("No arguments specified, listing your Gists. Try '%s help' if you need help." % util.fileName)
    print ''

  del args[0] # Delete the filename
  cmd = None

  log.debug ("Arguments " + str( args ))

  #--------------------------------------------
  # If args[0] is a command. We remove it from the list. args now contains only the  command arguments
  # else we keep as is and try to evaluate the command
  #--------------------------------------------
  if _hasCmd( args ):
    cmd = args[0]
    del args[0] # Delete the command. Arguments remaining are the options for each command
  else:
    cmd = _deriveCmd( args )

  log.debug ("Adjusted cmd: " + str(cmd))
  log.debug ("Adjusted arguments " + str( args ))
  #--------------------------------------------
  # Handle commands
  #--------------------------------------------
  if cmd == None:
    _printNoMatch()
  elif cmd in (_cmds['Help']):
    actions.help()
  elif cmd in (_cmds['List']):
    actions.list()
  elif cmd in (_cmds['Token']):
    actions.updateCredentials()
  elif cmd in (_cmds['View']):
    if len(args) == 1:
      actions.view( args[0] )
    elif len(args) == 2:
      actions.view( args[0], fileName=args[1])
  elif cmd in (_cmds['Download']):
    if len(args) == 2:
      actions.get( args[0], path=args[1] )
    elif len(args) == 3:
      actions.get( args[0], fileName=args[1], path=args[2] )
  elif cmd in (_cmds['New']):
    # Each option will prompt for public/pvt and description. In silent mode, assumes private and no description.
    if len(args) == 0:
      actions.new()
    elif len(args) == 1:
      # create File
      # create Content
      if util.isFileOrDir(args[0]) == True:
        actions.new( filename = args[0] )
      else:
        actions.new( content = args[0] )
    elif len(args) == 2: 
      # create Boolean and File
      # create Boolean and Content
      # create Description and File 
      # create Description and Content 
      if util.parseBool( args[0] ) != None:
        if util.isFileOrDir(args[1]) == True:
          actions.new( public=util.parseBool( args[0] ), filename=args[1] )
        else:
          actions.new( public=util.parseBool( args[0] ), content=args[1] )
      else:
        if util.isFileOrDir(args[1]) == True:
          actions.new( description=args[0], filename=args[1] )
        else:
          actions.new( description=args[0], content=args[1] )
    elif len(args) == 3 and util.parseBool( args[0] ) != None:
      # create Boolean, Description and File
      # create Boolean, Description and Content
      if util.isFileOrDir(args[2]) == True:
        actions.new( public=util.parseBool( args[0] ), description=args[1], filename=args[2] )
      else:
        actions.new( public=util.parseBool( args[0] ), description=args[1], content=args[2] )
    else:
      _printNoMatch()
  elif cmd in (_cmds['Append']):
    # Each option will prompt for public/pvt and description.
    if len(args) == 0:
      _printNoMatch()
    elif len(args) == 2: 
      # append: id File
      # append: id Content 
      if util.isFileOrDir(args[1]) == True:
        actions.append( args[0], filename=args[1] )
      else:
        actions.append( args[0], content=args[1] )
    elif len(args) == 3:
      # append: id Description File
      # append: id Description Content
      if util.isFileOrDir(args[2]) == True:
        actions.append( args[0], description=args[1], filename=args[2] )
      else:
        actions.append( args[0], description=args[1], content=args[2] )
    else:
      actions.append( args[0] )
  elif cmd in (_cmds['Update']):
    # Each option will prompt for public/pvt and description.
    if len(args) == 0:
      _printNoMatch()
    elif len(args) == 2: 
      # append: id File
      # append: id Content 
      if util.isFileOrDir(args[1]) == True:
        actions.update( args[0], filename=args[1] )
      else:
        actions.update( args[0], content=args[1] )
    elif len(args) == 3:
      # append: id Description File
      # append: id Description Content
      if util.isFileOrDir(args[2]) == True:
        actions.update( args[0], description=args[1], filename=args[2] )
      else:
        actions.update( args[0], description=args[1], content=args[2] )
    else:
      actions.update( args[0] )
  elif cmd in (_cmds['Delete']):
    actions.delete( args[0] )
  elif cmd in (_cmds['Backup']):
    _printNoImpl()
    actions.backup( )
  elif cmd in (_cmds['Search']):
    _printNoImpl()
    actions.search( )
  else:
    _printNoMatch()

  log.debug ("Done.")
  print ''