recoil_effect.asm 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. RecoilEffect_:
  2. ld a, [H_WHOSETURN]
  3. and a
  4. ld a, [wPlayerMoveNum]
  5. ld hl, wBattleMonMaxHP
  6. jr z, .recoilEffect
  7. ld a, [wEnemyMoveNum]
  8. ld hl, wEnemyMonMaxHP
  9. .recoilEffect
  10. ld d, a
  11. ld a, [wDamage]
  12. ld b, a
  13. ld a, [wDamage + 1]
  14. ld c, a
  15. srl b
  16. rr c
  17. ld a, d
  18. cp STRUGGLE ; struggle deals 50% recoil damage
  19. jr z, .gotRecoilDamage
  20. srl b
  21. rr c
  22. .gotRecoilDamage
  23. ld a, b
  24. or c
  25. jr nz, .updateHP
  26. inc c ; minimum recoil damage is 1
  27. .updateHP
  28. ; subtract HP from user due to the recoil damage
  29. ld a, [hli]
  30. ld [wHPBarMaxHP+1], a
  31. ld a, [hl]
  32. ld [wHPBarMaxHP], a
  33. push bc
  34. ld bc, wBattleMonHP - wBattleMonMaxHP
  35. add hl, bc
  36. pop bc
  37. ld a, [hl]
  38. ld [wHPBarOldHP], a
  39. sub c
  40. ld [hld], a
  41. ld [wHPBarNewHP], a
  42. ld a, [hl]
  43. ld [wHPBarOldHP+1], a
  44. sbc b
  45. ld [hl], a
  46. ld [wHPBarNewHP+1], a
  47. jr nc, .getHPBarCoords
  48. ; if recoil damage is higher than the Pokemon's HP, set its HP to 0
  49. xor a
  50. ld [hli], a
  51. ld [hl], a
  52. ld hl, wHPBarNewHP
  53. ld [hli], a
  54. ld [hl], a
  55. .getHPBarCoords
  56. coord hl, 10, 9
  57. ld a, [H_WHOSETURN]
  58. and a
  59. ld a, $1
  60. jr z, .updateHPBar
  61. coord hl, 2, 2
  62. xor a
  63. .updateHPBar
  64. ld [wHPBarType], a
  65. predef UpdateHPBar2
  66. ld hl, HitWithRecoilText
  67. jp PrintText
  68. HitWithRecoilText:
  69. TX_FAR _HitWithRecoilText
  70. db "@"