 #06/10/11
#==============================================================================
# ■ エネミー追加データ
#==============================================================================
module Enemy_Ex
  #--------------------------------------------------------------------------
  # Ex[エネミーID] = {1=>[盗むアイテム/盗むレア/変化アイテム]}
  # "i(ID)" ：アイテム  "w(ID)"　：武器　"a(ID)"　：防具　"g(金額)"　：お金　 ""　：無しの場合
  #,2=>[変身後のID]}
  #--------------------------------------------------------------------------
  Ex = []
  Ex[0] = {1=>["","",""],2=>[]} # エネミーID未設定の場合
  
  Ex[1] = {1=>["i1","g1000","a1"],2=>[2]} # ゴースト
  Ex[2] = {1=>["i1","w1",""],2=>[1]} # バジリスク
  
  
end
#==============================================================================
# ■ 盗む/変化/変身
#------------------------------------------------------------------------------
# スキルに追加（アクター専用）　名前：ぬすむ、へんか、ぶんどる　効果範囲：敵単体
# スキルに追加（エネミー専用）　名前：変身　効果範囲：自分自身
#==============================================================================
class Game_Enemy < Game_Battler
  include Enemy_Ex
  attr_accessor :enemy_id                 # エネミーID
  attr_accessor :steal_item               # 盗めるアイテム
  attr_accessor :change_item              # アイテムに変化
  attr_accessor :enemy_change             # 変身する
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  alias hidesp2_initialize initialize
  def initialize(troop_id, member_index)
    super()
    # 元の処理を呼び出し
    hidesp2_initialize(troop_id, member_index)
    # ■ オリジナル変数
    original_variable(@enemy_id)
  end
  
  #--------------------------------------------------------------------------
  # ■ オリジナル変数の初期化
  #--------------------------------------------------------------------------
  def original_variable(enemy_id)
    @enemy_id = enemy_id
    @change_item = [false,nil,nil,nil,nil,false]
    @steal_item = [0]
    e = @enemy_id
    # □Enemy_Ex未設定の場合
    if Enemy_Ex::Ex[@enemy_id] == nil
      e = 0
      @steal_item[5] = true
    end
    # □[ぬすむ/ぶんどる]アイテム
    Enemy_Ex::Ex[e][1][0].scan(/([iwag])([0-9]+)/)
    @steal_item[1] = $1
    @steal_item[2] = $2.to_i
    Enemy_Ex::Ex[e][1][1].scan(/([iwag])([0-9]+)/)
    @steal_item[3] = $1
    @steal_item[4] = $2.to_i
    # □[へんか]アイテム
    Enemy_Ex::Ex[e][1][2].scan(/([iwag])([0-9]+)/)
    @change_item[1] = $1
    @change_item[2] = $2.to_i
    # □[ぬすむ]アイテム未設定の場合
    if @steal_item[1] == nil && @steal_item[3] == nil
      @steal_item[5] = true
    end
    # □[変身]の初期化
    @enemy_change = [false,Enemy_Ex::Ex[e][2][0]]
  end
end

class Game_Battler
  #--------------------------------------------------------------------------
  # ■ スキルの効果適用
  #--------------------------------------------------------------------------
  alias hidesp2_skill_effect skill_effect
  def skill_effect(user, skill)
    # アクター専用
    if skill != nil && user.is_a?(Game_Actor) && self.is_a?(Game_Enemy)
      case skill.name
      #…………………………………………………………………………………………………
      # ■[ぬすむ]の場合
      #…………………………………………………………………………………………………
      when "ぬすむ"
        self.damage = "Steal!"
        self.steal_item[0] = true
        return true
      #…………………………………………………………………………………………………
      # ■[ぶんどる]の場合
      #…………………………………………………………………………………………………
      when "ぶんどる"
        if self.steal_item[8] == true
          self.damage = "Steal!"
          self.steal_item[0] = true
          self.steal_item[8] = false
          return true
        else
          self.steal_item[8] = true
        end
      #…………………………………………………………………………………………………
      # ■[へんか]の場合
      #…………………………………………………………………………………………………
      when "へんか"
        self.damage = "Change!"
        self.change_item[0] = true
        return true
      end
    # エネミー専用
    elsif skill != nil && user.is_a?(Game_Enemy) && self.is_a?(Game_Enemy)
      case skill.name
      #…………………………………………………………………………………………………
      # ■[変身]の場合
      #…………………………………………………………………………………………………
      when "変身"
        self.damage = ""
        self.enemy_change[0] = true
        return true
      end
    end
    # 元の処理を呼び出し
    hidesp2_skill_effect(user, skill)
  end
