Ejemplo n.º 1
0
def switch_or_drag(battle, split_msg):
    """The opponent's pokemon has changed
       If the new one hasn't been seen, create it"""
    if is_opponent(battle, split_msg):
        battle.opponent.side_conditions[constants.TOXIC_COUNT] = 0

        if battle.opponent.active is not None:
            # reset the boost of the pokemon being replaced
            battle.opponent.active.boosts.clear()

            # reset the volatile statuses of the pokemon being replaced
            battle.opponent.active.volatile_statuses.clear()

        # check if the pokemon exists in the reserves
        # if it does not, then the newly-created pokemon is used (for formats without team preview)
        pkmn = Pokemon.from_switch_string(split_msg[3])
        pkmn = find_pokemon_in_reserves(pkmn.name, battle.opponent.reserve)

        if pkmn is None:
            pkmn = Pokemon.from_switch_string(split_msg[3])
        else:
            battle.opponent.reserve.remove(pkmn)

        # pkmn != active is a special edge-case for Zoroark
        if battle.opponent.active is not None and pkmn != battle.opponent.active:
            battle.opponent.reserve.append(battle.opponent.active)

        battle.opponent.active = pkmn
        if battle.opponent.active.name in constants.UNKOWN_POKEMON_FORMES:
            battle.opponent.active = Pokemon.from_switch_string(split_msg[3])

    else:
        battle.user.side_conditions[constants.TOXIC_COUNT] = 0
        battle.user.active.boosts.clear()
Ejemplo n.º 2
0
    def start_random_battle(self, user_json, opponent_switch_string):
        self.user.from_json(user_json, first_turn=True)

        pkmn_information = opponent_switch_string.split('|')[3]
        pkmn = Pokemon.from_switch_string(pkmn_information)
        self.opponent.active = pkmn

        self.started = True
        self.rqid = user_json[constants.RQID]
Ejemplo n.º 3
0
    def initialize_team_preview(self, user_json, opponent_pokemon):
        self.user.from_json(user_json, first_turn=True)
        self.user.reserve.insert(0, self.user.active)
        self.user.active = None
        for pkmn_string in opponent_pokemon:
            pokemon = Pokemon.from_switch_string(pkmn_string)
            nature, evs = get_spread(pokemon.name)
            pokemon.set_spread(nature, evs)
            self.opponent.reserve.append(pokemon)

        self.started = True
        self.rqid = user_json[constants.RQID]
Ejemplo n.º 4
0
def form_change(battle, split_msg):
    if is_opponent(battle, split_msg):
        base_name = battle.opponent.active.base_name
        hp_percent = float(
            battle.opponent.active.hp) / battle.opponent.active.max_hp

        new_pokemon = Pokemon.from_switch_string(split_msg[3])
        if new_pokemon in battle.opponent.reserve:
            battle.opponent.reserve.remove(new_pokemon)

        battle.opponent.active = new_pokemon
        battle.opponent.active.hp = hp_percent * battle.opponent.active.max_hp

        if battle.opponent.active.name != "zoroark":
            battle.opponent.active.base_name = base_name
Ejemplo n.º 5
0
    def from_json(self, user_json, first_turn=False):
        if first_turn:
            existing_conditions = (None, None, None)
        else:
            existing_conditions = (self.active.name, self.active.boosts,
                                   self.active.volatile_statuses)

        try:
            trapped = user_json[constants.ACTIVE][0].get(
                constants.TRAPPED, False)
            maybe_trapped = user_json[constants.ACTIVE][0].get(
                constants.MAYBE_TRAPPED, False)
            self.trapped = trapped or maybe_trapped
        except KeyError:
            self.trapped = False

        try:
            can_mega_evo = user_json[constants.ACTIVE][0][
                constants.CAN_MEGA_EVO]
        except KeyError:
            can_mega_evo = False

        try:
            can_ultra_burst = user_json[constants.ACTIVE][0][
                constants.CAN_ULTRA_BURST]
        except KeyError:
            can_ultra_burst = False

        try:
            can_z_move = []
            for m in user_json[constants.ACTIVE][0][constants.CAN_Z_MOVE]:
                if m is not None:
                    can_z_move.append(True)
                else:
                    can_z_move.append(False)
        except KeyError:
            can_z_move = [False, False, False, False]

        self.name = user_json[constants.SIDE][constants.ID]
        self.reserve.clear()
        for index, pkmn_dict in enumerate(
                user_json[constants.SIDE][constants.POKEMON]):

            pkmn = Pokemon.from_switch_string(pkmn_dict[constants.DETAILS])
            pkmn.ability = pkmn_dict[constants.REQUEST_DICT_ABILITY]
            pkmn.index = index + 1
            pkmn.hp, pkmn.status = get_pokemon_info_from_condition(
                pkmn_dict[constants.CONDITION])
            pkmn.item = pkmn_dict[constants.ITEM] if pkmn_dict[
                constants.ITEM] else None

            if pkmn_dict[constants.ACTIVE]:
                self.active = pkmn
                if existing_conditions[0] == pkmn.name:
                    pkmn.boosts = existing_conditions[1]
                    pkmn.volatile_statuses = existing_conditions[2]
            else:
                self.reserve.append(pkmn)

            for move_name in pkmn_dict[constants.MOVES]:
                if move_name.startswith(constants.HIDDEN_POWER):
                    pkmn.add_move('{}{}'.format(
                        move_name, constants.
                        HIDDEN_POWER_RESERVE_MOVE_BASE_DAMAGE_STRING))
                else:
                    pkmn.add_move(move_name)

        # if there is no active pokemon, we do not want to look through it's moves
        if constants.ACTIVE not in user_json:
            return

        self.active.can_mega_evo = can_mega_evo
        self.active.can_ultra_burst = can_ultra_burst

        # clear the active moves so they can be reset by the options available
        self.active.moves.clear()

        # update the active pokemon's moves to show disabled status/pp remaining
        # this assumes that there is only one active pokemon (single-battle)
        for index, move in enumerate(
                user_json[constants.ACTIVE][0][constants.MOVES]):
            if move[constants.ID] == constants.HIDDEN_POWER:
                self.active.add_move('{}{}{}'.format(
                    constants.HIDDEN_POWER, move['move'].split()[
                        constants.HIDDEN_POWER_TYPE_STRING_INDEX].lower(),
                    constants.HIDDEN_POWER_ACTIVE_MOVE_BASE_DAMAGE_STRING))
            else:
                self.active.add_move(move[constants.ID])
            self.active.moves[-1].disabled = move.get(constants.DISABLED,
                                                      False)
            self.active.moves[-1].current_pp = move.get(constants.PP, 1)
            if can_z_move[index]:
                self.active.moves[index].can_z = True