#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Easy Overdrive System by Blizzard
# Version: 2.2
# Type: Limit Break / Overdrive System
# Date 2.0b: 7.3.2009
# Date 2.01b: 8.3.2009
# Date 2.1b: 26.7.2009
# Date 2.2: 11.1.2011
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#   
#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# #  
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# #  
# #  You are free:
# #  
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# #  
# #  Under the following conditions:
# #  
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# #  
# #  Noncommercial. You may not use this work for commercial purposes.
# #  
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# #  
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# #  
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# #  
# #  - Nothing in this license impairs or restricts the author's moral rights.
# #  
# #----------------------------------------------------------------------------
# 
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# 
# Compatibility:
# 
#   99% compatible with SDK 1.x. 90% compatible with SDK 2.x. WILL corrupt your
#   old savegames. Can cause incompatibilty issues with following scripts
#   and/or systems:
#   - exotic CBS-es
#   - other Limit Break / Overdrive systems
#   
#   Not compatible with:
#   - Chaos Rage Limit System
#   
#   
# Features:
# 
#   - extremely simple Overdrive System
#   - using Blizzard gradient styler 4.x with 7 different styles
#   - compatible with Tons of Add-ons
#   - compatible with Blizz-ABS
#   - compatible with RTAB
#   - maximum compatibility with other scripts
#   - moving Overdrive command in defineable color and a faster animated cursor
#   - actors learn Overdrive skills seperately
# 
# new in v2.01b:
#   - fixed an issue with RTAB
# 
# new in v2.1b:
#   - fixed a bug with Blizz-ABS
#   - now compatible with HP Consuming Skills from Tons of Add-ons
# 
# new in v2.2:
#   - now compatible with Blizz-ABS 2.82
# 
# 
# Explanation:
# 
#   This script allows actors to use an alternative set of skills which
#   consumes the OD attribute. OD is gained when losing HP.
#   
#   
# Configuration:
# 
#   OVERDRIVE_RATE         - set the filling rate of the SR, 1000 is standard,
#                            500 is 2 times slower and 2000 would be 2 times
#                            faster
#   DRAW_OVERDRIVE         - set this value to false if you don't want OD%
#                            display at all
#   DRAW_OVERDRIVE_BAR     - set this value to false if you don't want an OD
#                            bar at all (does not work if you don't have a
#                            script for HP/SP/EXP bars)
#   OVERDRIVE_ENABLED      - add any actor ID of actors who actually have the
#                            OD attribute drawn in battle
#   OVERDRIVE_NAME         - this is the name of the OD %
#   OVERDRIVE_COMMAND_NAME - this is the name of the Overdrive Command
#   OVERDRIVE_COLOR        - set the values in the () to numbers between 0-255,
#                            also note that they determine the color ammount in
#                            the color like this example:
#                            (RED, GREEN, BLUE, ALPHA) - note: alpha = opacity
#   RTAB_ACTIVE            - set to true if using RTAB
#   
# Additional info:
# 
#   If you want to change the value of the OD % ingame use the "Call script"
#   event command and use this syntax:
# 
#     $game_actors[X].overdrive = Y
# 
#   X - ID of the hero in the database
#   Y - new value of the OD
# 
#   You can also use another syntax:
# 
#     $game_party.actors[X].overdrive = Y
# 
#   X - position of the hero in the party
#   Y - new value of the OD
# 
#   Note that X starts from 0 and NOT 1. The ammount is shown as 100,0%, this
#   is 1000 OD. i.e. 59,1% would be 591 OD.
# 
#   To add a new Overdrive to a characer use the "Call Script" event command
#   and use following syntax:
# 
#     $game_actors[ID].learn_overdrive(CD)
# 
#   To remove a Overdrive from a character use this syntax:
# 
#     $game_actors[ID].forget_overdrive(CD)
# 
#   ID - ID of the actor in the database
#   CD - ID of the Overdrive skill in the database
# 
# Note:
# 
#   Using Overdrive skills as normal skills will work without problems. Though,
#   it is better you create a different skill if you want to use it as
#   Overdrive. BUT IF YOU ARE USING BLIZZ-ABS, YOU SHOULD NOT DO THIS!!!
#   Create new skills for Overdrive Skills!
# 
# 
# If you find any bugs, please report them here:
# http://forum.chaos-project.com
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

$easy_overdrive = 2.2

#==============================================================================
# module BlizzCFG
#==============================================================================

