drain_hp_effect.asm 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. DrainHPEffect_:
  2. ld hl, wDamage
  3. ld a, [hl]
  4. srl a ; divide damage by 2
  5. ld [hli], a
  6. ld a, [hl]
  7. rr a
  8. ld [hld], a
  9. or [hl] ; is damage 0?
  10. jr nz, .getAttackerHP
  11. ; if damage is 0, increase to 1 so that the attacker gains at least 1 HP
  12. inc hl
  13. inc [hl]
  14. .getAttackerHP
  15. ld hl, wBattleMonHP
  16. ld de, wBattleMonMaxHP
  17. ld a, [H_WHOSETURN]
  18. and a
  19. jp z, .addDamageToAttackerHP
  20. ld hl, wEnemyMonHP
  21. ld de, wEnemyMonMaxHP
  22. .addDamageToAttackerHP
  23. ld bc, wHPBarOldHP+1
  24. ; copy current HP to wHPBarOldHP
  25. ld a, [hli]
  26. ld [bc], a
  27. ld a, [hl]
  28. dec bc
  29. ld [bc], a
  30. ; copy max HP to wHPBarMaxHP
  31. ld a, [de]
  32. dec bc
  33. ld [bc], a
  34. inc de
  35. ld a, [de]
  36. dec bc
  37. ld [bc], a
  38. ; add damage to attacker's HP and copy new HP to wHPBarNewHP
  39. ld a, [wDamage + 1]
  40. ld b, [hl]
  41. add b
  42. ld [hld], a
  43. ld [wHPBarNewHP], a
  44. ld a, [wDamage]
  45. ld b, [hl]
  46. adc b
  47. ld [hli], a
  48. ld [wHPBarNewHP+1], a
  49. jr c, .capToMaxHP ; if HP > 65,535, cap to max HP
  50. ; compare HP with max HP
  51. ld a, [hld]
  52. ld b, a
  53. ld a, [de]
  54. dec de
  55. sub b
  56. ld a, [hli]
  57. ld b, a
  58. ld a, [de]
  59. inc de
  60. sbc b
  61. jr nc, .next
  62. .capToMaxHP
  63. ld a, [de]
  64. ld [hld], a
  65. ld [wHPBarNewHP], a
  66. dec de
  67. ld a, [de]
  68. ld [hli], a
  69. ld [wHPBarNewHP+1], a
  70. inc de
  71. .next
  72. ld a, [H_WHOSETURN]
  73. and a
  74. coord hl, 10, 9
  75. ld a, $1
  76. jr z, .next2
  77. coord hl, 2, 2
  78. xor a
  79. .next2
  80. ld [wHPBarType], a
  81. predef UpdateHPBar2
  82. predef DrawPlayerHUDAndHPBar
  83. predef DrawEnemyHUDAndHPBar
  84. callab ReadPlayerMonCurHPAndStatus
  85. ld hl, SuckedHealthText
  86. ld a, [H_WHOSETURN]
  87. and a
  88. ld a, [wPlayerMoveEffect]
  89. jr z, .next3
  90. ld a, [wEnemyMoveEffect]
  91. .next3
  92. cp DREAM_EATER_EFFECT
  93. jr nz, .printText
  94. ld hl, DreamWasEatenText
  95. .printText
  96. jp PrintText
  97. SuckedHealthText:
  98. TX_FAR _SuckedHealthText
  99. db "@"
  100. DreamWasEatenText:
  101. TX_FAR _DreamWasEatenText
  102. db "@"