Skip to content

Commit

Permalink
Properly Parse As One Glastrier and As One Spectrier
Browse files Browse the repository at this point in the history
|t:|1737013582
|switch|p2a: Calyrex|Calyrex-Shadow, L64|235/235
|-ability|p2a: Calyrex|As One
|-ability|p2a: Calyrex|Unnerve
|turn|7
  • Loading branch information
pmariglia committed Feb 4, 2025
1 parent 80bf702 commit a8d9450
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
25 changes: 22 additions & 3 deletions fp/battle_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ def _switch_active_with_zoroark_from_reserves(
opponent_side.reserve.remove(zoroark_from_reserves)


def set_opponent_ability_from_ability_tag(battle, split_msg):
def update_ability(battle, split_msg):
if is_opponent(battle, split_msg):
side = battle.opponent
other_side = battle.user
Expand All @@ -1607,7 +1607,6 @@ def set_opponent_ability_from_ability_tag(battle, split_msg):
other_side = battle.opponent

ability = normalize_name(split_msg[3])
logger.info("Setting {}'s ability to {}".format(side.active.name, ability))
if len(split_msg) >= 6 and "ability:" in split_msg[4]:
original_ability = normalize_name(split_msg[4].split(":")[-1])
logger.info(
Expand All @@ -1622,7 +1621,27 @@ def set_opponent_ability_from_ability_tag(battle, split_msg):
"Setting {}'s ability to {}".format(other_side.active.name, ability)
)
other_side.active.ability = ability
elif ability == "asone":
if side.active.name == "calyrexice":
ability = "asoneglastrier"
elif side.active.name == "calyrexshadow":
ability = "asonespectrier"
else:
logger.warning(
"Unknown asone ability for {} - defaulting to asoneglastrier".format(
side.active.name
)
)
ability = "asoneglastrier"
elif side.active.ability in ["asoneglastrier", "asonespectrier"]:
logger.info(
"{} has the ability {}, will not change to {}".format(
side.active.name, side.active.ability, ability
)
)
ability = side.active.ability

logger.info("Setting {}'s ability to {}".format(side.active.name, ability))
side.active.ability = ability


Expand Down Expand Up @@ -2761,7 +2780,7 @@ def update_battle(battle, msg):
"-item": set_item,
"-enditem": remove_item,
"-immune": immune,
"-ability": set_opponent_ability_from_ability_tag,
"-ability": update_ability,
"detailschange": form_change,
"replace": illusion_end,
"-formechange": form_change,
Expand Down
44 changes: 36 additions & 8 deletions tests/test_battle_modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from fp.battle_modifier import start_volatile_status
from fp.battle_modifier import end_volatile_status
from fp.battle_modifier import immune
from fp.battle_modifier import set_opponent_ability_from_ability_tag
from fp.battle_modifier import update_ability
from fp.battle_modifier import form_change
from fp.battle_modifier import zpower
from fp.battle_modifier import clearnegativeboost
Expand Down Expand Up @@ -2657,6 +2657,34 @@ def setUp(self):
self.user_active = Pokemon("weedle", 100)
self.battle.user.active = self.user_active

def test_sets_as_one_spectrier(self):
self.battle.opponent.active.name = "calyrexshadow"
split_msg = ["", "-ability", "p2a: Calyrex", "As One"]
update_ability(self.battle, split_msg)
self.assertEqual("asonespectrier", self.battle.opponent.active.ability)

def test_sets_as_one_glastrier(self):
self.battle.opponent.active.name = "calyrexice"
split_msg = ["", "-ability", "p2a: Calyrex", "As One"]
update_ability(self.battle, split_msg)
self.assertEqual("asoneglastrier", self.battle.opponent.active.ability)

def test_does_not_update_asoneglastrier_to_unnerve(self):
self.battle.opponent.active.name = "calyrexice"
split_msg = ["", "-ability", "p2a: Calyrex", "As One"]
update_ability(self.battle, split_msg)
split_msg = ["", "-ability", "p2a: Calyrex", "Unnerve"]
update_ability(self.battle, split_msg)
self.assertEqual("asoneglastrier", self.battle.opponent.active.ability)

def test_does_not_update_asonespectrier_to_unnerve(self):
self.battle.opponent.active.name = "calyrexshadow"
split_msg = ["", "-ability", "p2a: Calyrex", "As One"]
update_ability(self.battle, split_msg)
split_msg = ["", "-ability", "p2a: Calyrex", "Unnerve"]
update_ability(self.battle, split_msg)
self.assertEqual("asonespectrier", self.battle.opponent.active.ability)

def test_sets_original_ability_from_trace(self):
self.battle.user.active.ability = "intimidate"
self.battle.opponent.active.ability = None
Expand All @@ -2669,7 +2697,7 @@ def test_sets_original_ability_from_trace(self):
"[from] ability: Trace",
"[of] p1a: Caterpie",
]
set_opponent_ability_from_ability_tag(self.battle, split_msg)
update_ability(self.battle, split_msg)

self.assertEqual("intimidate", self.battle.opponent.active.ability)
self.assertEqual("trace", self.battle.opponent.active.original_ability)
Expand All @@ -2688,8 +2716,8 @@ def test_sets_original_ability_from_trace_with_intimidate(self):
"[from] ability: Trace",
"[of] p1a: Caterpie",
]
set_opponent_ability_from_ability_tag(self.battle, split_msg_1)
set_opponent_ability_from_ability_tag(self.battle, split_msg_2)
update_ability(self.battle, split_msg_1)
update_ability(self.battle, split_msg_2)

self.assertEqual("intimidate", self.battle.opponent.active.ability)
self.assertEqual("trace", self.battle.opponent.active.original_ability)
Expand All @@ -2708,24 +2736,24 @@ def test_sets_original_ability_from_trace_with_intimidate_for_bot(self):
"[from] ability: Trace",
"[of] p2a: Caterpie",
]
set_opponent_ability_from_ability_tag(self.battle, split_msg_1)
set_opponent_ability_from_ability_tag(self.battle, split_msg_2)
update_ability(self.battle, split_msg_1)
update_ability(self.battle, split_msg_2)

self.assertEqual("intimidate", self.battle.opponent.active.ability)
self.assertEqual("trace", self.battle.user.active.original_ability)
self.assertEqual("intimidate", self.battle.user.active.ability)

def test_update_ability_from_ability_string_properly_updates_ability(self):
split_msg = ["", "-ability", "p2a: Caterpie", "Lightning Rod", "boost"]
set_opponent_ability_from_ability_tag(self.battle, split_msg)
update_ability(self.battle, split_msg)

expected_ability = "lightningrod"

self.assertEqual(expected_ability, self.battle.opponent.active.ability)

def test_update_ability_from_ability_string_properly_updates_ability_for_bot(self):
split_msg = ["", "-ability", "p1a: Caterpie", "Lightning Rod", "boost"]
set_opponent_ability_from_ability_tag(self.battle, split_msg)
update_ability(self.battle, split_msg)

expected_ability = "lightningrod"

Expand Down

0 comments on commit a8d9450

Please sign in to comment.