def weaponry_tick(self) -> str: # Do the hits for the current turn: results = "" for shot in self.planned_shots: (damaging, x, y) = shot hits = {} if damaging: hits = self.damaging(x, y) else: hits = self.nondamaging(x, y) direct_hits = list_to_and_separated( list(map(lambda entity: entity.name(), hits["direct"]))) if direct_hits == "": direct_hits = "nobody" indirect_hits = list_to_and_separated( list(map(lambda entity: entity.name(), hits["indirect"]))) if indirect_hits == "": indirect_hits = "nobody" damaging_str = "damaging" if damaging else "non-damaging" results += f"Shot {damaging_str} shot at ({x}, {y}) - directly hit {direct_hits}; indirectly hit {indirect_hits}.\n" self.planned_shots = [] # Then recharge. weapons_power = self.sub.power.get_power("weapons") recharge = math.ceil(weapons_power / 2) old_charge = self.weapons_charge self.weapons_charge = min(weapons_power, old_charge + recharge) if old_charge != self.weapons_charge: return f"{results}Recharged weapons up to {self.weapons_charge} charge!" return results
def offer_as_text(self, offer: Dict[str, int]) -> str: if len(offer) == 0: return "nothing" offer_list = [] for item in offer: offer_list.append(f"{offer[item]}x {item.title()}") return list_to_and_separated(offer_list)
def draw_map(subs: List[Submarine], to_show: List[str], show_hidden: bool) -> Tuple[str, List[Dict[str, Any]]]: """ Draws an ASCII version of the map. Also returns a JSON of additional information. `subs` is a list of submarines, which are marked 0-9 on the map. """ SUB_CHARS = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '+', '=' ] map_string = "" map_json = [] for y in range(Y_LIMIT): row = "" for x in range(X_LIMIT): square = get_square(x, y) if square is None: raise SquareOutOfBoundsError((x, y)) tile_char = square.to_char(to_show, show_hidden, list(map(lambda sub: sub._name, subs))) tile_name = square.map_name(to_show, show_hidden, list(map(lambda sub: sub._name, subs))) if tile_name is not None: map_json.append({"x": x, "y": y, "name": tile_name}) if "n" in to_show: npcs_in_square = filtered_npcs(lambda n: n.x == x and n.y == y) if len(npcs_in_square) > 0: tile_char = "N" npcs_str = list_to_and_separated( list(map(lambda n: n.name(), npcs_in_square))) map_json.append({"x": x, "y": y, "name": npcs_str}) for i in range(len(subs)): (sx, sy) = subs[i].movement.get_position() if sx == x and sy == y: tile_char = SUB_CHARS[i] map_json.append({"x": x, "y": y, "name": subs[i].name()}) row += tile_char map_string += row + "\n" return map_string, map_json
def treasure_string(self) -> str: return list_to_and_separated(list(map(lambda t: t.title(), self.treasure)))
def printout_npc_types() -> DiscordAction: types = list_to_and_separated(get_npc_types()) return Message(f"Possible NPC types: {types}.")