2016-06-12 00:24:04 +00:00
|
|
|
SubstituteEffect_:
|
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
|
2015-08-31 02:38:41 +00:00
|
|
|
ld bc, wPlayerBattleStatus2
|
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
|
2015-08-31 02:38:41 +00:00
|
|
|
ld bc, wEnemyBattleStatus2
|
2014-05-22 22:13:20 +00:00
|
|
|
.notEnemy
|
2015-06-11 22:41:33 +00:00
|
|
|
ld a, [bc]
|
2017-12-29 23:59:48 +00:00
|
|
|
bit HAS_SUBSTITUTE_UP, 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
|
2017-06-24 20:01:43 +00:00
|
|
|
; bug: since it only branches on carry, it will possibly leave user with 0 HP
|
2014-05-22 22:13:20 +00:00
|
|
|
.userHasZeroOrMoreHP
|
2017-06-24 20:01:43 +00:00
|
|
|
ldi [hl], a ; save resulting HP after subtraction 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
|
2017-12-29 23:59:48 +00:00
|
|
|
set HAS_SUBSTITUTE_UP, [hl]
|
2015-08-31 02:38:41 +00:00
|
|
|
ld a, [wOptions]
|
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
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
SubstituteText:
|
2014-05-22 22:13:20 +00:00
|
|
|
TX_FAR _SubstituteText
|
|
|
|
db "@"
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
HasSubstituteText:
|
2014-05-22 22:13:20 +00:00
|
|
|
TX_FAR _HasSubstituteText
|
|
|
|
db "@"
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
TooWeakSubstituteText:
|
2014-05-22 22:13:20 +00:00
|
|
|
TX_FAR _TooWeakSubstituteText
|
|
|
|
db "@"
|