=begin
 ----------------------------------------------------------------------------
| One Soul Battle System [A Battle System Fitting for All Solo Playing Games]
| Author: Soulpour777
| Web URL: infinitytears.wordpress.com
| For more info, please email me at my website.
| Exact Creation Date: August 21, 2014 - Thursday, 6:00AM
| ------------------------------------------------------------------------- |


 | August 22, 2014 Log:
  - Created the simple documentation
  - Created the Guard Damage 
  - Shortened the Aliased Codes
  - Official 1.0 Release
 |
 
 
[Introduction]
One Soul Battle System is a short script system that is intended to making
a battle system that uses only one actor. Though you can only have one
actor, some features were added to ensure that the battle system would be 
quite interesting for people to use. If no one ever uses this crappy battle
system, that's okay. This is for those people who just wants to have this
kind of stuff.

By that, I have explained why I have created this battle system. This is
fair quite and simple, anyone can achieve this. In fact, some one actor
battle system is even better than this.

[Features]

One Soul Battle System has the following features that are intended to only
work when you're using this system:

1. Guard Break Mode
 - The Guard Break Mode allows the player (actor) to gain points (1 - 100)
 and interpreted through a meter on Battle that heals the actor when the
 Guard Break mode reaches 100. The points increases only when the Actor
 guards. Once the Healing Skill is casted by the user, the points go down
 to 0.
 
2. Burst Mode
 - The Burst Mode in this Battle System is different to other Burst Modes
 you might have known or seen. The Burst Mode allows the player to gain
 points interpreted through a meter on Battle, which if it reaches the
 maximum value (default: 10), would multiply the Attack damage of the
 actor by Burst Mode / 2.
 
 Burst Mode Formula: Physical Damage Rate * Burst Mode / 2
 
3. Critical Overdrive
 - The Critical Overdrive is a feature wherein if the Actor dreals Critical
 Hits three times (by default, you can change the max reach), you will be
 able to multiply your damage in the next critical hit with this new
 formula:
 
 damage *= (3 * critical_overdrive)
 
 Therefore: Damage * 9 (by default)
 
4. Simple GUI for the Battle Scene
 - The OSBS features a simple editable graphical user interface of the battle
 sequence.
 
5. Battlers XP Style
 - OSBS retains the feature in RPG Maker XP where you can have Battlers
 to represent your character.
 
[Configuration | Core Script]

For configuration or anything that deals with how the battle system looks like,
please refer to the core script:
 
 - Values - 
 
    MAX_PARTY = 1 # Do not change this area
    MAX_BURST_MODE = 10 # Maximum Burst Mode Value Before Burst Activates
    MAX_GUARD_BREAK = 100 # Guard Break Max
    MAX_OVERDRIVE = 3 # Max Overdrive before Break
    Burst_Mode_Name = "Burst Mode" # => Burst Mode Name
    Guard_Break_Name = "Guard Break" # => Guard Break Name
    Overdrive_Name = "Critical Meter"  # => Overdrive Name
    
    Action_Sounds = {
    :use_skill_or_item => "Skill2", # => SE when skill is used
    :apply_normal_attack => "Skill1" # => SE when normal attack is used
    }
    
    Guard_Break_Heal_Skill = [26, 27, 28] # => Healing Spells Casted when
    # Guard Break is achieved.
    
    Actor_Command_Graphic = "command_table" # => Actor Commands Window
    Actor_Status_Graphic = "status_table" # => Battle Status Window
    Battler_Turn_Graphic = "battler_turn" # => Graphic to show when the
    # actor makes a turn 

 -----------------------------------------------------------------------------
 
 # TERMS OF USE #
 
 In this script, the terms of use are as follows:
 
 EDITING AND CONFIG
 
  - You are free to configure, edit or change any part of the script. If
  you are wishing to release it as your own, just put my name as a credit.
  You don't have to pay me or anything when you edit this script nor
  even ask my permission. This means you can change anything, but if you
  are doing this, please make sure that a credit of my name as the 
  base creator / scripter is still inside.
  
 USING THE SCRIPT
 
  - This script is free for Non-Commercial and Commercial User, but please
  give credit to where it is due.
  
 ------------------------------------------------------------------------------
 
 CREDITS:
   - Soulpour777 for the OSBS and VXA Battlers Version
   - Dervvulfman for the Battlers (VX Original)
 
 Special Thanks:
   - Xypher for the Guard information
   - Mithran for the Graphical Object Reference (during testing)
   
   | FOR MORE INFORMATION OR ANYTHING YOU WANT TO SUGGEST, PLEASE CONTACT
     ME AT THE FOLLOWING LINKS:
     
     [url]http://save-point.org/user-4677.html[/url]
     [url]http://www.rpgmakervxace.net/user/13765-soulpour777/[/url]
     [url]http://rmrk.net/index.php?action=profile;u=28990;sa=forumProfile[/url]
     [url]http://rpgmaker.net/users/SoulPour777/[/url]
     [url]http://infinitytears.wordpress.com/mail/[/url]
