def try_drop(player): chosen_item = inventory_menu( player, 'Press the key next to an item to drop it, x to examine, or any other to cancel.\n') if chosen_item is not None: actions.drop(player, chosen_item.owner) return True return False
def monster_death(monster): # Transform it into a nasty corpse! it doesn't block, can't be # attacked, and doesn't move. log.message( 'The ' + monster.name + ' is dead!', libtcod.orange) monster.char = '%' monster.color = libtcod.dark_red monster.blocks = False monster.fighter = None monster.ai = None if hasattr(monster, 'inventory'): while len(monster.inventory) > 0: # Might be nice to report what's dropped; even though we # have drop-all, we can't suppress unequip reporting while # still reporting dropping. actions.drop(monster, monster.inventory[0], report=False, drop_all=True) monster.name = 'remains of ' + monster.name monster.current_map.objects.remove(monster) monster.current_map.objects.insert(0, monster)
def monster_death(monster): # Transform it into a nasty corpse! it doesn't block, can't be # attacked, and doesn't move. log.message('The ' + monster.name + ' is dead!', libtcod.orange) monster.char = '%' monster.color = libtcod.dark_red monster.blocks = False monster.fighter = None monster.ai = None if hasattr(monster, 'inventory'): while len(monster.inventory) > 0: # Might be nice to report what's dropped; even though we # have drop-all, we can't suppress unequip reporting while # still reporting dropping. actions.drop(monster, monster.inventory[0], report=False, drop_all=True) monster.name = 'remains of ' + monster.name monster.current_map.objects.remove(monster) monster.current_map.objects.insert(0, monster)
def parse_args(user_input, player): """ Args: user_input (string): raw string of user input player (Player object): object of active player """ # Accounting for null input if user_input.strip() == "": print(random.choice(CONFUSED_RESPONSES)) return # Split string into list of strings (separated by spaces) list_of_input = user_input.split() # Splitting command into a verb and its following argument command = list_of_input[0].lower() if len(list_of_input) > 1: arguments = [x.lower() for x in list_of_input[1:]] # Formatting each argument if command == "pick" and arguments[0] == "up": if len(arguments) > 1: actions.pick_up(player, "".join(arguments[1:]), " ".join(arguments[1:])) else: print("What do you want to pick up?") return elif command == "use" and ("on" in arguments): # Deals with "use ___ on ___ " input actions.use_on(arguments, player) return elif command == "interact" and (arguments[0] == "with"): # Deals with "interact with _____ " input if len(arguments) < 2: # If user just says "interact with" print("Specify what you'd like to interact with.") else: actions.interact_with(arguments[1:], player) return raw_argument = " ".join(list_of_input[1:]) # Here's the raw argument argument = (" ".join(arguments)) # Turning into name format. else: argument = "" raw_argument = "" if command == "go" or command == "move": actions.move(argument, player) elif command in ["east", "west", "north", "south"]: actions.move(command, player) elif command == "observe" and argument == "" or command == "look" and (argument == "around" or argument == ""): actions.examine_surroundings(player) elif command == "inventory" or (command == "view" and argument == "inventory") or (command == "i" and argument==""): actions.print_inventory(player) elif command == "where" and argument == "am i" or (command == "location" and argument == ""): actions.where(player) elif command == "drop": actions.drop(player, argument, raw_argument) elif command == "grab" or command == "take" or command == "get": actions.pick_up(player, argument, raw_argument) elif command == "examine": actions.examine(player, arguments, raw_argument) elif command == "enter": actions.enter(player, argument, raw_argument) elif (command == "kill" and argument == "myself") or (command == "kms"): actions.kill_player(player) elif command == "drink": actions.drink(player, argument, raw_argument) elif command == "eat": actions.eat(player, argument, raw_argument) elif command == "uuddlrlrbastart": # Konami code print("Nice try, bud.") else: print(random.choice(CONFUSED_RESPONSES)) return
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
def command(cmd): """Send a command to the server. .. Keyword Arguments: :param: cmd: String with the command. .. Types: :type: cmd: A string. """ resp = None args = {} cmd_splitted = cmd.split() action = cmd_splitted[0] cmd_rest = cmd_splitted[1:] print_key = None ################ navigatement begin ############ if action == "w": resp = navigate.up() elif action == "e": resp = navigate.right_up() elif action == "a": resp = navigate.left() elif action == "s": resp = navigate.down() elif action == "d": resp = navigate.right() elif action == "q": resp = navigate.left_up() elif action == "z": resp = navigate.left_down() elif action == "c": resp = navigate.right_down() ################ navigatement end ############ elif action == "p" or action == "pickup": resp = actions.pickup() elif action == "l" or action == "drop": if len(cmd_rest) < 1: print("Missing thing to drop") else: thingid = cmd_rest[0] resp = actions.drop(thingid) elif action == "reset": resp = actions.reset() elif action == "scan": resp = scan.scan() if len(cmd_rest) >= 1: print_key = cmd_rest[0] else: print("Unknown command") if resp is None: print("Error with command.") return 1 if print_key: resp = resp['payload'] if print_key in resp: pprint(resp[print_key]) else: print("Selected key %s does not exists" % print_key) else: pprint(resp) return 0