#==============================================================================
#                          「宝箱鑑定」(ACE) Ver.1.2
#   製作者:奈々(なな)
#   へぷたなすくろーる http://heptanas.mamagoto.com/
#
#   ◇使用規約
#   使用される場合はスクリプト作成者として「奈々」を明記して下さい。
#   スクリプトの改変は自由に行って頂いて構いませんが
#   その場合も元のスクリプトの作成者として名前を載せて下さい。
#   また配布前に必ず、ブログにある利用規約を確認して下さい。
#
#------------------------------------------------------------------------------
#   
#   宝箱の中身を識別する、いわゆるイ○パスのような
#   「鑑定」魔法を再現するためのスクリプトです。
#   
#   使い方は、まずイベントの「注釈」で設定を行います。
#   
#   <鑑定 n>            全方向から鑑定可能
#   <正面鑑定 n>        イベントの正面からのみ鑑定可能
#   <下鑑定 n>          下からのみ鑑定可能(他に左右上も設定可能)
#   <画面鑑定 n>        全画面鑑定(後述)でのみ使用
#   
#   nはアニメーションIDで、鑑定時に表示されます。
#   アニメーションなので、フラッシュや効果音も設定できます。
#   各タグは重複可能、ページ内の好きな場所に設定可能で
#   設定はページ毎になるため、ページ変更で切り替えが可能です。
#   
#   次に、鑑定行動は以下のイベントコマンド「スクリプト」で行います。
#   
#   n7_ez_imp           通常鑑定
#   n7_screen_imp       全画面鑑定
#   
#   鑑定魔法を作る場合は、適当なコモンイベントに n7_ez_imp を設定し
#   そのコモンイベントを呼び出すスキルやアイテムを作って下さい。
#   イベントを介すため、文章や外れ効果音などの追加も可能です。
#   
#   通常鑑定を行った場合、目の前にあるイベントを鑑定し
#   設定されている番号のアニメーションを表示します。
#   また初期設定で、指定の変数に鑑定結果を取得できます。
#   
#   全画面鑑定を行った場合、画面内の全てのイベントを鑑定します。
#   これはどちらかと言えば、隠し罠の発見や、友好度の識別など
#   宝箱の鑑定とは異なる用途を想定した機能です。(使い方次第ですが)
#   なので、設定タグは通常鑑定のものと別にしてあります。
#   
#==============================================================================

#初期設定
module N7_EZ_IMP
  
  #鑑定結果(アニメーションID)を取得する変数のID
  VA = 0
  
end
#==============================================================================
# ■ Game_Interpreter
#------------------------------------------------------------------------------
#  イベントコマンドを実行するインタプリタです。このクラスは Game_Map クラス、
# Game_Troop クラス、Game_Event クラスの内部で使用されます。
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # ● 宝箱鑑定の発動
  #--------------------------------------------------------------------------
  def n7_ez_imp
    $game_variables[N7_EZ_IMP::VA] = 0 if N7_EZ_IMP::VA > 0
    tx = $game_player.x
    ty = $game_player.y
    pd = $game_player.direction
    case pd
    when 2
      ty += 1
    when 4
      tx -= 1
    when 6
      tx += 1
    when 8
      ty -= 1
    end
    te = $game_map.events_xy(tx, ty)[0]
    
    if te && te.list
      te.list.each do |ev|
        next unless ev.code == 108 || ev.code == 408
        if ev.parameters[0][/\<鑑定\s*(\d+)>/]
          $game_variables[N7_EZ_IMP::VA] = $1.to_i if N7_EZ_IMP::VA > 0
          te.animation_id = $1.to_i
          break
        end
        if ev.parameters[0][/\<正面鑑定\s*(\d+)>/]
          case pd
          when 2
            break unless te.direction == 8
          when 4
            break unless te.direction == 6
          when 6
            break unless te.direction == 4
          when 8
            break unless te.direction == 2
          end
          $game_variables[N7_EZ_IMP::VA] = $1.to_i if N7_EZ_IMP::VA > 0
          te.animation_id = $1.to_i
          break
        end
        if ev.parameters[0][/\<下鑑定\s*(\d+)>/] && pd == 8
          $game_variables[N7_EZ_IMP::VA] = $1.to_i if N7_EZ_IMP::VA > 0
          te.animation_id = $1.to_i
          break
        elsif ev.parameters[0][/\<左鑑定\s*(\d+)>/] && pd == 6
          $game_variables[N7_EZ_IMP::VA] = $1.to_i if N7_EZ_IMP::VA > 0
          te.animation_id = $1.to_i
          break
        elsif ev.parameters[0][/\<右鑑定\s*(\d+)>/] && pd == 4
          $game_variables[N7_EZ_IMP::VA] = $1.to_i if N7_EZ_IMP::VA > 0
          te.animation_id = $1.to_i
          break
        elsif ev.parameters[0][/\<上鑑定\s*(\d+)>/] && pd == 2
          $game_variables[N7_EZ_IMP::VA] = $1.to_i if N7_EZ_IMP::VA > 0
          te.animation_id = $1.to_i
          break
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 宝箱鑑定の発動(全画面)
  #--------------------------------------------------------------------------
  def n7_screen_imp
    $game_map.events.each do |key, te|
      next unless te.list && te.near_the_screen?
      te.list.each do |ev|
        next unless ev.code == 108 || ev.code == 408
        if ev.parameters[0][/\<画面鑑定\s*(\d+)>/]
          te.animation_id = $1.to_i
          break
        end
      end
    end
  end
end