#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#_/  ◆无敌状态 - KGC_Invincible◆
#_/----------------------------------------------------------------------------
#_/ 在状态中设置个“无敌”二字的状态即可使用。
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

$imported = {} if $imported == nil
$imported["Invincible"] = true

if $game_special_states == nil
  $game_special_states = {}
  $data_states = load_data("Data/States.rxdata")
end
# 無敵状態ステートIDa取得
state = $data_states.compact.find { |s| s.name == "无敌" }
$game_special_states["invincible"] = state != nil ? state.id : 0

#==============================================================================
# ■ Game_Battler (分割定義 2)
#==============================================================================

class Game_Battler
  #--------------------------------------------------------------------------
  # ● ステート [無敵] 判定
  #     act : 処理対象
  #--------------------------------------------------------------------------
  def invincible?(act = nil)
    # ステート[無敵]が付加されている場合
    if self.states.include?($game_special_states["invincible"])
      # 処理対象で分岐
      case act
      when RPG::Skill
        return true if act.scope == 1 || act.scope == 2
      when RPG::Item
        return true if act.scope == 1 || act.scope == 2
      when nil
        return true
      end
    end
    return false
  end
end

#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

#==============================================================================
# ■ Game_Battler (分割定義 3)
#==============================================================================

class Game_Battler
  #--------------------------------------------------------------------------
  # ● 通常攻撃の効果適用
  #--------------------------------------------------------------------------
  alias attack_effect_KGC_Invincible attack_effect
  def attack_effect(attacker)
    # 無敵状態の場合
    if self.invincible?
      # ダメージに "Miss" を設定
      self.damage = "Miss"
      # クリティカルフラグをクリア
      self.critical = false
      # 偽を返す
      return false
    end

    # 元の処理を実行
    return attack_effect_KGC_Invincible(attacker)
  end
  #--------------------------------------------------------------------------
  # ● スキルの効果適用
  #--------------------------------------------------------------------------
  alias skill_effect_KGC_Invincible skill_effect
  def skill_effect(user, skill)
    # 無敵状態の場合
    if self.invincible?(skill)
      # ダメージに "Miss" を設定
      self.damage = "Miss"
      # クリティカルフラグをクリア
      self.critical = false
      # 偽を返す
      return false
    end

    # 元の処理を実行
    return skill_effect_KGC_Invincible(user, skill)
  end
  #--------------------------------------------------------------------------
  # ● アイテムの効果適用
  #--------------------------------------------------------------------------
  alias item_effect_KGC_Invincible item_effect
  def item_effect(item)
    # 無敵状態の場合
    if self.invincible?(item)
      # ダメージに "Miss" を設定
      self.damage = "Miss"
      # クリティカルフラグをクリア
      self.critical = false
      # 偽を返す
      return false
    end

    # 元の処理を実行
    return item_effect_KGC_Invincible(item)
  end
end