def add_npc(npctype: str, x: int, y: int, sub: Optional[str]): if not in_world(x, y): return "Cannot place an NPC outside of the map." if npctype in npc_types: id = len(npcs) new_npc = npc_types[npctype](id, x, y) if sub is not None: new_npc.add_parent(sub) npcs.append(new_npc) return f"Created NPC #{id} of type {npctype.title()}!" return "That NPC type does not exist."
def zoom_in(x: int, y: int, loop) -> DiscordAction: if in_world(x, y): report = f"Report for square **({x}, {y})**\n" # since in_world => get_square : Cell (not None) report += get_square(x, y).square_status() + "\n\n" # type: ignore # See if any subs are here, and if so print their status. subs_in_square = filtered_teams( lambda sub: sub.movement.x == x and sub.movement.y == y) for sub in subs_in_square: report += sub.status_message(loop) + "\n\n" return Message(report) return Message("Chosen square is outside the world boundaries!")
def add_npc(npctype: str, x: int, y: int, sub: Optional[str]): if not in_world(x, y): return "Cannot place an NPC outside of the map." if npctype in npc_types: global npc_max_id id = npc_max_id npc_max_id += 1 new_npc = npc_types[npctype](id, x, y) if sub is not None: new_npc.add_parent(sub) npcs[id] = new_npc return f"Created NPC #{id} of type {npctype.title()}!" return "That NPC type does not exist."
async def move(self) -> str: motion = directions[self.direction] new_x = self.x + motion[0] new_y = self.y + motion[1] if not in_world(new_x, new_y): # Crashed into the boundaries of the world, whoops. self.set_direction(reverse_dir[self.get_direction()]) return f"Your submarine reached the boundaries of the world, so was pushed back (now facing **{self.direction.upper()}**) and did not move this turn!" message, obstacle = get_square(new_x, new_y).on_entry(self.sub) if obstacle: return message self.x = new_x self.y = new_y return message
def prepare_shot(self, damaging: bool, x: int, y: int) -> str: if not in_world(x, y): return "Coordinate outside of world." if diagonal_distance(self.sub.movement.get_position(), (x, y)) > self.range: return "Coordinate outside of range." if damaging and self.weapons_charge >= 2: self.planned_shots.append((True, x, y)) self.weapons_charge -= 2 return f"Damaging shot fired at ({x}, {y})!" if (not damaging) and self.weapons_charge >= 1: self.planned_shots.append((False, x, y)) self.weapons_charge -= 1 return f"Non-damaging shot fired at ({x}, {y})!" return "Not enough charge to use that."
def set_position(self, x: int, y: int) -> bool: if in_world(x, y): self.x = x self.y = y return True return False