end

class Scene_Battle
  include Enemy_Ex
  #--------------------------------------------------------------------------
  # ■ フレーム更新 (メインフェーズ ステップ 3 : 行動側アニメーション)
  #--------------------------------------------------------------------------
  alias hidesp_update_phase4_step3 update_phase4_step3
  def update_phase4_step3
    hidesp_update_phase4_step3
    if @bundoru != nil
      # ヘルプウィンドウを隠す
      @help_window.visible = false
      # 行動側アニメーション無し
      @active_battler.animation_id = 0
      @active_battler.animation_hit = false
    end
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新 (メインフェーズ ステップ 4 : 対象側アニメーション)
  #--------------------------------------------------------------------------
  alias hidesp_update_phase4_step4 update_phase4_step4
  def update_phase4_step4
    hidesp_update_phase4_step4
    if @bundoru != nil
      # 対象側アニメーション
      @bundoru.animation_id = 0
      @bundoru.animation_hit = false
      # [ぶんどる]フラグOFF
      @bundoru = nil
    end
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新 (メインフェーズ ステップ 5 : ダメージ表示)
  #--------------------------------------------------------------------------
  alias hidesp2_update_phase4_step5 update_phase4_step5
  def update_phase4_step5
    # スキルの効果範囲を敵単体に設定している為ターゲットは[0]
    tc = @target_battlers[0]
    if tc != nil
      if tc.is_a?(Game_Enemy)
        #…………………………………………………………………………………………………
        # ■[へんか]の場合
        #…………………………………………………………………………………………………
        if tc.change_item[0] == true
          # アイテムデータの取得
          tc.change_item_effect(tc,@active_battler)
          @help_window.set_text_icon(tc,tc.change_item[3], 1)
          @wait_count = 40
          # [へんか]フラグOFF
          tc.change_item[0] = false
          # [へんか]成功の場合
          if tc.change_item[5] == true
            # 変化したモンスターの行動をクリア
            tc.current_action.clear
            # 隠れフラグをON(隠れる)
            tc.hidden = true
          end
        #…………………………………………………………………………………………………
        # ■[ぬすむ]の場合
        #…………………………………………………………………………………………………
        elsif tc.steal_item[0] == true
          # アイテムデータの取得
          tc.steal_item_effect(tc,@active_battler)
          @help_window.set_text_icon(tc,tc.steal_item[6], 1)
          @wait_count = 40
          # [ぬすむ]フラグOFF
          tc.steal_item[0] = false
        #…………………………………………………………………………………………………
        # ■[ぶんどる]の場合
        #…………………………………………………………………………………………………
        elsif tc.steal_item[8] == true
          if ! tc.exist?
            # [ぶんどる]フラグOFF
            tc.steal_item[8] = false
            @bundoru = nil
          else
            hidesp2_update_phase4_step5
            @bundoru = tc
            @phase4_step = 2
            return
          end
        #…………………………………………………………………………………………………
        # ■[変身]の場合
        #…………………………………………………………………………………………………
        elsif tc.enemy_change[0] == true
          # アニメの表示
          tc.animation_id = 1
          @wait_count = 16
          tc.animation_hit = true
          if tc.enemy_change[1] != nil
            tc.transform(tc.enemy_change[1])
            tc.original_variable(tc.enemy_change[1])
            return
          else
            p "存在しないエネミーIDを指定（エラー）"
          end
        else
          # 元の処理を呼び出し
          hidesp2_update_phase4_step5
          return
        end
        tc.damage_pop = true
        # ステップ 6 に移行
        @phase4_step = 6
        return
      end
    end
    # 元の処理を呼び出し
    hidesp2_update_phase4_step5
  end
  
end


