KDLPro

512 Max EVs test

Apr 1st, 2021 (edited)
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.54 KB | None | 0 0
  1. GiveExperiencePoints:
  2. ; Give experience.
  3. ; Don't give experience if linked or in the Battle Tower.
  4. ld a, [wLinkMode]
  5. and a
  6. ret nz
  7.  
  8. ld a, [wInBattleTowerBattle]
  9. bit 0, a
  10. ret nz
  11.  
  12. call .EvenlyDivideExpAmongParticipants
  13. xor a
  14. ld [wCurPartyMon], a
  15. ld bc, wPartyMon1Species
  16.  
  17. .loop
  18. ld hl, MON_HP
  19. add hl, bc
  20. ld a, [hli]
  21. or [hl]
  22. jp z, .next_mon ; fainted
  23.  
  24. push bc
  25. ld hl, wBattleParticipantsNotFainted
  26. ld a, [wCurPartyMon]
  27. ld c, a
  28. ld b, CHECK_FLAG
  29. ld d, 0
  30. predef SmallFarFlagAction
  31. ld a, c
  32. and a
  33. pop bc
  34. jp z, .next_mon
  35.  
  36. ; Give EVs
  37. ; e = 0 for no Pokerus, 1 for Pokerus
  38. ld e, 0
  39. ld hl, MON_PKRUS
  40. add hl, bc
  41. ld a, [hl]
  42. and a
  43. jr z, .no_pokerus
  44. inc e
  45. .no_pokerus
  46. ld hl, MON_EVS
  47. add hl, bc
  48. push bc
  49. ld a, [wEnemyMonSpecies]
  50. ld [wCurSpecies], a
  51. call GetBaseData
  52. ; EV yield format: %hhaaddss %ttff0000
  53. ; h = hp, a = atk, d = def, s = spd
  54. ; t = sat, f = sdf, 0 = unused bits
  55. ld a, [wBaseHPAtkDefSpdEVs]
  56. ld b, a
  57. ld c, 6 ; six EVs
  58. .ev_loop
  59. rlc b
  60. rlc b
  61. ld a, b
  62. and %11
  63. bit 0, e
  64. jr z, .no_pokerus_boost
  65. add a
  66. .no_pokerus_boost
  67. ; Make sure total EVs never surpass 512
  68. ld d, a
  69. push af
  70. push bc
  71. push hl
  72. ld e, 6
  73. ld bc, 0
  74. .count_evs
  75. ld a, [hli]
  76. add c
  77. ld c, a
  78. jr nc, .cont
  79. inc b
  80. .cont
  81. dec e
  82. jr nz, .count_evs
  83. ld a, d
  84. add c
  85. ld c, a
  86. adc b
  87. sub c
  88. ld b, a
  89. ld e, a
  90. .decrease_evs_gained
  91. call IsEvsGreaterThan512
  92. jr z, .check_ev_overflow
  93. jr c, .check_ev_overflow
  94. dec e
  95. dec bc
  96. jr .decrease_evs_gained
  97. .check_ev_overflow
  98. pop hl
  99. pop bc
  100. pop af
  101. ld a, e
  102. add [hl]
  103. cp MAX_EV
  104. jr nc, .ev_overflow
  105. cp MAX_EV + 1
  106. jr c, .got_ev
  107. .ev_overflow
  108. ld a, MAX_EV
  109. .got_ev
  110. ld [hli], a
  111. dec c
  112. jr z, .evs_done
  113. ; Use the second byte for Sp.Atk and Sp.Def
  114. ld a, c
  115. cp 2 ; two stats left, Sp.Atk and Sp.Def
  116. jr nz, .ev_loop
  117. ld a, [wBaseSpAtkSpDefEVs]
  118. ld b, a
  119. jr .ev_loop
  120. .evs_done
  121. xor a
  122. ldh [hMultiplicand + 0], a
  123. ldh [hMultiplicand + 1], a
  124. ld a, [wEnemyMonBaseExp]
  125. ldh [hMultiplicand + 2], a
  126. ld a, [wEnemyMonLevel]
  127. ldh [hMultiplier], a
  128. call Multiply
  129. ld a, 7
  130. ldh [hDivisor], a
  131. ld b, 4
  132. call Divide
  133. ; Boost Experience for traded Pokemon
  134. pop bc
  135. ld hl, MON_ID
  136. add hl, bc
  137. ld a, [wPlayerID]
  138. cp [hl]
  139. jr nz, .boosted
  140. inc hl
  141. ld a, [wPlayerID + 1]
  142. cp [hl]
  143. ld a, 0
  144. jr z, .no_boost
  145.  
  146. .boosted
  147. call BoostExp
  148. ld a, 1
  149.  
  150. .no_boost
  151. ; Boost experience for a Trainer Battle
  152. ld [wStringBuffer2 + 2], a
  153. ld a, [wBattleMode]
  154. dec a
  155. call nz, BoostExp
  156. ; Boost experience for Lucky Egg
  157. push bc
  158. ld a, MON_ITEM
  159. call GetPartyParamLocation
  160. ld a, [hl]
  161. cp LUCKY_EGG
  162. call z, BoostExp
  163. ldh a, [hQuotient + 3]
  164. ld [wStringBuffer2 + 1], a
  165. ldh a, [hQuotient + 2]
  166. ld [wStringBuffer2], a
  167. ld a, [wCurPartyMon]
  168. ld hl, wPartyMonNicknames
  169. call GetNick
  170. ld hl, Text_MonGainedExpPoint
  171. call BattleTextbox
  172. ld a, [wStringBuffer2 + 1]
  173. ldh [hQuotient + 3], a
  174. ld a, [wStringBuffer2]
  175. ldh [hQuotient + 2], a
  176. pop bc
  177. call AnimateExpBar
  178. push bc
  179. call LoadTilemapToTempTilemap
  180. pop bc
  181. ld hl, MON_EXP + 2
  182. add hl, bc
  183. ld d, [hl]
  184. ldh a, [hQuotient + 3]
  185. add d
  186. ld [hld], a
  187. ld d, [hl]
  188. ldh a, [hQuotient + 2]
  189. adc d
  190. ld [hl], a
  191. jr nc, .no_exp_overflow
  192. dec hl
  193. inc [hl]
  194. jr nz, .no_exp_overflow
  195. ld a, $ff
  196. ld [hli], a
  197. ld [hli], a
  198. ld [hl], a
  199.  
  200. .no_exp_overflow
  201. ld a, [wCurPartyMon]
  202. ld e, a
  203. ld d, 0
  204. ld hl, wPartySpecies
  205. add hl, de
  206. ld a, [hl]
  207. ld [wCurSpecies], a
  208. call GetBaseData
  209. push bc
  210. ld d, MAX_LEVEL
  211. callfar CalcExpAtLevel
  212. pop bc
  213. ld hl, MON_EXP + 2
  214. add hl, bc
  215. push bc
  216. ldh a, [hQuotient + 1]
  217. ld b, a
  218. ldh a, [hQuotient + 2]
  219. ld c, a
  220. ldh a, [hQuotient + 3]
  221. ld d, a
  222. ld a, [hld]
  223. sub d
  224. ld a, [hld]
  225. sbc c
  226. ld a, [hl]
  227. sbc b
  228. jr c, .not_max_exp
  229. ld a, b
  230. ld [hli], a
  231. ld a, c
  232. ld [hli], a
  233. ld a, d
  234. ld [hld], a
  235.  
  236. .not_max_exp
  237. ; Check if the mon leveled up
  238. xor a ; PARTYMON
  239. ld [wMonType], a
  240. predef CopyMonToTempMon
  241. callfar CalcLevel
  242. pop bc
  243. ld hl, MON_LEVEL
  244. add hl, bc
  245. ld a, [hl]
  246. cp MAX_LEVEL
  247. jp nc, .next_mon
  248. cp d
  249. jp z, .next_mon
  250. ; <NICKNAME> grew to level ##!
  251. ld [wTempLevel], a
  252. ld a, [wCurPartyLevel]
  253. push af
  254. ld a, d
  255. ld [wCurPartyLevel], a
  256. ld [hl], a
  257. ld hl, MON_SPECIES
  258. add hl, bc
  259. ld a, [hl]
  260. ld [wCurSpecies], a
  261. ld [wTempSpecies], a ; unused?
  262. call GetBaseData
  263. ld hl, MON_MAXHP + 1
  264. add hl, bc
  265. ld a, [hld]
  266. ld e, a
  267. ld d, [hl]
  268. push de
  269. ld hl, MON_MAXHP
  270. add hl, bc
  271. ld d, h
  272. ld e, l
  273. ld hl, MON_EVS - 1
  274. add hl, bc
  275. push bc
  276. ld b, TRUE
  277. predef CalcMonStats
  278. pop bc
  279. pop de
  280. ld hl, MON_MAXHP + 1
  281. add hl, bc
  282. ld a, [hld]
  283. sub e
  284. ld e, a
  285. ld a, [hl]
  286. sbc d
  287. ld d, a
  288. dec hl
  289. ld a, [hl]
  290. add e
  291. ld [hld], a
  292. ld a, [hl]
  293. adc d
  294. ld [hl], a
  295. ld a, [wCurBattleMon]
  296. ld d, a
  297. ld a, [wCurPartyMon]
  298. cp d
  299. jr nz, .skip_active_mon_update
  300. ld de, wBattleMonHP
  301. ld a, [hli]
  302. ld [de], a
  303. inc de
  304. ld a, [hli]
  305. ld [de], a
  306. ld de, wBattleMonMaxHP
  307. push bc
  308. ld bc, PARTYMON_STRUCT_LENGTH - MON_MAXHP
  309. call CopyBytes
  310. pop bc
  311. ld hl, MON_LEVEL
  312. add hl, bc
  313. ld a, [hl]
  314. ld [wBattleMonLevel], a
  315. ld a, [wPlayerSubStatus5]
  316. bit SUBSTATUS_TRANSFORMED, a
  317. jr nz, .transformed
  318. ld hl, MON_ATK
  319. add hl, bc
  320. ld de, wPlayerStats
  321. ld bc, PARTYMON_STRUCT_LENGTH - MON_ATK
  322. call CopyBytes
  323.  
  324. .transformed
  325. xor a ; FALSE
  326. ld [wApplyStatLevelMultipliersToEnemy], a
  327. call ApplyStatLevelMultiplierOnAllStats
  328. callfar ApplyStatusEffectOnPlayerStats
  329. callfar BadgeStatBoosts
  330. callfar UpdatePlayerHUD
  331. call EmptyBattleTextbox
  332. call LoadTilemapToTempTilemap
  333. ld a, $1
  334. ldh [hBGMapMode], a
  335.  
  336. .skip_active_mon_update
  337. farcall LevelUpHappinessMod
  338. ld a, [wCurBattleMon]
  339. ld b, a
  340. ld a, [wCurPartyMon]
  341. cp b
  342. jr z, .skip_exp_bar_animation
  343. ld de, SFX_HIT_END_OF_EXP_BAR
  344. call PlaySFX
  345. call WaitSFX
  346. ld hl, BattleText_StringBuffer1GrewToLevel
  347. call StdBattleTextbox
  348. call LoadTilemapToTempTilemap
  349.  
  350. .skip_exp_bar_animation
  351. xor a ; PARTYMON
  352. ld [wMonType], a
  353. predef CopyMonToTempMon
  354. hlcoord 9, 0
  355. ld b, 10
  356. ld c, 9
  357. call Textbox
  358. hlcoord 11, 1
  359. ld bc, 4
  360. predef PrintTempMonStats
  361. ld c, 30
  362. call DelayFrames
  363. call WaitPressAorB_BlinkCursor
  364. call SafeLoadTempTilemapToTilemap
  365. xor a ; PARTYMON
  366. ld [wMonType], a
  367. ld a, [wCurSpecies]
  368. ld [wTempSpecies], a ; unused?
  369. ld a, [wCurPartyLevel]
  370. push af
  371. ld c, a
  372. ld a, [wTempLevel]
  373. ld b, a
  374.  
  375. .level_loop
  376. inc b
  377. ld a, b
  378. ld [wCurPartyLevel], a
  379. push bc
  380. predef LearnLevelMoves
  381. pop bc
  382. ld a, b
  383. cp c
  384. jr nz, .level_loop
  385. pop af
  386. ld [wCurPartyLevel], a
  387. ld hl, wEvolvableFlags
  388. ld a, [wCurPartyMon]
  389. ld c, a
  390. ld b, SET_FLAG
  391. predef SmallFarFlagAction
  392. pop af
  393. ld [wCurPartyLevel], a
  394.  
  395. .next_mon
  396. ld a, [wPartyCount]
  397. ld b, a
  398. ld a, [wCurPartyMon]
  399. inc a
  400. cp b
  401. jr z, .done
  402. ld [wCurPartyMon], a
  403. ld a, MON_SPECIES
  404. call GetPartyParamLocation
  405. ld b, h
  406. ld c, l
  407. jp .loop
  408.  
  409. .done
  410. jp ResetBattleParticipants
  411.  
  412. .EvenlyDivideExpAmongParticipants:
  413. ; count number of battle participants
  414. ld a, [wBattleParticipantsNotFainted]
  415. ld b, a
  416. ld c, PARTY_LENGTH
  417. ld d, 0
  418. .count_loop
  419. xor a
  420. srl b
  421. adc d
  422. ld d, a
  423. dec c
  424. jr nz, .count_loop
  425. cp 2
  426. ret c
  427.  
  428. ld [wTempByteValue], a
  429. ld hl, wEnemyMonBaseStats
  430. ld c, wEnemyMonEnd - wEnemyMonBaseStats
  431. .base_stat_division_loop
  432. xor a
  433. ldh [hDividend + 0], a
  434. ld a, [hl]
  435. ldh [hDividend + 1], a
  436. ld a, [wTempByteValue]
  437. ldh [hDivisor], a
  438. ld b, 2
  439. call Divide
  440. ldh a, [hQuotient + 3]
  441. ld [hli], a
  442. dec c
  443. jr nz, .base_stat_division_loop
  444. ret
  445.  
  446. IsEvsGreaterThan512:
  447. ; EV total in bc
  448. ; Returns c if lower
  449. ld a, b
  450. cp HIGH(MAX_TOTAL_EV)
  451. ret nz
  452. ld a, c
  453. cp LOW(MAX_TOTAL_EV)
  454. ret
Add Comment
Please, Sign In to add comment