Skip to content

Commit 3ecf34c

Browse files
Merge branch 'master' of github.com:cameronangliss/poke-env into allow-no-status-overwrite
2 parents d75e37b + 7b624ee commit 3ecf34c

File tree

9 files changed

+56
-28
lines changed

9 files changed

+56
-28
lines changed

src/poke_env/battle/abstract_battle.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,17 @@ def _end_illusion_on(
378378
)
379379
illusionist_mon.set_hp(f"{illusioned.current_hp}/{illusioned.max_hp}")
380380

381-
illusioned.was_illusioned()
381+
illusioned.was_illusioned(self.fields)
382382

383383
return illusionist_mon
384384

385385
def _field_end(self, field_str: str):
386386
field = Field.from_showdown_message(field_str)
387387
if field is not Field.UNKNOWN:
388-
self._fields.pop(field)
388+
if field is Field.NEUTRALIZING_GAS:
389+
self._fields.pop(field, 0)
390+
else:
391+
self._fields.pop(field)
389392

390393
def field_start(self, field_str: str):
391394
field = Field.from_showdown_message(field_str)
@@ -676,8 +679,22 @@ def parse_message(self, split_message: List[str]):
676679
self.get_pokemon(pokemon).boost(stat, -int(amount))
677680
elif event[1] == "-ability":
678681
pokemon, cause = event[2:4]
679-
if len(event) > 4 and event[4].startswith("[from] move:"):
682+
if (
683+
len(event) > 4
684+
and (
685+
event[4].startswith("[from] move:")
686+
or event[4].startswith("[from] ability: Trace")
687+
)
688+
) or (
689+
len(event) > 5
690+
and (
691+
event[5].startswith("[from] move:")
692+
or event[5].startswith("[from] ability: Trace")
693+
)
694+
):
680695
self.get_pokemon(pokemon).set_temporary_ability(cause)
696+
elif cause == "Neutralizing Gas":
697+
self.field_start(cause)
681698
else:
682699
self.get_pokemon(pokemon).ability = cause
683700
elif split_message[1] == "-start":
@@ -711,6 +728,9 @@ def parse_message(self, split_message: List[str]):
711728
self.get_pokemon(target).start_effect(effect, event[4:6])
712729
actor = event[6].replace("[of] ", "")
713730
self.get_pokemon(actor).set_temporary_ability(event[5])
731+
elif effect == "ability: Mummy":
732+
target = event[5].replace("[of] ", "")
733+
self.get_pokemon(target).set_temporary_ability("mummy")
714734
elif effect == "ability: Symbiosis":
715735
self.get_pokemon(event[5].replace("[of] ", "")).item = event[4].replace(
716736
"[item] ", ""
@@ -750,7 +770,10 @@ def parse_message(self, split_message: List[str]):
750770
mon.cure_status()
751771
elif event[1] == "-end":
752772
pokemon, effect = event[2:4]
753-
self.get_pokemon(pokemon).end_effect(effect)
773+
if effect == "ability: Neutralizing Gas":
774+
self._field_end(effect)
775+
else:
776+
self.get_pokemon(pokemon).end_effect(effect)
754777
elif event[1] == "-endability":
755778
pokemon = event[2]
756779
self.get_pokemon(pokemon).set_temporary_ability(None)

src/poke_env/battle/battle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ def switch(self, pokemon_str: str, details: str, hp_status: str):
130130

131131
if identifier == self._player_role:
132132
if self.active_pokemon:
133-
self.active_pokemon.switch_out()
133+
self.active_pokemon.switch_out(self.fields)
134134
else:
135135
if self.opponent_active_pokemon:
136-
self.opponent_active_pokemon.switch_out()
136+
self.opponent_active_pokemon.switch_out(self.fields)
137137

138138
pokemon = self.get_pokemon(pokemon_str, details=details)
139139

src/poke_env/battle/double_battle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def switch(self, pokemon_str: str, details: str, hp_status: str):
220220
)
221221
pokemon_out = team.pop(pokemon_identifier, None)
222222
if pokemon_out is not None:
223-
pokemon_out.switch_out()
223+
pokemon_out.switch_out(self.fields)
224224
pokemon_in = self.get_pokemon(pokemon_str, details=details)
225225
pokemon_in.switch_in()
226226
pokemon_in.set_hp_status(hp_status)

