Adjust Ate-Ability code a bit to make it more readable (#4640)

* Adjust Ate-Ability code a bit to make it more readable

* stupid oversight

* fixed

* pull normal type move check out of function

* unused var

* switch and tests

* oversight

* Apply suggestions from code review

---------

Co-authored-by: Bassoonian <iasperbassoonian@gmail.com>
This commit is contained in:
Alex 2024-05-31 12:22:18 +02:00 committed by GitHub
parent 52d45674f0
commit bebc13b5a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 140 additions and 19 deletions

View file

@ -5976,9 +5976,59 @@ void RunBattleScriptCommands(void)
gBattleScriptingCommandsTable[gBattlescriptCurrInstr[0]]();
}
bool32 TrySetAteType(u32 move, u32 battlerAtk, u32 attackerAbility)
{
u32 ateType;
switch (gMovesInfo[move].effect)
{
case EFFECT_TERA_BLAST:
if (IsTerastallized(battlerAtk))
return FALSE;
break;
case EFFECT_TERA_STARSTORM:
if (gBattleMons[battlerAtk].species == SPECIES_TERAPAGOS_STELLAR)
return FALSE;
break;
case EFFECT_HIDDEN_POWER:
case EFFECT_WEATHER_BALL:
case EFFECT_CHANGE_TYPE_ON_ITEM:
case EFFECT_NATURAL_GIFT:
return FALSE;
}
ateType = TYPE_NONE;
switch (attackerAbility)
{
case ABILITY_PIXILATE:
ateType = TYPE_FAIRY;
break;
case ABILITY_REFRIGERATE:
ateType = TYPE_ICE;
break;
case ABILITY_AERILATE:
ateType = TYPE_FLYING;
break;
case ABILITY_GALVANIZE:
ateType = TYPE_ELECTRIC;
break;
default:
ateType = TYPE_NONE;
break;
}
if (ateType != TYPE_NONE)
{
gBattleStruct->dynamicMoveType = ateType | F_DYNAMIC_TYPE_SET;
return TRUE;
}
return FALSE;
}
void SetTypeBeforeUsingMove(u32 move, u32 battlerAtk)
{
u32 moveType, ateType, attackerAbility;
u32 moveType, attackerAbility;
u16 holdEffect = GetBattlerHoldEffect(battlerAtk, TRUE);
if (move == MOVE_STRUGGLE)
@ -6080,29 +6130,15 @@ void SetTypeBeforeUsingMove(u32 move, u32 battlerAtk)
}
attackerAbility = GetBattlerAbility(battlerAtk);
if (gMovesInfo[move].type == TYPE_NORMAL
&& gMovesInfo[move].effect != EFFECT_HIDDEN_POWER
&& gMovesInfo[move].effect != EFFECT_WEATHER_BALL
&& gMovesInfo[move].effect != EFFECT_CHANGE_TYPE_ON_ITEM
&& gMovesInfo[move].effect != EFFECT_NATURAL_GIFT
&& !(gMovesInfo[move].effect == EFFECT_TERA_BLAST && IsTerastallized(battlerAtk))
&& !(gMovesInfo[move].effect == EFFECT_TERA_STARSTORM && gBattleMons[battlerAtk].species == SPECIES_TERAPAGOS_STELLAR)
&& ((attackerAbility == ABILITY_PIXILATE && (ateType = TYPE_FAIRY))
|| (attackerAbility == ABILITY_REFRIGERATE && (ateType = TYPE_ICE))
|| (attackerAbility == ABILITY_AERILATE && (ateType = TYPE_FLYING))
|| ((attackerAbility == ABILITY_GALVANIZE) && (ateType = TYPE_ELECTRIC))
)
)
if (gMovesInfo[move].type == TYPE_NORMAL && TrySetAteType(move, battlerAtk, attackerAbility))
{
gBattleStruct->dynamicMoveType = ateType | F_DYNAMIC_TYPE_SET;
if (!IsDynamaxed(battlerAtk))
gBattleStruct->ateBoost[battlerAtk] = 1;
}
else if (gMovesInfo[move].type != TYPE_NORMAL
&& gMovesInfo[move].effect != EFFECT_HIDDEN_POWER
&& gMovesInfo[move].effect != EFFECT_WEATHER_BALL
&& attackerAbility == ABILITY_NORMALIZE)
&& gMovesInfo[move].effect != EFFECT_HIDDEN_POWER
&& gMovesInfo[move].effect != EFFECT_WEATHER_BALL
&& attackerAbility == ABILITY_NORMALIZE)
{
gBattleStruct->dynamicMoveType = TYPE_NORMAL | F_DYNAMIC_TYPE_SET;
if (!IsDynamaxed(battlerAtk))

View file

@ -0,0 +1,85 @@
#include "global.h"
#include "test/battle.h"
ASSUMPTIONS
{
ASSUME(gMovesInfo[MOVE_TACKLE].type == TYPE_NORMAL);
ASSUME(gMovesInfo[MOVE_TACKLE].power > 0);
}
SINGLE_BATTLE_TEST("Galvanize can not turn certain moves into Electric type moves")
{
u32 move;
PARAMETRIZE { move = MOVE_HIDDEN_POWER; }
PARAMETRIZE { move = MOVE_WEATHER_BALL; }
PARAMETRIZE { move = MOVE_MULTI_ATTACK; }
ASSUME(gMovesInfo[MOVE_HIDDEN_POWER].effect == EFFECT_HIDDEN_POWER);
ASSUME(gMovesInfo[MOVE_WEATHER_BALL].effect == EFFECT_WEATHER_BALL);
ASSUME(gMovesInfo[MOVE_MULTI_ATTACK].effect == EFFECT_CHANGE_TYPE_ON_ITEM);
GIVEN {
PLAYER(SPECIES_KRABBY);
OPPONENT(SPECIES_GEODUDE_ALOLAN) { Ability(ABILITY_GALVANIZE); }
} WHEN {
TURN { MOVE(opponent, move); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, move, opponent);
NOT MESSAGE("It's super effective!");
}
}
SINGLE_BATTLE_TEST("Galvanize turns a normal type move into Electric")
{
GIVEN {
PLAYER(SPECIES_KRABBY);
OPPONENT(SPECIES_GEODUDE_ALOLAN) { Ability(ABILITY_GALVANIZE); }
} WHEN {
TURN { MOVE(opponent, MOVE_TACKLE); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent);
MESSAGE("It's super effective!");
}
}
SINGLE_BATTLE_TEST("Pixilate turns a normal type move into Fairy")
{
GIVEN {
PLAYER(SPECIES_DRAGONITE);
OPPONENT(SPECIES_ALTARIA) { Item(ITEM_ALTARIANITE); }
} WHEN {
TURN { MOVE(opponent, MOVE_TACKLE, megaEvolve: TRUE); }
} SCENE {
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_MEGA_EVOLUTION, opponent);
ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent);
MESSAGE("It's super effective!");
}
}
SINGLE_BATTLE_TEST("Refrigerate turns a normal type move into Ice")
{
GIVEN {
PLAYER(SPECIES_MEGANIUM);
OPPONENT(SPECIES_AMAURA) { Ability(ABILITY_REFRIGERATE); }
} WHEN {
TURN { MOVE(opponent, MOVE_TACKLE, megaEvolve: TRUE); }
} SCENE {
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_MEGA_EVOLUTION, opponent);
ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent);
MESSAGE("It's super effective!");
}
}
SINGLE_BATTLE_TEST("Aerilate turns a normal type move into Flying")
{
GIVEN {
PLAYER(SPECIES_MEGANIUM);
OPPONENT(SPECIES_SALAMENCE) { Item(ITEM_SALAMENCITE); }
} WHEN {
TURN { MOVE(opponent, MOVE_TACKLE, megaEvolve: TRUE); }
} SCENE {
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_MEGA_EVOLUTION, opponent);
ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent);
MESSAGE("It's super effective!");
}
}