def _start_effect(self, effect): effect = Effect.from_showdown_message(effect) if effect not in self._effects: self._effects[effect] = 0 elif effect.is_action_countable: self._effects[Effect] += 1 if effect.breaks_protect: self._protect_counter = 0
def _start_effect(self, effect): effect = Effect.from_showdown_message(effect) self._effects.add(effect)
def _end_effect(self, effect): effect = Effect.from_showdown_message(effect) if effect in self._effects: self._effects.remove(effect)
def test_battle_request_and_interactions(example_request): logger = MagicMock() battle = Battle("tag", "username", logger) battle._parse_request(example_request) mon = battle.active_pokemon battle._parse_message(["", "-boost", "p2: Venusaur", "atk", "4"]) assert mon.boosts["atk"] == 4 battle._parse_message(["", "-clearallboost"]) assert mon.boosts["atk"] == 0 battle._parse_message(["", "-boost", "p2: Venusaur", "atk", "4"]) assert mon.boosts["atk"] == 4 battle._parse_message(["", "-clearboost", "p2: Venusaur"]) assert mon.boosts["atk"] == 0 battle._parse_message(["", "-boost", "p2: Venusaur", "atk", "4"]) assert mon.boosts["atk"] == 4 battle._parse_message(["", "-clearpositiveboost", "p2: Venusaur"]) assert mon.boosts["atk"] == 0 battle._parse_message(["", "-boost", "p2: Venusaur", "atk", "4"]) assert mon.boosts["atk"] == 4 battle._parse_message(["", "-clearpositiveboost", "p2: Venusaur"]) assert mon.boosts["atk"] == 0 battle._parse_message(["", "-boost", "p2: Venusaur", "atk", "4"]) assert mon.boosts["atk"] == 4 battle._parse_message(["", "-clearnegativeboost", "p2: Venusaur"]) assert mon.boosts["atk"] == 4 battle._parse_message( ["", "switch", "p2: Necrozma", "Necrozma, L82", "121/293 tox"]) assert mon.boosts["atk"] == 0 assert mon.level == 82 assert battle.active_pokemon.species == "necrozma" assert battle.active_pokemon.status == Status.TOX battle._parse_message(["", "-curestatus", "p2: Necrozma", "par"]) assert battle.active_pokemon.status == Status.TOX battle._parse_message(["", "-curestatus", "p2: Necrozma", "tox"]) assert not battle.active_pokemon.status battle._parse_message( ["", "switch", "p1: Gabite", "Gabite, L99, F", "311/311"]) assert battle.opponent_active_pokemon.species == "gabite" assert battle.opponent_active_pokemon.level == 99 assert battle._parse_message(["", "-supereffective"]) is None battle._parse_message(["", "-activate", "p2: Necrozma", "leech seed"]) leech_seed_effect = Effect.from_showdown_message("leech seed") assert leech_seed_effect in battle.active_pokemon.effects cleared_boosts = { "accuracy": 0, "atk": 0, "def": 0, "evasion": 0, "spa": 0, "spd": 0, "spe": 0, } some_boosts = { "accuracy": -6, "atk": 6, "def": -1, "evasion": 1, "spa": 4, "spd": -3, "spe": 2, } assert battle.active_pokemon.boosts == cleared_boosts battle._parse_message( ["", "switch", "p1: Tyranitar", "Tyranitar, L82", "100/100"]) battle.active_pokemon._boosts = some_boosts battle._parse_message(["", "-copyboost", "p2: Necrozma", "p1: Tyranitar"]) assert battle.opponent_active_pokemon.boosts == some_boosts assert battle.active_pokemon.current_hp == 121 battle._parse_message(["", "-damage", "p2: Necrozma", "10/293"]) assert battle.active_pokemon.current_hp == 10 assert battle.active_pokemon.ability is not None battle._parse_message(["", "-endability", "p2: Necrozma"]) assert battle.active_pokemon.ability is None battle.active_pokemon.item = "focussash" battle._parse_message(["", "-enditem", "p2: Necrozma", "focussash"]) assert battle.active_pokemon.item is None assert battle.opponent_active_pokemon.base_stats["atk"] == 134 battle._parse_message( ["", "detailschange", "p1: Tyranitar", "Tyranitar-Mega, L82"]) assert battle.opponent_active_pokemon.base_stats["atk"] == 164 battle._parse_message(["", "-heal", "p2: Necrozma", "293/293"]) assert battle.active_pokemon.current_hp == 293 boosts_before_invertion = battle.opponent_active_pokemon.boosts.copy() battle._parse_message(["", "-invertboost", "p1: Tyranitar"]) for stat, boost in battle.opponent_active_pokemon.boosts.items(): assert boost == -boosts_before_invertion[stat] battle._parse_message([ "", "-item", "p1: Tyranitar", "Tyranitarite", "[from] ability: Frisk", "[of] p2: Necrozma", "[identify]", ]) assert battle.opponent_active_pokemon.item == "tyranitarite" battle._parse_message( ["", "switch", "p1: Latias", "Latias, L82", "100/100"]) assert battle.opponent_active_pokemon.base_stats["def"] == 90 battle._parse_message(["", "-mega", "p1: Latias", "latiasite"]) assert battle.opponent_active_pokemon.species == "latias" assert battle.opponent_active_pokemon.base_stats["def"] == 120 battle._parse_message(["", "-mustrecharge", "p1: Latias"]) assert battle.opponent_active_pokemon.must_recharge is True battle._parse_message( ["", "-prepare", "p1: Latias", "Solar Beam", "p2: Necrozma"]) move, target = battle.opponent_active_pokemon._preparing assert move == "Solar Beam" assert target.species == "necrozma" battle._parse_message( ["", "switch", "p1: Groudon", "Groudon, L82", "100/100"]) battle._parse_message(["", "-primal", "p1: Groudon"]) assert battle.opponent_active_pokemon.species == "groudon" battle._parse_message(["", "-setboost", "p1: Groudon", "atk", "6"]) assert battle.opponent_active_pokemon.boosts["atk"] == 6 assert battle.opponent_active_pokemon.current_hp == 100 battle._parse_message(["", "-sethp", "p1: Groudon", "99/100"]) assert battle.opponent_active_pokemon.current_hp == 99 battle._parse_message(["", "-status", "p1: Groudon", "tox"]) assert battle.opponent_active_pokemon.status == Status.TOX battle.active_pokemon.boosts["atk"] = 0 battle.active_pokemon.boosts["def"] = 3 battle.active_pokemon.boosts["spe"] = -1 battle.opponent_active_pokemon.boosts["atk"] = 6 battle.opponent_active_pokemon.boosts["def"] = -2 battle.opponent_active_pokemon.boosts["spe"] = 0 battle._parse_message( ["", "-swapboost", "p1: Groudon", "p2: Necrozma", "atk, def"]) assert battle.active_pokemon.boosts["atk"] == 6 assert battle.active_pokemon.boosts["def"] == -2 assert battle.active_pokemon.boosts["spe"] == -1 assert battle.opponent_active_pokemon.boosts["atk"] == 0 assert battle.opponent_active_pokemon.boosts["def"] == 3 assert battle.opponent_active_pokemon.boosts["spe"] == 0 battle._parse_message(["", "-transform", "p1: Groudon", "p2: Necrozma"]) assert battle.opponent_active_pokemon.species == "groudon" assert battle.opponent_active_pokemon.base_stats == POKEDEX["necrozma"][ "baseStats"] assert battle.opponent_active_pokemon.boosts == battle.active_pokemon.boosts battle._parse_message( ["", "switch", "p1: Sunflora", "Sunflora, L82", "100/100"]) battle.opponent_active_pokemon._boosts = cleared_boosts.copy() battle.opponent_active_pokemon._boosts["atk"] = 4 battle._parse_message(["", "-unboost", "p1: Sunflora", "atk", "5"]) assert battle.opponent_active_pokemon._boosts["atk"] == -1 battle.opponent_active_pokemon.item = "grassiumz" battle._parse_message(["", "-zpower", "p1: Sunflora"]) assert battle.opponent_active_pokemon.item is None sunflora = battle.opponent_active_pokemon assert sunflora.fainted is False battle._parse_message(["", "faint", "p1: Sunflora"]) assert sunflora.fainted is True battle._parse_message( ["", "switch", "p1: Groudon", "Groudon, L82", "100/100"]) battle._parse_message( ["", "move", "p1: Groudon", "Precipice Blades", "p2: Necrozma"]) assert "precipiceblades" in battle.opponent_active_pokemon.moves battle._player_username = "******" battle._opponent_username = "******" battle._parse_message([ "", "raw", "ray's rating: 1049 → <strong>1079</strong><br />(+30 for winning)", ]) assert battle.rating == 1049 battle._parse_message([ "", "raw", "wolfe's rating: 1025 → <strong>1012</strong><br />(-13 for losing)", ]) assert battle.opponent_rating == 1025 battle._in_team_preview = True battle._parse_message(["", "start"]) assert battle._in_team_preview is False with pytest.raises(NotImplementedError) as excinfo: msg_type = "bad message type that should raise an exception" battle._parse_message(["", msg_type]) assert msg_type in str(excinfo.value)
def test_effect_build(): assert Effect["TRICK"] == Effect.from_showdown_message("move: trick") assert Effect["MUMMY"] == Effect.from_showdown_message("ability: mummy") assert Effect["CUSTAP_BERRY"] == Effect.from_showdown_message( "item: custap berry") assert Effect["_UNKNOWN"] == Effect.from_showdown_message("i don't know")
def _end_effect(self, effect): if Effect.from_showdown_message(effect) in self._effects: self._effects.remove(Effect.from_showdown_message(effect))