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