pokemon_shiny.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <src/include/pokemon_data.h>
  2. /* This just assumes gen ii for now */
  3. /* For a Gen II pokemon to be shiny, the following must be met:
  4. * Spd, Def, and Spc must all be 10
  5. * Atk must be 2, 3, 6, 7, 10, 11, 14, or 15
  6. */
  7. bool pokemon_is_shiny(PokemonData* pdata) {
  8. uint8_t atk_iv = pokemon_stat_get(pdata, STAT_ATK_IV, NONE);
  9. uint8_t def_iv = pokemon_stat_get(pdata, STAT_DEF_IV, NONE);
  10. uint8_t spd_iv = pokemon_stat_get(pdata, STAT_SPD_IV, NONE);
  11. uint8_t spc_iv = pokemon_stat_get(pdata, STAT_SPC_IV, NONE);
  12. bool rc = 1;
  13. if(spd_iv != 10) rc = 0;
  14. if(def_iv != 10) rc = 0;
  15. if(spc_iv != 10) rc = 0;
  16. switch(atk_iv) {
  17. case 0:
  18. case 1:
  19. case 4:
  20. case 5:
  21. case 8:
  22. case 9:
  23. case 12:
  24. case 13:
  25. rc = 0;
  26. break;
  27. default:
  28. break;
  29. }
  30. return rc;
  31. }
  32. void pokemon_set_shiny(PokemonData* pdata, bool shiny) {
  33. if(!shiny) {
  34. do {
  35. /* First, reset the IV to the selected stat */
  36. pokemon_stat_set(pdata, STAT_SEL, NONE, pokemon_stat_get(pdata, STAT_SEL, NONE));
  37. /* XXX: This may not be right? */
  38. /* Next, ensure the current IVs wouldn't make the pokemon shiny */
  39. } while(pokemon_is_shiny(pdata));
  40. } else {
  41. /* Set Def, Spd, Spc to 10 */
  42. pokemon_stat_set(pdata, STAT_DEF_IV, NONE, 10);
  43. pokemon_stat_set(pdata, STAT_SPD_IV, NONE, 10);
  44. pokemon_stat_set(pdata, STAT_SPC_IV, NONE, 10);
  45. /* Increase ATK IV until we hit a shiny number. Note that, this only
  46. * affects IVs that are randomly generated, max IV will already be set
  47. * at 15 which will make it shiny.
  48. */
  49. while(!pokemon_is_shiny(pdata)) {
  50. pokemon_stat_set(
  51. pdata, STAT_ATK_IV, NONE, pokemon_stat_get(pdata, STAT_ATK_IV, NONE) + 1);
  52. }
  53. }
  54. }