Advertisement
KDLPro

512 Max EVs test snippet

Apr 1st, 2021
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. GiveExperiencePoints:
  2. ; Give experience.
  3. ; Don't give experience if linked or in the Battle Tower.
  4.  
  5. ...
  6.  
  7. .no_pokerus_boost
  8. ; Make sure total EVs never surpass 512
  9. ld d, a
  10. push af
  11. push bc
  12. push hl
  13. ld e, 6
  14. ld bc, 0
  15. .count_evs
  16. ld a, [hli]
  17. add c
  18. ld c, a
  19. jr nc, .cont
  20. inc b
  21. .cont
  22. dec e
  23. jr nz, .count_evs
  24. ld a, d
  25. add c
  26. ld c, a
  27. adc b
  28. sub c
  29. ld b, a
  30. ld e, a
  31. .decrease_evs_gained
  32. call IsEvsGreaterThan512
  33. jr z, .check_ev_overflow
  34. jr c, .check_ev_overflow
  35. dec e
  36. dec bc
  37. jr .decrease_evs_gained
  38. .check_ev_overflow
  39. pop hl
  40. pop bc
  41. pop af
  42. ld a, e
  43. add [hl]
  44. cp MAX_EV
  45. jr nc, .ev_overflow
  46. cp MAX_EV + 1
  47. jr c, .got_ev
  48. .ev_overflow
  49. ld a, MAX_EV
  50. .got_ev
  51. ld [hli], a
  52. dec c
  53. jr z, .evs_done
  54. ; Use the second byte for Sp.Atk and Sp.Def
  55. ld a, c
  56. cp 2 ; two stats left, Sp.Atk and Sp.Def
  57. jr nz, .ev_loop
  58. ld a, [wBaseSpAtkSpDefEVs]
  59. ld b, a
  60. jr .ev_loop
  61. .evs_done
  62. xor a
  63. ldh [hMultiplicand + 0], a
  64. ldh [hMultiplicand + 1], a
  65. ld a, [wEnemyMonBaseExp]
  66. ldh [hMultiplicand + 2], a
  67. ld a, [wEnemyMonLevel]
  68. ldh [hMultiplier], a
  69. call Multiply
  70. ld a, 7
  71. ldh [hDivisor], a
  72. ld b, 4
  73. call Divide
  74.  
  75. ...
  76.  
  77. ldh a, [hQuotient + 3]
  78. ld [hli], a
  79. dec c
  80. jr nz, .base_stat_division_loop
  81. ret
  82.  
  83. IsEvsGreaterThan512:
  84. ; EV total in bc
  85. ; Returns c if lower
  86. ld a, b
  87. cp HIGH(MAX_TOTAL_EV) ; 512
  88. ret nz
  89. ld a, c
  90. cp LOW(MAX_TOTAL_EV) ; 512
  91. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement