#===============================================================================
# 
# Yanfly Engine Melody - Status Menu Melody
# Last Date Updated: 2010.06.19
# Level: Normal, Hard
# 
# The status menu doesn't appear to help much at all in the default RPG Maker VX
# scripts. Instead, it's been altered to a centralized single actor management
# screen regarding stats. Here, the player can apply stat boosters, elemental
# resistance boosters, and more.
# 
#===============================================================================
# Updates
# -----------------------------------------------------------------------------
# o 2010.06.19 - Compatibility update for Equipment Overhaul.
# o 2010.06.03 - General stats window refresh bugfix.
# o 2010.05.24 - HECO stats are now drawn properly.
# o 2010.05.19 - Finished Script.
# o 2010.05.17 - Started Script.
#===============================================================================
# Instructions
# -----------------------------------------------------------------------------
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials but above ▼ Main. Remember to save.
# 
# -----------------------------------------------------------------------------
# Item Tags - For Items only.
# -----------------------------------------------------------------------------
# <stat growth: +x>  or  <stat growth: -x>
# This will increase or decrease the target's base stat by x amount. Just like
# items normally would in the database editor regarding MaxHP, MaxMP, ATK, DEF,
# SPI, and AGI, increasing by +x will raise the maximum by that value. However,
# what wasn't possible before was decreasing base stats. This function is now
# added within this script.
# 
#===============================================================================

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

module YEM
  module STATUS
    
    #===========================================================================
    # Section I. Main Settings
    # -------------------------------------------------------------------------
    # This section adjusts what items appear for the command window in the upper
    # left corner and how it appears as far as vocabulary is concerned. This
    # section also adjusts how the EXP gauge appears in the upper right actor
    # mini-status window.
    #===========================================================================
    # This array determines what items will appear in the status scene and
    # what order they appear in. Remove them if you wish for them to not appear.
    COMMANDS =[
      :general,    # Displays general actor information.
      :boosters,   # Displays the actor's parameters and item boosts.
      :elements,   # Displays the actor's elemental affinities.
      :states,     # Displays the actor's status effect resistances.
    ] # Do not remove this.
    
    # This hash determines how the vocabulary appears in your game. Modify them
    # as you see fit if you wish to rename certain aspects.
    COMMAND_VOCAB ={
      :general    => "General",
      :boosters   => "Boosters",
      :elements   => "Elements",
      :states     => "Ailments",
    } # Do not remove this.
    
    # This determines the colour of the EXP bars used for the actor's exp
    # gauge in the status menu.
    EXP_TEXT    = "EXP"      # Text used for EXP
    PERCENT_EXP = "%1.2f%%"  # Text format used for EXP percentage
    EXP_GAUGE_1 = 28         # Colour 1 for the EXP Gauge
    EXP_GAUGE_2 = 29         # Colour 2 for the EXP Gauge
    
    # This arrow appears in the stat comparison windows.
    ARROW = "→"
    
    #===========================================================================
    # Section II.A. General Window
    # -------------------------------------------------------------------------
    # This section adjusts the general window and how it appears. The general
    # window displays basic information for the player regarding the actor.
    #===========================================================================
    
    # This array shows the stats for the left side of the window. Simply remove
    # a stat from this list if you don't want it to appear or reaarnage them as
    # you see fit. You may place other stats here, too. Note that stats that
    # require special scripts won't appear unless that script is installed.
    #   Legal Stats:
    #   :hp, :mp, :atk, :def, :spi, :res, :dex, :agi, :hit, :eva, :cri, :odds
    SHOWN_STATS = [:hp, :mp, :atk, :def, :spi, :res, :dex, :agi]
    
    # This constant adjusts the category column title for general page.
    PARAMETERS = "Parameters"
    EQUIPMENT  = "Equipment"
    
    # Some of the more unusual stats do not have defined vocabulary to go
    # along with it. Adjust the following hash to give them names.
    STAT_VOCAB ={
      :hit  => "HIT", # Stat that modifies hit rate.
      :eva  => "EVA", # Stat that modifies evasion rate.
      :cri  => "CRI", # Stat that modifies critical rate.
      :odds => "AGR", # Stat that modifies aggro rate.
    } # Do not remove this.
    
    #===========================================================================
    # Section II.B. Booster Windows
    # -------------------------------------------------------------------------
    # This section adjusts the booster window, elements window, and status
    # windows. These windows provide power up opportunities for the player
    # and a forecast of how the new stat changes will appear.
    #===========================================================================
    
    # Even if the player doesn't have the boost item, if this option is enabled
    # then all the boost items in the game will be revealed to the player.
    SHOW_ALL_BOOSTS = true
    
    # For those who would like to change the font size of the booster windows,
    # adjust this constant.
    BOOSTER_FONT_SIZE = 16
    
    # This array contains all of the elements you want displayed and in which
    # order to display them in. You can display them as individual integers or
    # as number ranges.
    SHOWN_ELEMENTS = [3, 4, 5, 6..10]
    
    # Since elements do not have icons innately, use the following hash below
    # adjust and apply icons to them.
    ELEMENT_ICONS ={
      3 => 104,  # Fire element.
      4 => 105,  # Ice element.
      5 => 106,  # Volt element.
      6 => 108,  # Earth element.
      7 => 107,  # Water element.
      8 => 109,  # Air element.
      9 => 110,  # Light element.
     10 => 111,  # Dark element.
    } # Do not remove this.
    
    # This array contains all of the states you want displayed and in which
    # order to display them in. You can display them as individual integers or
    # as number ranges.
    SHOWN_STATES = [1, 2, 3, 4..8]
    
  end # STATUS
end # YEM

#===============================================================================
# Editting anything past this point may potentially result in causing computer
# damage, incontinence, explosion of user's head, coma, death, and/or halitosis.
# Therefore, edit at your own risk.
#===============================================================================

module YEM
  module REGEXP
  module ITEM
    
    STAT_GROW = /<(.*)[ ](?:BOOST|growth):[ ]([\+\-]\d+)>/i
    
  end # ITEM
  end # REGEXP
  module STATUS
    module_function
    #--------------------------------------------------------------------------
    # convert_integer_array
    #--------------------------------------------------------------------------
    def convert_integer_array(array)
      result = []
      array.each { |i|
        case i
        when Range; result |= i.to_a
        when Integer; result |= [i]
        end }
      return result
    end
    #--------------------------------------------------------------------------
    # converted_contants
    #--------------------------------------------------------------------------
    SHOWN_ELEMENTS = convert_integer_array(SHOWN_ELEMENTS)
    SHOWN_STATES   = convert_integer_array(SHOWN_STATES)
  end # STATUS
