heal_effect.asm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. HealEffect_:
  2. ld a, [H_WHOSETURN]
  3. and a
  4. ld de, wBattleMonHP
  5. ld hl, wBattleMonMaxHP
  6. ld a, [wPlayerMoveNum]
  7. jr z, .healEffect
  8. ld de, wEnemyMonHP
  9. ld hl, wEnemyMonMaxHP
  10. ld a, [wEnemyMoveNum]
  11. .healEffect
  12. ld b, a
  13. ld a, [de]
  14. cp [hl] ; most significant bytes comparison is ignored
  15. ; causes the move to miss if max HP is 255 or 511 points higher than the current HP
  16. inc de
  17. inc hl
  18. ld a, [de]
  19. sbc [hl]
  20. jp z, .failed ; no effect if user's HP is already at its maximum
  21. ld a, b
  22. cp REST
  23. jr nz, .healHP
  24. push hl
  25. push de
  26. push af
  27. ld c, 50
  28. call DelayFrames
  29. ld hl, wBattleMonStatus
  30. ld a, [H_WHOSETURN]
  31. and a
  32. jr z, .restEffect
  33. ld hl, wEnemyMonStatus
  34. .restEffect
  35. ld a, [hl]
  36. and a
  37. ld [hl], 2 ; clear status and set number of turns asleep to 2
  38. ld hl, StartedSleepingEffect ; if mon didn't have an status
  39. jr z, .printRestText
  40. ld hl, FellAsleepBecameHealthyText ; if mon had an status
  41. .printRestText
  42. call PrintText
  43. pop af
  44. pop de
  45. pop hl
  46. .healHP
  47. ld a, [hld]
  48. ld [wHPBarMaxHP], a
  49. ld c, a
  50. ld a, [hl]
  51. ld [wHPBarMaxHP+1], a
  52. ld b, a
  53. jr z, .gotHPAmountToHeal
  54. ; Recover and Softboiled only heal for half the mon's max HP
  55. srl b
  56. rr c
  57. .gotHPAmountToHeal
  58. ; update HP
  59. ld a, [de]
  60. ld [wHPBarOldHP], a
  61. add c
  62. ld [de], a
  63. ld [wHPBarNewHP], a
  64. dec de
  65. ld a, [de]
  66. ld [wHPBarOldHP+1], a
  67. adc b
  68. ld [de], a
  69. ld [wHPBarNewHP+1], a
  70. inc hl
  71. inc de
  72. ld a, [de]
  73. dec de
  74. sub [hl]
  75. dec hl
  76. ld a, [de]
  77. sbc [hl]
  78. jr c, .playAnim
  79. ; copy max HP to current HP if an overflow occurred
  80. ld a, [hli]
  81. ld [de], a
  82. ld [wHPBarNewHP+1], a
  83. inc de
  84. ld a, [hl]
  85. ld [de], a
  86. ld [wHPBarNewHP], a
  87. .playAnim
  88. ld hl, PlayCurrentMoveAnimation
  89. call BankswitchEtoF
  90. ld a, [H_WHOSETURN]
  91. and a
  92. coord hl, 10, 9
  93. ld a, $1
  94. jr z, .updateHPBar
  95. coord hl, 2, 2
  96. xor a
  97. .updateHPBar
  98. ld [wHPBarType], a
  99. predef UpdateHPBar2
  100. ld hl, DrawHUDsAndHPBars
  101. call BankswitchEtoF
  102. ld hl, RegainedHealthText
  103. jp PrintText
  104. .failed
  105. ld c, 50
  106. call DelayFrames
  107. ld hl, PrintButItFailedText_
  108. jp BankswitchEtoF
  109. StartedSleepingEffect:
  110. TX_FAR _StartedSleepingEffect
  111. db "@"
  112. FellAsleepBecameHealthyText:
  113. TX_FAR _FellAsleepBecameHealthyText
  114. db "@"
  115. RegainedHealthText:
  116. TX_FAR _RegainedHealthText
  117. db "@"