Path: blob/master/engine/battle/move_effects/substitute.asm
1271 views
SubstituteEffect_:1ld c, 502call DelayFrames3ld hl, wBattleMonMaxHP4ld de, wPlayerSubstituteHP5ld bc, wPlayerBattleStatus26ldh a, [hWhoseTurn]7and a8jr z, .notEnemy9ld hl, wEnemyMonMaxHP10ld de, wEnemySubstituteHP11ld bc, wEnemyBattleStatus212.notEnemy13ld a, [bc]14bit HAS_SUBSTITUTE_UP, a ; user already has substitute?15jr nz, .alreadyHasSubstitute16; quarter health to remove from user17; assumes max HP is 1023 or lower18push bc19ld a, [hli]20ld b, [hl]21srl a22rr b23srl a24rr b ; max hp / 425push de26ld de, wBattleMonHP - wBattleMonMaxHP27add hl, de ; point hl to current HP low byte28pop de29ld a, b30ld [de], a ; save copy of HP to subtract in wPlayerSubstituteHP/wEnemySubstituteHP31ld a, [hld]32; subtract [max hp / 4] to current HP33sub b34ld d, a35ld a, [hl]36sbc 037pop bc38jr c, .notEnoughHP ; underflow means user would be left with negative health39; bug: since it only branches on carry, it will possibly leave user with 0 HP40.userHasZeroOrMoreHP41ldi [hl], a ; save resulting HP after subtraction into current HP42ld [hl], d43ld h, b44ld l, c45set HAS_SUBSTITUTE_UP, [hl]46ld a, [wOptions]47bit BIT_BATTLE_ANIMATION, a48ld hl, PlayCurrentMoveAnimation49ld b, BANK(PlayCurrentMoveAnimation)50jr z, .animationEnabled51ld hl, AnimationSubstitute52ld b, BANK(AnimationSubstitute)53.animationEnabled54call Bankswitch ; jump to routine depending on animation setting55ld hl, SubstituteText56call PrintText57jpfar DrawHUDsAndHPBars58.alreadyHasSubstitute59ld hl, HasSubstituteText60jr .printText61.notEnoughHP62ld hl, TooWeakSubstituteText63.printText64jp PrintText6566SubstituteText:67text_far _SubstituteText68text_end6970HasSubstituteText:71text_far _HasSubstituteText72text_end7374TooWeakSubstituteText:75text_far _TooWeakSubstituteText76text_end777879