shithub: pokered

ref: bcfca2e267a6ee023271d90e27e4a7fde06f66fc
dir: /engine/battle/moveEffects/recoil_effect.asm/

View raw version
RecoilEffect_: ; 1392c (4:792c)
	ld a, [H_WHOSETURN]
	and a
	ld a, [W_PLAYERMOVENUM]
	ld hl, wBattleMonMaxHP
	jr z, .recoilEffect
	ld a, [W_ENEMYMOVENUM]
	ld hl, wEnemyMonMaxHP
.recoilEffect
	ld d, a
	ld a, [W_DAMAGE]
	ld b, a
	ld a, [W_DAMAGE + 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
; substract 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
	hlCoord 10, 9
	ld a, [H_WHOSETURN]
	and a
	ld a, $1
	jr z, .updateHPBar
	hlCoord 2, 2
	xor a
.updateHPBar
	ld [wHPBarType], a
	predef UpdateHPBar2
	ld hl, HitWithRecoilText
	jp PrintText
HitWithRecoilText: ; 1399e (4:799e)
	TX_FAR _HitWithRecoilText
	db "@"