=end

module Soulpour
  module OSBS
    MAX_PARTY = 1 # Do not change this area
    MAX_BURST_MODE = 10 # Maximum Burst Mode Value Before Burst Activates
    MAX_GUARD_BREAK = 100 # Guard Break Max
    MAX_OVERDRIVE = 3 # Max Overdrive before Break
    Burst_Mode_Name = "Burst Mode" # => Burst Mode Name
    Guard_Break_Name = "Guard Break" # => Guard Break Name
    Overdrive_Name = "Critical Meter"  # => Overdrive Name
    
    Action_Sounds = {
    :use_skill_or_item => "Skill2", # => SE when skill is used
    :apply_normal_attack => "Skill1" # => SE when normal attack is used
    }
    
    Guard_Break_Heal_Skill = [26, 27, 28] # => Healing Spells Casted when
    # Guard Break is achieved.
    
    Actor_Command_Graphic = "command_table" # => Actor Commands Window
    Actor_Status_Graphic = "status_table" # => Battle Status Window
    Battler_Turn_Graphic = "battler_turn" # => Graphic to show when the
    # actor makes a turn
    
  end
  
  module OSBS_Battlers_SEA
    # Actor battler array
    ACTOR_BATTLER = Array.new
    # ------------------ Positioning ------------------# 
    BATTLER_PLACE_ON_CENTER = true #Places the Battlers on the Center
    BATTLER_MAXIMUM_PARTY  = OSBS::MAX_PARTY   # Default maximum number of party.
    BATTLER_VERTICAL_HEIGHT    = 400 # Vertical height of battlers
    BATTLER_TRANSPARENT_OPTION = true  # makes the battlers transparent before attacking option
    # ------------------ List of Actors ------------------# 
    # Actor Number      Filename,  Hue (optional)
    # The Battler Images should be inside the Battlers folder.
    # ------------------ Add Your Actors ------------------# 
    ACTOR_BATTLER[1] = ["Kirito"]
    # ------------------ ------------------#      
  end     
  
end

class Game_System
  attr_accessor                                                 :overdrive_ok
  attr_accessor                                                      :reburst
  attr_accessor                                   :one_soul_guard_break_bonus
  attr_accessor                                          :one_soul_burst_mode
  attr_accessor                                           :critical_overdrive
  alias :one_soul_battle_system_initialize                        :initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    one_soul_battle_system_initialize
    @one_soul_guard_break_bonus = 0
    @one_soul_burst_mode = 0
    @critical_overdrive = 0
    @overdrive_ok = 0
    @reburst = false
  end
  #--------------------------------------------------------------------------
  # * Reset all the Mode Values
  #--------------------------------------------------------------------------  
  def reset_all_modes(breaks, bursts, overdrives)
    @one_soul_guard_break_bonus = breaks
    @one_soul_burst_mode = 0
    @critical_overdrive = overdrives
  end
  #--------------------------------------------------------------------------
  # * Reset All Boolean Values
  #--------------------------------------------------------------------------  
  def reset_all_drives
    @reburst = false
    @overdrive_ok = false
  end
end


