def open(self, obj): if not obj.loot: print("The {} is empty!".format(obj.name.title())) return #col_padding = max(len(i.name) for i in obj.loot) print("\t\t***** CONTENTS *****") for item in obj.loot: print('\t\t{}'.format(item.name)) item_names = input("What items do you take? ".lower().split(',')) items_to_take = ( getobj_by_name_or_hotkey(name, obj.loot) for name in item_names) for i in items_to_take: if i is not None: self.add_to_inventory(i) obj.loot.remove(i)
def parse_input(self, playercmd): # Parse player input, returning an action object or None mo = cmdregex.match(playercmd) if not mo: return None cmd, target = map(lambda x: re.sub('\s+', ' ', x), mo.groups() ) # ID cmd and target, stripping whitespace cmd = cmd.strip() target = target.strip() # TODO: define a remove_whitespace func...pass cmd and target into it. action = actionsdict.get(cmd) # Will always match, since a mo was found. ##MOVEMENT## if action.__name__ == 'ViewInventory': return action() # This is ALWAYS a valid action if action.__name__.startswith('Move'): return action() if action() in self.valid_movements else None # Else: it's a targetting action if action in (adventureactions.Inspect, adventureactions.PickUp, adventureactions.Open): context = self.player.current_location.objects elif action in (adventureactions.Equip, adventureactions.Use): context = self.player.inventory criteria = action.criteria item = getobj_by_name_or_hotkey(target, context, criteria) # Retrieve item if not item: print('{} is not an item in your CONTEXT'.format(target)) return None return action(item)