end # YEM

#===============================================================================
# RPG::Item
#===============================================================================

class RPG::Item < RPG::UsableItem
  
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :stat_growth
  
  #--------------------------------------------------------------------------
  # common cache: yem_cache_item_smm
  #--------------------------------------------------------------------------
  def yem_cache_item_smm
    return if @cached_item_smm; @cached_item_smm = true
    @stat_growth = {} if @stat_growth == nil
    case @parameter_type
    when 1; @stat_growth[:hp]  = @parameter_points
    when 2; @stat_growth[:mp]  = @parameter_points
    when 3; @stat_growth[:atk] = @parameter_points
    when 4; @stat_growth[:def] = @parameter_points
    when 5; @stat_growth[:spi] = @parameter_points
    when 6; @stat_growth[:agi] = @parameter_points
    end
    @parameter_points = 0
    #---
    self.note.split(/[\r\n]+/).each { |line|
      case line
      #---
      when YEM::REGEXP::ITEM::STAT_GROW
        case $1.upcase
        when "HP", "MAXHP"
          type = :hp
        when "MP", "MAXMP", "SP", "MAXSP"
          type = :mp
        when "ATK", "ATTACK"
          type = :atk
        when "DEF", "DEFENSE"
          type = :def
        when "SPI", "INT", "SPIRIT", "INTELLIGENCE"
          type = :spi
        when "AGI", "AGILITY"
          type = :agi
        else; next
        end
        @stat_growth[type] = $2.to_i
      end
    } # self.note.split
  end # yem_cache_item_smm
  
end # RPG::Item

#===============================================================================
# Scene_Title
#===============================================================================

class Scene_Title < Scene_Base
  
  #--------------------------------------------------------------------------
  # alias method: load_bt_database
  #--------------------------------------------------------------------------
  alias load_bt_database_smm load_bt_database unless $@
  def load_bt_database
    load_bt_database_smm
    load_smm_cache
  end
  
  #--------------------------------------------------------------------------
  # alias method: load_database
  #--------------------------------------------------------------------------
  alias load_database_smm load_database unless $@
  def load_database
    load_database_smm
    load_smm_cache
  end
  
  #--------------------------------------------------------------------------
  # new method: load_smm_cache
  #--------------------------------------------------------------------------
  def load_smm_cache
    groups = [$data_items]
    for group in groups
      for obj in group
        next if obj == nil
        obj.yem_cache_item_smm if obj.is_a?(RPG::Item)
      end
    end
  end
  
end # Scene_Title

#===============================================================================
# Vocab
#===============================================================================

module Vocab
  
  #--------------------------------------------------------------------------
  # new method: self.exp
  #--------------------------------------------------------------------------
  def self.exp; return YEM::STATUS::EXP_TEXT; end
    
  #--------------------------------------------------------------------------
  # new method: self.exp_format
  #--------------------------------------------------------------------------
  def self.exp_format; return YEM::STATUS::PERCENT_EXP; end
  
  #--------------------------------------------------------------------------
  # self.hit
  #--------------------------------------------------------------------------
  def self.hit; return YEM::STATUS::STAT_VOCAB[:hit]; end
  
  #--------------------------------------------------------------------------
  # self.eva
  #--------------------------------------------------------------------------
  def self.eva; return YEM::STATUS::STAT_VOCAB[:eva]; end
  
  #--------------------------------------------------------------------------
  # self.cri
  #--------------------------------------------------------------------------
  def self.cri; return YEM::STATUS::STAT_VOCAB[:cri]; end
    
  #--------------------------------------------------------------------------
  # self.odds
  #--------------------------------------------------------------------------
  def self.odds; return YEM::STATUS::STAT_VOCAB[:odds]; end
  
end # Vocab
  
#===============================================================================
# module Icon
#===============================================================================
if !$imported["BattleEngineMelody"] and !$imported["IconModuleLibrary"]
module Icon
  
  #--------------------------------------------------------------------------
  # self.element
  #--------------------------------------------------------------------------
  def self.element(element_id)
    icon = YEM::STATUS::ELEMENT_ICONS[element_id]
    return (icon == nil) ? 0 : icon
  end
  
  #--------------------------------------------------------------------------
  # self.stat
  #--------------------------------------------------------------------------
  def self.stat(actor, item); return 0; end
  
end # Icon
end # !$imported["BattleEngineMelody"] and !$imported["IconModuleLibrary"]

#===============================================================================
# Game_Temp
#===============================================================================

class Game_Temp
  
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :last_status_index
  attr_accessor :status_oy
  
  #--------------------------------------------------------------------------
  # new method: booster_items
  #--------------------------------------------------------------------------
  def booster_items
    return @booster_items if @booster_items != nil
    @booster_items = []
    for item in $data_items
      next if item == nil
      next if item.stat_growth == {}
      @booster_items.push(item)
    end
    return @booster_items
  end
  
  #--------------------------------------------------------------------------
  # new method: element_growth_items
  #--------------------------------------------------------------------------
  def element_growth_items
    return @element_growth_items if @element_growth_items != nil
    @element_growth_items = []
    return @element_growth_items unless $imported["BattleEngineMelody"]
    for item in $data_items
      next if item == nil
      next if item.element_growth == {}
      @element_growth_items.push(item)
    end
    return @element_growth_items
  end
  
  #--------------------------------------------------------------------------
  # new method: state_growth_items
  #--------------------------------------------------------------------------
  def state_growth_items
    return @state_growth_items if @state_growth_items != nil
    @state_growth_items = []
    return @state_growth_items unless $imported["BattleEngineMelody"]
    for item in $data_items
      next if item == nil
      next if item.state_growth == {}
      @state_growth_items.push(item)
    end
    return @state_growth_items
  end
  
end # Game_Temp

#===============================================================================
# Game_Battler
#===============================================================================

