aboutsummaryrefslogtreecommitdiffstats
path: root/engine/battle/move_effects/recoil.asm
diff options
context:
space:
mode:
Diffstat (limited to 'engine/battle/move_effects/recoil.asm')
-rw-r--r--engine/battle/move_effects/recoil.asm70
1 files changed, 70 insertions, 0 deletions
diff --git a/engine/battle/move_effects/recoil.asm b/engine/battle/move_effects/recoil.asm
new file mode 100644
index 00000000..0f2f087b
--- /dev/null
+++ b/engine/battle/move_effects/recoil.asm
@@ -0,0 +1,70 @@
+RecoilEffect_:
+ ld a, [H_WHOSETURN]
+ and a
+ ld a, [wPlayerMoveNum]
+ ld hl, wBattleMonMaxHP
+ jr z, .recoilEffect
+ ld a, [wEnemyMoveNum]
+ ld hl, wEnemyMonMaxHP
+.recoilEffect
+ ld d, a
+ ld a, [wDamage]
+ ld b, a
+ ld a, [wDamage + 1]
+ ld c, a
+ srl b
+ rr c
+ ld a, d
+ cp STRUGGLE ; struggle deals 50% recoil damage
+ jr z, .gotRecoilDamage
+ srl b
+ rr c
+.gotRecoilDamage
+ ld a, b
+ or c
+ jr nz, .updateHP
+ inc c ; minimum recoil damage is 1
+.updateHP
+; subtract HP from user due to the recoil damage
+ ld a, [hli]
+ ld [wHPBarMaxHP+1], a
+ ld a, [hl]
+ ld [wHPBarMaxHP], a
+ push bc
+ ld bc, wBattleMonHP - wBattleMonMaxHP
+ add hl, bc
+ pop bc
+ ld a, [hl]
+ ld [wHPBarOldHP], a
+ sub c
+ ld [hld], a
+ ld [wHPBarNewHP], a
+ ld a, [hl]
+ ld [wHPBarOldHP+1], a
+ sbc b
+ ld [hl], a
+ ld [wHPBarNewHP+1], a
+ jr nc, .getHPBarCoords
+; if recoil damage is higher than the Pokemon's HP, set its HP to 0
+ xor a
+ ld [hli], a
+ ld [hl], a
+ ld hl, wHPBarNewHP
+ ld [hli], a
+ ld [hl], a
+.getHPBarCoords
+ coord hl, 10, 9
+ ld a, [H_WHOSETURN]
+ and a
+ ld a, $1
+ jr z, .updateHPBar
+ coord hl, 2, 2
+ xor a
+.updateHPBar
+ ld [wHPBarType], a
+ predef UpdateHPBar2
+ ld hl, HitWithRecoilText
+ jp PrintText
+HitWithRecoilText:
+ TX_FAR _HitWithRecoilText
+ db "@"