2018-06-24 07:09:41 -07:00
|
|
|
BattleCommand_Protect:
|
2013-09-09 18:51:41 -07:00
|
|
|
; protect
|
|
|
|
call ProtectChance
|
|
|
|
ret c
|
|
|
|
|
|
|
|
ld a, BATTLE_VARS_SUBSTATUS1
|
2014-06-14 00:34:57 -07:00
|
|
|
call GetBattleVarAddr
|
2013-09-09 18:51:41 -07:00
|
|
|
set SUBSTATUS_PROTECT, [hl]
|
|
|
|
|
2014-01-01 05:09:15 -08:00
|
|
|
call AnimateCurrentMove
|
2013-09-09 18:51:41 -07:00
|
|
|
|
|
|
|
ld hl, ProtectedItselfText
|
2019-04-08 05:15:10 -07:00
|
|
|
jp StdBattleTextbox
|
2013-09-09 18:51:41 -07:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
ProtectChance:
|
2018-01-23 14:39:09 -08:00
|
|
|
ld de, wPlayerProtectCount
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hBattleTurn]
|
2013-09-09 18:51:41 -07:00
|
|
|
and a
|
2020-10-04 16:43:28 -07:00
|
|
|
jr z, .got_count
|
2018-01-23 14:39:09 -08:00
|
|
|
ld de, wEnemyProtectCount
|
2020-10-04 16:43:28 -07:00
|
|
|
.got_count
|
2013-09-09 18:51:41 -07:00
|
|
|
|
2015-11-09 13:41:09 -08:00
|
|
|
call CheckOpponentWentFirst
|
2013-09-09 18:51:41 -07:00
|
|
|
jr nz, .failed
|
|
|
|
|
|
|
|
; Can't have a substitute.
|
|
|
|
|
|
|
|
ld a, BATTLE_VARS_SUBSTATUS4
|
2013-10-11 00:04:21 -07:00
|
|
|
call GetBattleVar
|
2013-09-09 18:51:41 -07:00
|
|
|
bit SUBSTATUS_SUBSTITUTE, a
|
|
|
|
jr nz, .failed
|
|
|
|
|
|
|
|
; Halve the chance of a successful Protect for each consecutive use.
|
|
|
|
|
|
|
|
ld b, $ff
|
|
|
|
ld a, [de]
|
|
|
|
ld c, a
|
|
|
|
.loop
|
|
|
|
ld a, c
|
|
|
|
and a
|
|
|
|
jr z, .done
|
|
|
|
dec c
|
|
|
|
|
|
|
|
srl b
|
|
|
|
ld a, b
|
|
|
|
and a
|
|
|
|
jr nz, .loop
|
|
|
|
jr .failed
|
|
|
|
.done
|
|
|
|
|
|
|
|
.rand
|
|
|
|
call BattleRandom
|
|
|
|
and a
|
|
|
|
jr z, .rand
|
|
|
|
|
|
|
|
dec a
|
|
|
|
cp b
|
|
|
|
jr nc, .failed
|
|
|
|
|
|
|
|
; Another consecutive Protect use.
|
|
|
|
|
|
|
|
ld a, [de]
|
|
|
|
inc a
|
|
|
|
ld [de], a
|
|
|
|
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.failed
|
|
|
|
xor a
|
|
|
|
ld [de], a
|
2014-01-01 05:09:15 -08:00
|
|
|
call AnimateFailedMove
|
2013-09-09 18:51:41 -07:00
|
|
|
call PrintButItFailed
|
|
|
|
scf
|
|
|
|
ret
|