module BlizzCFG
  
  OVERDRIVE_KIND = 11
  
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# START Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  
  OVERDRIVE_RATE = 1000
  DRAW_OVERDRIVE = true
  DRAW_OVERDRIVE_BAR = true
  OVERDRIVE_ENABLED = [1, 2, 3, 4, 5, 6, 7, 8]
  OVERDRIVE_USERS = [1, 2, 3, 4, 5, 6, 7, 8]
  OVERDRIVE_NAME = 'OD'
  OVERDRIVE_COMMAND_NAME = 'Overdrive'
  OVERDRIVE_COLOR = Color.new(0, 128, 255)
  RTAB_ACTIVE = false
  
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# END Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  
end

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

class Game_Battler
  
  alias hp_is_equal_to_eos_later hp=
  def hp=(val)
    last_hp = self.hp
    hp_is_equal_to_eos_later(val)
    if self.is_a?(Game_Actor)
      if self.dead?
        self.overdrive = 0
      elsif self.hp < last_hp
        self.overdrive += (last_hp - self.hp) * BlizzCFG::OVERDRIVE_RATE /
            [last_hp, self.hp].min
      end
    end
  end
  
end

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

class Game_Actor
  
  attr_reader :overdrive
  attr_reader :overdrive_skills
  
  alias setup_eos_later setup
  def setup(actor_id)
    @overdrive = 0
    @overdrive_skills = []
    setup_eos_later(actor_id)
  end
  
  def overdrive=(val)
    @overdrive = val
    @overdrive = 0 if @overdrive < 0
    @overdrive = 1000 if @overdrive > 1000
  end
  
  def learn_overdrive(skill_id)
    if skill_id > 0 && !@overdrive_skills.include?(skill_id)
      @overdrive_skills.push(skill_id)
      @overdrive_skills.sort!
    end
  end
  
  def forget_overdrive(skill_id)
    @overdrive_skills.delete(skill_id)
  end
  
  def overdrive_can_use?(id)
    return (item_req_test(id) && overdrive_left(id) != 0)
  end
  
  def overdrive_left(id)
    return -1 if $data_skills[id].sp_cost == 0
    return (self.overdrive / 10 / $data_skills[id].sp_cost)
  end
  
  def item_req_test(id)
    if $tons_version != nil && $tons_version >= 6.0 &&
        $game_system.ITEM_REQUIREMENT
      data = BlizzCFG.item_reqs(id)
      return ($game_party.item_number(data[0]) >= data[1])
    end
    return true
  end
  
  def overdrive_text
    return "#{@overdrive/10}.#{@overdrive%10}%"
  end
  
end

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

class Window_Base
  
  def draw_actor_overdrive(actor, x, y, w = 144)
    w = 120 if !$scene.is_a?(Scene_Menu) && !BlizzCFG::RTAB_ACTIVE
    self.contents.font.color = system_color
    self.contents.draw_text(x, y-16, width, 64, BlizzCFG::OVERDRIVE_NAME)
    self.contents.font.color = normal_color
    self.contents.draw_text(x, y, w, 32, actor.overdrive_text, 2)
  end
  
  def draw_actor_overdrive_with_bar(actor, x, y, w = 148)
    w -= 12
    rate = actor.overdrive.to_f / 1000
    color1 = Color.new(80, 0, 0, 192)
    color2 = Color.new(240, 0, 0, 192)
    color3 = Color.new(80, 0, 0, 192)
    if BlizzCFG::RTAB_ACTIVE
      color1.alpha = color2.alpha = 255
      draw_slant_bar(x, y + 12, actor.overdrive, 1000, w, 6, color1, color2)
    else
      self.contents.gradient_bar(x, y, w, color1, color2, color3, rate)
    end
    if $scene.is_a?(Scene_Battle)
      draw_actor_overdrive(actor, x, y, w)
    else
      draw_actor_overdrive(actor, x, y)
    end
  end
  
end

#==============================================================================
# Window_BattleStatus
#==============================================================================

