Fixed Grassy Terrain not healing

This commit is contained in:
Eduardo Quezada D'Ottone 2023-03-23 22:33:47 -03:00
parent 2658fe32c2
commit 1da65c4051
2 changed files with 37 additions and 11 deletions

View File

@ -2127,15 +2127,25 @@ enum
ENDTURN_FIELD_COUNT,
};
static bool32 TryEndTerrain(u32 terrainFlag, u32 stringTableId)
static bool32 EndTurnTerrain(u32 terrainFlag, u32 stringTableId)
{
if (gFieldStatuses & terrainFlag
&& (!(gFieldStatuses & STATUS_FIELD_TERRAIN_PERMANENT) && --gFieldTimers.terrainTimer == 0))
if (gFieldStatuses & terrainFlag)
{
gFieldStatuses &= ~terrainFlag;
TryToRevertMimicry();
gBattleCommunication[MULTISTRING_CHOOSER] = stringTableId;
BattleScriptExecute(BattleScript_TerrainEnds);
if (!(gFieldStatuses & STATUS_FIELD_TERRAIN_PERMANENT) && --gFieldTimers.terrainTimer == 0)
{
gFieldStatuses &= ~terrainFlag;
TryToRevertMimicry();
if (terrainFlag != STATUS_FIELD_GRASSY_TERRAIN)
{
gBattleCommunication[MULTISTRING_CHOOSER] = stringTableId;
BattleScriptExecute(BattleScript_TerrainEnds);
}
}
if (terrainFlag == STATUS_FIELD_GRASSY_TERRAIN)
{
BattleScriptExecute(BattleScript_GrassyTerrainHeals);
}
return TRUE;
}
return FALSE;
@ -2492,19 +2502,19 @@ u8 DoFieldEndTurnEffects(void)
gBattleStruct->turnCountersTracker++;
break;
case ENDTURN_ELECTRIC_TERRAIN:
effect = TryEndTerrain(STATUS_FIELD_ELECTRIC_TERRAIN, B_MSG_TERRAINENDS_ELECTRIC);
effect += EndTurnTerrain(STATUS_FIELD_ELECTRIC_TERRAIN, B_MSG_TERRAINENDS_ELECTRIC);
gBattleStruct->turnCountersTracker++;
break;
case ENDTURN_MISTY_TERRAIN:
effect = TryEndTerrain(STATUS_FIELD_MISTY_TERRAIN, B_MSG_TERRAINENDS_MISTY);
effect += EndTurnTerrain(STATUS_FIELD_MISTY_TERRAIN, B_MSG_TERRAINENDS_MISTY);
gBattleStruct->turnCountersTracker++;
break;
case ENDTURN_GRASSY_TERRAIN:
effect = TryEndTerrain(STATUS_FIELD_GRASSY_TERRAIN, B_MSG_TERRAINENDS_GRASS);
effect += EndTurnTerrain(STATUS_FIELD_GRASSY_TERRAIN, B_MSG_TERRAINENDS_GRASS);
gBattleStruct->turnCountersTracker++;
break;
case ENDTURN_PSYCHIC_TERRAIN:
effect = TryEndTerrain(STATUS_FIELD_PSYCHIC_TERRAIN, B_MSG_TERRAINENDS_PSYCHIC);
effect += EndTurnTerrain(STATUS_FIELD_PSYCHIC_TERRAIN, B_MSG_TERRAINENDS_PSYCHIC);
gBattleStruct->turnCountersTracker++;
break;
case ENDTURN_WATER_SPORT:

16
test/terrain_grassy.c Normal file
View File

@ -0,0 +1,16 @@
#include "global.h"
#include "test_battle.h"
SINGLE_BATTLE_TEST("Grassy Terrain recovers 1/16th HP at end of turn")
{
GIVEN {
PLAYER(SPECIES_WOBBUFFET) { MaxHP(100); HP(1); }
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { MOVE(player, MOVE_GRASSY_TERRAIN); }
} SCENE {
s32 maxHP = GetMonData(&PLAYER_PARTY[0], MON_DATA_MAX_HP);
MESSAGE("Wobbuffet is healed by the grassy terrain!");
HP_BAR(player, damage: -maxHP / 16);
}
}