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
|
|
|
|
; Only need to check these next things if it's your turn
|
|
|
|
ld a, [hBattleTurn]
|
|
|
|
and a
|
|
|
|
jr nz, .enemy_turn
|
|
|
|
; Can't teleport from a trainer battle
|
|
|
|
ld a, [wBattleMode]
|
|
|
|
dec a
|
|
|
|
jr nz, .failed
|
|
|
|
; If your level is greater than the opponent's, you run without fail.
|
2018-02-03 15:21:53 -08:00
|
|
|
ld a, [wCurPartyLevel]
|
2018-01-26 08:36:00 -08:00
|
|
|
ld b, a
|
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
|
|
|
|
; Generate a number between 0 and (YourLevel + TheirLevel).
|
|
|
|
add b
|
|
|
|
ld c, a
|
|
|
|
inc c
|
|
|
|
.loop_player
|
|
|
|
call BattleRandom
|
|
|
|
cp c
|
|
|
|
jr nc, .loop_player
|
|
|
|
; If that number is greater than 4 times your level, run away.
|
|
|
|
srl b
|
|
|
|
srl b
|
|
|
|
cp b
|
|
|
|
jr nc, .run_away
|
|
|
|
|
|
|
|
.failed
|
|
|
|
call AnimateFailedMove
|
|
|
|
jp PrintButItFailed
|
|
|
|
|
|
|
|
.enemy_turn
|
|
|
|
ld a, [wBattleMode]
|
|
|
|
dec a
|
|
|
|
jr nz, .failed
|
2018-02-03 15:21:53 -08:00
|
|
|
ld a, [wBattleMonLevel]
|
2018-01-26 08:36:00 -08:00
|
|
|
ld b, a
|
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
|
|
|
|
add b
|
|
|
|
ld c, a
|
|
|
|
inc c
|
|
|
|
.loop_enemy
|
|
|
|
call BattleRandom
|
|
|
|
cp c
|
|
|
|
jr nc, .loop_enemy
|
|
|
|
srl b
|
|
|
|
srl b
|
|
|
|
cp b
|
|
|
|
; This does the wrong thing. What was
|
|
|
|
; probably intended was jr c, .failed
|
|
|
|
; The way this is made makes enemy use
|
|
|
|
; of Teleport always succeed if able
|
|
|
|
jr nc, .run_away
|
|
|
|
.run_away
|
|
|
|
call UpdateBattleMonInParty
|
|
|
|
xor a
|
|
|
|
ld [wNumHits], a
|
|
|
|
inc a
|
|
|
|
ld [wForcedSwitch], a
|
|
|
|
ld [wKickCounter], a
|
|
|
|
call SetBattleDraw
|
|
|
|
call BattleCommand_LowerSub
|
|
|
|
call LoadMoveAnim
|
|
|
|
ld c, 20
|
|
|
|
call DelayFrames
|
|
|
|
call SetBattleDraw
|
|
|
|
|
|
|
|
ld hl, FledFromBattleText
|
|
|
|
jp StdBattleTextBox
|