substitute_effect.asm 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. SubstituteEffect_:
  2. ld c, 50
  3. call DelayFrames
  4. ld hl, wBattleMonMaxHP
  5. ld de, wPlayerSubstituteHP
  6. ld bc, wPlayerBattleStatus2
  7. ld a, [H_WHOSETURN]
  8. and a
  9. jr z, .notEnemy
  10. ld hl, wEnemyMonMaxHP
  11. ld de, wEnemySubstituteHP
  12. ld bc, wEnemyBattleStatus2
  13. .notEnemy
  14. ld a, [bc]
  15. bit HAS_SUBSTITUTE_UP, a ; user already has substitute?
  16. jr nz, .alreadyHasSubstitute
  17. ; quarter health to remove from user
  18. ; assumes max HP is 1023 or lower
  19. push bc
  20. ld a, [hli]
  21. ld b, [hl]
  22. srl a
  23. rr b
  24. srl a
  25. rr b ; max hp / 4
  26. push de
  27. ld de, wBattleMonHP - wBattleMonMaxHP
  28. add hl, de ; point hl to current HP low byte
  29. pop de
  30. ld a, b
  31. ld [de], a ; save copy of HP to subtract in ccd7/ccd8 [how much HP substitute has]
  32. ld a, [hld]
  33. ; subtract [max hp / 4] to current HP
  34. sub b
  35. ld d, a
  36. ld a, [hl]
  37. sbc 0
  38. pop bc
  39. jr c, .notEnoughHP ; underflow means user would be left with negative health
  40. ; bug: since it only branches on carry, it will possibly leave user with 0 HP
  41. .userHasZeroOrMoreHP
  42. ldi [hl], a ; save resulting HP after subtraction into current HP
  43. ld [hl], d
  44. ld h, b
  45. ld l, c
  46. set HAS_SUBSTITUTE_UP, [hl]
  47. ld a, [wOptions]
  48. bit 7, a ; battle animation is enabled?
  49. ld hl, PlayCurrentMoveAnimation
  50. ld b, BANK(PlayCurrentMoveAnimation)
  51. jr z, .animationEnabled
  52. ld hl, AnimationSubstitute
  53. ld b, BANK(AnimationSubstitute)
  54. .animationEnabled
  55. call Bankswitch ; jump to routine depending on animation setting
  56. ld hl, SubstituteText
  57. call PrintText
  58. jpab DrawHUDsAndHPBars
  59. .alreadyHasSubstitute
  60. ld hl, HasSubstituteText
  61. jr .printText
  62. .notEnoughHP
  63. ld hl, TooWeakSubstituteText
  64. .printText
  65. jp PrintText
  66. SubstituteText:
  67. TX_FAR _SubstituteText
  68. db "@"
  69. HasSubstituteText:
  70. TX_FAR _HasSubstituteText
  71. db "@"
  72. TooWeakSubstituteText:
  73. TX_FAR _TooWeakSubstituteText
  74. db "@"