#==============================================================================
# Get Menu Info [VXA]
# Author: Mesiah A.K.A. Mako Infused
# Version: 1.00
# Contact: www.cetrastudios.com/
#------------------------------------------------------------------------------
# ■ Short Description
#------------------------------------------------------------------------------
# This script allows the developer get more information about the current
# menu without scripting knowledge. It allows you to retrieve information 
# and use it for eventing purposes.
#
#------------------------------------------------------------------------------
# ͏ Notetags - 0
#------------------------------------------------------------------------------
# There is no notetag options for this script.
#
#------------------------------------------------------------------------------
# ͏ Script Calls - 3
#------------------------------------------------------------------------------
# CALL: menu_info_user
# HELP: This command will get the user of the current action from the menu.
#
# CALL: menu_info_used
# HELP: This command will get the the current action from the skill/item menu.
#
# CALL: menu_info_targets
# HELP: This command will get an array of all the targets of the current action
#       from the menu.
#       Array starts at 1.
#
# NOTE: To retrieve a single actor/enemy from an array you must append a [id]
#       to the end of the script call. Examples can be found below!
# 
#------------------------------------------------------------------------------
# ● Examples:
#------------------------------------------------------------------------------
# CALL: menu_info_user.id
# HELP: This would retrieve the id of the current user whose executing an
#       action from the menu.
# 
# CALL: menu_info_used.id
# HELP: This would retrieve the id of the current action that has been executed
#       from the menu.
# 
# CALL: menu_info_targets[1].id
# HELP: This would retrieve the id of the first target whose had am action
#       used on them from the menu.
# 
#------------------------------------------------------------------------------
# ● Customization:
#------------------------------------------------------------------------------
# There is no customization options for this script.
#------------------------------------------------------------------------------
# ● Requirements:
#------------------------------------------------------------------------------
# None
#------------------------------------------------------------------------------
# * Terms:
#------------------------------------------------------------------------------
# - Don't claim you made this script.
# - Credit is appreciated, but not necessary.
#------------------------------------------------------------------------------
# ● Change Log:
#------------------------------------------------------------------------------
# 04/10/2013 - Started and finished script.
#==============================================================================

#==============================================================================
# [STOP] End of Edittable Area
#==============================================================================

$imported = {} if $imported.nil?
$imported["MESI-GetMenuInfo"] = true

#==============================================================================
# ** Game_Temp
#==============================================================================

class Game_Temp
  
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :menu_skill_user
  attr_accessor :menu_skill_used
  attr_accessor :menu_skill_targets
  
  #--------------------------------------------------------------------------
  # * Alias Method: Initialize
  #--------------------------------------------------------------------------
  alias mesiah_gmi_initialize initialize
  def initialize
    mesiah_gmi_initialize
    @menu_skill_user = nil
    @menu_skill_used = nil
    @menu_skill_targets = [nil]
  end
  
end

#==============================================================================
# ** Game_Interpreter
#==============================================================================

class Game_Interpreter
  
  #--------------------------------------------------------------------------
  # * Get Last User
  #--------------------------------------------------------------------------
  def menu_info_user
    return if menu_only_error?
    return $game_temp.menu_skill_user
  end
  
  #--------------------------------------------------------------------------
  # * Get Last Used Item/Skill
  #--------------------------------------------------------------------------
  def menu_info_used
    return if menu_only_error?
    return $game_temp.menu_skill_used
  end
  
  #--------------------------------------------------------------------------
  # * Get Last Targets
  #--------------------------------------------------------------------------
  def menu_info_targets
    return if menu_only_error?
    return $game_temp.menu_skill_targets
  end
  
  #--------------------------------------------------------------------------
  # * Checks if the command is valid?
  #--------------------------------------------------------------------------
  def menu_only_error?
    unless SceneManager.scene.class == Scene_Map
      message = "This script call can only be used on the map!"
      if $imported["MESI-GetErrorInfo"]
        event_script_error(2, message)
      else
        missing = "Install the script 'Get Error Info' for more information"
        msgbox(message + "\n" + missing)
      end
      return true
    end
    return false
  end
  
end

#==============================================================================
# ** Scene_ItemBase
#==============================================================================

class Scene_ItemBase < Scene_MenuBase
  
  #--------------------------------------------------------------------------
  # * Alias Method: Use Item
  #--------------------------------------------------------------------------
  alias mesiah_gmi_use_item use_item
  def use_item
    mesiah_gmi_use_item
    $game_temp.menu_skill_user = $game_party.members[0]
    $game_temp.menu_skill_used = item
  end
  
  #--------------------------------------------------------------------------
  # * Get Array of Actors Targeted by Item Use
  #--------------------------------------------------------------------------
  alias mesiah_gmi_check_common_event check_common_event
  def check_common_event
    targets = item_target_actors
    $game_temp.menu_skill_targets = [nil]
    $game_temp.menu_skill_targets += targets.is_a?(Array) ? targets : [targets]
    mesiah_gmi_check_common_event
  end
  
end

#==============================================================================
# ** Scene_Skill
#==============================================================================

class Scene_Skill < Scene_ItemBase
  
  #--------------------------------------------------------------------------
  # * Alias Method: Use Item
  #--------------------------------------------------------------------------
  alias mesiah_gmi_use_skill use_item
  def use_item
    mesiah_gmi_use_skill
    $game_temp.menu_skill_user = user
  end
  
end