pokemon_shiny.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <gui/modules/submenu.h>
  2. #include "../pokemon_app.h"
  3. #include "../pokemon_data.h"
  4. #include "pokemon_menu.h"
  5. /* This just assumes gen ii for now */
  6. /* For a Gen II pokemon to be shiny, the following must be met:
  7. * Spd, Def, and Spc must all be 10
  8. * Atk must be 2, 3, 6, 7, 10, 11, 14, or 15
  9. */
  10. bool select_shiny_is_shiny(PokemonData* pdata) {
  11. uint8_t atk_iv = pokemon_stat_get(pdata, STAT_ATK_IV, NONE);
  12. uint8_t def_iv = pokemon_stat_get(pdata, STAT_DEF_IV, NONE);
  13. uint8_t spd_iv = pokemon_stat_get(pdata, STAT_SPD_IV, NONE);
  14. uint8_t spc_iv = pokemon_stat_get(pdata, STAT_SPC_IV, NONE);
  15. bool rc = 1;
  16. if(spd_iv != 10) rc = 0;
  17. if(def_iv != 10) rc = 0;
  18. if(spc_iv != 10) rc = 0;
  19. switch(atk_iv) {
  20. case 0:
  21. case 1:
  22. case 4:
  23. case 5:
  24. case 8:
  25. case 9:
  26. case 12:
  27. case 13:
  28. rc = 0;
  29. break;
  30. default:
  31. break;
  32. }
  33. return rc;
  34. }
  35. static void select_shiny_selected_callback(void* context, uint32_t index) {
  36. PokemonFap* pokemon_fap = (PokemonFap*)context;
  37. PokemonData* pdata = pokemon_fap->pdata;
  38. if(!index) {
  39. do {
  40. /* First, reset the IV to the selected stat */
  41. pokemon_stat_set(pdata, STAT_SEL, NONE, pokemon_stat_get(pdata, STAT_SEL, NONE));
  42. /* Next, ensure the current IVs wouldn't make the pokemon shiny */
  43. } while(select_shiny_is_shiny(pdata));
  44. } else {
  45. /* Set Def, Spd, Spc to 10 */
  46. pokemon_stat_set(pdata, STAT_DEF_IV, NONE, 10);
  47. pokemon_stat_set(pdata, STAT_SPD_IV, NONE, 10);
  48. pokemon_stat_set(pdata, STAT_SPC_IV, NONE, 10);
  49. /* Increase ATK IV until we hit a shiny number. Note that, this only
  50. * affects IVs that are randomly generated, max IV will already be set
  51. * at 15 which will make it shiny.
  52. */
  53. while(!select_shiny_is_shiny(pdata)) {
  54. pokemon_stat_set(
  55. pdata, STAT_ATK_IV, NONE, pokemon_stat_get(pdata, STAT_ATK_IV, NONE) + 1);
  56. }
  57. }
  58. scene_manager_previous_scene(pokemon_fap->scene_manager);
  59. }
  60. void select_shiny_scene_on_enter(void* context) {
  61. PokemonFap* pokemon_fap = (PokemonFap*)context;
  62. submenu_reset(pokemon_fap->submenu);
  63. submenu_add_item(
  64. pokemon_fap->submenu, "Shiny", 1, select_shiny_selected_callback, pokemon_fap);
  65. submenu_add_item(
  66. pokemon_fap->submenu, "Not Shiny", 0, select_shiny_selected_callback, pokemon_fap);
  67. }