2018-06-24 07:09:41 -07:00
|
|
|
BattleCommand_Teleport:
|
2018-01-26 08:36:00 -08:00
|
|
|
; teleport
|
|
|
|
|
2018-02-03 15:21:53 -08:00
|
|
|
ld a, [wBattleType]
|
2018-01-26 08:36:00 -08:00
|
|
|
cp BATTLETYPE_SHINY
|
|
|
|
jr z, .failed
|
|
|
|
cp BATTLETYPE_TRAP
|
|
|
|
jr z, .failed
|
|
|
|
cp BATTLETYPE_CELEBI
|
|
|
|
jr z, .failed
|
|
|
|
cp BATTLETYPE_SUICUNE
|
|
|
|
jr z, .failed
|
|
|
|
|
|
|
|
ld a, BATTLE_VARS_SUBSTATUS5_OPP
|
|
|
|
call GetBattleVar
|
|
|
|
bit SUBSTATUS_CANT_RUN, a
|
|
|
|
jr nz, .failed
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hBattleTurn]
|
2018-01-26 08:36:00 -08:00
|
|
|
and a
|
|
|
|
jr nz, .enemy_turn
|
2021-06-20 07:56:11 -07:00
|
|
|
|
|
|
|
; Can't teleport from a trainer battle
|
2018-01-26 08:36:00 -08:00
|
|
|
ld a, [wBattleMode]
|
|
|
|
dec a
|
|
|
|
jr nz, .failed
|
2021-06-20 07:56:11 -07:00
|
|
|
; b = player level
|
2018-02-03 15:21:53 -08:00
|
|
|
ld a, [wCurPartyLevel]
|
2018-01-26 08:36:00 -08:00
|
|
|
ld b, a
|
2021-06-20 07:56:11 -07:00
|
|
|
; If player level >= enemy level, Teleport will succeed
|
2018-02-03 15:21:53 -08:00
|
|
|
ld a, [wBattleMonLevel]
|
2018-01-26 08:36:00 -08:00
|
|
|
cp b
|
|
|
|
jr nc, .run_away
|
2021-06-20 07:56:11 -07:00
|
|
|
; c = player level + enemy level + 1
|
2018-01-26 08:36:00 -08:00
|
|
|
add b
|
|
|
|
ld c, a
|
|
|
|
inc c
|
2021-06-20 07:56:11 -07:00
|
|
|
; Generate a number less than c
|
2018-01-26 08:36:00 -08:00
|
|
|
.loop_player
|
|
|
|
call BattleRandom
|
|
|
|
cp c
|
|
|
|
jr nc, .loop_player
|
2021-06-20 07:56:11 -07:00
|
|
|
; b = enemy level / 4
|
2018-01-26 08:36:00 -08:00
|
|
|
srl b
|
|
|
|
srl b
|
2021-06-20 07:56:11 -07:00
|
|
|
; If the random number >= enemy level / 4, Teleport will succeed
|
2018-01-26 08:36:00 -08:00
|
|
|
cp b
|
|
|
|
jr nc, .run_away
|
|
|
|
|
|
|
|
.failed
|
|
|
|
call AnimateFailedMove
|
|
|
|
jp PrintButItFailed
|
|
|
|
|
|
|
|
.enemy_turn
|
2021-06-20 07:56:11 -07:00
|
|
|
; Can't teleport from a trainer battle
|
2018-01-26 08:36:00 -08:00
|
|
|
ld a, [wBattleMode]
|
|
|
|
dec a
|
|
|
|
jr nz, .failed
|
2021-06-20 07:56:11 -07:00
|
|
|
; b = enemy level
|
2018-02-03 15:21:53 -08:00
|
|
|
ld a, [wBattleMonLevel]
|
2018-01-26 08:36:00 -08:00
|
|
|
ld b, a
|
2021-06-20 07:56:11 -07:00
|
|
|
; If enemy level >= player level, Teleport will succeed
|
2018-02-03 15:21:53 -08:00
|
|
|
ld a, [wCurPartyLevel]
|
2018-01-26 08:36:00 -08:00
|
|
|
cp b
|
|
|
|
jr nc, .run_away
|
2021-06-20 07:56:11 -07:00
|
|
|
; c = enemy level + player level + 1
|
2018-01-26 08:36:00 -08:00
|
|
|
add b
|
|
|
|
ld c, a
|
|
|
|
inc c
|
2021-06-20 07:56:11 -07:00
|
|
|
; Generate a number less than c
|
2018-01-26 08:36:00 -08:00
|
|
|
.loop_enemy
|
|
|
|
call BattleRandom
|
|
|
|
cp c
|
|
|
|
jr nc, .loop_enemy
|
2021-06-20 07:56:11 -07:00
|
|
|
; b = player level / 4
|
2018-01-26 08:36:00 -08:00
|
|
|
srl b
|
|
|
|
srl b
|
2021-06-20 07:56:11 -07:00
|
|
|
; This should be "jr c, .failed"
|
2020-02-28 08:17:58 -08:00
|
|
|
; As written, it makes enemy use of Teleport always succeed if able
|
2021-06-20 07:56:11 -07:00
|
|
|
cp b
|
2018-01-26 08:36:00 -08:00
|
|
|
jr nc, .run_away
|
2021-06-20 07:56:11 -07:00
|
|
|
|
2018-01-26 08:36:00 -08:00
|
|
|
.run_away
|
|
|
|
call UpdateBattleMonInParty
|
|
|
|
xor a
|
|
|
|
ld [wNumHits], a
|
|
|
|
inc a
|
|
|
|
ld [wForcedSwitch], a
|
2020-08-29 17:35:49 -07:00
|
|
|
ld [wBattleAnimParam], a
|
2018-01-26 08:36:00 -08:00
|
|
|
call SetBattleDraw
|
|
|
|
call BattleCommand_LowerSub
|
|
|
|
call LoadMoveAnim
|
|
|
|
ld c, 20
|
|
|
|
call DelayFrames
|
|
|
|
call SetBattleDraw
|
|
|
|
|
|
|
|
ld hl, FledFromBattleText
|
2019-04-08 05:15:10 -07:00
|
|
|
jp StdBattleTextbox
|