Created Shiny Creation With a Flag (markdown)

ghoulslash 2021-06-17 11:20:51 -06:00
parent 3457f166bb
commit 8ddbcd7359
1 changed files with 50 additions and 0 deletions

@ -0,0 +1,50 @@
## Create Shiny Pokemon with a Flag
### 1. Create a flag
Define a flag named `FLAG_SHINY_CREATION` in `include/constants/flags.h`
### 2. Make it do something
1. Open [pokemon.c](../blob/master/src/pokemon.c) and find `CreateBoxMon`
2. Make the following changes:
```diff
- SetBoxMonData(boxMon, MON_DATA_PERSONALITY, &personality);
//Determine original trainer ID
if (otIdType == OT_ID_RANDOM_NO_SHINY) //Pokemon cannot be shiny
{
u32 shinyValue;
do
{
value = Random32();
shinyValue = HIHALF(value) ^ LOHALF(value) ^ HIHALF(personality) ^ LOHALF(personality);
} while (shinyValue < SHINY_ODDS);
}
else if (otIdType == OT_ID_PRESET) //Pokemon has a preset OT ID
{
value = fixedOtId;
}
else //Player is the OT
{
value = gSaveBlock2Ptr->playerTrainerId[0]
| (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);
```
`FLAG_SHINY_CREATION` is NOT cleared internally because you might want to make multiple shiny pokemon. Feel free to add `FlagClear(FLAG_SHINY_CREATION)` at the end of `CreateBoxMon` to make sure only one shiny mon is created.