2015-04-01 09:41:20 +00:00
|
|
|
SubstituteEffect_: ; 17dad (5:7dad)
|
2014-05-22 22:13:20 +00:00
|
|
|
ld c, 50
|
|
|
|
call DelayFrames
|
2014-06-14 11:12:40 +00:00
|
|
|
ld hl, wBattleMonMaxHP
|
2014-05-22 22:13:20 +00:00
|
|
|
ld de, wPlayerSubstituteHP
|
|
|
|
ld bc, W_PLAYERBATTSTATUS2
|
2015-02-08 00:24:16 +00:00
|
|
|
ld a, [H_WHOSETURN]
|
2014-05-22 22:13:20 +00:00
|
|
|
and a
|
|
|
|
jr z, .notEnemy
|
2014-06-14 11:12:40 +00:00
|
|
|
ld hl, wEnemyMonMaxHP
|
2014-05-22 22:13:20 +00:00
|
|
|
ld de, wEnemySubstituteHP
|
|
|
|
ld bc, W_ENEMYBATTSTATUS2
|
|
|
|
.notEnemy
|
2015-06-11 22:41:33 +00:00
|
|
|
ld a, [bc]
|
2015-04-08 10:15:08 +00:00
|
|
|
bit HasSubstituteUp, a ; user already has substitute?
|
2015-06-11 22:41:33 +00:00
|
|
|
jr nz, .alreadyHasSubstitute
|
2015-04-08 10:15:08 +00:00
|
|
|
; quarter health to remove from user
|
2015-06-11 22:41:33 +00:00
|
|
|
; assumes max HP is 1023 or lower
|
2014-05-22 22:13:20 +00:00
|
|
|
push bc
|
2015-04-08 10:15:08 +00:00
|
|
|
ld a, [hli]
|
2014-05-22 22:13:20 +00:00
|
|
|
ld b, [hl]
|
2015-06-11 22:41:33 +00:00
|
|
|
srl a
|
2014-05-22 22:13:20 +00:00
|
|
|
rr b
|
|
|
|
srl a
|
2015-04-08 10:15:08 +00:00
|
|
|
rr b ; max hp / 4
|
2014-05-22 22:13:20 +00:00
|
|
|
push de
|
2015-02-08 00:24:16 +00:00
|
|
|
ld de, wBattleMonHP - wBattleMonMaxHP
|
2015-04-08 10:15:08 +00:00
|
|
|
add hl, de ; point hl to current HP low byte
|
2014-05-22 22:13:20 +00:00
|
|
|
pop de
|
2015-06-11 22:41:33 +00:00
|
|
|
ld a, b
|
2015-04-08 10:15:08 +00:00
|
|
|
ld [de], a ; save copy of HP to subtract in ccd7/ccd8 [how much HP substitute has]
|
|
|
|
ld a, [hld]
|
2015-06-11 22:41:33 +00:00
|
|
|
; subtract [max hp / 4] to current HP
|
|
|
|
sub b
|
2015-04-08 10:15:08 +00:00
|
|
|
ld d, a
|
2014-05-22 22:13:20 +00:00
|
|
|
ld a, [hl]
|
2015-06-11 22:41:33 +00:00
|
|
|
sbc 0
|
2014-05-22 22:13:20 +00:00
|
|
|
pop bc
|
2015-04-08 10:15:08 +00:00
|
|
|
jr c, .notEnoughHP ; underflow means user would be left with negative health
|
|
|
|
; bug: since it only brances on carry, it will possibly leave user with 0 HP
|
2014-05-22 22:13:20 +00:00
|
|
|
.userHasZeroOrMoreHP
|
2015-04-08 10:15:08 +00:00
|
|
|
ldi [hl], a ; save resulting HP after substraction into current HP
|
2015-06-11 22:41:33 +00:00
|
|
|
ld [hl], d
|
2014-05-22 22:13:20 +00:00
|
|
|
ld h, b
|
|
|
|
ld l, c
|
2015-06-11 22:41:33 +00:00
|
|
|
set HasSubstituteUp, [hl]
|
|
|
|
ld a, [W_OPTIONS]
|
2015-04-08 10:15:08 +00:00
|
|
|
bit 7, a ; battle animation is enabled?
|
2015-06-11 22:41:33 +00:00
|
|
|
ld hl, PlayCurrentMoveAnimation
|
2015-02-08 00:24:16 +00:00
|
|
|
ld b, BANK(PlayCurrentMoveAnimation)
|
2014-05-22 22:13:20 +00:00
|
|
|
jr z, .animationEnabled
|
2015-06-11 22:41:33 +00:00
|
|
|
ld hl, AnimationSubstitute
|
2014-05-22 22:13:20 +00:00
|
|
|
ld b, BANK(AnimationSubstitute)
|
|
|
|
.animationEnabled
|
2015-04-08 10:15:08 +00:00
|
|
|
call Bankswitch ; jump to routine depending on animation setting
|
2014-05-22 22:13:20 +00:00
|
|
|
ld hl, SubstituteText
|
|
|
|
call PrintText
|
2015-07-19 18:56:13 +00:00
|
|
|
jpab DrawHUDsAndHPBars
|
2014-05-22 22:13:20 +00:00
|
|
|
.alreadyHasSubstitute
|
|
|
|
ld hl, HasSubstituteText
|
|
|
|
jr .printText
|
|
|
|
.notEnoughHP
|
|
|
|
ld hl, TooWeakSubstituteText
|
|
|
|
.printText
|
|
|
|
jp PrintText
|
|
|
|
|
|
|
|
SubstituteText: ; 17e1d (5:7e1d)
|
|
|
|
TX_FAR _SubstituteText
|
|
|
|
db "@"
|
|
|
|
|
|
|
|
HasSubstituteText: ; 17e22 (5:7e22)
|
|
|
|
TX_FAR _HasSubstituteText
|
|
|
|
db "@"
|
|
|
|
|
|
|
|
TooWeakSubstituteText: ; 17e27 (5:7e27)
|
|
|
|
TX_FAR _TooWeakSubstituteText
|
|
|
|
db "@"
|