src/poke_env/battle/effect.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ class Effect(Enum):
126126
MISTY_TERRAIN = auto()
127127
MUMMY = auto()
128128
MUST_RECHARGE = auto()
129-
NEUTRALIZING_GAS = auto()
130129
NIGHTMARE = auto()
131130
NO_RETREAT = auto()
132131
OBLIVIOUS = auto()
@@ -406,7 +405,6 @@ def is_from_move(self) -> bool:
406405
Effect.LIQUID_OOZE,
407406
Effect.MIMICRY,
408407
Effect.MUMMY,
409-
Effect.NEUTRALIZING_GAS,
410408
Effect.OBLIVIOUS,
411409
Effect.ORICHALCUM_PULSE,
412410
Effect.OWN_TEMPO,
@@ -891,7 +889,6 @@ def is_from_move(self) -> bool:
891889
"MISTYTERRAIN": Effect.MISTY_TERRAIN,
892890
"MUMMY": Effect.MUMMY,
893891
"MUSTRECHARGE": Effect.MUST_RECHARGE,
894-
"NEUTRALIZINGGAS": Effect.NEUTRALIZING_GAS,
895892
"NIGHTMARE": Effect.NIGHTMARE,
896893
"NORETREAT": Effect.NO_RETREAT,
897894
"OBLIVIOUS": Effect.OBLIVIOUS,

