class Scene_Battle

  #--------------------------------------------------------------------------
  # ○ CT的计算
  #--------------------------------------------------------------------------
  def update_ct
    # 在计算提高被许可的时候
    if @countup
    
      for actor in $game_party.actors
        # 是否能活动
        if actor.movable? == false and actor.ct_visible and @phase4_step != 5
          # 用看不见状态计算,并且有提高
          actor.ct_visible = false
          actor.countup = true
          actor.full_ct = false
        elsif actor.movable? and actor.ct_visible == false
          # 解除看不见计算提高
          clear_ct(actor)
          actor.ct_visible = true
        end
        # アクターの入れ替えに対応
        if actor.max_ct == 0
          actor.max_ct = @max_ct
        end
        # アクターのカウントアップ
        if actor.countup
          
          #==================================================================
          if actor.now_ct > 0.9 * @max_ct #ct快要满了
            ct_skip = PARA_CTB::CT_SKIP != 0 ? PARA_CTB::CT_SKIP : 1
            inc = actor.current_action.speed * PARA_CTB::BATTLE_SPEED * ct_skip
            if (actor.now_ct + inc >= @max_ct && @flag.nil?) #将要满了
              actor.sp += 100 
              @status_window.refresh
              # エネミー名リストを更新
              @status_window2.refresh
              @flag = true
            end
            
          end
          #改了这里(战斗前增加SP1)
          #==================================================================
          
          #==================================================================
          if actor.state?(20) #附加20号状态时 增加CT
            actor.now_ct = @max_ct * 0.99
            actor.remove_state(20) #增加后解除状态
          end
          #改了这里(SP技能)
          #==================================================================
          
          
          
          # CTがmaxになっており、コマンド入力待ちアクターに含まれない
          if actor.now_ct >= @max_ct and !(@pre_action_battlers.include?(actor))
            # コマンド入力待ちアクターに追加
            #==================================================================
            @flag = nil
            #改了这里(战斗前增加SP2)
            #==================================================================

            @pre_action_battlers.push(actor)
            @action_count += 1
            
            # 効果音を鳴らす
            if PARA_CTB::FULL_CT_SE != "" and actor.ct_visible
              Audio.se_play("Audio/SE/" + PARA_CTB::FULL_CT_SE,PARA_CTB::FULL_CT_SE_VOL)
            end
            
            # それ以上カウントアップしない
            actor.countup = false
            actor.full_ct = true
          else
            # カウントアップ
            actor.make_action_speed
            ct_skip = PARA_CTB::CT_SKIP != 0 ? PARA_CTB::CT_SKIP : 1
            actor.now_ct += actor.current_action.speed * PARA_CTB::BATTLE_SPEED * ct_skip
          end
        end
      end
      for enemy in $game_troop.enemies
        # 行動できるか
        if enemy.movable? == false and enemy.ct_visible and @phase4_step == 5
          # 不可視状態でカウントアップ
          enemy.ct_visible = false
          enemy.countup = true
          enemy.full_ct = false
        elsif enemy.movable? and enemy.ct_visible == false
          # 不可視カウントアップを解除
          clear_ct(enemy)
          enemy.ct_visible = true
        end
        # エネミーのカウントアップ
        if enemy.countup
          # CTがmaxになっており、行動待ちエネミーに含まれない
          if enemy.now_ct >= @max_ct and ! @pre_action_battlers.include?(enemy)
            # 行動待ちエネミーに追加
            
            @pre_action_battlers.push(enemy)
            @action_count += 1
            # それ以上カウントアップしない
            enemy.countup = false
            enemy.full_ct = true
          else
            # カウントアップ
            enemy.make_action_speed
            enemy.now_ct += enemy.current_action.speed * PARA_CTB::BATTLE_SPEED
          end
        end
      end
      # CTゲージを再描画
      @status_window.refresh_ct
      @status_window2.refresh_ct
    end
  end
end