class Window_BattleStatus
  
  alias refresh_eos_later refresh
  def refresh(number = 0)
    if BlizzCFG::RTAB_ACTIVE
      refresh_eos_later(number)
      return
    elsif !BlizzCFG::DRAW_OVERDRIVE
      refresh_eos_later
      return
    end
    self.contents.clear
    if $fontface != nil
      self.contents.font.name = $fontface
      self.contents.font.size = $fontsize
    elsif $defaultfonttype != nil
      self.contents.font.name = $defaultfonttype
      self.contents.font.size = $defaultfontsize
    end
    $game_party.actors.each_index {|i|
        if $tons_version != nil && $tons_version >= 4.82 &&
            $game_system.CENTER_BATTLER
          actor_x = case $game_party.actors.size
          when 1 then 4 + 240
          when 2 then 4 + 80 + i * 320
          when 3 then 4 + 80 + i * 160
          when 4 then 4 + i * 160
          end
        else
          actor_x = i * 160 + 4
        end
        draw_actor_name($game_party.actors[i], actor_x, -8)
        draw_actor_hp($game_party.actors[i], actor_x, 14, 120)
        draw_actor_sp($game_party.actors[i], actor_x, 44, 120)
        if BlizzCFG::OVERDRIVE_ENABLED.include?($game_party.actors[i].id)
          if BlizzCFG::DRAW_OVERDRIVE_BAR && $tons_version != nil &&
              $tons_version >= 4.82
            draw_actor_overdrive_with_bar($game_party.actors[i], actor_x, 74, 120)
          else
            draw_actor_overdrive($game_party.actors[i], actor_x, 74, 120)
          end
        end
        if @level_up_flags[i]
          self.contents.font.color = normal_color
          self.contents.draw_text(actor_x, 100, 120, 32, 'LEVEL UP!')
        else
          draw_actor_state($game_party.actors[i], actor_x, 100)
        end}
  end
  
end

# if using RTAB
if BlizzCFG::RTAB_ACTIVE
#==============================================================================
# Window_DetailsStatus
#==============================================================================

class Window_ActorStatus < Window_Base
  
  alias refresh_eos_later refresh
  def refresh(level_up_flags)
    refresh_eos_later(level_up_flags)
    @status_window[1].refresh($game_party.actors[@actor_num])
  end
  
end

#==============================================================================
# Window_DetailsStatus
#==============================================================================

class Window_DetailsStatus
  
  def refresh(actor, level_up_flags = false)
    self.contents.clear
    if $bstat_align == 0
      case @status_id
      when 0 then draw_actor_name(actor, 4, -8)
      when 1
        draw_actor_hp(actor, 84, -8, 80)
        draw_actor_overdrive_with_bar(actor, 266, -8, 112)
      when 2 then draw_actor_sp(actor, 180, -8, 80)
      when 3
        if level_up_flags
          self.contents.font.color = normal_color
          self.contents.draw_text(324, -8, 120, 32, 'LEVEL UP!')
        else
          draw_actor_state(actor, 324, -8)
        end
      when 4 then draw_actor_atg(actor, 488, -8, 120)
      end
    else  
      case @status_id
      when 0 then draw_actor_name(actor, 488, -8)
      when 1
        draw_actor_hp(actor, 228, -8, 80)
        draw_actor_overdrive_with_bar(actor, 420, -8, 112)
      when 2 then draw_actor_sp(actor, 324, -8, 80)
      when 3
        if level_up_flags
          self.contents.font.color = normal_color
          self.contents.draw_text(140, -8, 120, 32, 'LEVEL UP!')
        else
          draw_actor_state(actor, 140, -8)
        end
      when 4 then draw_actor_atg(actor, 0, -8, 120)
      end
    end
  end
  
end

end

#==============================================================================
# Window_Command
#==============================================================================

class Window_Command
  
  attr_accessor :commands
  attr_accessor :actor
  
  alias initialize_eos_later initialize
  def initialize(width, commands)
    initialize_eos_later(width, commands)
    @command2 = BlizzCFG::OVERDRIVE_COMMAND_NAME
  end
  
  def swap_commands
    @commands[1], @command2 = @command2, @commands[1]
    refresh
  end
  
  alias refresh_eos_later refresh
  def refresh
    refresh_eos_later
    if $fontface != nil
      self.contents.font.name = $fontface
      self.contents.font.size = $fontsize
    elsif $defaultfonttype != nil
      self.contents.font.name = $defaultfonttype
      self.contents.font.size = $defaultfontsize
    end
    if @actor != nil
      if BlizzCFG::OVERDRIVE_USERS.include?(@actor.id)
        if self.index != 1 || @commands[1] != BlizzCFG::OVERDRIVE_COMMAND_NAME
          draw_item(1, normal_color)
          self.contents.draw_text(4, 31, width-40, 32, '››', 2)
        elsif @commands[1] == BlizzCFG::OVERDRIVE_COMMAND_NAME
          self.contents.font.color = BlizzCFG::OVERDRIVE_COLOR
          (0...6).each {|j|
              self.contents.fill_rect(0, 32, width-32, 32, Color.new(0, 0, 0, 0))
              rect = Rect.new(164-j * 32, 32, width-40, 32)
              self.contents.draw_text(rect, @commands[1])
              Graphics.update}
        end
      else
        draw_item(1, normal_color)
      end
    end
  end
  