class Game_Battler < Game_BattlerBase
  alias :one_soul_battle_system_game_battler_item_apply           :item_apply
  #--------------------------------------------------------------------------
  # * Calculate Damage
  #--------------------------------------------------------------------------
  def make_damage_value(user, item)
    value = item.damage.eval(user, self, $game_variables)
    value *= item_element_rate(user, item)
    
    if item.physical?
      if user.is_a?(Game_Actor)
        if $game_system.one_soul_burst_mode >= 100
          $game_system.reburst = true
        else
          $game_system.reburst = false if $game_system.reburst
          $game_system.one_soul_burst_mode += pdr / 2
        end
        if $game_system.reburst
          value *= pdr  * $game_system.burst_mode / 2
          $game_system.one_soul_burst_mode = 0
        else
          value *= pdr 
        end
      end
    end
    value *= mdr if item.magical?
    value *= rec if item.damage.recover?
    value = apply_critical(user, value) if @result.critical
    value = apply_variance(value, item.damage.variance)
    value = apply_guard(value)
    @result.make_damage(value.to_i, item)
  end  
  
  #--------------------------------------------------------------------------
  # * Apply Critical
  #--------------------------------------------------------------------------
  def apply_critical(user, damage)
    if user.is_a?(Game_Actor)
      if $game_system.critical_overdrive >= 3
        $game_system.overdrive_ok = true
      else
        $game_system.critical_overdrive += 1
      end
      if $game_system.overdrive_ok
        damage *= (3 * $game_system.critical_overdrive)
      else
        damage *= 3
      end
    else
      damage *= 3
    end
  end  
  #--------------------------------------------------------------------------
  # * Apply Effect of Skill/Item
  #--------------------------------------------------------------------------
  def item_apply(user, item)
    one_soul_battle_system_game_battler_item_apply(user, item)
    if user.is_a?(Game_Actor)
      RPG::SE.new(Soulpour::OSBS::Action_Sounds.values[0], 100, 100).play
    end
    $game_system.one_soul_guard_break_bonus += 1 if actor? && guard? && user == self
  end
  
  
  #--------------------------------------------------------------------------
  # * Apply Normal Attack Effects
  #--------------------------------------------------------------------------
  def attack_apply(attacker)
    if attacker.is_a?(Game_Actor)
      RPG::SE.new(Soulpour::OSBS::Action_Sounds.values[1], 100, 100).play
    end
    item_apply(attacker, $data_skills[attacker.attack_skill_id])
  end
  
end

module RPG
  #============================================================================
  # ** Actor
  #----------------------------------------------------------------------------
  class Actor
    alias soul_battler_init initialize
    def initialize
      soul_battler_init() #call original method
      @battler_name = ""
      @battler_hue = 0
    end
  end
end
 
#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
#  This class handles temporary data that is not included with save data.
# The instance of this class is referenced by $game_temp.
#==============================================================================
 
class Game_Temp
  
  attr_accessor :soul_battler_battle_main_phase 
  
  alias soul_battler_init initialize
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------
  def initialize
    soul_battler_init() #call original method
    @soul_battler_battle_main_phase = false
  end
end
#~  
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles system-related data. Also manages vehicles and BGM, etc.
# The instance of this class is referenced by $game_system.
#==============================================================================
 
class Game_System
  
  attr_accessor :battler_for_actors_max_value 
  
  alias soul_battler_init initialize
  def initialize
    soul_battler_init() #call original method
    @battler_for_actors_max_value = Soulpour::OSBS_Battlers_SEA::BATTLER_MAXIMUM_PARTY
  end
  
end
 
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles actors. It's used within the Game_Actors class
# ($game_actors) and referenced by the Game_Party class ($game_party).
#==============================================================================
 
