From ed1ea69759ab2efaa4cf9568b57b2d0c311d4dc9 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada D'Ottone Date: Sat, 26 Feb 2022 21:40:20 -0300 Subject: [PATCH] Fixed Shelmet and Karrablast being able to evolve if the partner is holding an Everstone --- include/pokemon.h | 2 +- src/battle_main.c | 2 +- src/party_menu.c | 4 ++-- src/pokemon.c | 26 +++++++++++++++++++++++--- src/trade.c | 6 +++--- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/include/pokemon.h b/include/pokemon.h index 1dc3ed461..fbb6612e3 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -385,7 +385,7 @@ u8 GetItemEffectParamOffset(u16 itemId, u8 effectByte, u8 effectBit); u8 *UseStatIncreaseItem(u16 itemId); u8 GetNature(struct Pokemon *mon); u8 GetNatureFromPersonality(u32 personality); -u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 type, u16 evolutionItem, u16 tradePartnerSpecies); +u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 type, u16 evolutionItem, struct Pokemon *tradePartner); u16 HoennPokedexNumToSpecies(u16 hoennNum); u16 NationalPokedexNumToSpecies(u16 nationalNum); u16 NationalToHoennOrder(u16 nationalNum); diff --git a/src/battle_main.c b/src/battle_main.c index 9f33450f5..594c3779d 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -5150,7 +5150,7 @@ static void TryEvolvePokemon(void) levelUpBits &= ~(gBitTable[i]); gLeveledUpInBattle = levelUpBits; - species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_NORMAL, levelUpBits, SPECIES_NONE); + species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_NORMAL, levelUpBits, NULL); if (species != SPECIES_NONE) { FreeAllWindowBuffers(); diff --git a/src/party_menu.c b/src/party_menu.c index 7c24eeb7a..1e281032e 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -915,7 +915,7 @@ static bool8 DisplayPartyPokemonDataForMoveTutorOrEvolutionItem(u8 slot) DisplayPartyPokemonDataToTeachMove(slot, item, 0); break; case 2: // Evolution stone - if (!GetMonData(currentPokemon, MON_DATA_IS_EGG) && GetEvolutionTargetSpecies(currentPokemon, EVO_MODE_ITEM_CHECK, item, SPECIES_NONE) != SPECIES_NONE) + if (!GetMonData(currentPokemon, MON_DATA_IS_EGG) && GetEvolutionTargetSpecies(currentPokemon, EVO_MODE_ITEM_CHECK, item, NULL) != SPECIES_NONE) return FALSE; DisplayPartyPokemonDescriptionData(slot, PARTYBOX_DESC_NO_USE); break; @@ -5026,7 +5026,7 @@ static void Task_TryLearningNextMove(u8 taskId) static void PartyMenuTryEvolution(u8 taskId) { struct Pokemon *mon = &gPlayerParty[gPartyMenu.slotId]; - u16 targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_NORMAL, ITEM_NONE, SPECIES_NONE); + u16 targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_NORMAL, ITEM_NONE, NULL); if (targetSpecies != SPECIES_NONE) { diff --git a/src/pokemon.c b/src/pokemon.c index 73df906c2..a57bbd203 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -6086,7 +6086,7 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov case 7: // ITEM4_EVO_STONE { - u16 targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_ITEM_USE, item, SPECIES_NONE); + u16 targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_ITEM_USE, item, NULL); if (targetSpecies != SPECIES_NONE) { @@ -6410,7 +6410,7 @@ u8 GetNatureFromPersonality(u32 personality) return personality % NUM_NATURES; } -u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem, u16 tradePartnerSpecies) +u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem, struct Pokemon *tradePartner) { int i, j; u16 targetSpecies = 0; @@ -6423,6 +6423,26 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem, u u16 upperPersonality = personality >> 16; u8 holdEffect; u16 currentMap; + u16 partnerSpecies; + u16 partnerHeldItem; + u8 partnerHoldEffect; + + if (tradePartner != NULL) + { + partnerSpecies = GetMonData(tradePartner, MON_DATA_SPECIES, 0); + partnerHeldItem = GetMonData(tradePartner, MON_DATA_HELD_ITEM, 0); + + if (partnerHeldItem == ITEM_ENIGMA_BERRY) + partnerHoldEffect = gSaveBlock1Ptr->enigmaBerry.holdEffect; + else + partnerHoldEffect = ItemId_GetHoldEffect(partnerHeldItem); + } + else + { + partnerSpecies = SPECIES_NONE; + partnerHeldItem = ITEM_NONE; + partnerHoldEffect = HOLD_EFFECT_NONE; + } if (heldItem == ITEM_ENIGMA_BERRY) holdEffect = gSaveBlock1Ptr->enigmaBerry.holdEffect; @@ -6654,7 +6674,7 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem, u } break; case EVO_TRADE_SPECIFIC_MON: - if (gEvolutionTable[species][i].param == tradePartnerSpecies) + if (gEvolutionTable[species][i].param == partnerSpecies && partnerHoldEffect != HOLD_EFFECT_PREVENT_EVOLVE) targetSpecies = gEvolutionTable[species][i].targetSpecies; break; } diff --git a/src/trade.c b/src/trade.c index ba07b9291..cd3c5f436 100644 --- a/src/trade.c +++ b/src/trade.c @@ -3798,7 +3798,7 @@ static bool8 AnimateTradeSequenceCable(void) case TS_STATE_TRY_EVOLUTION: // Only if in-game trade, link trades use CB2_TryLinkTradeEvolution TradeMons(gSpecialVar_0x8005, 0); gCB2_AfterEvolution = CB2_UpdateInGameTrade; - evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE, GetMonData(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PARTNER]], MON_DATA_SPECIES)); + evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE, &gPlayerParty[gSelectedTradeMonPositions[TRADE_PARTNER]]); if (evoTarget != SPECIES_NONE) { TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeData->monSpriteIds[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]); @@ -4298,7 +4298,7 @@ static bool8 AnimateTradeSequenceWireless(void) case TS_STATE_TRY_EVOLUTION: // Only if in-game trade, link trades use CB2_TryLinkTradeEvolution TradeMons(gSpecialVar_0x8005, 0); gCB2_AfterEvolution = CB2_UpdateInGameTrade; - evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE, GetMonData(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PARTNER]], MON_DATA_SPECIES)); + evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE, &gPlayerParty[gSelectedTradeMonPositions[TRADE_PARTNER]]); if (evoTarget != SPECIES_NONE) { TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeData->monSpriteIds[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]); @@ -4343,7 +4343,7 @@ static void CB2_TryLinkTradeEvolution(void) break; case 4: gCB2_AfterEvolution = CB2_SaveAndEndTrade; - evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE, GetMonData(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PARTNER]], MON_DATA_SPECIES)); + evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE, &gPlayerParty[gSelectedTradeMonPositions[TRADE_PARTNER]]); if (evoTarget != SPECIES_NONE) TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeData->monSpriteIds[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]); else if (IsWirelessTrade())