Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Rivalry's effect + Tests #3381

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/battle_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ bool32 ChangeTypeBasedOnTerrain(u32 battler);
void RemoveConfusionStatus(u32 battler);
u8 GetBattlerGender(u32 battler);
bool32 AreBattlersOfOppositeGender(u32 battler1, u32 battler2);
bool32 AreBattlersOfSameGender(u32 battler1, u32 battler2);
u32 CalcSecondaryEffectChance(u32 battler, u8 secondaryEffectChance);
u8 GetBattlerType(u32 battler, u8 typeIndex);

Expand Down
12 changes: 10 additions & 2 deletions src/battle_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -8905,9 +8905,9 @@ static inline u32 CalcMoveBasePowerAfterModifiers(u32 move, u32 battlerAtk, u32
modifier = uq4_12_multiply(modifier, UQ_4_12(1.3));
break;
case ABILITY_RIVALRY:
if (AreBattlersOfOppositeGender(battlerAtk, battlerDef))
if (AreBattlersOfSameGender(battlerAtk, battlerDef))
modifier = uq4_12_multiply(modifier, UQ_4_12(1.25));
else
else if (AreBattlersOfOppositeGender(battlerAtk, battlerDef))
modifier = uq4_12_multiply(modifier, UQ_4_12(0.75));
break;
case ABILITY_ANALYTIC:
Expand Down Expand Up @@ -11174,6 +11174,14 @@ bool32 AreBattlersOfOppositeGender(u32 battler1, u32 battler2)
return (gender1 != MON_GENDERLESS && gender2 != MON_GENDERLESS && gender1 != gender2);
}

bool32 AreBattlersOfSameGender(u32 battler1, u32 battler2)
{
u8 gender1 = GetBattlerGender(battler1);
u8 gender2 = GetBattlerGender(battler2);

return (gender1 != MON_GENDERLESS && gender2 != MON_GENDERLESS && gender1 == gender2);
}

u32 CalcSecondaryEffectChance(u32 battler, u8 secondaryEffectChance)
{
if (GetBattlerAbility(battler) == ABILITY_SERENE_GRACE)
Expand Down
99 changes: 99 additions & 0 deletions test/battle/ability/rivalry.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include "global.h"
#include "test/battle.h"

ASSUMPTIONS
{
ASSUME(gSpeciesInfo[SPECIES_NIDOKING].genderRatio == MON_MALE);
ASSUME(gSpeciesInfo[SPECIES_NIDOQUEEN].genderRatio == MON_FEMALE);
ASSUME(gSpeciesInfo[SPECIES_PORYGON].genderRatio == MON_GENDERLESS);
}

SINGLE_BATTLE_TEST("Rivalry increases power by x1.25 towards Pokémon of the same gender", s16 damage)
{
u16 species, ability;
PARAMETRIZE { species = SPECIES_NIDOKING; ability = ABILITY_POISON_POINT; }
PARAMETRIZE { species = SPECIES_NIDOKING; ability = ABILITY_RIVALRY; }
PARAMETRIZE { species = SPECIES_NIDOQUEEN; ability = ABILITY_POISON_POINT; }
PARAMETRIZE { species = SPECIES_NIDOQUEEN; ability = ABILITY_RIVALRY; }

GIVEN {
PLAYER(species) { Ability(ability); }
OPPONENT(species);
} WHEN {
TURN { MOVE(player, MOVE_TACKLE); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, player);
HP_BAR(opponent, captureDamage: &results[i].damage);
} FINALLY {
EXPECT_MUL_EQ(results[0].damage, Q_4_12(1.25), results[1].damage);
EXPECT_MUL_EQ(results[2].damage, Q_4_12(1.25), results[3].damage);
}
}

SINGLE_BATTLE_TEST("Rivalry decreases power by x0.75 towards Pokémon of different gender", s16 damage)
{
u16 species1, species2, ability;
PARAMETRIZE { species1 = SPECIES_NIDOKING; species2 = SPECIES_NIDOQUEEN; ability = ABILITY_POISON_POINT; }
PARAMETRIZE { species1 = SPECIES_NIDOKING; species2 = SPECIES_NIDOQUEEN; ability = ABILITY_RIVALRY; }
PARAMETRIZE { species1 = SPECIES_NIDOQUEEN; species2 = SPECIES_NIDOKING; ability = ABILITY_POISON_POINT; }
PARAMETRIZE { species1 = SPECIES_NIDOQUEEN; species2 = SPECIES_NIDOKING; ability = ABILITY_RIVALRY; }

GIVEN {
PLAYER(species1) { Ability(ability); }
OPPONENT(species2);
} WHEN {
TURN { MOVE(player, MOVE_TACKLE); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, player);
HP_BAR(opponent, captureDamage: &results[i].damage);
} FINALLY {
EXPECT_MUL_EQ(results[0].damage, Q_4_12(0.75), results[1].damage);
EXPECT_MUL_EQ(results[2].damage, Q_4_12(0.75), results[3].damage);
}
}

SINGLE_BATTLE_TEST("Rivalry doesn't modify power if the attacker is genderless", s16 damage)
{
u16 species, ability;
PARAMETRIZE { species = SPECIES_NIDOKING; ability = ABILITY_POISON_POINT; }
PARAMETRIZE { species = SPECIES_NIDOKING; ability = ABILITY_RIVALRY; }
PARAMETRIZE { species = SPECIES_NIDOQUEEN; ability = ABILITY_POISON_POINT; }
PARAMETRIZE { species = SPECIES_NIDOQUEEN; ability = ABILITY_RIVALRY; }

GIVEN {
ASSUME(gSpeciesInfo[SPECIES_PORYGON].abilities[0] == ABILITY_TRACE);
PLAYER(SPECIES_PORYGON) { Ability(ABILITY_TRACE); } // No genderless mon naturally gets Rivalry
OPPONENT(species) { Ability(ability); };
} WHEN {
TURN { MOVE(player, MOVE_TACKLE); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, player);
HP_BAR(opponent, captureDamage: &results[i].damage);
} FINALLY {
EXPECT(results[0].damage == results[1].damage);
EXPECT(results[2].damage == results[3].damage);
}
}


SINGLE_BATTLE_TEST("Rivalry doesn't modify power if the target is genderless", s16 damage)
{
u16 species, ability;
PARAMETRIZE { species = SPECIES_NIDOKING; ability = ABILITY_POISON_POINT; }
PARAMETRIZE { species = SPECIES_NIDOKING; ability = ABILITY_RIVALRY; }
PARAMETRIZE { species = SPECIES_NIDOQUEEN; ability = ABILITY_POISON_POINT; }
PARAMETRIZE { species = SPECIES_NIDOQUEEN; ability = ABILITY_RIVALRY; }

GIVEN {
PLAYER(species) { Ability(ability); };
OPPONENT(SPECIES_PORYGON);
} WHEN {
TURN { MOVE(player, MOVE_TACKLE); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, player);
HP_BAR(opponent, captureDamage: &results[i].damage);
} FINALLY {
EXPECT(results[0].damage == results[1].damage);
EXPECT(results[2].damage == results[3].damage);
}
}
Loading