class Game_Battler
  
  #--------------------------------------------------------------------------
  # alias method: item_test
  #--------------------------------------------------------------------------
  alias item_test_smm item_test unless $@
  def item_test(user, item)
    return true if item.stat_growth != {}
    return item_test_smm(user, item)
  end
  
  #--------------------------------------------------------------------------
  # alias method: item_growth_effect
  #--------------------------------------------------------------------------
  alias item_growth_effect_smm item_growth_effect unless $@
  def item_growth_effect(user, item)
    item_growth_effect_smm(user, item)
    create_actor_boosts if actor?
    if item.stat_growth != {}
      for key in item.stat_growth
        stat = key[0]; value = key[1]
        case stat
        when :hp
          @maxhp_plus += value if !actor?
          @boost_maxhp += value if actor?
        when :mp
          @maxmp_plus += value if !actor?
          @boost_maxmp += value if actor?
        when :atk
          @atk_plus += value if !actor?
          @boost_atk += value if actor?
        when :def
          @def_plus += value if !actor?
          @boost_def += value if actor?
        when :spi
          @spi_plus += value if !actor?
          @boost_spi += value if actor?
        when :agi
          @agi_plus += value if !actor?
          @boost_agi += value if actor?
        end
      end
    end
  end
  
  #--------------------------------------------------------------------------
  # new method: create_actor_boosts
  #--------------------------------------------------------------------------
  def create_actor_boosts
    @boost_maxhp = 0 if @boost_maxhp == nil
    @boost_maxmp = 0 if @boost_maxmp == nil
    @boost_atk = 0 if @boost_atk == nil
    @boost_def = 0 if @boost_def == nil
    @boost_spi = 0 if @boost_spi == nil
    @boost_agi = 0 if @boost_agi == nil
  end
  
end # Game_Battler

#===============================================================================
# Game_Actor
#===============================================================================

class Game_Actor < Game_Battler
  
  #--------------------------------------------------------------------------
  # new method: now_exp
  #--------------------------------------------------------------------------
  def now_exp
    return @exp - @exp_list[@level]
  end
  
  #--------------------------------------------------------------------------
  # new method: next_exp
  #--------------------------------------------------------------------------
  def next_exp
    return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
  end
  
  #--------------------------------------------------------------------------
  # alias method: base_maxhp
  #--------------------------------------------------------------------------
  alias base_maxhp_smm base_maxhp unless $@
  def base_maxhp
    create_actor_boosts if @boost_maxhp == nil
    return base_maxhp_smm + @boost_maxhp
  end
  
  #--------------------------------------------------------------------------
  # alias method: base_maxmp
  #--------------------------------------------------------------------------
  alias base_maxmp_smm base_maxmp unless $@
  def base_maxmp
    create_actor_boosts if @boost_maxmp == nil
    return base_maxmp_smm + @boost_maxmp
  end
  
  #--------------------------------------------------------------------------
  # alias method: base_atk
  #--------------------------------------------------------------------------
  alias base_atk_smm base_atk unless $@
  def base_atk
    create_actor_boosts if @boost_atk == nil
    return base_atk_smm + @boost_atk
  end
  
  #--------------------------------------------------------------------------
  # alias method: base_def
  #--------------------------------------------------------------------------
  alias base_def_smm base_def unless $@
  def base_def
    create_actor_boosts if @boost_def == nil
    return base_def_smm + @boost_def
  end
  
  #--------------------------------------------------------------------------
  # alias method: base_spi
  #--------------------------------------------------------------------------
  alias base_spi_smm base_spi unless $@
  def base_spi
    create_actor_boosts if @boost_spi == nil
    return base_spi_smm + @boost_spi
  end
  
  #--------------------------------------------------------------------------
  # alias method: base_agi
  #--------------------------------------------------------------------------
  alias base_agi_smm base_agi unless $@
  def base_agi
    create_actor_boosts if @boost_agi == nil
    return base_agi_smm + @boost_agi
  end
  
end # Game_Actor

#===============================================================================
# Window_Base
#===============================================================================

