Implement Enigma Berry's hold effect + tests (#3300)

* Fix Enigma Berry

* Tests

* Update enigma_berry.c
This commit is contained in:
kittenchilly 2023-09-14 06:08:24 -05:00 committed by GitHub
parent db039ee4e2
commit 2ce3f4db78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 0 deletions

View File

@ -6554,6 +6554,29 @@ static u8 TrySetMicleBerry(u32 battler, u32 itemId, bool32 end2)
return 0;
}
static u8 TrySetEnigmaBerry(u32 battler)
{
if (IsBattlerAlive(battler)
&& TARGET_TURN_DAMAGED
&& !DoesSubstituteBlockMove(gBattlerAttacker, battler, gCurrentMove)
&& !(gBattleScripting.overrideBerryRequirements && gBattleMons[battler].hp == gBattleMons[battler].maxHP)
#if B_HEAL_BLOCKING >= GEN_5
&& !(gStatuses3[battler] & STATUS3_HEAL_BLOCK)
#endif
&& gMoveResultFlags & MOVE_RESULT_SUPER_EFFECTIVE)
{
gBattleScripting.battler = battler;
gBattleMoveDamage = (gBattleMons[battler].maxHP * 25 / 100) * -1;
if (GetBattlerAbility(battler) == ABILITY_RIPEN)
gBattleMoveDamage *= 2;
BattleScriptPushCursor();
gBattlescriptCurrInstr = BattleScript_ItemHealHP_RemoveItemRet;
return ITEM_HP_CHANGE;
}
return 0;
}
static u8 DamagedStatBoostBerryEffect(u8 battler, u8 statId, u8 split)
{
if (IsBattlerAlive(battler)
@ -6767,6 +6790,9 @@ static u8 ItemEffectMoveEnd(u32 battler, u16 holdEffect)
case HOLD_EFFECT_SP_DEFENSE_UP:
effect = StatRaiseBerry(battler, gLastUsedItem, STAT_SPDEF, FALSE);
break;
case HOLD_EFFECT_ENIGMA_BERRY: // consume and heal if hit by super effective move
effect = TrySetEnigmaBerry(battler);
break;
case HOLD_EFFECT_KEE_BERRY: // consume and boost defense if used physical move
effect = DamagedStatBoostBerryEffect(battler, STAT_DEF, SPLIT_PHYSICAL);
break;
@ -7730,6 +7756,9 @@ u8 ItemBattleEffects(u8 caseID, u8 battler, bool8 moveTurn)
gBattleScripting.statChanger = SET_STATCHANGER(STAT_SPATK, 1, FALSE);
}
break;
case HOLD_EFFECT_ENIGMA_BERRY: // consume and heal if hit by super effective move
effect = TrySetEnigmaBerry(battler);
break;
case HOLD_EFFECT_JABOCA_BERRY: // consume and damage attacker if used physical move
if (IsBattlerAlive(battler)
&& TARGET_TURN_DAMAGED

View File

@ -0,0 +1,60 @@
#include "global.h"
#include "test/battle.h"
ASSUMPTIONS
{
gItems[ITEM_ENIGMA_BERRY].holdEffect == HOLD_EFFECT_ENIGMA_BERRY;
}
SINGLE_BATTLE_TEST("Enigma Berry recovers 25% of HP if hit by super effective move")
{
GIVEN {
PLAYER(SPECIES_WYNAUT) { MaxHP(100); HP(2); Item(ITEM_ENIGMA_BERRY); }
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { MOVE(player, MOVE_ENDURE); MOVE(opponent, MOVE_BITE); }
} SCENE {
s32 maxHP = GetMonData(&PLAYER_PARTY[0], MON_DATA_MAX_HP);
ANIMATION(ANIM_TYPE_MOVE, MOVE_ENDURE, player);
ANIMATION(ANIM_TYPE_MOVE, MOVE_BITE, opponent);
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player);
MESSAGE("Wynaut's Enigma Berry restored health!");
HP_BAR(player, damage: -maxHP / 4);
}
}
SINGLE_BATTLE_TEST("Enigma Berry does nothing if not hit by super effective move")
{
GIVEN {
PLAYER(SPECIES_MIGHTYENA) { MaxHP(100); HP(2); Item(ITEM_ENIGMA_BERRY); }
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { MOVE(player, MOVE_ENDURE); MOVE(opponent, MOVE_BITE); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_ENDURE, player);
ANIMATION(ANIM_TYPE_MOVE, MOVE_BITE, opponent);
NONE_OF {
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player);
MESSAGE("Mightyena's Enigma Berry restored health!");
}
}
}
SINGLE_BATTLE_TEST("Enigma Berry does nothing if Heal Block applies")
{
GIVEN {
PLAYER(SPECIES_WYNAUT) { MaxHP(100); HP(2); Item(ITEM_ENIGMA_BERRY); }
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { MOVE(opponent, MOVE_HEAL_BLOCK); }
TURN { MOVE(player, MOVE_ENDURE); MOVE(opponent, MOVE_BITE); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_HEAL_BLOCK, opponent);
ANIMATION(ANIM_TYPE_MOVE, MOVE_ENDURE, player);
ANIMATION(ANIM_TYPE_MOVE, MOVE_BITE, opponent);
NONE_OF {
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player);
MESSAGE("Wynaut's Enigma Berry restored health!");
}
}
}