class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :screen_x                # battle screen X coordinate
  attr_accessor :screen_y                # battle screen Y coordinate
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias soul_actor_battler_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #    actor_id : actor ID
  #--------------------------------------------------------------------------
  def initialize(actor_id)
    soul_actor_battler_initialize(actor_id) #call original method
    # Creates the Battler Graphic
    @battler_name = Soulpour::OSBS_Battlers_SEA::ACTOR_BATTLER[actor_id][0]
    # Apply Default Hue when nothing is indicated
    if Soulpour::OSBS_Battlers_SEA::ACTOR_BATTLER[actor_id][1] != nil
      @battler_hue  = Soulpour::OSBS_Battlers_SEA::ACTOR_BATTLER[actor_id][1]
    else
      @battler_hue  = 0
    end
  end
  #--------------------------------------------------------------------------
  # * Change Battler
  #    battler_name  : new battler graphic filename
  #    battler_hue  : new battler hue setting (default = 0)
  #--------------------------------------------------------------------------
  def set_battler(battler_name = "", battler_hue = 0)
    @battler_name = battler_name
    @battler_hue = battler_hue
  end
  #--------------------------------------------------------------------------
  # * Use Sprites?
  #--------------------------------------------------------------------------
  def use_sprite?
    return true
  end
  #--------------------------------------------------------------------------
  # * Get Battle Screen X-Coordinate
  #--------------------------------------------------------------------------
  def screen_x
    if self.index != nil
      if Soulpour::OSBS_Battlers_SEA::BATTLER_PLACE_ON_CENTER
        # Return after calculating x-coords of centered party members
        return self.index * (544 / $game_system.battler_for_actors_max_value) +
              ($game_system.battler_for_actors_max_value - $game_party.members.size) *
              (272 / $game_system.battler_for_actors_max_value) +
              (272 / $game_system.battler_for_actors_max_value)
      else
        # Return after calculating x-coords of default-aligned party members
        return self.index * 136 + 68
      end
    else
      return 0
    end
  end
  #--------------------------------------------------------------------------
  # * Get Battle Screen Y-Coordinate
  #--------------------------------------------------------------------------
  def screen_y
    return Soulpour::OSBS_Battlers_SEA::BATTLER_VERTICAL_HEIGHT + 50
  end
  #--------------------------------------------------------------------------
  # * Get Battle Screen Z-Coordinate
  #--------------------------------------------------------------------------
  def screen_z
    if self.index != nil
      return $game_party.members.size - self.index
    else
      return 0
    end
  end
end

 
#==============================================================================
# ** Sprite_Battler
#------------------------------------------------------------------------------
#  This sprite is used to display battlers. It observes a instance of the
# Game_Battler class and automatically changes sprite conditions.
#==============================================================================
 
class Sprite_Battler < Sprite_Base
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias soul_actor_battler_update update
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    soul_actor_battler_update() #Call Original Method
    # Create Transparent function
    if Soulpour::OSBS_Battlers_SEA::BATTLER_TRANSPARENT_OPTION == true
      # If visible?
      if @battler.is_a?(Game_Actor) and @battler_visible
        if $game_temp.soul_battler_battle_main_phase
          self.opacity += 3 if self.opacity < 255
        else
          self.opacity -= 3 if self.opacity > 207
        end
      end 
    end
  end
end
 
#==============================================================================
# ** Spriteset_Battle
#------------------------------------------------------------------------------
#  This class brings together battle screen sprites. It's used within the
# Scene_Battle class.
#==============================================================================
 
class Spriteset_Battle
  #--------------------------------------------------------------------------
  # * Create Actor Sprite
  #    Removes the 'empty' battler image used by the default system and
  #    replaces it.  It also observes the actual size of the party and
  #    not a predetermined 4-party limit.
  #--------------------------------------------------------------------------
  def create_actors
    @actor_sprites = []
    for actor in $game_party.members.reverse
      @actor_sprites.push(Sprite_Battler.new(@viewport2, actor))
    end
  end
  #--------------------------------------------------------------------------
  # * Update Actor Sprite
  #--------------------------------------------------------------------------
  def update_actors
    if $game_party.members.size > @actor_sprites.size
      dispose_actors
      create_actors
    end
    for sprite in @actor_sprites
      sprite.update
    end
  end
end

module BattleManager
  #--------------------------------------------------------------------------
  # * Victory Processing
  #--------------------------------------------------------------------------
  def self.process_victory
    $game_temp.soul_battler_battle_main_phase = false
    play_battle_end_me
    replay_bgm_and_bgs
    $game_message.add(sprintf(Vocab::Victory, $game_party.name))
    display_exp
    gain_gold
    gain_drop_items
    gain_exp
    SceneManager.return
    battle_end(0)
    return true
  end  
  
  #--------------------------------------------------------------------------
  # * Battle Start
  #--------------------------------------------------------------------------
  def self.battle_start
    $game_system.battle_count += 1
    $game_party.on_battle_start
    $game_troop.on_battle_start
    $game_troop.enemy_names.each do |name|
      $game_message.add(sprintf(Vocab::Emerge, name))
    end
    if @preemptive
      $game_message.add(sprintf(Vocab::Preemptive, $game_party.name))
    elsif @surprise
      $game_message.add(sprintf(Vocab::Surprise, $game_party.name))
    end
    wait_for_message
    $game_temp.soul_battler_battle_main_phase = true
  end  
  
