#==============================================================================
#           「スキル必要ステータス」(ACE) ver1.00  by奈々
#
#   ◇使用規約
#   使用される場合はスクリプト作成者として「奈々」を明記して下さい。
#   このスクリプトを改変したり、改変したものを配布するなどは自由ですが
#   その場合も元のスクリプトの作成者として名前は載せて下さい。
#
#------------------------------------------------------------------------------
#
#   一定以上のステータスがないと使用できないスキルを作成できます。
#   スキルのメモ欄に<必要ステータス "ステータス名" "数値">
#   もしくは<上限ステータス "ステータス名" "数値">と入れます。
#   使用できるステータスは
#   「mhp hp mmp mp max_tp tp atk def mat mdf agi luk」です。
#   <必要ステータス atk 50>なら攻撃力50以上で使用可能なスキル
#   <上限ステータス hp 50>なら現在HPが50以下で使用可能なスキルとなります。
#   
#   複数のタグを設定することも可能で
#   その場合はタグ全ての条件を満たしているときにのみ使用可能になります。
#
#==============================================================================

class RPG::Skill < RPG::UsableItem
  #--------------------------------------------------------------------------
  # ● 必要ステータスの定義(追加定義)
  #--------------------------------------------------------------------------  
  # mhp hp mmp mp max_tp tp atk def mat mdf agi luk
  # 以上の順番で配列に格納してreturnされる
  def need_status_over
    status = []
    @note.scan(/<必要ステータス\s?mhp\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(0)
    @note.scan(/<必要ステータス\s?hp\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(0)
    @note.scan(/<必要ステータス\s?mmp\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(0)
    @note.scan(/<必要ステータス\s?mp\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(0)
    @note.scan(/<必要ステータス\s?max_tp\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(0)
    @note.scan(/<必要ステータス\s?tp\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(0)
    @note.scan(/<必要ステータス\s?atk\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(0)
    @note.scan(/<必要ステータス\s?def\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(0)
    @note.scan(/<必要ステータス\s?mat\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(0)
    @note.scan(/<必要ステータス\s?mdf\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(0)
    @note.scan(/<必要ステータス\s?agi\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(0)
    @note.scan(/<必要ステータス\s?luk\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(0)
    return status
  end
  def need_status_under
    status = []
    @note.scan(/<上限ステータス\s?mhp\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(999999)
    @note.scan(/<上限ステータス\s?hp\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(999999)
    @note.scan(/<上限ステータス\s?mmp\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(999999)
    @note.scan(/<上限ステータス\s?mp\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(999999)
    @note.scan(/<上限ステータス\s?max_tp\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(999999)
    @note.scan(/<上限ステータス\s?tp\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(999999)
    @note.scan(/<上限ステータス\s?atk\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(999999)
    @note.scan(/<上限ステータス\s?def\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(999999)
    @note.scan(/<上限ステータス\s?mat\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(999999)
    @note.scan(/<上限ステータス\s?mdf\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(999999)
    @note.scan(/<上限ステータス\s?agi\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(999999)
    @note.scan(/<上限ステータス\s?luk\s?(\d+)>/)
    $1 ? status.push($1.to_i) : status.push(999999)
    return status
  end
end

class Game_BattlerBase
  #--------------------------------------------------------------------------
  # ● スキルの使用可能条件チェック(エイリアス)
  #--------------------------------------------------------------------------
  alias skill_conditions_met2? skill_conditions_met?
  def skill_conditions_met?(skill)
    skill_conditions_met2?(skill) && skill_need_status?(skill)
  end
  #--------------------------------------------------------------------------
  # ● スキルの必要ステータス(新規メソッド)
  #--------------------------------------------------------------------------
  def skill_need_status?(skill)
    need = skill.need_status_over
    need2 = skill.need_status_under
    need[0] <= self.mhp && need[1] <= self.hp && need[2] <= self.mmp &&
    need[3] <= self.mp && need[4] <= self.max_tp && need[5] <= self.tp &&
    need[6] <= self.atk && need[7] <= self.def && need[8] <= self.mat &&
    need[9] <= self.mdf && need[10] <= self.agi && need[11] <= self.luk &&
    need2[0] >= self.mhp && need2[1] >= self.hp && need2[2] >= self.mmp &&
    need2[3] >= self.mp && need2[4] >= self.max_tp && need2[5] >= self.tp &&
    need2[6] >= self.atk && need2[7] >= self.def && need2[8] >= self.mat &&
    need2[9] >= self.mdf && need2[10] >= self.agi && need2[11] >= self.luk
  end
end