From 608dd9ddc589702a9157054cd5e6857214ea160b Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Thu, 17 Jun 2021 11:15:53 -0600 Subject: [PATCH] add shiny chaining --- include/constants/flags.h | 2 +- src/dexnav.c | 4 ++++ src/pokemon.c | 20 ++++++++++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/constants/flags.h b/include/constants/flags.h index c9ba073789..88a282ef3c 100644 --- a/include/constants/flags.h +++ b/include/constants/flags.h @@ -1382,7 +1382,7 @@ #define FLAG_NURSE_UNION_ROOM_REMINDER (SYSTEM_FLAGS + 0x20) #define FLAG_SYS_DEXNAV_SEARCH (SYSTEM_FLAGS + 0x21) -#define FLAG_UNUSED_0x882 (SYSTEM_FLAGS + 0x22) // Unused Flag +#define FLAG_SHINY_CREATION (SYSTEM_FLAGS + 0x22) // force creation of a shiny mon #define FLAG_UNUSED_0x883 (SYSTEM_FLAGS + 0x23) // Unused Flag #define FLAG_UNUSED_0x884 (SYSTEM_FLAGS + 0x24) // Unused Flag #define FLAG_UNUSED_0x885 (SYSTEM_FLAGS + 0x25) // Unused Flag diff --git a/src/dexnav.c b/src/dexnav.c index da456848bd..41e2c8b68e 100644 --- a/src/dexnav.c +++ b/src/dexnav.c @@ -1215,6 +1215,9 @@ static void CreateDexNavWildMon(u16 species, u8 potential, u8 level, u8 abilityN u8 i; u8 perfectIv = 31; + if (DexNavTryMakeShinyMon()) + FlagSet(FLAG_SHINY_CREATION); // just easier this way + CreateWildMon(species, level); // shiny rate bonus handled in CreateBoxMon //Pick potential unique ivs to set to 31 @@ -1239,6 +1242,7 @@ static void CreateDexNavWildMon(u16 species, u8 potential, u8 level, u8 abilityN SetMonMoveSlot(mon, moves[i], i); CalculateMonStats(mon); + FlagClear(FLAG_SHINY_CREATION); } // gets a random level of the species based on map data. diff --git a/src/pokemon.c b/src/pokemon.c index 1ba7bf9326..775e8db1b9 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -2179,8 +2179,6 @@ void CreateBoxMon(struct BoxPokemon *boxMon, u16 species, u8 level, u8 fixedIV, else personality = Random32(); - SetBoxMonData(boxMon, MON_DATA_PERSONALITY, &personality); - //Determine original trainer ID if (otIdType == OT_ID_RANDOM_NO_SHINY) //Pokemon cannot be shiny { @@ -2198,11 +2196,21 @@ void CreateBoxMon(struct BoxPokemon *boxMon, u16 species, u8 level, u8 fixedIV, else //Player is the OT { value = gSaveBlock2Ptr->playerTrainerId[0] - | (gSaveBlock2Ptr->playerTrainerId[1] << 8) - | (gSaveBlock2Ptr->playerTrainerId[2] << 16) - | (gSaveBlock2Ptr->playerTrainerId[3] << 24); + | (gSaveBlock2Ptr->playerTrainerId[1] << 8) + | (gSaveBlock2Ptr->playerTrainerId[2] << 16) + | (gSaveBlock2Ptr->playerTrainerId[3] << 24); + + if (FlagGet(FLAG_SHINY_CREATION)) + { + u8 nature = personality % NUM_NATURES; // keep current nature + do { + personality = Random32(); + personality = ((((Random() % SHINY_ODDS) ^ (HIHALF(value) ^ LOHALF(value))) ^ LOHALF(personality)) << 16) | LOHALF(personality); + } while (nature != GetNatureFromPersonality(personality)); + } } - + + SetBoxMonData(boxMon, MON_DATA_PERSONALITY, &personality); SetBoxMonData(boxMon, MON_DATA_OT_ID, &value); checksum = CalculateBoxMonChecksum(boxMon);