end

#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle < Scene_Base
  
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  alias battler_activate_start start
  def start
    battler_activate_start #call original method
     $game_temp.soul_battler_battle_main_phase = false
  end

  #--------------------------------------------------------------------------
  # * Start Party Command Selection
  #--------------------------------------------------------------------------
  alias battler_start_party_command_selection start_party_command_selection
  def start_party_command_selection
    battler_start_party_command_selection #call original method
      if BattleManager.input_start
        $game_temp.soul_battler_battle_main_phase = false 
      end
  end  

  #--------------------------------------------------------------------------
  # * Battle Start
  #--------------------------------------------------------------------------
  alias battler_battle_start battle_start
  def battle_start
    battler_battle_start #call original method
    $game_temp.soul_battler_battle_main_phase = true
  end  

end

class Window_BattleStatus < Window_Selectable
  #--------------------------------------------------------------------------
  # * Draw Basic Area
  #--------------------------------------------------------------------------
  def draw_basic_area(rect, actor)
    draw_actor_name(actor, rect.x + 0, rect.y, 100)
    draw_actor_icons(actor, rect.x + 104, rect.y, rect.width - 104)
  end
  
  #--------------------------------------------------------------------------
  # * Draw Gauge Area (with TP)
  #--------------------------------------------------------------------------
  def draw_gauge_area_with_tp(rect, actor)
    draw_actor_hp(actor, rect.x + 0, rect.y, 72)
    draw_actor_mp(actor, rect.x + 82, rect.y, 64)
    draw_actor_tp(actor, rect.x + 156, rect.y, 64)
    draw_actor_gb(actor, rect.x, rect.y + 20, 224)
    draw_actor_bm(actor, rect.x, rect.y + 40, 224)
    draw_actor_level(actor, rect.x - 80, rect.y)    
    draw_actor_critical_overdrive(actor, rect.x, rect.y + 60, 224)
#~     draw_actor_face(actor, x, y, enabled = true)
  end
  #--------------------------------------------------------------------------
  # * Draw Gauge Area (without TP)
  #--------------------------------------------------------------------------
  def draw_gauge_area_without_tp(rect, actor)
    draw_actor_hp(actor, rect.x + 0, rect.y, 134)
    draw_actor_mp(actor, rect.x + 144,  rect.y, 76)
    draw_actor_gb(actor, rect.x, rect.y + 20, 224)
    draw_actor_bm(actor, rect.x, rect.y + 40, 224)
    draw_actor_level(actor, rect.x - 80, rect.y)    
    draw_actor_critical_overdrive(actor, rect.x, rect.y + 60, 224)
  end  
    
  #--------------------------------------------------------------------------
  # * Draw HP
  #--------------------------------------------------------------------------
  def draw_actor_gb(actor, x, y, width = 124)
    draw_gauge(x, y, width, $game_system.one_soul_guard_break_bonus/Soulpour::OSBS::MAX_GUARD_BREAK.to_f, hp_gauge_color1, hp_gauge_color2)
    change_color(system_color)
    draw_text(x, y, 100, line_height, Soulpour::OSBS::Guard_Break_Name)
    draw_current_and_max_values(x, y, width, $game_system.one_soul_guard_break_bonus, Soulpour::OSBS::MAX_GUARD_BREAK,
      hp_color(actor), normal_color)
  end
    
  #--------------------------------------------------------------------------
  # * Draw Critical Overdrive
  #--------------------------------------------------------------------------
  def draw_actor_critical_overdrive(actor, x, y, width = 124)
    draw_gauge(x, y, width, $game_system.critical_overdrive/Soulpour::OSBS::MAX_OVERDRIVE.to_f, hp_gauge_color1, hp_gauge_color2)
    change_color(system_color)
    draw_text(x, y, 150, line_height, Soulpour::OSBS::Overdrive_Name)
    draw_current_and_max_values(x, y, width, $game_system.critical_overdrive, Soulpour::OSBS::MAX_OVERDRIVE,
      hp_color(actor), normal_color)
  end  
    
  #--------------------------------------------------------------------------
  # * Draw Burst Mode
  #--------------------------------------------------------------------------
  def draw_actor_bm(actor, x, y, width = 124)
    draw_gauge(x, y, width, $game_system.one_soul_burst_mode/Soulpour::OSBS::MAX_BURST_MODE.to_f, hp_gauge_color1, hp_gauge_color2)
    change_color(system_color)
    draw_text(x, y, 100, line_height, Soulpour::OSBS::Burst_Mode_Name)
    draw_current_and_max_values(x, y, width, $game_system.one_soul_burst_mode, Soulpour::OSBS::MAX_BURST_MODE,
      hp_color(actor), normal_color)
  end    
    
