-- リバーサル
function reversal_act()
  -- 行動済みフラグ
  local done = false
  
  if my_act>=190 and my_act<200 then
    if reversal==1 or #reversal_candidates==0 then
      -- 無効 or 候補動作なし
    else
      -- 有効
      -- 候補から動作を選択
      local rand_num = math.random(1, #reversal_candidates)
      local reversal_input = reversal_candidates[rand_num]
      local wait_frame
      if my_act==199 then
        wait_frame = get_up_frame['there'][my_char]
      elseif my_act==197 then
        wait_frame = get_up_frame['front'][my_char]
      else
        wait_frame = get_up_frame['back'][my_char]
      end

      -- 動作の開始がスキルであるか判別
      local skill_command = {
        "236[bcBC]","623[bcBC]","214[bcBC]","421[bcBC]","252[bcBC]"
      }
      local reversal_is_skill = false
      local start
      for key,value in pairs(skill_command) do
        start = string.find(reversal_input, value)
        if start~=nil and start==1 then
          reversal_is_skill = true
          break
        end
      end
      -- ダウンからコマンド入力までの待機フレーム設定
      if reversal_is_skill then
        -- スキル
        if is_th123 then
          wait_frame = wait_frame - reversal_skill_pre_frame
        else
          wait_frame = wait_frame - 10
        end
      else
        -- スキル以外
        wait_frame = wait_frame - reversal_no_skill_pre_frame
      end
      wait(wait_frame)

      execute_command(reversal_candidates[rand_num], reversal_is_skill)
      debug_print("command_end")
      while my_act>=190 and my_act<200 do
        yield()
      end
      if guard_frame_after_reversal>0 then
        key_reset()
        key_on(back)
        local i
        for i=1, guard_frame_after_reversal do
          key_reset()
          key_on(back)
          yield()
        end
      end
      done = true
    end
  end
  
  return done
end
