class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
  # ● 能力強化
  #--------------------------------------------------------------------------
  def add_buff(param_id, turns , user)
    return unless alive?
    a = @buffs[param_id] + user.mat * $buff_change_degree[param_id] * turns
    @buffs[param_id] = [buff_max(param_id) , a].min.floor
    @result.added_buffs.push(param_id).uniq!
    refresh
  end

  #--------------------------------------------------------------------------
  # ● 能力弱体
  #--------------------------------------------------------------------------
  def add_debuff(param_id, turns , user)
    return unless alive?
    buff_degree = user.mat - self.mdf / 5 + rand(5)
    buff_degree = buff_degree * 4 / 5 + 2 * rand(buff_degree / 5)
    a = @buffs[param_id] - buff_degree * $debuff_change_degree[param_id] * turns
    @buffs[param_id] = [- debuff_max(param_id) , a].max.ceil   
    @result.added_debuffs.push(param_id).uniq!
    refresh
  end  


  #--------------------------------------------------------------------------
  # ● 強化／弱体の自動解除
  #--------------------------------------------------------------------------
  def remove_buffs_auto
    @buffs.size.times do |param_id|
      next if @buffs[param_id] != 0 #&& @buff_turns[param_id] > 0
      remove_buff(param_id)
    end
  end  

  #--------------------------------------------------------------------------
  # ● 能力強化の最大
  #--------------------------------------------------------------------------
  def buff_max(param_id)
    ($buff_change_degree_max[param_id] * param_default(param_id)).floor
  end
  #--------------------------------------------------------------------------
  # ● 能力弱体の最大
  #--------------------------------------------------------------------------
  def debuff_max(param_id)
    ($debuff_change_degree_max[param_id] * param_default(param_id)).floor
  end  
  #--------------------------------------------------------------------------
  # ● 使用効果［能力強化］
  #--------------------------------------------------------------------------
  def item_effect_add_buff(user, item, effect)
    add_buff(effect.data_id, effect.value1 ,user)
    @result.success = true
  end
  #--------------------------------------------------------------------------
  # ● 使用効果［能力弱体］
  #--------------------------------------------------------------------------
  def item_effect_add_debuff(user, item, effect)
    chance = debuff_rate(effect.data_id) * luk_effect_rate(user)
    if rand < chance
      add_debuff(effect.data_id, effect.value1 , user)
      @result.success = true
    end
  end 
  #--------------------------------------------------------------------------
  # ● 強化／弱体のターンカウント更新
  #--------------------------------------------------------------------------
  def update_buff_turns
    @buffs.each_index do |param_id|
      update_buff_value(param_id) if @buffs[param_id] > 0
      update_debuff_value(param_id) if @buffs[param_id] < 0
    end
  end  
  
  def update_buff_value(param_id)
    b = (@buffs[param_id] * $buff_update_degree).floor
    @buffs[param_id]  =  @buffs[param_id] > $buff_update_cut_degree[param_id] ? b : 0

  end
  def update_debuff_value(param_id)
    b = (@buffs[param_id] * $debuff_update_degree).ceil
    @buffs[param_id]  =  @buffs[param_id] < - $debuff_update_cut_degree[param_id] ? b : 0     
  end  
end  