end

class Game_Party < Game_Unit
  #--------------------------------------------------------------------------
  # * Get Maximum Number of Battle Members
  #--------------------------------------------------------------------------
  def max_battle_members
    return Soulpour::OSBS::MAX_PARTY
  end
end

class Window_BattleStatus < Window_Selectable  
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, window_width, window_height)
    refresh
    self.openness = 0
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    Graphics.width
  end
  
end

class Window_BattleStatus < Window_Selectable  
  alias :one_soul_battle_system_battle_status_initialize          :initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    one_soul_battle_system_battle_status_initialize
    self.opacity = 0
    create_status_table
  end
  
  #--------------------------------------------------------------------------
  # * Close Window
  #--------------------------------------------------------------------------
  def close
    @status_table.opacity = 0
    @closing = true unless close?
    @opening = false
    self
  end  
  
  #--------------------------------------------------------------------------
  # * Open Window
  #--------------------------------------------------------------------------
  def open
    @status_table.opacity = 255
    @opening = true unless open?
    @closing = false
    self
  end  
  
  def create_status_table
    @status_table = Plane.new
    @status_table.bitmap = Cache.system(Soulpour::OSBS::Actor_Status_Graphic)
  end
end

class Window_PartyCommand < Window_Command
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return Graphics.width
  end  
  def window_height
    return 50
  end
  
  def col_max
    return 2
  end
end

class Window_ActorCommand < Window_Command
  def col_max
    return 4
  end
  def window_height
    return 50
  end
  
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return Graphics.width
  end
end

class Window_PartyCommand < Window_Command
  alias :one_soul_battle_system_party_command_initialize          :initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    one_soul_battle_system_party_command_initialize
    self.opacity = 0
    create_command_table
  end
  
  def create_command_table
    @command_table = Plane.new
    @command_table.bitmap = Cache.system(Soulpour::OSBS::Actor_Command_Graphic)
    @command_table.opacity = 255
  end
  
  def hide_command_table
    @command_table.opacity = 0
  end
  
  #--------------------------------------------------------------------------
  # * Close Window
  #--------------------------------------------------------------------------
  def close
    hide_command_table
    @closing = true unless close?
    @opening = false
    self
  end  
  
  #--------------------------------------------------------------------------
  # * Open Window
  #--------------------------------------------------------------------------
  def open
    @command_table.opacity = 255
    @opening = true unless open?
    @closing = false
    self
  end    
  
  #--------------------------------------------------------------------------
  # * Free
  #--------------------------------------------------------------------------
  def dispose
    @command_table.bitmap.dispose
    @command_table.dispose
    contents.dispose unless disposed?
    super
  end   
  
end

class Window_ActorCommand < Window_Command
  alias :one_soul_battle_system_actor_command_initialize          :initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    one_soul_battle_system_actor_command_initialize
    self.opacity = 0
    create_command_table
  end
  
  
  def create_command_table
    @command_table = Plane.new
    @command_table.bitmap = Cache.system(Soulpour::OSBS::Actor_Command_Graphic)
    @command_table.opacity = 255
  end
  
  def hide_command_table
    @command_table.opacity = 0
  end
  
  #--------------------------------------------------------------------------
  # * Close Window
  #--------------------------------------------------------------------------
  def close
    hide_command_table
    @closing = true unless close?
    @opening = false
    self
  end  
  
  #--------------------------------------------------------------------------
  # * Open Window
  #--------------------------------------------------------------------------
  def open
    @command_table.opacity = 255
    @opening = true unless open?
    @closing = false
    self
  end    
  
  #--------------------------------------------------------------------------
  # * Free
  #--------------------------------------------------------------------------
  def dispose
    @command_table.bitmap.dispose
    @command_table.dispose
    contents.dispose unless disposed?
    super
  end  
  
