diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 4817dd95a1..dba4b3ea33 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2172,3 +2172,16 @@ .2byte \status1 .2byte \slot .endm + + @ Sets VAR_RESULT to the Pokémon in \slot's Tera Type + .macro checkteratype slot:req + callnative CheckTeraType + .2byte \slot + .endm + + @ Sets the Pokémon in \slot's Tera Type + .macro setteratype type:req, slot:req + callnative SetTeraType + .byte \type + .2byte \slot + .endm diff --git a/src/script_pokemon_util.c b/src/script_pokemon_util.c index 763bb3f9e6..f7dacbbfb7 100644 --- a/src/script_pokemon_util.c +++ b/src/script_pokemon_util.c @@ -294,6 +294,25 @@ void ToggleGigantamaxFactor(struct ScriptContext *ctx) } } +void CheckTeraType(struct ScriptContext *ctx) +{ + u32 partyIndex = VarGet(ScriptReadHalfword(ctx)); + + gSpecialVar_Result = TYPE_NONE; + + if (partyIndex < PARTY_SIZE) + gSpecialVar_Result = GetMonData(&gPlayerParty[partyIndex], MON_DATA_TERA_TYPE); +} + +void SetTeraType(struct ScriptContext *ctx) +{ + u32 type = ScriptReadByte(ctx); + u32 partyIndex = VarGet(ScriptReadHalfword(ctx)); + + if (type < NUMBER_OF_MON_TYPES && partyIndex < PARTY_SIZE) + SetMonData(&gPlayerParty[partyIndex], MON_DATA_TERA_TYPE, &type); +} + u32 ScriptGiveMonParameterized(u16 species, u8 level, u16 item, u8 ball, u8 nature, u8 abilityNum, u8 gender, u8 *evs, u8 *ivs, u16 *moves, bool8 isShiny, bool8 ggMaxFactor, u8 teraType) { u16 nationalDexNum; diff --git a/test/pokemon.c b/test/pokemon.c index 1ae655ab3c..2e35896027 100644 --- a/test/pokemon.c +++ b/test/pokemon.c @@ -307,3 +307,19 @@ TEST("givemon [vars]") EXPECT_EQ(GetMonData(&gPlayerParty[0], MON_DATA_GIGANTAMAX_FACTOR), TRUE); EXPECT_EQ(GetMonData(&gPlayerParty[0], MON_DATA_TERA_TYPE), TYPE_FIRE); } + +TEST("checkteratype/setteratype work") +{ + CreateMon(&gPlayerParty[0], SPECIES_WOBBUFFET, 100, 0, FALSE, 0, OT_ID_PRESET, 0); + + RUN_OVERWORLD_SCRIPT( + checkteratype 0; + ); + EXPECT(VarGet(VAR_RESULT) == TYPE_PSYCHIC); + + RUN_OVERWORLD_SCRIPT( + setteratype TYPE_FIRE, 0; + checkteratype 0; + ); + EXPECT(VarGet(VAR_RESULT) == TYPE_FIRE); +}