shithub: pokered

ref: 710c3275fc6a4caeeff3ad89c029a05984cf8388
dir: /engine/battle/move_effects/drain_hp.asm/

View raw version
DrainHPEffect_:
	ld hl, wDamage
	ld a, [hl]
	srl a ; divide damage by 2
	ld [hli], a
	ld a, [hl]
	rr a
	ld [hld], a
	or [hl] ; is damage 0?
	jr nz, .getAttackerHP
; if damage is 0, increase to 1 so that the attacker gains at least 1 HP
	inc hl
	inc [hl]
.getAttackerHP
	ld hl, wBattleMonHP
	ld de, wBattleMonMaxHP
	ld a, [H_WHOSETURN]
	and a
	jp z, .addDamageToAttackerHP
	ld hl, wEnemyMonHP
	ld de, wEnemyMonMaxHP
.addDamageToAttackerHP
	ld bc, wHPBarOldHP+1
; copy current HP to wHPBarOldHP
	ld a, [hli]
	ld [bc], a
	ld a, [hl]
	dec bc
	ld [bc], a
; copy max HP to wHPBarMaxHP
	ld a, [de]
	dec bc
	ld [bc], a
	inc de
	ld a, [de]
	dec bc
	ld [bc], a
; add damage to attacker's HP and copy new HP to wHPBarNewHP
	ld a, [wDamage + 1]
	ld b, [hl]
	add b
	ld [hld], a
	ld [wHPBarNewHP], a
	ld a, [wDamage]
	ld b, [hl]
	adc b
	ld [hli], a
	ld [wHPBarNewHP+1], a
	jr c, .capToMaxHP ; if HP > 65,535, cap to max HP
; compare HP with max HP
	ld a, [hld]
	ld b, a
	ld a, [de]
	dec de
	sub b
	ld a, [hli]
	ld b, a
	ld a, [de]
	inc de
	sbc b
	jr nc, .next
.capToMaxHP
	ld a, [de]
	ld [hld], a
	ld [wHPBarNewHP], a
	dec de
	ld a, [de]
	ld [hli], a
	ld [wHPBarNewHP+1], a
	inc de
.next
	ld a, [H_WHOSETURN]
	and a
	coord hl, 10, 9
	ld a, $1
	jr z, .next2
	coord hl, 2, 2
	xor a
.next2
	ld [wHPBarType], a
	predef UpdateHPBar2
	predef DrawPlayerHUDAndHPBar
	predef DrawEnemyHUDAndHPBar
	callab ReadPlayerMonCurHPAndStatus
	ld hl, SuckedHealthText
	ld a, [H_WHOSETURN]
	and a
	ld a, [wPlayerMoveEffect]
	jr z, .next3
	ld a, [wEnemyMoveEffect]
.next3
	cp DREAM_EATER_EFFECT
	jr nz, .printText
	ld hl, DreamWasEatenText
.printText
	jp PrintText

SuckedHealthText:
	TX_FAR _SuckedHealthText
	db "@"

DreamWasEatenText:
	TX_FAR _DreamWasEatenText
	db "@"