end

class Scene_Battle < Scene_Base
  alias :one_soul_battle_system_scene_battle_turn_start           :turn_start
  alias :one_soul_battle_system_scene_battle_next_command       :next_command  
  alias :one_soul_battle_system_scene_battle_update                   :update
  alias :one_soul_battle_system_scene_battle_terminate             :terminate
  alias :one_soul_battle_system_scene_battle_turn_end               :turn_end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    one_soul_battle_system_scene_battle_update
    @status_window.refresh
  end  
  #--------------------------------------------------------------------------
  # * Create Status Window
  #--------------------------------------------------------------------------
  def create_status_window
    @status_window = Window_BattleStatus.new
    @status_window.x = 0
  end  
  #--------------------------------------------------------------------------
  # * Create Party Commands Window
  #--------------------------------------------------------------------------
  def create_party_command_window
    @party_command_window = Window_PartyCommand.new
    @party_command_window.y = 245
    @party_command_window.set_handler(:fight,  method(:command_fight))
    @party_command_window.set_handler(:escape, method(:command_escape))
    @party_command_window.unselect
  end
  #--------------------------------------------------------------------------
  # * Start Actor Command Selection
  #--------------------------------------------------------------------------
  def start_actor_command_selection
    @status_window.select(BattleManager.actor.index)
    @status_window.x = 0
    @party_command_window.close
    @actor_command_window.setup(BattleManager.actor)
  end  
  
  def create_actors_turn_indicator
    @indicator_actors_turn = Sprite.new
    @indicator_actors_turn.bitmap = Cache.system(Soulpour::OSBS::Battler_Turn_Graphic)
  end
  
  def destroy_actors_turn_indicator
    @indicator_actors_turn.bitmap.dispose
    @indicator_actors_turn.dispose
  end
  
  #--------------------------------------------------------------------------
  # * Update Information Display Viewport
  #--------------------------------------------------------------------------
  def update_info_viewport
    move_info_viewport(0)   if @party_command_window.active
  end
  #--------------------------------------------------------------------------
  # * Create Actor Commands Window
  #--------------------------------------------------------------------------
  def create_actor_command_window
    @actor_command_window = Window_ActorCommand.new
    @actor_command_window.y = 245
    @actor_command_window.set_handler(:attack, method(:command_attack))
    @actor_command_window.set_handler(:skill,  method(:command_skill))
    @actor_command_window.set_handler(:guard,  method(:command_guard))
    @actor_command_window.set_handler(:item,   method(:command_item))
    @actor_command_window.set_handler(:cancel, method(:prior_command))
  end  
  #--------------------------------------------------------------------------
  # * End Turn
  #--------------------------------------------------------------------------
  def turn_end
    one_soul_battle_system_scene_battle_turn_end
    one_soul_battle_system_cast(player) if $game_system.one_soul_guard_break_bonus >= 100
    $game_system.critical_overdrive = 0 if $game_system.overdrive_ok
    $game_system.overdrive_ok = false
    destroy_actors_turn_indicator
  end  
  
  
  #--------------------------------------------------------------------------
  # * Start Turn
  #--------------------------------------------------------------------------
  def turn_start
    one_soul_battle_system_scene_battle_turn_start
    destroy_actors_turn_indicator
  end
  
  #--------------------------------------------------------------------------
  # * To Next Command Input
  #--------------------------------------------------------------------------
  def next_command
    one_soul_battle_system_scene_battle_next_command
    create_actors_turn_indicator
  end
  
  #--------------------------------------------------------------------------
  # * Cast Guard Meter Effect
  #--------------------------------------------------------------------------  
  def one_soul_battle_system_cast(battler)
    last_subject = @subject
    @subject = battler
    action = Game_Action.new(battler)
    action.set_skill(Soulpour::OSBS::Guard_Break_Heal_Skill[rand(Soulpour::OSBS::Guard_Break_Heal_Skill.size)])
    battler.actions.unshift(action)
    use_item
    battler.actions.shift
    @subject = last_subject
    $game_system.one_soul_guard_break_bonus = 0
  end     
  #--------------------------------------------------------------------------
  # * Termination Processing
  #--------------------------------------------------------------------------
  def terminate
    one_soul_battle_system_scene_battle_terminate
    $game_system.reset_all_drives
  end  
end