def execute(self, player, args): players = db.find_all(lambda x: isinstance(x, db.Player) and x.connected) player.send("{number} {playersare} connected: {players}.".format( number=len(players), playersare="player is" if len(players) == 1 else "players are", players=utils.comma_and(map(str, list(players)))))
def execute(self, player, args): players = db.find_all( lambda x: isinstance(x, db.Player) and x.connected) player.send("{number} {playersare} connected: {players}.".format( number=len(players), playersare="player is" if len(players) == 1 else "players are", players=utils.comma_and(map(str, list(players)))))
def equipment_string(self): equipment = find_all(lambda x: x.location == self and hasattr( x, 'equipped') and x.equipped) text = utils.comma_and(map(str, list(equipment))) if equipment: return "{} is wearing {}.".format(self.name, text) else: return ""
def contents_string(self): contents = find_all(lambda x: x.location == self and not (hasattr( x, 'equipped') and x.equipped)) text = utils.comma_and(map(str, list(contents))) if contents: return "{} is carrying {}.".format(self.name, text) else: return ""
def equipment_string(self): equipment = find_all(lambda x: x.location == self and hasattr(x, 'equipped') and x.equipped) text = utils.comma_and(map(str, list(equipment))) if equipment: return "{} is wearing {}.".format(self.name, text) else: return ""
def contents_string(self): contents = find_all(lambda x: x.location == self and not (hasattr(x, 'equipped') and x.equipped)) text = utils.comma_and(map(str, list(contents))) if contents: return "{} is carrying {}.".format(self.name, text) else: return ""
def exits_string(self): """ List the object's exits as a string formatted for display. If no exits, return an empty string. Exits from an object are pretty unlikely if the object isn't a room, but they're not illegal. """ exits = find_all(lambda x: x.type == 'exit' and x.location is self) text = utils.comma_and(map(str, exits)) if exits: return "Exits: {}".format(text) else: return ""
def equipment_string(self): """ List the object's equipment as a string formatted for display. If no equipment, return an empty string. """ objects = find_all( lambda x: x.type != 'player' and x.type != 'exit' and x.location is self and hasattr(x, 'equipped') and x.equipped) names = [o.position_string() for o in objects] text = utils.comma_and(names) if objects: return "Equipment: {}".format(text) else: return ""
def equipment_string(self): """ List the object's equipment as a string formatted for display. If no equipment, return an empty string. """ objects = find_all(lambda x: x.type != 'player' and x.type != 'exit' and x.location is self and hasattr(x, 'equipped') and x.equipped) names = [o.position_string() for o in objects] text = utils.comma_and(names) if objects: return "Equipment: {}".format(text) else: return ""
def population_string(self): """ List the players inside an object as a string formatted for display. If no one's inside the object, return an empty string. """ population = find_all( lambda x: x.type == 'player' and x.location is self) if population: names = [] for player in population: if player.connected: names.append(player.position_string()) else: names.append(player.name + " (disconnected)") return "Players: {}".format(utils.comma_and(names)) else: return ""
def population_string(self): """ List the players inside an object as a string formatted for display. If no one's inside the object, return an empty string. """ population = find_all(lambda x: x.type == 'player' and x.location is self) if population: names = [] for player in population: if player.connected: names.append(player.position_string()) else: names.append(player.name + " (disconnected)") return "Players: {}".format(utils.comma_and(names)) else: return ""
def test_comma_and_three(self): self.assertEqual(utils.comma_and(["one", "two", "three"]), "one, two, and three")
def test_comma_and_one(self): self.assertEqual(utils.comma_and(["one"]), "one")
def test_comma_and_zero(self): self.assertEqual(utils.comma_and([]), "")
def test_comma_and_four(self): self.assertEqual(utils.comma_and(["one", "two", "three", "four"]), "one, two, three, and four")
def test_comma_and_two(self): self.assertEqual(utils.comma_and(["one", "two"]), "one and two")