class Scene_Battle
 #06/10/04
  #--------------------------------------------------------------------------
  # ■ フレーム更新 (パーティコマンドフェーズ : 逃げる)
  #--------------------------------------------------------------------------
  def update_phase2_escape
    # エネミーの素早さ平均値を計算
    enemies_agi = 0
    enemies_number = 0
    for enemy in $game_troop.enemies
      if enemy.exist?
        enemies_agi += enemy.agi
        enemies_number += 1
      end
    end
    if enemies_number > 0
      enemies_agi /= enemies_number
    end
    # アクターの素早さ平均値を計算
    actors_agi = 0
    actors_number = 0
    for actor in $game_party.actors
      if actor.exist?
        actors_agi += actor.agi
        actors_number += 1
      end
    end
    if actors_number > 0
      actors_agi /= actors_number
    end
    # 逃走成功判定
    success = rand(100) < 50 * actors_agi / enemies_agi
    # 逃走成功の場合
    if success
      # □ヘルプウィンドウに描画
      @help_window.set_text("逃走成功", 1)
      # □パーティコマンドウィンドウの不可視化
      if @party_command_window != nil
        # ウィンドウが一瞬表示される為
        @party_command_window.visible = false
      end
      # □ウェイトが完了するまで待つ
      @wait_count = 20
      while @wait_count > 0
        Graphics.update
        @wait_count -= 1
      end
      # 逃走 SE を演奏
      $game_system.se_play($data_system.escape_se)
      # バトル開始前の BGM に戻す
      $game_system.bgm_play($game_temp.map_bgm)
      # バトル終了
      battle_end(1)
    # 逃走失敗の場合
    else
      # □ヘルプウィンドウに描画
      @help_window.set_text("逃走失敗", 1)
      @wait_count = 20
      # パーティ全員のアクションをクリア
      $game_party.clear_actions
      # メインフェーズ開始
      start_phase4
    end
  end
end