def put_unit(self, type_id: int = None, path_id: int = None, base_unit: BaseUnit = None, path: Path = None) -> None: fail = False if type_id is not None and type(type_id) is not int: Logs.show_log("put_unit function called with invalid type_id argument!") fail = True if path_id is not None and type(path_id) is not int: Logs.show_log("put_unit function called with invalid path_id argument!") fail = True if base_unit is not None and type(base_unit) is not BaseUnit: Logs.show_log("put_unit function called with invalid base_unit argument") fail = True if path is not None and type(path) is not Path: Logs.show_log("put_unit function called with invalid path argument") fail = True if fail is True: return if base_unit is not None: type_id = base_unit.type_id if path is not None: path_id = path.id if path_id is None or type_id is None: return None if type_id is None: Logs.show_log("type_id is None in cast_area spell function call!") return message = Message(turn=self.get_current_turn(), type="putUnit", info={ "typeId": type_id, "pathId": path_id }) self._queue.put(message)
def get_area_spell_targets(self, center: Cell = None, row: int = None, col: int = None, spell: Spell = None, type_id: int = None) -> List["Unit"]: if spell is None: if type_id is not None: spell = self.get_cast_spell_by_id(type_id) else: return [] if type(spell) is not Spell: Logs.show_log("invalid spell chosen in get_area_spell_targets") return [] if not spell.is_area_spell(): return [] if center is None: center = Cell(row, col) ls = [] for i in range(max(0, center.row - spell.range), min(center.row + spell.range + 1, self._map.row_num)): for j in range( max(0, center.col - spell.range), min(center.col + spell.range + 1, self._map.col_num)): cell = self._map.get_cell(i, j) for u in cell.units: if self._is_unit_targeted(u, spell.target): ls.append(u) return ls
def get_cell_units(self, cell=None, row=None, col=None): if cell is None: if row is None and col is None: Logs.show_log("get_paths_crossing cell function called with no valid argument") return None cell = self.map.get_cell(row, col) if not isinstance(cell, Cell): Logs.show_log("Given cell is invalid!") return return cell.units
def get_cell_units(self, cell: Cell = None, row: int = None, col: int = None) -> List[Unit]: if cell is None: if row is None and col is None: Logs.show_log("get_paths_crossing cell function called with no valid argument") return [] cell = self._map.get_cell(row, col) if not isinstance(cell, Cell): Logs.show_log("Given cell is invalid!") return [] return cell.units
def choose_hand(self, base_units: List[BaseUnit]) -> None: message = Message(type="pick", turn=self.get_current_turn(), info=None) if base_units is not None: for base_unit in base_units: if type(base_unit) is not BaseUnit: Logs.show_log("base_units is not an array of BaseUnits") return message.info = {"units": [unit.type_id for unit in base_units]} self._queue.put(message) else: Logs.show_log("choose_hand function called with None base_units")
def upgrade_unit_damage(self, unit: Unit = None, unit_id: int = None): if unit is not None: unit_id = unit.unit_id if unit_id is not None and type(unit_id) is int: self._queue.put( Message(type="damageUpgrade", turn=self.get_current_turn(), info={"unitId": unit_id})) else: Logs.show_log("invalid unit or unit_id in upgrade_unit_damage")
def _get_friend_by_id(self, player_id): if self.player.player_id == player_id: return self.player_friend elif self.player_friend.player_id == player_id: return self.player elif self.player_first_enemy.player_id == player_id: return self.player_second_enemy elif self.player_second_enemy.player_id == player_id: return self.player_first_enemy else: Logs.show_log("get_friend_by_id function no player with given player_id") return None
def choose_hand_by_id(self, type_ids): message = Message(type="pick", turn=self.get_current_turn(), info=None) if type_ids is not None: for type_id in type_ids: if type(type_id) is not int: Logs.show_log("type_ids are not int") return message.info = {"units": type_ids} self.queue.put(message) else: Logs.show_log("choose_hand_by_id function called with None type_eds")
def get_paths_crossing_cell(self, cell=None, row=None, col=None): if cell is None: if row is None or col is None: Logs.show_log("get_paths_crossing cell function called with no valid argument") return cell = self.map.get_cell(row, col) if not isinstance(cell, Cell): Logs.show_log("Given cell is invalid!") return paths = [] for p in self.map.paths: if cell in p.cells: paths.append(p) return paths
def cast_area_spell(self, center: Cell = None, row: int = None, col: int = None, spell: Spell = None, spell_id: int = None) -> None: if spell is None: if spell_id is None or type(spell_id) is not int: Logs.show_log("no valid spell selected in cast_area_spell!") return spell = self.get_spell_by_id(spell_id) if type(spell) is not Spell: Logs.show_log("no valid spell selected in cast_area_spell!") return if row is not None and col is not None: center = self._map.get_cell(row, col) if center is not None: message = Message(type="castSpell", turn=self.get_current_turn(), info={ "typeId": spell.type_id, "cell": { "row": center.row, "col": center.col }, "unitId": -1, "pathId": -1 }) self._queue.put(message) else: Logs.show_log("invalid cell selected in cast_area_spell")
def cast_unit_spell(self, unit: Unit = None, unit_id: int = None, path: Path = None, path_id: int = None, cell: Cell = None, row: int = None, col: int = None, spell: Spell = None, spell_id: int = None) -> None: if spell is None and spell_id is None: Logs.show_log( "cast_unit_spell function called with no spell input!") return None if spell is None: if type(spell_id) is not int: Logs.show_log( "spell_id is not an integer in cast_unit_spell function call!" ) return spell = self.get_spell_by_id(spell_id) if row is not None and col is not None: if type(row) is not int or type(col) is not int: Logs.show_log( "row and column arguments are invalid in cast_unit_spell function call" ) return cell = Cell(row, col) if unit is not None: if type(unit) is not Unit: Logs.show_log( "unit argument is invalid in cast_unit_spell function call" ) return unit_id = unit.unit_id if path is not None: if type(path) is not Path: Logs.show_log( "path argument is invalid in cast_unit_spell function call" ) return path_id = path.id if type(unit_id) is not int: Logs.show_log( "unit_id argument is invalid in cast_unit_spell function call") return if type(path_id) is not int: Logs.show_log( "path_id argument is invalid in cast_unit_spell function call") return message = Message(type="castSpell", turn=self.get_current_turn(), info={ "typeId": spell.type_id, "cell": { "row": cell.row, "col": cell.col }, "unitId": unit_id, "pathId": path_id }) self._queue.put(message)