class Window_Base < Window
  
  #--------------------------------------------------------------------------
  # new method: draw_actor_exp
  #--------------------------------------------------------------------------
  def draw_actor_exp(actor, x, y, width = 120)
    draw_actor_exp_gauge(actor, x, y, width)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 30, WLH, Vocab.exp)
    self.contents.font.color = normal_color
    last_font_size = self.contents.font.size
    xr = x + width
    if actor.next_exp == 0
      text = sprintf(Vocab.exp_format, 100.0)
    else
      text = sprintf(Vocab.exp_format, actor.now_exp * 100.0 / actor.next_exp)
    end
    self.contents.draw_text(x, y, width, WLH, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # new method: draw_actor_exp_gauge
  #--------------------------------------------------------------------------
  def draw_actor_exp_gauge(actor, x, y, width = 120)
    gc0 = gauge_back_color
    gc1 = text_color(YEM::STATUS::EXP_GAUGE_1)
    gc2 = text_color(YEM::STATUS::EXP_GAUGE_2)
    gh = $imported["CoreFixesUpgradesMelody"] ? YEM::UPGRADE::GAUGE_HEIGHT : 6
    gh += 2 if $imported["CoreFixesUpgradesMelody"] and YEM::UPGRADE::OUTLINE
    gy = y + WLH - 8 - (gh - 6)
    self.contents.fill_rect(x, gy, width, gh, gc0)
    if $imported["CoreFixesUpgradesMelody"] and YEM::UPGRADE::OUTLINE
      gy += 1
      gh -= 2
      width -= 2
    end
    if actor.next_exp == 0
      gbw = width
    else
      gbw = width * actor.now_exp / [actor.next_exp, 1].max
    end
    x += 1 if $imported["CoreFixesUpgradesMelody"] and YEM::UPGRADE::OUTLINE
    self.contents.gradient_fill_rect(x, gy, gbw, gh, gc1, gc2)
  end
  
end # Window_Base

#===============================================================================
# Window_Command_Centered
#===============================================================================

class Window_Command_Centered < Window_Command
  
  #--------------------------------------------------------------------------
  # new method: draw_item
  #--------------------------------------------------------------------------
  def draw_item(index, enabled = true)
    rect = item_rect(index)
    rect.x += 4
    rect.width -= 8
    self.contents.clear_rect(rect)
    self.contents.font.color = normal_color
    self.contents.font.color.alpha = enabled ? 255 : 128
    self.contents.draw_text(rect, @commands[index],1)
  end
  
end # Window_Command_Centered

#===============================================================================
# Window_Actor_Status
#===============================================================================

class Window_Actor_Status < Window_Base
  
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(actor)
    super(160, 0, Graphics.width - 160, 128)
    @actor = actor
    refresh
  end
  
  #--------------------------------------------------------------------------
  # actor=
  #--------------------------------------------------------------------------
  def actor=(new_actor)
    @actor = new_actor
    refresh
  end
  
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    draw_actor_face(@actor, 0, 0)
    dx = 108; dy = 0
    draw_actor_name(@actor, dx, dy)
    draw_actor_class(@actor, dx + 120, dy)
    draw_actor_level(@actor, dx, dy + WLH * 1)
    draw_actor_state(@actor, dx, dy + WLH * 2)
    draw_actor_hp(@actor, dx + 120, dy + WLH * 1)
    draw_actor_mp(@actor, dx + 120, dy + WLH * 2)
    draw_actor_exp(@actor, dx + 120, dy + WLH * 3)
  end
  
end # Window_Actor_Status

#===============================================================================
# Window_Status_General
#===============================================================================

class Window_Status_General < Window_Base
  
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(actor)
    super(0, 128, Graphics.width, Graphics.height - 128)
    @actor = actor
    refresh
  end
  
  #--------------------------------------------------------------------------
  # actor=
  #--------------------------------------------------------------------------
  def actor=(new_actor)
    @actor = new_actor
    refresh
  end
  
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    draw_parameters(24, 0)
    draw_exp_info(contents.width/2, 0)
    draw_equipments(contents.width/2, WLH*4)
  end
  
  #--------------------------------------------------------------------------
  # draw_parameters
  #--------------------------------------------------------------------------
  def draw_parameters(dx, dy)
    self.contents.font.size = Font.default_size
    self.contents.font.color = system_color
    text = YEM::STATUS::PARAMETERS
    self.contents.draw_text(dx + 24, dy, contents.width/3, WLH, text, 1)
    dy += WLH*2
    for stat in YEM::STATUS::SHOWN_STATS
      icon = Icon.stat(@actor, stat)
      case stat
      when :hp
        name = Vocab.hp
        stat = @actor.maxhp
      when :mp
        name = Vocab.mp
        stat = @actor.maxmp
      when :atk
        name = Vocab.atk
        stat = @actor.atk
      when :def
        name = Vocab.def
        stat = @actor.def
      when :spi
        name = Vocab.spi
        stat = @actor.spi
      when :res
        next unless $imported["RES Stat"]
        name = Vocab.res
        stat = @actor.res
      when :dex
        next unless $imported["DEX Stat"]
        name = Vocab.dex
        stat = @actor.dex
      when :agi
        name = Vocab.agi
        stat = @actor.agi
      when :hit
        name = Vocab.hit
        stat = @actor.hit
        stat = sprintf("%d%%", stat)
      when :eva
        name = Vocab.eva
        stat = @actor.eva
        stat = sprintf("%d%%", stat)
      when :cri
        name = Vocab.cri
        stat = @actor.cri
        stat = sprintf("%d%%", stat)
      when :odds
        name = Vocab.odds
        stat = @actor.odds
      else; next
      end
      draw_icon(icon, dx+24, dy)
      self.contents.font.color = system_color
      self.contents.draw_text(dx+48, dy, 48, WLH, name)
      self.contents.font.color = normal_color
      self.contents.draw_text(dx+96, dy, 84, WLH, stat, 2)
      dy += WLH
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_exp_info
  #--------------------------------------------------------------------------
  def draw_exp_info(dx, dy)
    s1 = @actor.exp_s
    s2 = @actor.next_rest_exp_s
    s_next = sprintf(Vocab::ExpNext, Vocab::level)
    self.contents.font.color = system_color
    self.contents.draw_text(dx, dy + WLH * 0, 180, WLH, Vocab::ExpTotal)
    self.contents.draw_text(dx, dy + WLH * 2, 180, WLH, s_next)
    self.contents.font.color = normal_color
    self.contents.draw_text(dx, dy + WLH * 1, 180, WLH, s1, 2)
    self.contents.draw_text(dx, dy + WLH * 3, 180, WLH, s2, 2)
  end
  
  #--------------------------------------------------------------------------
  # draw_equipments
  #--------------------------------------------------------------------------
  def draw_equipments(dx, dy)
    self.contents.font.color = system_color
    self.contents.draw_text(dx, dy, 120, WLH, YEM::STATUS::EQUIPMENT)
    maximum = $imported["EquipmentOverhaul"] ? 4+@actor.extra_armor_number : 4
    if maximum > 5
      dx += 24
      fx = dx
      dy += WLH
      for equip in @actor.equips
        draw_icon(equip.icon_index, dx, dy) unless equip == nil
        dx += 24
        next unless dx >= fx + 24 * 5
        dx = fx
        dy += WLH
      end
    else
      for i in 0..4
        draw_item_name(@actor.equips[i], dx, dy + WLH * (i + 1))
      end
    end
  end
  
end # Window_Status_General

#===============================================================================
# Window_Status_Booster
#===============================================================================

class Window_Status_Booster < Window_Selectable
  
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(actor, help_window)
    @actor = actor
    @help_window = help_window
    dy = @help_window.y + @help_window.height
    super(0, dy, Graphics.width - 240, Graphics.height - dy)
    self.active = false
    self.index = 0
    refresh
  end
  
  #--------------------------------------------------------------------------
  # actor=
  #--------------------------------------------------------------------------
  def actor=(new_actor)
    @actor = new_actor
    refresh
  end
  
  #--------------------------------------------------------------------------
  # item
  #--------------------------------------------------------------------------
  def item; return @data[self.index]; end
  
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    @data = []
    if YEM::STATUS::SHOW_ALL_BOOSTS
      @data = $game_temp.booster_items.clone
    else
      for item in $game_temp.booster_items
        next if item == nil
        next unless $game_party.item_number(item) > 0
        @data.push(item)
      end
    end
    @item_max = @data.size
    self.index = [[self.index, @item_max-1].min, 0].max
    create_contents
    for i in 0...@item_max; draw_item(i); end
  end
  
  #--------------------------------------------------------------------------
  # draw_item
  #--------------------------------------------------------------------------
  def draw_item(index)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    item = @data[index]
    return if item == nil
    enabled = enable?(item)
    draw_obj_name(item, rect.clone, enabled)
    draw_obj_charges(item, rect.clone, enabled)
    draw_obj_total(item, rect.clone, enabled)
  end
  
  #--------------------------------------------------------------------------
  # enable?
  #--------------------------------------------------------------------------
  def enable?(item)
    return false if item == nil
    return false if $game_party.item_number(item) <= 0
    clone = @actor.clone
    clone.item_growth_effect(clone, item)
    for key in item.stat_growth
      case key[0]
      when :hp
        return true if clone.maxhp != @actor.maxhp
      when :mp
        return true if clone.maxmp != @actor.maxmp
      when :atk
        return true if clone.atk != @actor.atk
      when :def
        return true if clone.def != @actor.def
      when :spi
        return true if clone.spi != @actor.spi
      when :res
        next unless $imported["RES Stat"]
        return true if clone.res != @actor.res
      when :dex
        next unless $imported["DEX Stat"]
        return true if clone.dex != @actor.dex
      when :agi
        return true if clone.agi != @actor.agi
      else; next
      end
    end
    return false
  end
  
  #--------------------------------------------------------------------------
  # new method: draw_obj_name
  #--------------------------------------------------------------------------
  def draw_obj_name(obj, rect, enabled)
    draw_icon(obj.icon_index, rect.x, rect.y, enabled)
    self.contents.font.size = Font.default_size
    self.contents.font.color = normal_color
    self.contents.font.color.alpha = enabled ? 255 : 128
    rect.width -= 48
    self.contents.draw_text(rect.x+24, rect.y, rect.width-24, WLH, obj.name)
  end
  
  #--------------------------------------------------------------------------
  # new method: draw_obj_charges
  #--------------------------------------------------------------------------
  def draw_obj_charges(obj, rect, enabled)
    return unless $imported["BattleEngineMelody"]
    return unless obj.is_a?(RPG::Item)
    return unless obj.consumable
    return if obj.charges <= 1
    $game_party.item_charges = {} if $game_party.item_charges == nil
    $game_party.item_charges[obj.id] = obj.charges if
      $game_party.item_charges[obj.id] == nil
    charges = $game_party.item_charges[obj.id]
    dx = rect.x; dy = rect.y + WLH/3
    self.contents.font.size = YEM::BATTLE_ENGINE::ITEM_SETTINGS[:charge]
    self.contents.font.color = normal_color
    self.contents.font.color.alpha = enabled ? 255 : 128
    self.contents.draw_text(dx, dy, 24, WLH * 2/3, charges, 2)
    self.contents.font.size = Font.default_size
  end
  
  #--------------------------------------------------------------------------
  # new method: draw_obj_total
  #--------------------------------------------------------------------------
  def draw_obj_total(obj, rect, enabled)
    if $imported["BattleEngineMelody"]
      hash = YEM::BATTLE_ENGINE::ITEM_SETTINGS
    else
      hash ={ :text => ":%d", :size => Font.default_size, :colour => 0 }
    end
    number = $game_party.item_number(obj)
    dx = rect.x + rect.width - 36; dy = rect.y; dw = 32
    text = sprintf(hash[:text], number)
    self.contents.font.size = hash[:size]
    self.contents.font.color = text_color(hash[:colour])
    self.contents.font.color.alpha = enabled ? 255 : 128
    self.contents.draw_text(dx, dy, dw, WLH, text, 2)
  end
  
  #--------------------------------------------------------------------------
  # update_help
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(item == nil ? "" : item.description)
  end
  
end # Window_Status_Booster

#===============================================================================
# Window_Status_Elements
#===============================================================================

class Window_Status_Elements < Window_Status_Booster
  
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    @data = []
    if YEM::STATUS::SHOW_ALL_BOOSTS
      @data = $game_temp.element_growth_items.clone
    else
      for item in $game_temp.element_growth_items
        next if item == nil
        next unless $game_party.item_number(item) > 0
        @data.push(item)
      end
    end
    @item_max = @data.size
    self.index = [[self.index, @item_max-1].min, 0].max
    create_contents
    for i in 0...@item_max; draw_item(i); end
  end
  
  #--------------------------------------------------------------------------
  # enable?
  #--------------------------------------------------------------------------
  def enable?(item)
    return false if item == nil
    return false if $game_party.item_number(item) <= 0
    @actor.create_affinity_bonus
    former_rates = @actor.bonus_element_affinity.clone
    clone = @actor.clone
    clone.item_growth_effect(clone, item)
    @actor.bonus_element_affinity = former_rates
    for key in item.element_growth
      id = key[0]
      return true if @actor.element_rate(id) != clone.element_rate(id)
    end
    return false
  end
  
end # Window_Status_Elements

#===============================================================================
# Window_Status_States
#===============================================================================

class Window_Status_States < Window_Status_Booster
  
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    @data = []
    if YEM::STATUS::SHOW_ALL_BOOSTS
      @data = $game_temp.state_growth_items.clone
    else
      for item in $game_temp.state_growth_items
        next if item == nil
        next unless $game_party.item_number(item) > 0
        @data.push(item)
      end
    end
    @item_max = @data.size
    self.index = [[self.index, @item_max-1].min, 0].max
    create_contents
    for i in 0...@item_max; draw_item(i); end
  end
  
  #--------------------------------------------------------------------------
  # enable?
  #--------------------------------------------------------------------------
  def enable?(item)
    return false if item == nil
    return false if $game_party.item_number(item) <= 0
    @actor.create_affinity_bonus
    former_rates = @actor.bonus_state_affinity.clone
    clone = @actor.clone
    clone.item_growth_effect(clone, item)
    @actor.bonus_state_affinity = former_rates
    for key in item.state_growth
      id = key[0]
      return true if @actor.state_probability(id) != clone.state_probability(id)
    end
    return false
  end
  
end # Window_Status_States

#===============================================================================
# Window_Status_Booster_Stats
#===============================================================================

class Window_Booster_Stats < Window_Base
  
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(actor, main_window)
    @actor = actor
    @main_window = main_window
    dx = @main_window.x + @main_window.width
    dy = @main_window.y
    super(dx, dy, Graphics.width - dx, Graphics.height - dy)
    self.contents.font.size = YEM::STATUS::BOOSTER_FONT_SIZE
    refresh
  end
  
  #--------------------------------------------------------------------------
  # actor=
  #--------------------------------------------------------------------------
  def actor=(new_actor)
    @actor = new_actor
    refresh
  end
  
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    @item = @main_window.item
    draw_parameters
  end
  
  #--------------------------------------------------------------------------
  # draw_parameters
  #--------------------------------------------------------------------------
  def draw_parameters
    dx = 0; dy = 0; arrow = YEM::STATUS::ARROW
    clone = @actor.clone
    if @item != nil and $game_party.has_item?(@item)
      clone.item_growth_effect(clone, @item)
    end
    for stat in YEM::STATUS::SHOWN_STATS
      icon = Icon.stat(@actor, stat)
      case stat
      when :hp
        name = Vocab.hp
        stat1 = @actor.maxhp
        stat2 = clone.maxhp
      when :mp
        name = Vocab.mp
        stat1 = @actor.maxmp
        stat2 = clone.maxmp
      when :atk
        name = Vocab.atk
        stat1 = @actor.atk
        stat2 = clone.atk
      when :def
        name = Vocab.def
        stat1 = @actor.def
        stat2 = clone.def
      when :spi
        name = Vocab.spi
        stat1 = @actor.spi
        stat2 = clone.spi
      when :res
        next unless $imported["RES Stat"]
        name = Vocab.res
        stat1 = @actor.res
        stat2 = clone.res
      when :dex
        next unless $imported["DEX Stat"]
        name = Vocab.dex
        stat1 = @actor.dex
        stat2 = clone.dex
      when :agi
        name = Vocab.agi
        stat1 = @actor.agi
        stat2 = clone.agi
      else; next
      end
      draw_icon(icon, dx, dy); dx += 24
      self.contents.font.color = system_color
      self.contents.draw_text(dx, dy, 60, WLH, name, 0); dx += 60
      self.contents.font.color = normal_color
      self.contents.draw_text(dx, dy, 45, WLH, stat1, 2); dx += 45
      self.contents.font.color = system_color
      self.contents.font.size = Font.default_size
      self.contents.draw_text(dx, dy, 30, WLH, arrow, 1); dx += 30
      self.contents.font.size = YEM::STATUS::BOOSTER_FONT_SIZE
      if @item != nil
        if stat2 > stat1
          self.contents.font.color = power_up_color
        elsif stat2 < stat1
          self.contents.font.color = power_down_color
        else
          self.contents.font.color = normal_color
        end
        self.contents.draw_text(dx, dy, 45, WLH, stat2, 2)
      end
      dx = 0
      dy += WLH
    end
  end
  
end # Window_Booster_Stats

#===============================================================================
# Window_Elements_Stats
#===============================================================================

class Window_Elements_Stats < Window_Booster_Stats
  
  #--------------------------------------------------------------------------
  # draw_parameters
  #--------------------------------------------------------------------------
  def draw_parameters
    dx = 0; dy = 0; arrow = YEM::STATUS::ARROW
    @actor.create_affinity_bonus
    former_rates = @actor.bonus_element_affinity.clone
    clone = @actor.clone
    if @item != nil and $game_party.has_item?(@item)
      clone.item_growth_effect(clone, @item)
    end
    @actor.bonus_element_affinity = former_rates
    for element_id in YEM::STATUS::SHOWN_ELEMENTS
      icon = Icon.element(element_id)
      name = $data_system.elements[element_id]
      stat1 = @actor.element_rate(element_id)
      stat2 = clone.element_rate(element_id)
      text1 = sprintf("%s%%", stat1)
      text2 = sprintf("%s%%", stat2)
      draw_icon(icon, dx, dy); dx += 24
      self.contents.font.color = system_color
      self.contents.draw_text(dx, dy, 60, WLH, name, 0); dx += 60
      self.contents.font.color = normal_color
      self.contents.draw_text(dx, dy, 45, WLH, text1, 2); dx += 45
      self.contents.font.color = system_color
      self.contents.font.size = Font.default_size
      self.contents.draw_text(dx, dy, 30, WLH, arrow, 1); dx += 30
      self.contents.font.size = YEM::STATUS::BOOSTER_FONT_SIZE
      if @item != nil
        if stat2 < stat1
          self.contents.font.color = power_up_color
        elsif stat2 > stat1
          self.contents.font.color = power_down_color
        else
          self.contents.font.color = normal_color
        end
        self.contents.draw_text(dx, dy, 45, WLH, text2, 2)
      end
      dx = 0
      dy += WLH
    end
  end
  
end # Window_Elements_Stats

#===============================================================================
# Window_States_Stats
#===============================================================================

class Window_States_Stats < Window_Booster_Stats
  
  #--------------------------------------------------------------------------
  # draw_parameters
  #--------------------------------------------------------------------------
  def draw_parameters
    dx = 0; dy = 0; arrow = YEM::STATUS::ARROW
    @actor.create_affinity_bonus
    former_rates = @actor.bonus_state_affinity.clone
    clone = @actor.clone
    if @item != nil and $game_party.has_item?(@item)
      clone.item_growth_effect(clone, @item)
    end
    @actor.bonus_state_affinity = former_rates
    for state_id in YEM::STATUS::SHOWN_STATES
      state = $data_states[state_id]
      next if state == nil
      icon = state.icon_index
      name = state.name
      stat1 = @actor.state_probability(state_id)
      stat2 = clone.state_probability(state_id)
      text1 = sprintf("%s%%", stat1)
      text2 = sprintf("%s%%", stat2)
      draw_icon(icon, dx, dy); dx += 24
      self.contents.font.color = system_color
      self.contents.draw_text(dx, dy, 60, WLH, name, 0); dx += 60
      self.contents.font.color = normal_color
      self.contents.draw_text(dx, dy, 45, WLH, text1, 2); dx += 45
      self.contents.font.color = system_color
      self.contents.font.size = Font.default_size
      self.contents.draw_text(dx, dy, 30, WLH, arrow, 1); dx += 30
      self.contents.font.size = YEM::STATUS::BOOSTER_FONT_SIZE
      if @item != nil
        if stat2 < stat1
          self.contents.font.color = power_up_color
        elsif stat2 > stat1
          self.contents.font.color = power_down_color
        else
          self.contents.font.color = normal_color
        end
        self.contents.draw_text(dx, dy, 45, WLH, text2, 2)
      end
      dx = 0
      dy += WLH
    end
  end
  
end # Window_States_Stats

#===============================================================================
# Scene_Status
#===============================================================================

class Scene_Status < Scene_Base

  #--------------------------------------------------------------------------
  # overwrite method: start
  #--------------------------------------------------------------------------
  def start
    super
    create_menu_background
    @actor = $game_party.members[@actor_index]
    @status_window = Window_Actor_Status.new(@actor)
    @help_window = Window_Help.new
    @help_window.y = @status_window.height
    create_command_window
  end
  
  #--------------------------------------------------------------------------
  # overwrite method: terminate
  #--------------------------------------------------------------------------
  def terminate
    super
    dispose_menu_background
    @command_window.dispose
    @status_window.dispose
    @help_window.dispose
    for window in @windows; window.dispose unless window.disposed?; end
  end
  
  #--------------------------------------------------------------------------
  # new method: create_command_window
  #--------------------------------------------------------------------------
  def create_command_window
    @data = []
    commands = []
    @windows = []
    for command in YEM::STATUS::COMMANDS
      case command
      when :general
        @general_window = Window_Status_General.new(@actor)
        @windows.push(@general_window)
      when :boosters
        @boosters_window = Window_Status_Booster.new(@actor, @help_window)
        @boosters_stats = Window_Booster_Stats.new(@actor, @boosters_window)
        @windows.push(@boosters_window)
        @windows.push(@boosters_stats)
      when :elements
        next unless $imported["BattleEngineMelody"]
        @elements_window = Window_Status_Elements.new(@actor, @help_window)
        @elements_stats = Window_Elements_Stats.new(@actor, @elements_window)
        @windows.push(@elements_window)
        @windows.push(@elements_stats)
      when :states
        next unless $imported["BattleEngineMelody"]
        @states_window = Window_Status_States.new(@actor, @help_window)
        @states_stats = Window_States_Stats.new(@actor, @states_window)
        @windows.push(@states_window)
        @windows.push(@states_stats)
      else; next
      end
      @data.push(command)
      commands.push(YEM::STATUS::COMMAND_VOCAB[command])
    end
    @command_window = Window_Command_Centered.new(160, commands)
    @command_window.height = 128
    @command_window.active = true
    #---
    if $game_temp.last_status_index != nil
      @command_window.oy = $game_temp.status_oy
      @command_window.index = $game_temp.last_status_index
    end
    #---
    update_visible_windows
  end
  
  #--------------------------------------------------------------------------
  # overwrite method: next_actor
  #--------------------------------------------------------------------------
  def next_actor
    @actor_index += 1
    @actor_index %= $game_party.members.size
    set_new_actor
  end
  
  #--------------------------------------------------------------------------
  # overwrite method: prev_actor
  #--------------------------------------------------------------------------
  def prev_actor
    @actor_index += $game_party.members.size - 1
    @actor_index %= $game_party.members.size
    set_new_actor
  end
  
  #--------------------------------------------------------------------------
  # new method: set_new_actor
  #--------------------------------------------------------------------------
  def set_new_actor
    $game_party.last_actor_index = @actor_index
    @actor = $game_party.members[@actor_index]
    @status_window.actor = @actor
    for window in @windows; window.actor = @actor; end
  end
  
  #--------------------------------------------------------------------------
  # overwrite method: update
  #--------------------------------------------------------------------------
  def update
    super
    update_menu_background
    if @command_window.active
      update_command_window
    elsif @boosters_window != nil and @boosters_window.active
      update_boosters_window
    elsif @elements_window != nil and @elements_window.active
      update_elements_window
    elsif @states_window != nil and @states_window.active
      update_states_window
    end
  end
  
  #--------------------------------------------------------------------------
  # new method: update_command_window
  #--------------------------------------------------------------------------
  def update_command_window
    @command_window.update
    if $game_temp.last_status_index != @command_window.index
      $game_temp.last_status_index = @command_window.index
      $game_temp.status_oy = @command_window.oy
      update_visible_windows
    end
    if Input.trigger?(Input::B)
      Sound.play_cancel
      return_scene
      $game_temp.last_status_index = nil
      $game_temp.status_oy = nil
    elsif Input.repeat?(Input::LEFT)
      Sound.play_cursor
      prev_actor
    elsif Input.repeat?(Input::RIGHT)
      Sound.play_cursor
      next_actor
    elsif Input.trigger?(Input::C)
      case @data[@command_window.index]
      when :boosters
        Sound.play_decision
        @boosters_window.active = true
        @command_window.active = false
      when :elements
        Sound.play_decision
        @elements_window.active = true
        @command_window.active = false
      when :states
        Sound.play_decision
        @states_window.active = true
        @command_window.active = false
      end
    end
  end
  
  #--------------------------------------------------------------------------
  # new method: update_visible_windows
  #--------------------------------------------------------------------------
  def update_visible_windows
    @help_window.y = Graphics.height * 8
    for window in @windows; window.y = Graphics.height * 8; end
    case @data[@command_window.index]
    when :general
      @general_window.y = @command_window.height
    when :boosters
      @help_window.y = @command_window.height
      @boosters_window.y = @help_window.y + @help_window.height
      @boosters_stats.y = @help_window.y + @help_window.height
      @boosters_window.update_help
    when :elements
      @help_window.y = @command_window.height
      @elements_window.y = @help_window.y + @help_window.height
      @elements_stats.y = @help_window.y + @help_window.height
      @elements_window.update_help
    when :states
      @help_window.y = @command_window.height
      @states_window.y = @help_window.y + @help_window.height
      @states_stats.y = @help_window.y + @help_window.height
      @states_window.update_help
    end
  end
  
  #--------------------------------------------------------------------------
  # new method: update_boosters_window
  #--------------------------------------------------------------------------
  def update_boosters_window
    @boosters_window.update
    if @last_booster_index != @boosters_window.index
      @last_booster_index = @boosters_window.index
      @boosters_stats.refresh
    end
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @boosters_window.active = false
      @command_window.active = true
      @general_window.refresh if @general_window != nil
    elsif Input.repeat?(Input::LEFT)
      Sound.play_cursor
      prev_actor
    elsif Input.repeat?(Input::RIGHT)
      Sound.play_cursor
      next_actor
    #--- Debug Commands ---
    elsif $TEST and Input.repeat?(Input::F8)
      Sound.play_equip
      for item in $game_temp.booster_items
        next if item == nil
        amount = Input.press?(Input::SHIFT) ? 10 : 1 + rand(3)
        $game_party.gain_item(item, amount)
      end
      @boosters_window.refresh
    elsif $TEST and Input.repeat?(Input::F7)
      Sound.play_equip
      for item in $game_temp.booster_items
        next if item == nil
        amount = Input.press?(Input::SHIFT) ? 10 : 1 + rand(3)
        $game_party.lose_item(item, amount)
      end
      @boosters_window.refresh
    elsif $TEST and Input.repeat?(Input::F6)
      item = @boosters_window.item
      return if item == nil
      Sound.play_equip
      amount = Input.press?(Input::SHIFT) ? 10 : 1 + rand(3)
      $game_party.gain_item(item, amount)
      @boosters_window.draw_item(@boosters_window.index)
    elsif $TEST and Input.repeat?(Input::F5)
      item = @boosters_window.item
      return if item == nil
      Sound.play_equip
      amount = Input.press?(Input::SHIFT) ? 10 : 1 + rand(3)
      $game_party.lose_item(item, amount)
      @boosters_window.draw_item(@boosters_window.index)
    #--- Debug Commands ---
    elsif Input.repeat?(Input::C)
      item = @boosters_window.item
      if @boosters_window.enable?(item)
        Sound.play_use_item
        @actor.item_growth_effect(@actor, item)
        $game_party.consume_item(item)
        @boosters_window.draw_item(@boosters_window.index)
        @boosters_stats.refresh
        if item.stat_growth.include?(:hp) or item.stat_growth.include?(:mp)
          @status_window.refresh
        end
      elsif Input.trigger?(Input::C)
        Sound.play_buzzer
      end
    end
  end
  
  #--------------------------------------------------------------------------
  # new method: update_elements_window
  #--------------------------------------------------------------------------
  def update_elements_window
    @elements_window.update
    if @last_elements_index != @elements_window.index
      @last_elements_index = @elements_window.index
      @elements_stats.refresh
    end
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @elements_window.active = false
      @command_window.active = true
      @general_window.refresh if @general_window != nil
    elsif Input.repeat?(Input::LEFT)
      Sound.play_cursor
      prev_actor
    elsif Input.repeat?(Input::RIGHT)
      Sound.play_cursor
      next_actor
    #--- Debug Commands ---
    elsif $TEST and Input.repeat?(Input::F8)
      Sound.play_equip
      for item in $game_temp.element_growth_items
        next if item == nil
        amount = Input.press?(Input::SHIFT) ? 10 : 1 + rand(3)
        $game_party.gain_item(item, amount)
      end
      @elements_window.refresh
    elsif $TEST and Input.repeat?(Input::F7)
      Sound.play_equip
      for item in $game_temp.element_growth_items
        next if item == nil
        amount = Input.press?(Input::SHIFT) ? 10 : 1 + rand(3)
        $game_party.lose_item(item, amount)
      end
      @elements_window.refresh
    elsif $TEST and Input.repeat?(Input::F6)
      item = @elements_window.item
      return if item == nil
      Sound.play_equip
      amount = Input.press?(Input::SHIFT) ? 10 : 1 + rand(3)
      $game_party.gain_item(item, amount)
      @elements_window.draw_item(@elements_window.index)
    elsif $TEST and Input.repeat?(Input::F5)
      item = @elements_window.item
      return if item == nil
      Sound.play_equip
      amount = Input.press?(Input::SHIFT) ? 10 : 1 + rand(3)
      $game_party.lose_item(item, amount)
      @elements_window.draw_item(@elements_window.index)
    #--- Debug Commands ---
    elsif Input.repeat?(Input::C)
      item = @elements_window.item
      if @elements_window.enable?(item)
        Sound.play_use_item
        @actor.item_growth_effect(@actor, item)
        $game_party.consume_item(item)
        @elements_window.draw_item(@elements_window.index)
        @elements_stats.refresh
      elsif Input.trigger?(Input::C)
        Sound.play_buzzer
      end
    end
  end
  
  #--------------------------------------------------------------------------
  # new method: update_states_window
  #--------------------------------------------------------------------------
  def update_states_window
    @states_window.update
    if @last_states_index != @states_window.index
      @last_states_index = @states_window.index
      @states_stats.refresh
    end
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @states_window.active = false
      @command_window.active = true
      @general_window.refresh if @general_window != nil
    elsif Input.repeat?(Input::LEFT)
      Sound.play_cursor
      prev_actor
    elsif Input.repeat?(Input::RIGHT)
      Sound.play_cursor
      next_actor
    #--- Debug Commands ---
    elsif $TEST and Input.repeat?(Input::F8)
      Sound.play_equip
      for item in $game_temp.state_growth_items
        next if item == nil
        amount = Input.press?(Input::SHIFT) ? 10 : 1 + rand(3)
        $game_party.gain_item(item, amount)
      end
      @states_window.refresh
    elsif $TEST and Input.repeat?(Input::F7)
      Sound.play_equip
      for item in $game_temp.state_growth_items
        next if item == nil
        amount = Input.press?(Input::SHIFT) ? 10 : 1 + rand(3)
        $game_party.lose_item(item, amount)
      end
      @states_window.refresh
    elsif $TEST and Input.repeat?(Input::F6)
      item = @states_window.item
      return if item == nil
      Sound.play_equip
      amount = Input.press?(Input::SHIFT) ? 10 : 1 + rand(3)
      $game_party.gain_item(item, amount)
      @states_window.draw_item(@states_window.index)
    elsif $TEST and Input.repeat?(Input::F5)
      item = @states_window.item
      return if item == nil
      Sound.play_equip
      amount = Input.press?(Input::SHIFT) ? 10 : 1 + rand(3)
      $game_party.lose_item(item, amount)
      @states_window.draw_item(@states_window.index)
    #--- Debug Commands ---
    elsif Input.repeat?(Input::C)
      item = @states_window.item
      if @states_window.enable?(item)
        Sound.play_use_item
        @actor.item_growth_effect(@actor, item)
        $game_party.consume_item(item)
        @states_window.draw_item(@states_window.index)
        @states_stats.refresh
      elsif Input.trigger?(Input::C)
        Sound.play_buzzer
      end
    end
  end
  
end # Scene_Status

#===============================================================================
# 
# END OF FILE
# 
#===============================================================================