end

#==============================================================================
# Window_Overdrive
#==============================================================================

class Window_Overdrive < Window_Skill
  
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    @actor.overdrive_skills.each {|i| @data.push($data_skills[i]) if $data_skills[i] != nil}
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      if $fontface != nil
        self.contents.font.name = $fontface
        self.contents.font.size = $fontsize
      elsif $defaultfonttype != nil
        self.contents.font.name = $defaultfonttype
        self.contents.font.size = $defaultfontsize
      end
      (0...@item_max).each {|i| draw_item(i)}
    end
  end
  
  def draw_item(i)
    skill = @data[i]
    if @actor.overdrive_can_use?(skill.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4 + i % 2 * (288 + 32)
    y = i / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(skill.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 204, 32, skill.name, 0)
    self.contents.draw_text(x + 232, y, 48, 32, "#{skill.sp_cost}%", 2)
  end
  
end

#==============================================================================
# Scene_Battle
#==============================================================================

class Scene_Battle
  
  alias main_eos_later main
  def main
    main_eos_later
    @overdrive_window.dispose if @overdrive_window != nil
  end
  
  alias phase3_setup_command_window_crls_later phase3_setup_command_window
  def phase3_setup_command_window
    phase3_setup_command_window_crls_later
    if BlizzCFG::RTAB_ACTIVE
      @actor_command_window.actor = @active_actor
    else
      @actor_command_window.actor = @active_battler
    end
    @actor_command_window.refresh
  end
  
  alias update_phase3_eos_later update_phase3
  def update_phase3
    if @overdrive_window != nil && @overdrive_window.visible
      @overdrive_window.update unless defined?(SDK)
      update_phase3_overdrive_select
    else
      update_phase3_eos_later
    end
  end
  
  alias update_phase3_enemy_select_eos_later update_phase3_enemy_select
  def update_phase3_enemy_select
    end_overdrive_select_plus if Input.trigger?(Input::B)
    if BlizzCFG::RTAB_ACTIVE && Input.trigger?(Input::C)
      kind = @active_actor.current_action.kind
      update_phase3_enemy_select_eos_later
      if kind == BlizzCFG::OVERDRIVE_KIND
        @active_actor.current_action.kind = kind
      end
    else
      update_phase3_enemy_select_eos_later
    end
  end
  
  alias update_phase3_actor_select_eos_later update_phase3_actor_select
  def update_phase3_actor_select
    end_overdrive_select_plus if Input.trigger?(Input::B)
    if BlizzCFG::RTAB_ACTIVE && Input.trigger?(Input::C)
      kind = @active_actor.current_action.kind
      update_phase3_actor_select_eos_later
      if kind == BlizzCFG::OVERDRIVE_KIND
        @active_actor.current_action.kind = kind
      end
    else
      update_phase3_actor_select_eos_later
    end
  end
  
  alias phase3_next_actor_eos_later phase3_next_actor
  def phase3_next_actor
    end_overdrive_select if @overdrive_window != nil
    phase3_next_actor_eos_later
  end
  
  def update_phase3_overdrive_select
    battler = (BlizzCFG::RTAB_ACTIVE ? @active_actor : @active_battler)
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      end_overdrive_select if @overdrive_window.visible
    elsif Input.trigger?(Input::C) 
      @skill = @overdrive_window.skill
      if @skill == nil || !battler.overdrive_can_use?(@skill.id)
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      $game_system.se_play($data_system.decision_se)
      battler.current_action.skill_id = @skill.id
      @overdrive_window.visible = false
      if @skill.scope == 1
        start_enemy_select
      elsif [3, 5].include?(@skill.scope)
        start_actor_select
      else
        phase3_next_actor
      end
    end
  end
  
  def start_overdrive_select
    battler = (BlizzCFG::RTAB_ACTIVE ? @active_actor : @active_battler)
    @overdrive_window = Window_Overdrive.new(battler)
    @overdrive_window.help_window = @help_window
    @actor_command_window.active = @actor_command_window.visible = false
  end
  
  def end_overdrive_select
    end_overdrive_select_plus
    @actor_command_window.swap_commands
    @overdrive_window.dispose
    @overdrive_window, @help_window.visible = nil, false
  end
  
  def end_overdrive_select_plus
    if @overdrive_window != nil
      if @overdrive_window.visible
        @actor_command_window.active = @actor_command_window.visible = true
        @help_window.visible = false
      else
        @overdrive_window.active = @overdrive_window.visible = true
      end
    end
  end
  
  def make_overdrive_action_result(battler)
    @skill = $data_skills[battler.current_action.skill_id]
    unless battler.current_action.forcing || battler.overdrive_can_use?(@skill.id)
      $game_temp.forcing_battler = nil
      @phase4_step = 1
      return
    end
    if !BlizzCFG::RTAB_ACTIVE && $tons_version != nil && $tons_version >= 5.0
      battler.overdrive -= @skill.sp_cost * 10 if @repeat[0] <= 1
    else
      battler.overdrive -= @skill.sp_cost * 10
    end
    if $tons_version != nil && $tons_version >= 7.2 && $game_system.HP_SKILL
      battler.hp -= @skill.hp_cost if @phase != 1 && @skill.hp_cost > 0
    end
    @status_window.refresh
    @help_window.set_text(@skill.name, 1)
    @animation1_id, @animation2_id = @skill.animation1_id, @skill.animation2_id
    @common_event_id = @skill.common_event_id
    if BlizzCFG::RTAB_ACTIVE
      set_target_battlers(@skill.scope, battler)
      battler.target.each {|target| target.skill_effect(battler, @skill)}
    else
      set_target_battlers(@skill.scope)
      @target_battlers.each {|target| target.skill_effect(battler, @skill)}
    end
  end
  
  alias update_phase4_step2_eos_later update_phase4_step2
  def update_phase4_step2(battler = nil)
    if BlizzCFG::RTAB_ACTIVE
      update_phase4_step2_eos_later(battler)
    else
      update_phase4_step2_eos_later
      battler = @active_battler
    end
    if battler.current_action.kind == BlizzCFG::OVERDRIVE_KIND
      make_overdrive_action_result(battler)
    end
  end
  
  alias update_phase3_basic_command_eos_later update_phase3_basic_command
  def update_phase3_basic_command
    battler = (BlizzCFG::RTAB_ACTIVE ? @active_actor : @active_battler)
    restore_commands(battler)
    return if update_overdrive_input(battler)
    if !BlizzCFG::RTAB_ACTIVE || !Input.press?(Input::LEFT) &&
        !Input.press?(Input::RIGHT)
      update_phase3_basic_command_eos_later
    end
  end
  
  def restore_commands(battler)
    if @actor_command_window.index != 1 &&
        @actor_command_window.commands[1] == BlizzCFG::OVERDRIVE_COMMAND_NAME
      @actor_command_window.swap_commands
    end
  end
  
  def update_overdrive_input(battler)
    if BlizzCFG::OVERDRIVE_USERS.include?(battler.id)
      if @actor_command_window.index == 1 && Input.press?(Input::RIGHT)
        if @actor_command_window.commands[1] != BlizzCFG::OVERDRIVE_COMMAND_NAME
          $game_system.se_play($data_system.decision_se)
          @actor_command_window.swap_commands
        end
        if !Input.press?(Input::UP) && !Input.press?(Input::DOWN)
          @actor_command_window.update
        end
      elsif @actor_command_window.commands[1] == BlizzCFG::OVERDRIVE_COMMAND_NAME
        $game_system.se_play($data_system.cancel_se)
        @actor_command_window.swap_commands
      end
      if @actor_command_window.commands[1] == BlizzCFG::OVERDRIVE_COMMAND_NAME &&
          Input.trigger?(Input::C)
        $game_system.se_play($data_system.decision_se)
        battler.current_action.kind = BlizzCFG::OVERDRIVE_KIND
        start_overdrive_select
        return true
      end
    end
    return false
  end
  
end

if $BlizzABS && BlizzABS::VERSION >= 2.2

#==============================================================================
# BlizzABS::Utility
#==============================================================================

class BlizzABS::Utility
  
  alias get_actor_skills_eos_later get_actor_skills
  def get_actor_skills(actor)
    return actor.overdrive_skills.clone
  end
  
end

$BlizzABS = BlizzABS::Processor.new

#==============================================================================
# Map_Battler
#------------------------------------------------------------------------------
#  This class serves as superclass for characters that fight on the map and
#  can use pixel movement.
#==============================================================================

class Map_Battler
  
  alias skill_can_use_eos_later? skill_can_use?
  def skill_can_use?(id, forced = false)
    if self.is_a?(Map_Actor)
      return @battler.overdrive_can_use?(id) if @battler.overdrive_skills.include?(id)
    end
    return skill_can_use_eos_later?(id, forced)
  end
  
  alias skill_consumption_eos_later skill_consumption
  def skill_consumption(skill)
    unless self.is_a?(Map_Actor)
      skill_consumption_eos_later(skill)
      return
    end
    if @battler.overdrive_skills.include?(skill.id)
      @battler.overdrive -= skill.sp_cost * 10
    else
      skill_consumption_eos_later(skill)
    end
  end
  
end

#==============================================================================
# Hud
#==============================================================================

class Hud < Sprite
  
  if BlizzCFG::DRAW_OVERDRIVE
  alias create_positions_eos_later create_positions
  def create_positions
    create_positions_eos_later
    @od_x, @od_y = 4, 49 + @hud_height - @original_height
    @hud_height += 16
    @hot_y += 16
    @left_y += 16
  end
  
  alias draw_basic_eos_later draw_basic
  def draw_basic
    draw_basic_eos_later
    color = case BlizzABS::Config::HUD_TYPE
    when 0 then Color.new(255, 255, 255, 192)
    when 1 then Color.new(0, 0, 0, 0)
    end
    self.bitmap.fill_rect(@od_x+32, @od_y+3, 116, 14, color) if color.is_a?(Color)
    self.bitmap.fill_rect(@od_x, @od_y, 32, 20, Color.new(0, 0, 0, 128))
    self.bitmap.font.color = system_color
    self.bitmap.draw_text_full(@od_x, @od_y, 80, 20, BlizzCFG::OVERDRIVE_NAME)
    self.bitmap.font.color = normal_color
  end
  
  alias draw_empty_eos_later draw_empty
  def draw_empty
    draw_empty_eos_later
    self.bitmap.gradient_bar_hud(@od_x+32, @od_y+3, 114, 0, 'hud_red_bar')
    self.bitmap.font.color = disabled_color
    self.bitmap.draw_text_full(@od_x+54, @od_y, 84, 20, '0,0%', 2)
    @overdrive = nil
  end
  
  def draw_overdrive
    @overdrive = actor.overdrive
    rate = actor.overdrive / 1000.0
    self.bitmap.gradient_bar_hud(@od_x+32, @od_y+3, 114, rate, 'hud_red_bar')
    self.bitmap.font.color = normal_color
    self.bitmap.draw_text_full(@od_x+54, @od_y, 84, 20, actor.overdrive_text, 2)
  end
  
  alias upd_eos_later update
  def update
    $game_temp.hud_refresh ? draw_overdrive : test_overdrive if actor != nil
    upd_eos_later
  end
  
  def test_overdrive
    draw_overdrive if actor.overdrive != @overdrive
  end
  end

  alias get_skills_left_crls_later get_skills_left
  def get_skills_left
    if @skill != nil && @skill > 0
      if actor.overdrive_skills.include?(@skill)
        return actor.overdrive_left(@skill)
      end
    end
    return get_skills_left_crls_later
  end
  
end

#==============================================================================
# Window_Skill_Hotkey
#==============================================================================

class Window_Skill_Hotkey < Window_Skill
  
  alias setup_skills_eos_later setup_skills
  def setup_skills
    setup_skills_eos_later
    @overdrive_skills = []
    if BlizzCFG::OVERDRIVE_USERS.include?(@actor.id)
      @actor.overdrive_skills.each {|id| @overdrive_skills.push($data_skills[id])}
    end
    @item_max += @overdrive_skills.size
  end
  
  alias draw_skills_eos_later draw_skills
  def draw_skills
    @item_max -= @overdrive_skills.size + 1
    draw_skills_eos_later
    @data.pop
    @data += @overdrive_skills + [nil]
    size_overdrive = @item_max + @overdrive_skills.size
    (@item_max...size_overdrive).each {|i| draw_overdrive(i)}
    @item_max = size_overdrive + 1
    draw_item(size_overdrive)
  end
  
  def draw_overdrive(i)
    if @actor.overdrive_can_use?(@data[i].id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    draw_data(i, BlizzCFG::OVERDRIVE_NAME + ' ')
    self.contents.draw_text(236, i*32, 48, 32, "#{@data[i].sp_cost}%", 2)
  end
  
  def draw_data(i, add)
    self.contents.fill_rect(Rect.new(4, i*32, 288, 32), Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(@data[i].icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(4, 4+i*32, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(32, i*32, 204, 32, add + @data[i].name)
  end
  
end

end