#==============================================================================
# ** TDS Movement Code
#    Ver: 1.0
#------------------------------------------------------------------------------
#  * Description:
#  This script adds more commands to simplify event movement.
#------------------------------------------------------------------------------
#  * Features: 
#  Move by amount. (Example: Move UP x 10 times)
#  Fading to opaicity.
#  Show balloon.
#------------------------------------------------------------------------------
#  * Instructions:
#  All of these script call commands are meant to be called from within the 
#  "Move Route" event command.
#
#  To move a character by an amount of times use this in a script call:
#
#    move_times(code, times)
#    
#    code = Movement code. You can look up movement code in the "Game_Character"
#           class. You can also use the preset symbols :UP, :DOWN, :LEFT, :RIGHT.
#
#    times = amount of times to execument movement code.
#
#    Example:
#    
#      move_times(:UP, 5)
#      move_times(4, 5)
#
#    They would both do the same thing since the movement code for up is 4.
#
#  To fade a character opacity to a value by a duration use this in a script
#  call:
#
#    fade_opacity_to(opacity, duration) 
#
#    opacity = opacity value to fade to
#    duration = duration for fade
#
#    Example:
#
#      fade_opacity_to(0, 60) 
#
#  To show a baloon icon on a character, use this in a script call:
#
#    show_balloon_icon(code, wait = false) 
#
#    code = Balloon code. This is the index of the balloon from 1 to 10. You
#           can also use the name of the balloon as a symbol.
#
#    wait = Wait until the balloon is done displaying before continuing move 
#           route.
#
#    Example:
#
#      show_balloon_icon(1) 
#      show_balloon_icon(:Exclamation)
#------------------------------------------------------------------------------
#  * Notes:
#  none.
#------------------------------------------------------------------------------
# WARNING:
#
# Do not release, distribute or change my work without my expressed written 
# consent, doing so violates the terms of use of this work.
#
# If you really want to share my work please just post a link to the original
# site.
#
# * Not Knowing English or understanding these terms will not excuse you in any
#   way from the consequenses.
#------------------------------------------------------------------------------
# * Import to Global Hash
#==============================================================================
($imported ||= {})[:TDS_Movement_Code] = true

#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
#  A character class with mainly movement route and other such processing
# added. It is used as a super class of Game_Player, Game_Follower,
# GameVehicle, and Game_Event.
#==============================================================================

class Game_Character < Game_CharacterBase
  #--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  # Move Commands Symbol Code 
  MOVE_SYMBOL_CODE = {
  :UP    => ROUTE_MOVE_UP,
  :DOWN  => ROUTE_MOVE_DOWN,
  :LEFT  => ROUTE_MOVE_LEFT,
  :RIGHT => ROUTE_MOVE_RIGHT,
  :FORWARD => ROUTE_MOVE_FORWARD,
  :BACKWARD => ROUTE_MOVE_BACKWARD,
  }
  # Balloon Symbol ID
  BALLOON_SYMBOL_ID = {
  :Exclamation => 1, :Question => 2, :Music_Note => 3, :Heart => 4, :Anger => 5,
  :Sweat => 6, :Cobweb => 7, :Silence => 8, :Light_Bulb => 9, :Zzz => 10
  }
  #--------------------------------------------------------------------------
  # * Fade Opacity to Value
  #     opacity  : target opacity value
  #     duration : fade duration
  #--------------------------------------------------------------------------
  def fade_opacity_to(opacity, duration) 
    # Get Step Opacity
    step = (opacity - @opacity).to_f / duration
    # Get Change Opacity
    c_opacity = @opacity    
    duration.times {|i| 
    # Add Opacity Change Move Command
    @move_route.list.insert(@move_route_index + i + 1, RPG::MoveCommand.new(ROUTE_CHANGE_OPACITY, [c_opacity]))
    # Set Change Opacity
    c_opacity += step    
    }
  end
  #--------------------------------------------------------------------------
  # * Show Balloon Icon
  #     code : balloon id (Index or Symbol)
  #     wait : wait until balloon is done displaying flag
  #--------------------------------------------------------------------------
  def show_balloon_icon(code, wait = false) 
    # Convert Code From Symbol to Integer if applicable
    code = BALLOON_SYMBOL_ID[code] if code.is_a?(Symbol)    
    # Set Balloon ID
    @balloon_id = code
    # Set Wait Count if Wait flag is true
    @wait_count = 8 * 8 + 12 if wait
  end
  #--------------------------------------------------------------------------
  # * Move by Times
  #    code  : move code
  #    times : times to move using code
  #--------------------------------------------------------------------------
  def move_times(code, times)
    # Convert Code From Symbol to Integer if applicable
    code = MOVE_SYMBOL_CODE[code] if code.is_a?(Symbol)
    # Add Move Route Code
    times.times {|i| @move_route.list.insert(@move_route_index + i + 1, RPG::MoveCommand.new(code))}
  end
end