ref: c480632d5494d04f7f5f0298a31877a2293b564e
dir: /engine/battle/move_effects/drain_hp.asm/
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, [hWhoseTurn] 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, [hWhoseTurn] 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, [hWhoseTurn] 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: text_far _SuckedHealthText text_end DreamWasEatenText: text_far _DreamWasEatenText text_end