src/poke_env/battle/field.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Field(Enum):
2020
MISTY_TERRAIN = auto()
2121
MUD_SPORT = auto()
2222
MUD_SPOT = auto()
23+
NEUTRALIZING_GAS = auto()
2324
PSYCHIC_TERRAIN = auto()
2425
TRICK_ROOM = auto()
2526
WATER_SPORT = auto()
@@ -37,6 +38,7 @@ def from_showdown_message(message: str) -> Field:
3738
:return: The corresponding Field object.
3839
:rtype: Field
3940
"""
41+
message = message.replace("ability: ", "")
4042
message = message.replace("move: ", "")
4143
message = message.replace(" ", "_")
4244

src/poke_env/battle/pokemon.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Any, Dict, List, Optional, Union
44

55
from poke_env.battle.effect import Effect
6+
from poke_env.battle.field import Field
67
from poke_env.battle.move import SPECIAL_MOVES, Move
78
from poke_env.battle.pokemon_gender import PokemonGender
89
from poke_env.battle.pokemon_type import PokemonType
@@ -437,7 +438,17 @@ def switch_in(self, details: Optional[str] = None):
437438
self._first_turn = True
438439
self._revealed = True
439440

440-
def switch_out(self):
441+
def switch_out(self, fields: Dict[Field, int]):
442+
if (
443+
self.ability == "regenerator"
444+
and (
445+
self.item == "abilityshield"
446+
or Field.NEUTRALIZING_GAS not in fields.keys()
447+
)
448+
and self.status != Status.FNT
449+
):
450+
self._current_hp = min(int(self.current_hp + self.max_hp / 3), self.max_hp)
451+
441452
self._active = False
442453
self.clear_boosts()
443454
self._clear_effects()
@@ -446,17 +457,12 @@ def switch_out(self):
446457
self._preparing_move = None
447458
self._preparing_target = None
448459
self._protect_counter = 0
460+
self._temporary_ability = None
461+
self._temporary_types = []
449462

450463
if self._status == Status.TOX:
451464
self._status_counter = 0
452465

453-
for effect in self.effects:
454-
if effect.ends_on_switch or effect.is_volatile_status:
455-
self.end_effect(effect.name)
456-
457-
self._temporary_ability = None
458-
self._temporary_types = []
459-
460466
def terastallize(self, type_: str):
461467
self._terastallized_type = PokemonType.from_name(type_)
462468
self._terastallized = True
@@ -666,7 +672,7 @@ def _update_from_teambuilder(self, tb: TeambuilderPokemon):
666672
def used_z_move(self):
667673
self._item = None
668674

669-
def was_illusioned(self):
675+
def was_illusioned(self, fields: Dict[Field, int]):
670676
self._current_hp = None
671677
self._max_hp = None
672678
self._status = None
@@ -677,7 +683,7 @@ def was_illusioned(self):
677683
if last_request:
678684
self.update_from_request(last_request)
679685

680-
self.switch_out()
686+
self.switch_out(fields)
681687

682688
def available_moves_from_request(self, request: Dict[str, Any]) -> List[Move]:
683689
moves: List[Move] = []

unit_tests/environment/test_battle.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ def test_battle_request_and_interactions(example_request):
545545
necrozma = battle.active_pokemon
546546
groudon = battle.opponent_active_pokemon
547547

548-
necrozma.switch_out()
548+
necrozma.switch_out(battle.fields)
549549
groudon.switch_in()
550550
groudon._ability = None
551551

@@ -595,7 +595,7 @@ def test_battle_request_and_interactions(example_request):
595595
["", "-ability", "p1a: Groudon", "Insomnia", "[from] move: Worry Seed"]
596596
)
597597
assert groudon.ability == "insomnia"
598-
groudon.switch_out()
598+
groudon.switch_out(battle.fields)
599599
groudon.switch_in()
600600
assert groudon.ability == "desolateland"
601601

@@ -614,7 +614,7 @@ def test_battle_request_and_interactions(example_request):
614614
assert groudon.ability == "prismarmor"
615615
assert necrozma.ability == "desolateland"
616616
groudon.switch_in()
617-
groudon.switch_out()
617+
groudon.switch_out(battle.fields)
618618
assert groudon.ability == "desolateland"
619619

620620
battle.parse_message(["", "switch", "p1a: Ho-oh", "Ho-oh, L82", "100/100"])
@@ -631,7 +631,7 @@ def test_battle_request_and_interactions(example_request):
631631
assert hooh.type_1 == PokemonType.THREE_QUESTION_MARKS
632632
assert hooh.type_2 == PokemonType.FLYING
633633
assert hooh.types == [PokemonType.THREE_QUESTION_MARKS, PokemonType.FLYING]
634-
hooh.switch_out()
634+
hooh.switch_out(battle.fields)
635635
hooh.switch_in()
636636
assert hooh.type_1 == PokemonType.FIRE
637637
assert hooh.type_2 == PokemonType.FLYING
@@ -642,7 +642,7 @@ def test_battle_request_and_interactions(example_request):
642642
assert hooh.type_1 == PokemonType.WATER
643643
assert hooh.type_2 is None
644644
assert hooh.types == [PokemonType.WATER]
645-
hooh.switch_out()
645+
hooh.switch_out(battle.fields)
646646
hooh.switch_in()
647647
assert hooh.type_1 == PokemonType.FIRE
648648
assert hooh.type_2 == PokemonType.FLYING

unit_tests/environment/test_enumerations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def test_effect_end():
115115
assert Effect.QUASH not in furret.effects
116116

117117
# Test end on switch
118-
furret.switch_out()
118+
furret.switch_out({})
119119
assert Effect.MUMMY not in furret.effects
120120

121121
# Test the definition of Volatile Status

unit_tests/environment/test_pokemon.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def test_temporary():
332332
furret.start_effect("typechange", "Fighting")
333333
assert furret.damage_multiplier(PokemonType.PSYCHIC) == 2
334334

335-
furret.switch_out()
335+
furret.switch_out({})
336336
furret.switch_in()
337337

338338
assert furret.ability == "adaptability"
@@ -348,6 +348,6 @@ def test_temporary():
348348
furret.set_temporary_ability(None)
349349
assert furret.ability is None
350350

351-
furret.switch_out()
351+
furret.switch_out({})
352352
assert furret.ability == "adaptability"
353353
assert furret.types == [PokemonType.DRAGON]

0 commit comments

Comments
 (0)