def add_minion(self, new_minion: Minion, position: Optional[int] = None) -> Optional[Minion]: """Add minion to the board if there is space Arguments: new_minion {Minion} -- Instance of minion to be added Keyword Arguments: position {Optional[int]} -- Optional position to insert the minion at, if None add at the end (default: {None}) Returns: Optional[Minion] -- Return the updated Minion if inserted succesfully, otherwise return None """ if len(self.minions) < 7: if position is None: position = len(self.minions) for minion in self.minions: minion.on_other_enter(other_minion=new_minion) new_minion.position = position new_minion.player_id = self.player_id self.minions.insert(position, new_minion) for minion in self.minions[position + 1:]: minion.shift_right() logging.debug(f"Adding {new_minion.minion_string()}") return new_minion else: logging.debug(f"Did not add {new_minion.minion_string()} because of a lack of space")
def add_minion( self, new_minion: Minion, position: Optional[int] = None, allow_copy: Optional[bool] = True, summoning_minion: Optional[Minion] = None) -> Optional[Minion]: """Add minion to the board if there is space Arguments: new_minion {Minion} -- Instance of minion to be added token {Bool} -- is this minion being added a token (including reborns)? For khadgar multipliers Keyword Arguments: position {Optional[int]} -- Optional position to insert the minion at, if None add at the end (default: {None}) """ if len(self.minions) == 7: return None if position is None: position = len(self.minions) new_minion.own_board = self # TODO: Avoid this? or lean into it? # Apply all Auras, Hero power effects, and any other triggers resulting from a minion being summoned self.call_triggers(TriggerType.ON_MINION_SUMMON, new_minion) new_minion.on_self_summon(self) self.add_minion_triggers(new_minion) # Set neighbors for new minion and existing minions left_neighbor, right_neighbor = None, None if len(self.minions) == 0: # left and right are None left_neighbor, right_neighbor = None, None elif position > len(self.minions) - 1: # left exists, right is None left_neighbor = self.minions[position - 1] left_neighbor.right_neighbor = new_minion elif position == 0 and len(self.minions) > 0: # right exists, left is None right_neighbor = self.minions[position] right_neighbor.left_neighbor = new_minion else: # left and right exist left_neighbor = self.minions[position - 1] right_neighbor = self.minions[position] left_neighbor.right_neighbor = new_minion right_neighbor.left_neighbor = new_minion new_minion.position = position new_minion.player_id = self.player_id new_minion.left_neighbor = left_neighbor new_minion.right_neighbor = right_neighbor self.minions.insert(position, new_minion) for minion in self.minions[position + 1:]: minion.shift_right() copied_minion = None if allow_copy: for _ in range(self.token_creation_multiplier): copied_minion = copy.deepcopy(new_minion) copied_minion = self.add_minion(copied_minion, copied_minion.position + 1, allow_copy=False) inserted_minion = copied_minion if copied_minion else new_minion # If there is a minion that is set aside (ie dead) that summoned this minion, (ie via deathrattle) # Then its important for the parent minion to track in case that minion will be reborn. # If it is reborn, then it should spawn to the right of its child minions (pending space restrictions) if summoning_minion: assert summoning_minion.dead summoning_minion.left_neighbor = inserted_minion return inserted_minion