Skip to content

Commit ee78689

Browse files
Merge branch 'master' of github.com:cameronangliss/poke-env into allow-no-status-overwrite
2 parents 5b3273c + e947293 commit ee78689

File tree

6 files changed

+30
-33
lines changed

6 files changed

+30
-33
lines changed

.github/workflows/update-data.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
./scripts/update_all_data.sh
1818
chmod -x ./scripts/update_all_data.sh
1919
- name: Create or update pull request
20-
uses: peter-evans/create-pull-request@v7
20+
uses: peter-evans/create-pull-request@v8
2121
with:
2222
commit-message: JSON data update from smogon
2323
branch: create-pull-request/update-data

src/poke_env/battle/abstract_battle.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,7 @@ def get_pokemon(
238238

239239
# if the pokemon has a nickname, this ensures we recognize it
240240
name_det = details.split(", ")[0]
241-
matches = [
242-
i
243-
for i, p in enumerate(team.values())
244-
if p.base_species == to_id_str(name_det)
245-
or p.base_species in [to_id_str(det) for det in name_det.split("-")]
246-
]
241+
matches = [i for i, p in enumerate(team.values()) if p.identifies_as(name_det)]
247242
assert len(matches) < 2
248243
if identifier not in team and matches:
249244
i = matches[0]
@@ -373,9 +368,7 @@ def _end_illusion_on(
373368
return illusionist_mon
374369

375370
illusionist_mon.switch_in(details=details)
376-
illusionist_mon.status = ( # type: ignore
377-
illusioned.status if illusioned.status is not None else None
378-
)
371+
illusionist_mon.status = illusioned.status
379372
illusionist_mon.set_hp(f"{illusioned.current_hp}/{illusioned.max_hp}")
380373

381374
illusioned.was_illusioned(self.fields)
@@ -699,7 +692,7 @@ def parse_message(self, split_message: List[str]):
699692
self.get_pokemon(pokemon).ability = cause
700693
elif split_message[1] == "-start":
701694
pokemon, effect = event[2:4]
702-
pokemon = self.get_pokemon(pokemon) # type: ignore
695+
mon = self.get_pokemon(pokemon)
703696

704697
if effect == "typechange":
705698
if len(event) > 5 and event[5].startswith("[of] "):
@@ -708,16 +701,16 @@ def parse_message(self, split_message: List[str]):
708701
)
709702
else:
710703
types = event[4]
711-
pokemon.start_effect(effect, details=types) # type: ignore
704+
mon.start_effect(effect, details=types)
712705
else:
713-
pokemon.start_effect(effect) # type: ignore
706+
mon.start_effect(effect)
714707

715-
if pokemon.is_dynamaxed: # type: ignore
716-
if pokemon in self.team.values() and self._dynamax_turn is None:
708+
if mon.is_dynamaxed:
709+
if mon in self.team.values() and self._dynamax_turn is None:
717710
self._dynamax_turn = self.turn
718711
self._used_dynamax = True
719712
elif (
720-
pokemon in self.opponent_team.values()
713+
mon in self.opponent_team.values()
721714
and self._opponent_dynamax_turn is None
722715
):
723716
self._opponent_dynamax_turn = self.turn
@@ -740,7 +733,7 @@ def parse_message(self, split_message: List[str]):
740733
self.get_pokemon(target).start_effect(effect)
741734
elif event[1] == "-status":
742735
pokemon, status = event[2:4]
743-
self.get_pokemon(pokemon).status = status # type: ignore
736+
self.get_pokemon(pokemon).status = status
744737
elif event[1] == "rule":
745738
self.rules.append(event[2])
746739

@@ -906,7 +899,6 @@ def parse_message(self, split_message: List[str]):
906899
else:
907900
self._opponent_used_z_move = True
908901
pokemon = event[2]
909-
self.get_pokemon(pokemon).used_z_move()
910902
elif event[1] == "clearpoke":
911903
self.in_team_preview = True
912904
for mon in self.team.values():
@@ -989,7 +981,7 @@ def parse_message(self, split_message: List[str]):
989981
self.in_team_preview = False
990982
elif event[1] == "swap":
991983
pokemon, position = event[2:4]
992-
self._swap(pokemon, position) # type: ignore
984+
self._swap(pokemon, position)
993985
elif event[1] == "teamsize":
994986
player, number = event[2:4]
995987
self._team_size[player] = int(number)
@@ -998,11 +990,11 @@ def parse_message(self, split_message: List[str]):
998990
self.logger.info("Received message: %s", event[2])
999991
elif event[1] == "-immune":
1000992
if len(event) == 4:
1001-
mon, cause = event[2:] # type: ignore
993+
pokemon, cause = event[2:]
1002994

1003995
if cause.startswith("[from] ability:"):
1004996
cause = cause.replace("[from] ability:", "")
1005-
self.get_pokemon(mon).ability = to_id_str(cause) # type: ignore
997+
self.get_pokemon(pokemon).ability = to_id_str(cause)
1006998
elif event[1] == "-swapsideconditions":
1007999
self._side_conditions, self._opponent_side_conditions = (
10081000
self._opponent_side_conditions,
@@ -1013,10 +1005,10 @@ def parse_message(self, split_message: List[str]):
10131005
self.players = player_1, player_2
10141006
elif event[1] == "-terastallize":
10151007
pokemon, type_ = event[2:]
1016-
pokemon = self.get_pokemon(pokemon) # type: ignore
1017-
pokemon.terastallize(type_) # type: ignore
1008+
mon = self.get_pokemon(pokemon)
1009+
mon.terastallize(type_)
10181010

1019-
if pokemon.is_terastallized: # type: ignore
1011+
if mon.is_terastallized:
10201012
if pokemon in self.team.values():
10211013
self._used_tera = True
10221014
elif pokemon in self.opponent_team.values():

src/poke_env/battle/effect.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class Effect(Enum):
108108
LEPPA_BERRY = auto()
109109
LIGHTNING_ROD = auto()
110110
LIMBER = auto()
111+
LINGERING_AROMA = auto()
111112
LIQUID_OOZE = auto()
112113
LOCKED_MOVE = auto()
113114
LOCK_ON = auto()
@@ -402,6 +403,7 @@ def is_from_move(self) -> bool:
402403
Effect.IRON_BARBS,
403404
Effect.LIGHTNING_ROD,
404405
Effect.LIMBER,
406+
Effect.LINGERING_AROMA,
405407
Effect.LIQUID_OOZE,
406408
Effect.MIMICRY,
407409
Effect.MUMMY,
@@ -871,6 +873,7 @@ def is_from_move(self) -> bool:
871873
"LEPPABERRY": Effect.LEPPA_BERRY,
872874
"LIGHTNINGROD": Effect.LIGHTNING_ROD,
873875
"LIMBER": Effect.LIMBER,
876+
"LINGERINGAROMA": Effect.LINGERING_AROMA,
874877
"LIQUIDOOZE": Effect.LIQUID_OOZE,
875878
"LOCKEDMOVE": Effect.LOCKED_MOVE,
876879
"LOCKON": Effect.LOCK_ON,

src/poke_env/battle/pokemon.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ def forme_change(self, species: str):
275275
species = species.split(",")[0]
276276
self._update_from_pokedex(species, store_species=False)
277277

278+
def identifies_as(self, ident: str) -> bool:
279+
return self.base_species in to_id_str(ident) or self.base_species in [
280+
to_id_str(substr) for substr in ident.split("-")
281+
]
282+
278283
def invert_boosts(self):
279284
self._boosts = {k: -v for k, v in self._boosts.items()}
280285

@@ -666,9 +671,6 @@ def _update_from_teambuilder(self, tb: TeambuilderPokemon):
666671
for stat, val in zip(["hp", "atk", "def", "spa", "spd", "spe"], stats):
667672
self._stats[stat] = val
668673

669-
def used_z_move(self):
670-
self._item = None
671-
672674
def was_illusioned(self, fields: Dict[Field, int]):
673675
self._current_hp = None
674676
self._max_hp = None
@@ -1096,6 +1098,10 @@ def status(self) -> Optional[Status]:
10961098
"""
10971099
return self._status
10981100

1101+
@status.setter
1102+
def status(self, status: Optional[Union[Status, str]]):
1103+
self._status = Status[status.upper()] if isinstance(status, str) else status
1104+
10991105
@property
11001106
def status_counter(self) -> int:
11011107
"""
@@ -1104,10 +1110,6 @@ def status_counter(self) -> int:
11041110
"""
11051111
return self._status_counter
11061112

1107-
@status.setter # type: ignore
1108-
def status(self, status: Optional[Union[Status, str]]):
1109-
self._status = Status[status.upper()] if isinstance(status, str) else status
1110-
11111113
@property
11121114
def stab_multiplier(self) -> float:
11131115
"""

src/poke_env/player/player.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ async def _handle_battle_message(self, split_messages: List[List[str]]):
303303
teambuilder_mon = [
304304
m
305305
for m in teambuilder_team
306-
if preview_mon.base_species in to_id_str(m.nickname)
306+
if m.nickname is not None
307+
and preview_mon.identifies_as(m.nickname)
307308
][0]
308309
mon = battle.get_pokemon(
309310
f"{role}: {teambuilder_mon.nickname}",

unit_tests/environment/test_battle.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ def test_battle_request_and_interactions(example_request):
413413

414414
battle.opponent_active_pokemon.item = "grassiumz"
415415
battle.parse_message(["", "-zpower", "p1: Sunflora"])
416-
assert battle.opponent_active_pokemon.item is None
417416

418417
sunflora = battle.opponent_active_pokemon
419418
assert sunflora.fainted is False

0 commit comments

Comments
 (0)