Jump to content
KayakoChan

Victor's animated battlers+Moghunter's HUD

Recommended Posts

So I have been experimenting a little with the battle engines, and while I have already decided that my project will be using Victor's animated battlers I have also found Moghunter's HUD quite interesting to look at.
 
After some trial and error I finally managed to get them to work together as seen below.
kCVL2Pn.png
 
The problem with the portrait effects, they work fine if the character is on the receiving end of an action
(EG: Being attacked, selected or healed) But not if they are the ones performing the actions
(EG: When they attack, use items, or cast) My best guess is that it's because Victor's battlers
overwrite the usual actions in some way, breaking compatibility. But I have no idea how to solve such
an issue given my non-existing coding skills.
 
The scripts related are probably Victor's animated battles:

 

 

#==============================================================================
# ** Victor Engine - Animated Battle
#------------------------------------------------------------------------------
# Author : Victor Sant
#
# Aditional Credit :
#   - Fomar0153 (Help with icons placement)
#
# Version History:
#  v beta - 2012.01.28 > Beta release
#  v 1.00 - 2012.03.08 > Full release
#  v 1.01 - 2012.03.11 > Better automatic facing direction handling
#                      > Added tags to control intro and victory poses
#                      > Added tags to assign equipment icons for enemies
#  v 1.02 - 2012.03.15 > Fixed enemies turing back when unmovable
#                      > Better active battler handling
#  v 1.03 - 2012.03.19 > Fixed last text error on fast damage skill
#                      > Fixed bug if number of members exceeds battle members
#  v 1.04 - 2012.03.21 > Fixed pose freeze error
#  v 1.05 - 2012.05.20 > Compatibility with Map Turn Battle
#  v 1.06 - 2012.05.22 > Compatibility with Passive States
#  v 1.07 - 2012.05.24 > Compatibility with State Auto Apply
#                      > Added note tags for cast poses
#  v 1.08 - 2012.05.25 > Fixed Counter and Reflect endless loop
#                      > Fixed freeze at the battle end
#  v 1.09 - 2012.07.17 > Fixed throw wait and effect animation
#                      > Fixed icons placement (Thanks to Fomar0153)
#                      > Fixed directions of actions
#                      > Fixed battle log showing too fast
#                      > Fixed freeze when escaping
#                      > Improved Dual Wielding options
#  v 1.10 - 2012.07.18 > Compatibility with Retaliation Damage
#                      > Improved direction handling
#                      > Improved animation wait time handling
#                      > Fixed throw animation skip if targets are near
#                      > Fixed shield icon flashing after defending
#                      > Fixed some log messages not showing
#                      > Fixed typo with move forward (replace all 'foward'
#                        text with 'forward')
#  v 1.11 - 2012.07.24 > Fixed game closing when cause death state on targets
#                      > Fixed issue with animation wait
#                      > Added "last" target tag for actions, this tag will
#                        use for the action the same target from the previous
#                        action.
#  v 1.12 - 2012.08.01 > Compatibility with State Aura
#  v 1.13 - 2012.08.02 > Compatibility with Custom Slip Effect
#                      > Compatibility with Basic Module 1.27
#  v 1.14 - 2012.08.17 > Compatibility with Custom Hit Formula
#  v 1.15 - 2012.11.03 > Added "frame size" value for pose settings, allowing
#                        to setup different frame sizes for each pose. Needed
#                        to use CCOA styled battlers.
#                      > Fixed issue with freeze when battlers enters the
#                        battle with events.
#                      > Fixed small jump during actions without movement.
#                      > Fixed issue with notetags priority.
#                      > Fixed issue with collapse time on battle end.
#  v 1.16 - 2012.12.13 > Compatibility with State Graphics
#  v 1.17 - 2012.12.24 > Compatibility with Active Time Battle
#                      > Compatibility with Counter Options
#  v 1.18 - 2012.12.30 > Compatibility with Leap Attack
#  v 1.19 - 2013.01.07 > Improved frame setup precision
#                      > Added target setting "next" that allows the sequence
#                        to select the "next" valid target
#                      > Added possibility to use script codes to setup the
#                        number of actions repeats, any valid game battler
#                        method that returns numeric values can be used.
#  v 1.20 - 2013.01.24 > Improved frame setup precision.
#  v 1.21 - 2013.01.13 > Major changes on various setups. More deatais at thr
#                        Additional Instructions.
#                      > Added new sprite settings: ox: and oy:. It can be used
#                        to adjust the positon of some battle graphics.
#                      > Added values: "condition", "script", "afterimage",
#                        "transform", "appear", "target". More information
#                        about those on the user manual.
#                      > Fixed issue with zoomed icons position.
#------------------------------------------------------------------------------
#  This script provides a totally customized animated battle system.
# This script allows a full customization of actions sequences, spritesheet
# and many things related to in battle display.
# This script ins't newbie friendly, be *VERY CAREFUL* with the settings.
#------------------------------------------------------------------------------
# Compatibility
#   Requires the script 'Victor Engine - Basic Module' v 1.35 or higher
#   If used with 'Victor Engine - Custom Slip Effect' place this bellow it.
#   If used with 'Victor Engine - Custom Hit Formula' place this bellow it.
#
#
# * Overwrite methods
#   class Game_BattlerBase
#     def refresh
#
#   class Game_Battler < Game_BattlerBase
#     def dead?
#
#   class Game_Actor < Game_Battler
#     def perform_collapse_effect
#     def perform_damage_effect
#
#   class Game_Enemy < Game_Battler
#     def perform_damage_effect
#
#   class Sprite_Battler < Sprite_Base
#     def update_bitmap
#     def init_visibility
#     def update_origin
#
#   class Spriteset_Battle
#     def create_actors
#
#   class Window_BattleLog < Window_Selectable
#     def wait_and_clear
#     def wait
#     def back_to(line_number)
#     def display_added_states(target)
#
#   class Scene_Battle < Scene_Base
#     def abs_wait_short
#     def process_action
#     def apply_item_effects(target, item)
#     def execute_action
#     def use_item
#     def show_animation(targets, animation_id)
#     def invoke_counter_attack(target, item)
#     def invoke_magic_reflection(target, item)
#     def apply_substitute(target, item)
#
# * Alias methods
#   class << BattleManager
#     def init_members
#     def battle_end(result)
#     def process_victory
#     def process_escape
#     def process_abort
#
#   class Game_Screen
#     def clear_tone
#     def update
#
#   class Game_Battler < Game_BattlerBase
#     def initialize
#     def item_apply(user, item)
#     def make_damage_value(user, item)
#     def regenerate_hp
#     def die
#     def revive
#
#   class Game_Actor < Game_Battler
#     def param_plus(param_id)
# 
#   class Game_Enemy < Game_Battler
#     def perform_collapse_effect
#
#   class Sprite_Battler < Sprite_Base
#     def initialize(viewport, battler = nil)
#     def update_effect
#     def revert_to_normal
#     def setup_new_effect
#
#   class Spriteset_Battle
#     def initialize
#     def update
#     def dispose
#     def create_pictures
#     def create_viewports
#     def update_viewports
#
#   class Window_BattleLog < Window_Selectable
#     def add_text(text)
#
#   class Scene_Battle < Scene_Base
#     def create_spriteset
#     def update_basic
#     def turn_end
#     def next_command
#     def prior_command
#
#------------------------------------------------------------------------------
# Instructions:
#  To instal the script, open you script editor and paste this script on
#  a new section bellow the Materials section. This script must also
#  be bellow the script 'Victor Engine - Basic'.
#  This script requires a very heavy user setup, refer to the User Manual
#  at http://victorscripts.wordpress.com/ for more information.
#------------------------------------------------------------------------------
# Weapons note tags:
#   Tags to be used on Weapons note boxes. 
#
#  <attack pose: action>
#   Changes the normal attack pose when using a weapon with this tag
#     action : action name
#
#  <dual pose: action>
#   Changes the double attack pose when using a weapon with this tag
#     action : action name
#
#  <skill pose: action>
#   Changes the physical skill pose when using a weapon with this tag
#     action : action name
#
#  <magic pose: action>
#   Changes the magical skill pose when using a weapon with this tag
#     action : action name
#
#  <item pose: action>
#   Changes the item pose when using a weapon with this tag
#     action : action name
#
#  <advance pose: action>
#   Changes the movement for actions when using a weapon with this tag
#   this change the movement of all actions that have movement (by default
#   only normal attacks and physical skills)
#     action : movement type name
#
#------------------------------------------------------------------------------
# Skills and Items note tags:
#   Tags to be used on Skills and Items note boxes. 
#
#  <action pose: action>
#   Changes the pose of the skill or item with this tag
#     action : action name
# 
#  <action movement>
#   By default, only physical skills have movement. So, if you want to add
#   movement to non-physical skills and items, add this tag.
#
#  <allow dual attack>
#   By default, skills and items do a single hit even if the character is
#   dual wielding, adding this tag to the skill will allow the actor to
#   attack twice when dual wielding. This only if the action don't use a
#   custom pose.
#
#------------------------------------------------------------------------------
# Actors note tags:
#   Tags to be used on Actors note boxes.
#
#  <no intro>
#   This tag will make the actor display no intro pose at the battle start.
#   By default, all actor display intro pose
#
#  <no victory>
#   This tag will make the actor display no victory pose at the battle start.
#   By default, all actors display victory pose
#
#------------------------------------------------------------------------------
# Enemies note tags:
#   Tags to be used on Enemies note boxes.
#
#  <intro pose>
#   This tag will make the enemy display intro pose at the battle start.
#   By default, no enemy display intro pose
#
#  <victory pose>
#   This tag will make the enemy display victory pose at the battle start.
#   By default, no enemy display victory pose
#
#  <weapon x: y>
#   This allows to display weapons for enemies when using the pose value
#   'icon: weapon *'.
#     x : the slot index of the weapon (1: right hand, 2: left hand)
#     y : the incon index
#
#  <armor x: y>
#   This allows to display armors for enemies when using the pose value
#   'icon: armor *'.
#     x : the slot index of the armor (1: shield, 2: helm, 3: armor, 4: acc)
#     y : the incon index
#
#------------------------------------------------------------------------------
# Actors, Enemies, Classes, States, Weapons and Armors note tags:
#   Tags to be used on Actors, Enemies, Classes, States, Weapons and Armors
#   note boxes.
#
#  <unmovable> 
#   This tag allows to make a totally unmovable battler. The battler will not
#   move to attack, neither be can forced to move by any action.
#  
#  <use dual attack>
#   By default, the attack when dual wielding calls the action sequence from
#   the equiped weapons. Adding this tag will make the actor use the custom
#   dual attack sequence <action: dual attack, reset>
#
#------------------------------------------------------------------------------
# Comment calls note tags:
#  Tags to be used in events comment box, works like a script call.
# 
#  <no intro>
#   When called, the next battle will have no intro pose.
#
#  <no victory>
#   When called, the next battle will have no victory pose.
#
#------------------------------------------------------------------------------
# Additional Instructions:
#
#  More detailed info about the settings can be found on the User Manual at:
#   http://victorscripts.wordpress.com/
#
#  From version 1.09 and later the dual attack pose is opitional, if not set
#  the actor will use the default attack for each weapon instead (wich
#  allows to use weapons with totally different poses), also it's possible 
#  to setup skills to inherit the double attack effect. So you can make
#  you physical single hit skills to deal 2 strikes if dual wielding.
#
#  From version 1.21 and later the "effect:" and "throw:" values have been
#  changed. Now you must refer two targets values.
#  For the "effect" value, the first is the user of the action, the second the
#  targets. 
#  For the "throw:" value, the first is the target of the throw, the second 
#  battler throwing.
#  Actions sequences made before this update might need to be ajusted to these
#  new settings if not working properly. So if a custom action made before
#  this update shows problems, update those actions before asking for help.
#
#==============================================================================

#==============================================================================
# ** Victor Engine
#------------------------------------------------------------------------------
#   Setting module for the Victor Engine
#==============================================================================

module Victor_Engine
  #--------------------------------------------------------------------------
  # * Initialize Variables
  #--------------------------------------------------------------------------
  VE_ACTION_SETTINGS = {} # Don't remove or change
  #--------------------------------------------------------------------------
  # * Animated battler sufix
  #   When using sprites, add this to the animated sprite sheet of the battler,
  #   that way you can keep the original battler a single sprite and make 
  #   easier to setup their position on the troop
  #--------------------------------------------------------------------------
  VE_SPRITE_SUFIX = "[anim]"
  #--------------------------------------------------------------------------
  # * Intro fade
  #   When true, there will be a small fade effect on the battlers during
  #   the battle start (like RMXP default battle)
  #--------------------------------------------------------------------------
  VE_BATTLE_INTRO_FADE = true
  #--------------------------------------------------------------------------
  # * Default sprite settings
  #   This is the settings for all battler graphics that doesn't have
  #   their own custom setting
  #--------------------------------------------------------------------------
  VE_DEFAULT_SPRITE = {
  # Basic Settings
  # name:   value,
    frames: 3,        # Number of frames
    rows:   4,       # Number of rows
    ox:     0,        # Adjust sprite X position
    oy:     0,        # Adjust sprite Y position
    mirror: false,     # Mirror battler when facing right
    invert: false,    # Invert the battler graphic
    mode:   :charset,  # Graphic style (:sprite or :chasert)
    action: :charset, # Action settings
    # IMPORTANT: using the ox: and oy: value will make the battle animation to
    # be moved also, if you want to adjust the battler position without
    # changing the position of the animation, use the script 
    # 'VE - Animations Settings' together with the batte.
    
  # Main Poses
  # name:       row,
    idle:      1,   # Idle pose
    guard:     2,   # Guard pose
    evade:     10,   # Evade pose
    danger:    3,   # Low HP pose
    hurt:      4,   # Damage pose
    attack:    5,   # Physical attack pose
    use:       6,   # No type use pose
    item:      6,   # Item use pose
    skill:     7,   # Skill use pose
    magic:     8,   # Magic use pose
    advance:   9,   # Advance pose
    retreat:   10,  # Retreat pose
    escape:    10,  # Escape pose
    victory:   11,  # Victory pose
    intro:     12,  # Battle start pose
    dead:      13,  # Incapacited pose
    ready:     nil, # Ready pose
    itemcast:  nil, # Item cast pose
    skillcast: nil, # Skill cast pose
    magiccast: nil, # Magic cast pose
    command:   nil, # Command pose
    input:     nil, # Input pose
    cancel:    nil, # Cancel pose
    # You can add other pose names and call them within the action settings
    # use only lowcase letters
    # IMPORTANT: the ready, itemcast, skillcast, magiccast, command, input and
    # cancel poses are skiped if nil, no matter what you setup on the pose
    # setting, so even using charset mode you need to setup a value to turn
    # on these poses.
  } # Don't remove
  #--------------------------------------------------------------------------
  # * Custom sprite settings
  #   Theses settings are set individually based on the battler graphic
  #   filename (even if using the charset mode, the setting will be based
  #   on the battler name, so it's suggested to use the same name for
  #   the battler and charset graphic when using charset mode)
  #   Any value from the default setting can be used, if a value is not set
  #   it's automatically uses the value from basic setting
  #--------------------------------------------------------------------------
  VE_SPRITE_SETTINGS = {
  # 'Filename' => {settings},
  #
  # 'Sample 1' => {frames: 4, rows: 14, mirror: true, mode: :sprite,
  #                action: :default},
  # 'Sample 2' => {frames: 3, rows: 4, mirror: true, invert: false,
  #                mode: :charset, action: :charset},
  # 'Sample 3' => {frames: 3, rows: 4, mirror: false, invert: false,
  #                mode: :charset, action: :kaduki},
  # 'Sample 1' => {frames: 4, rows: 14, mirror: true, mode: :sprite,
  #                action: :default, oy: 20, evade: 1, skill: 4},
    'Holder'   => {frames: 4, rows: 14, mirror: true, mode: :sprite,
                   action: :default},
    'Charset'  => {frames: 3, rows: 4, mirror: false, invert: false,
                   mode: :charset, action: :charset},
    'Kaduki'   => {frames: 3, rows: 4, mirror: true, invert: false,
                   mode: :charset, action: :kaduki},
    'Valkyrie' => {frames: 4, rows: 14, mirror: false, invert: false, 
                   mode: :sprite, action: :default},
    'Shade' => {frames: 4, rows: 14, mirror: true, invert: false, 
                   mode: :sprite, action: :default},
    'Rat' => {frames: 4, rows: 14, mirror: true, invert: false, 
                   mode: :sprite, action: :default},
    'Bat' => {frames: 4, rows: 14, mirror: true, invert: false, 
                   mode: :sprite, action: :default},
    'Slimeling' => {frames: 4, rows: 14, mirror: true, invert: false, 
                   mode: :sprite, action: :default},
    'Slime' => {frames: 4, rows: 14, mirror: true, invert: false, 
                   mode: :sprite, action: :default},
    'BeeHive' => {frames: 4, rows: 14, mirror: false, invert: false, 
                   mode: :sprite, action: :default},
    'Bee' => {frames: 4, rows: 14, mirror: true, invert: false, 
                   mode: :sprite, action: :default},
    'Paladin' => {frames: 4, rows: 14, mirror: true, invert: false, 
                   mode: :sprite, action: :default},
    'DemonKnight' => {frames: 4, rows: 14, mirror: true, invert: false, 
                   mode: :sprite, action: :default},
    'DemonLord' => {frames: 4, rows: 14, mirror: true, invert: false, 
                   mode: :sprite, action: :default},
    'Celeste' => {frames: 4, rows: 14, mirror: false, invert: false, 
                   mode: :sprite, action: :default},
    'Riliane' => {frames: 4, rows: 14, mirror: false, invert: false, 
                   mode: :sprite, action: :default},
    'Gaia' => {frames: 4, rows: 14, mirror: false, invert: false, 
                   mode: :sprite, action: :default},
    '4thWall' => {frames: 4, rows: 14, mirror: false, invert: false, 
                   mode: :sprite, action: :default},
                   
                   
  } # Don't remove
  #--------------------------------------------------------------------------
  # * Settings Used For all battlers that doesn't have specific settings
  #--------------------------------------------------------------------------
  VE_DEFAULT_ACTION = "

    # Pose displayed for skip actions
    <action: do nothing, reset>
    </action>

    # Pose displayed when idle
    <action: idle, loop>
    pose: self, row idle, all frames, wait 12;
    wait: self, pose;
    </action>
  
    # Pose displayed when incapacited
    <action: dead, loop>
    pose: self, row dead, all frames, wait 16;
    wait: self, pose;
    </action>
  
    # Pose displayed when hp is low
    <action: danger, loop>
    pose: self, row danger, all frames, wait 12;
    wait: self, pose;
    </action>
  
    # Pose displayed when guarding
    <action: guard, loop>
    pose: self, row guard, all frames, wait 24;
    wait: self, pose;
    </action>
  
    # Pose displayed during the battle start
    <action: intro, reset>
    pose: self, row intro, all frames, wait 16;
    wait: self, pose;
    </action>
  
    # Pose displayed during battle victory
    <action: victory, wait>
    pose: self, row victory, all frames, wait 16;
    wait: self, pose;
    </action>
    
    # Pose displayed when escaping (for ATB)
    <action: escaping, loop>
    pose: self, row retreat, all frames, wait 4, loop;
    wait: self, pose;
    </action>
  
    # Pose displayed while waiting to perfom actions
    <action: ready, loop>
    pose: self, row ready, frame 1;
    wait: self, pose;
    </action>
    
    # Pose displayed while waiting to perfom item actions
    <action: item cast, loop>
    pose: self, row itemcast, frame 1;
    wait: self, pose;
    </action>
    
    # Pose displayed while waiting to perfom skill actions
    <action: skill cast, loop>
    pose: self, row skillcast, frame 1;
    wait: self, pose;
    </action>
    
    # Pose displayed while waiting to perfom magic actions
    <action: magic cast, loop>
    pose: self, row magiccast, frame 1;
    wait: self, pose;
    </action>
    
    # Pose displayed before inputing commands
    <action: command, reset>
    </action>
    
    # Pose displayed after inputing commands
    <action: input, reset>
    </action>
    
    # Pose displayed when cancel inputing commands
    <action: cancel, reset>
    </action>
    
    # Pose displayed when recive damage
    <action: hurt, reset>
    action: self, hurt pose;
    wait: 16;
    </action>
    
    # Pose displayed when hurt
    <action: hurt pose, reset>
    pose: self, row hurt, all frames, wait 4;
    </action>

    # Pose displayed when evading attacks
    <action: evade, reset>
    pose: self, row evade, all frames, wait 4;
    wait: 16;
    </action>
  
    # Pose displayed when a attack miss
    <action: miss, reset>
    </action>
    
    # Pose displayed when sleeping
    <action: sleeping, loop>
    pose: self, row dead, all frames, wait 12;
    #wait: self, pose;
    anim: id 121;
    </action>

    # Pose displayed when poisoned
    <action: poisoned, loop>
    pose: self, row danger, all frames, wait 12;
    #wait: self, pose;
    anim: id 120;
    </action>
    
    # Pose displayed when burning
    <action: burning, loop>
    pose: self, row danger, all frames, wait 20;
    #wait: self, pose;
    anim: id 125;
    </action>
    
    # Pose displayed when poisoned
    <action: stunned, loop>
    pose: self, row danger, all frames, wait 12;
    #wait: self, pose;
    anim: id 132;
    </action>
    
    # Pose displayed when reviving
    <action: revive, reset>
    </action>
  
    # Pose displayed when dying
    <action: die, reset>
    </action>
  
    # Make the target inactive (important, avoid change)
    <action: inactive>
    countered;
    wait: self, countered;
    inactive;
    </action>
  
    # Finish offensive action (important, avoid change)
    <action: finish>
    finish;
    </action>
    
    # Reset to idle after action (important, avoid change)
    <action: clear, reset>
    </action>

    # Pose displayed during move reset (important, avoid change)
    <action: reset, reset>
    pose: self, row idle, all frames, wait 8, loop;
    </action>
    
    # Pose for counter attack preparation (important, avoid change)
    <action: prepare counter, reset>
    wait: self, action;
    wait: targets, counter;
    </action>

    # Pose for counter attack activation (important, avoid change)
    <action: counter on, reset>
    counter: self, on;
    </action>
    
    # Pose for counter attack deactivation (important, avoid change)
    <action: counter off, reset>
    counter: targets, off;
    </action>
    
    # Pose for magic reflection (important, avoid change)
    <action: reflection, reset>
    wait: self, animation;
    wait: 4;
    anim: self, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: self, animation;
    </action>
    
    # Pose for substitution activation (important, avoid change)
    <action: substitution on, reset>
    pose: self, row advance, all frames, wait 4, loop;
    move: self, substitution, move over;
    wait: self, movement;
    </action>
    
    # Pose for substitution deactivation (important, avoid change)
    <action: substitution off, reset>
    pose: self, row advance, all frames, wait 4, loop;
    move: self, retreat, move over;
    wait: self, movement;
    </action>
    
    # Set action advance
    <action: advance, reset>
    action: self, move to target;
    wait: self, action;
    </action>
    
    # Movement to target
    <action: move to target, reset>
    wait: targets, movement;
    move: self, move to;
    direction: self, subjects;
    jump: self, move, height 7;
    pose: self, row advance, all frames, wait 4, loop;
    wait: self, movement;
    </action>
    
    # Step forward movement
    <action: step forward, reset>
    wait: targets, movement;
    move: self, step forward, speed 6;
    pose: self, row advance, all frames, wait 4, loop;
    wait: self, movement;
    </action>
    
    # Step backward movement
    <action: step backward, reset>
    move: self, step backward, speed 6;
    pose: self, row retreat, all frames, wait 4, invert, loop;
    wait: self, movement;
    </action>

    # Return to original spot
    <action: retreat, reset>
    move: self, retreat;
    pose: self, row retreat, all frames, wait 4, loop;
    jump: self, move, height 7;
    wait: self, movement;
    direction: self, default;
    </action>
    
    # Move outside of the screen
    <action: escape, reset>
    move: self, escape;
    pose: self, row retreat, all frames, wait 4, invert, loop;
    wait: self, movement;
    </action>
    
    # Move outside of the screen
    <action: escape enemy, reset>
    move: self, escape;
    pose: self, row retreat, all frames, wait 4, invert, loop;
    wait: self, movement;
    effect: self, targets, 100%; 
    </action>
    
    
    # Pose used for Defend command
    <action: defend, reset>
    pose: self, row guard, all frames, wait 8;
    wait: 4;
    anim: targets, effect;
    wait: 4;
    effect: self, targets, 100%;
    wait: 20;
    </action>
    
    # Pose for physical attacks
    <action: attack, reset>
    wait: targets, movement;
    pose: self, row attack, all frames, wait 4, y +1;
    wait: 4;
    anim: targets, weapon;
    wait: 8;
    effect: self, targets, 100%;
    wait: 20;
    </action>
    
    # Pose for physical attack with two weapons
    <action: dual attack, reset>
    wait: targets, movement;
    pose: self, row attack, all frames, wait 4, y +1;
    wait: 4;
    anim: targets, weapon 1;
    wait: 8;
    effect: self, targets 75%, weapon 1;
    wait: targets, animation;
    pose: self, row skill, all frames, wait 4, y +1;
    wait: 8;
    anim: targets, weapon 2;
    wait: 8;
    effect: self, targets 75%, weapon 2;
    wait: 20;
    </action>
        
    # Pose for using actions without type
    <action: use, reset>
    wait: targets, movement;
    pose: self, row item, all frames, wait 4;
    wait: 4;
    anim: targets, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: 20;
    </action>
    
    # Pose for magical skill use
    <action: magic, reset>
    wait: targets, movement;
    pose: self, row magic, all frames, wait 4;
    wait: 4;
    anim: targets, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: 20;
    </action>
    
    # Pose for physical skill use
    <action: skill, reset>
    wait: targets, movement;
    pose: self, row attack, all frames, wait 4;
    wait: 4;
    anim: targets, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: 20;
    </action>

    # Pose for item use 
    <action: item, reset>
    wait: targets, movement;
    pose: self, row item, all frames, wait 4;
    wait: 4;
    anim: targets, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: 20;
    </action>

    # Pose for the skill 'Dual Attack'
    <action: double attack skill, reset>
    wait: targets, movement;
    pose: self, row attack, all frames, wait 4, y +1;
    wait: 4;
    anim: targets, weapon;
    wait: 8;
    effect: self, targets 75%;
    wait: targets, animation;
    pose: self, row skill, all frames, wait 4, y +1;
    wait: 8;
    anim: targets, weapon;
    wait: 8;
    effect: self, targets 75%;
    wait: 20;
    </action>
    
    # Pose for the skill 'Dual Slice'
    <action: double slice skill, reset>
    wait: targets, movement;
    pose: self, row attack, all frames, wait 4, y +1;
    wait: 4;
    anim: targets, id 7;
    wait: 8;
    effect: self, targets 75%;
    wait: targets, animation;
    pose: self, row skill, all frames, wait 4, y +1;
    wait: 8;
    anim: targets, id 122;
    wait: 8;
    effect: self, targets 75%;
    wait: 20;
    </action>
    
    # Pose for the skill 'Fury Cutter'
    <action: fury cutter, reset>
    wait: targets, movement;
    pose: self, row attack, all frames, wait 4 , loop;
    wait: 4;
    anim: targets, id 113;
    effect: self, targets 100%;
    wait: targets, animation;
    wait: 10;
    </action>
    
    # Pose for the skills 'Life Drain' and 'Manda Drain'
    <action: drain, reset>
    wait: targets, movement;
    wait: animation;
    pose: self, row magic, all frames, wait 4;
    wait: 4;
    anim: targets, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: 20;
    action: targets, user drain;
    wait: targets, action;
    </action>

    # Pose for the targets of the skills 'Life Drain' and 'Manda Drain'
    <action: user drain, reset>
    throw: self, user, icon 187, return, revert, init y -12, end y -12;
    wait: self, throw;
    drain: active;
    </action>    
    
    # Pose for the sample skill 'Throw Weapon'
    <action: throw weapon, reset>
    wait: targets, movement;
    pose: self, row attack, all frames, wait 4;
    action: targets, target throw;
    wait: targets, action;
    wait: 20;
    </action>
    
    # Pose for the targets of the sample skill 'Throw Weapon'
    <action: target throw, reset>
    throw: self, user, weapon, arc 12, spin +45, init y -12, end y -12;
    wait: self, throw;
    throw: self, user, weapon, arc 12, spin +45, return, revert, init y -12, end y -12;
    anim: self, weapon;
    wait: 8;
    effect: active, targets, 100%, clear;
    wait: self, throw;
    </action>
    
    # Pose for the sample skill 'Lightning Strike'
    <action: lightning strike, 5 times>
    direction: self, subjects;
    clear: targets, damage;
    move: targets, retreat, teleport;
    pose: self, row attack, frame 1, all frames, wait 2;
    move: self, x -48, speed 50;
    anim: targets, effect;
    effect: self, targets 30%;
    </action>
    
    # Pose for the sample skill 'Tempest'
    <action: tempest, reset>
    wait: targets, movement;
    pose: self, row magic, all frames, wait 4;
    wait: 4;
    tone: black, high priority, duration 20;
    wait: tone;
    movie: name 'Tempest', white, high priority;
    tone: clear, high priority, duration 20;
    wait: 15;
    anim: targets, effect;
    flash: screen, duration 10; 
    effect: self, targets, 100%;
    wait: 20;
    </action>
    
    # Pose for the sample skill 'Meteor'
    <action: meteor, reset>
    wait: targets, movement;
    pose: self, row magic, all frames, wait 4;
    wait: 4;
    tone: black, high priority, duration 20;
    wait: tone;
    movie: name 'Meteor';
    tone: clear, high priority, duration 20;
    anim: targets, effect;
    wait: 20;
    effect: self, targets, 100%;
    wait: 20;
    </action>
    
    # Pose for that attack
    <action: that, reset>
    wait: targets, movement;
    pose: self, row magic, all frames, wait 4;
    wait: 4;
    tone: black, high priority, duration 20;
    wait: tone;
    tone: clear, high priority, duration 20;
    anim: targets, effect;
    wait: 200;
    effect: self, targets, 100%;
    wait: 20;
    </action>
    
    # Pose for 'Bow' type weapons
    <action: bow, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row attack, all frames, wait 4;
    action: targets, arrow;
    wait: targets, action;
    wait: 20;
    </action>
    
    # Pose for the targets of 'Bow' attack
    <action: arrow, reset>
    throw: self, user, image 'Arrow', arc 10, angle 45, init x -6, init y -12;
    wait: self, throw;
    anim: self, weapon;
    wait: 8;
    effect: active, targets, 100%;
    </action>

    # Pose for the skill 'Multi Attack'
    <action: multi attack, opponents_unit.targetable_members.size times>
    wait: next;
    move: self, move to front;
    pose: self, row advance, all frames, wait 4, loop;
    wait: self, movement;
    direction: self, subjects;
    pose: self, row attack, all frames, wait 4;
    wait: 4;
    anim: last, effect, clear;
    wait: 8;
    effect: self, last, 100%;
    wait: 20;
    </action>
    
    # Pose for the skill 'Aura Spell'
    <action: aura spell, reset>
    wait: targets, movement;
    action: self, step forward;
    direction: self, subjects;
    pose: self, row magic, all frames, wait 4;
    action: aura effect;
    wait: action
    action: self, step backward;
    </action>

    <action: aura effect, friends_unit.targetable_members.size times>
    wait: next;
    anim: last, effect;
    wait: 4;
    effect: self, last, 100%;
    wait: last, animation;
    </action>
    
    "
  #--------------------------------------------------------------------------
  # * Sample settings used for battlers tagged as 'charset'
  #--------------------------------------------------------------------------
  VE_ACTION_SETTINGS[:charset] = "

    # Pose displayed for skip actions
    <action: do nothing, reset>
    </action>

    # Pose displayed when idle
    <action: idle, loop>
    pose: self, row direction, frame 2;
    wait: pose;
    </action>
  
    # Pose displayed when incapacited
    <action: dead, loop>
    pose: self, row 4, frame 2, angle -90, x -16, y -12;
    wait: pose;
    </action>
  
    # Pose displayed when hp is low
    <action: danger, loop>
    pose: self, row direction, frame 2;
    wait: pose;
    </action>
  
    # Pose displayed when guarding
    <action: guard, loop>
    icon: self, shield, y +8, above;
    pose: self, row direction, frame 1;
    wait: 16;
    </action>
  
    # Pose displayed during the battle start
    <action: intro, reset>
    pose: self, row direction, frame 2;
    wait: 64;
    </action>
  
    # Pose displayed during battle victory
    <action: victory, wait>
    pose: self, row 2, frame 2;
    wait: 2;
    pose: self, row 4, frame 2;
    wait: 2;
    pose: self, row 3, frame 2;
    wait: 2;
    pose: self, row 1, frame 2;
    wait: 2;
    pose: self, row 2, frame 2;
    wait: 2;
    pose: self, row 4, frame 2;
    wait: 2;
    pose: self, row 3, frame 2;
    wait: 2;
    pose: self, row 1, frame 2;
    wait: 2;
    jump: self, height 8, speed 8;
    wait: 10
    </action>
  
    # Pose displayed when escaping (for ATB)
    <action: escaping, loop>
    pose: self, row direction, all frames, return, wait 4, loop, invert;
    wait: pose;
    </action>
    
    # Pose displayed while waiting to perfom actions
    <action: ready, loop>
    pose: self, row direction, all frames, return, wait 8;
    wait: pose;
    </action>
    
    # Pose displayed while waiting to perfom item actions
    <action: item cast, loop>
    pose: self, row direction, all frames, return, wait 8;
    wait: pose;
    </action>
    
    # Pose displayed while waiting to perfom skill actions
    <action: skill cast, loop>
    pose: self, row direction, all frames, return, wait 8;
    wait: pose;
    </action>
    
    # Pose displayed while waiting to perfom magic actions
    <action: magic cast, loop>
    pose: self, row direction, all frames, return, wait 8;
    wait: pose;
    </action>
    
    # Pose displayed before inputing commands
    <action: command, reset>
    action: self, step forward;
    wait: action;
    </action>
    
    # Pose displayed after inputing commands
    <action: input, reset>
    action: self, step backward;
    wait: action;
    </action>
    
    # Pose displayed when cancel inputing commands
    <action: cancel, reset>
    action: self, step backward;
    wait: action;
    </action>
    
    # Pose displayed when recive damage
    <action: hurt, reset>
    direction: self, active;
    pose: self, row direction, all frames, wait 4, return;
    move: self, step backward, speed 4;
    wait: self, movement;
    pose: self, row direction, frame 2;
    wait: 4;
    pose: self, row direction, all frames, wait 4, return;
    move: self, step forward, speed 5;
    wait: self, movement;
    direction: self, default;
    </action>
    
    # Pose displayed when hurt
    <action: hurt pose, reset>
    pose: self, row direction, frame 1;
    </action>
    
    # Pose displayed when evading attacks
    <action: evade, reset>
    direction: self, active;
    pose: self, row 1, frame 2;
    move: self, step backward, speed 4;
    jump: self, move;
    wait: self, movement;
    pose: self, row direction, frame 2;
    wait: 4;
    pose: self, row direction, all frames, wait 4, return;
    move: self, step forward, speed 5;
    wait: self, movement;
    direction: self, default;
    </action>
  
    # Pose displayed when a attack miss
    <action: miss, reset>
    </action>
    
    # Pose displayed when sleeping
    <action: sleeping, reset>
    </action>
  
    # Pose displayed when reviving
    <action: revive, reset>
    </action>
  
    # Pose displayed when dying
    <action: die, reset>
    </action>
  
    # Make the target inactive (important, avoid change)
    <action: inactive>
    countered;
    wait: self, countered;
    inactive;
    </action>
  
    # Finish offensive action (important, avoid change)
    <action: finish>
    finish;
    </action>

    # Reset to idle after action (important, avoid change)
    <action: clear, reset>
    </action>
    
    # Pose displayed during move reset (important, avoid change)
    <action: reset, reset>
    pose: self, row direction, frame 2, loop;
    </action>
    
    # Pose for counter attack preparation (important, avoid change)
    <action: prepare counter, reset>
    wait: self, action;
    </action>

    # Pose for counter attack deactivation (important, avoid change)
    <action: counter on, reset>
    counter: self, on;
    wait: counter;
    </action>

    # Pose for counter attack activation (important, avoid change)
    <action: counter off, reset>
    counter: targets, off;
    </action>

    # Pose for magic reflection (important, avoid change)
    <action: reflection, reset>
    wait: animation;
    wait: 4;
    anim: self, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: animation;
    </action>
    
    # Pose for substitution activation (important, avoid change)
    <action: substitution on, reset>
    pose: self, row direction, all frames, return, wait 4, loop;
    move: self, substitution, move over;
    wait: self, movement;
    </action>
    
    # Pose for substitution deactivation (important, avoid change)
    <action: substitution off, reset>
    pose: self, row direction, all frames, return, wait 4, loop;
    move: self, retreat, move over;
    wait: self, movement;
    </action>

    # Set action advance
    <action: advance, reset>
    action: self, move to target;
    wait: action;
    </action>
    
    # Movement to target
    <action: move to target, reset>
    wait: targets, movement;
    move: self, move to;
    direction: self, subjects;
    pose: self, row direction, all frames, return, wait 4, loop;
    wait: self, movement;
    </action>
    
    # Step forward movement
    <action: step forward, reset>
    wait: targets, movement;
    move: self, step forward, speed 6;
    pose: self, row direction, all frames, return, wait 4, loop;
    wait: self, movement;
    </action>

    # Step backward movement
    <action: step backward, reset>
    move: self, step backward, speed 6;
    pose: self, row direction, all frames, return, wait 4, loop;
    wait: self, movement;
    </action>

    # Return to original spot
    <action: retreat, reset>
    direction: self, return;
    move: self, retreat;
    pose: self, row direction, all frames, return, wait 4, loop;
    wait: self, movement;
    direction: self, default;
    </action>
    
    # Move outside of the screen
    <action: escape, reset>
    move: self, escape;
    pose: self, row direction, all frames, return, wait 4, loop;
    wait: self, movement;
    </action>
    
    # Pose used for Defend command
    <action: defend, reset>
    pose: self, row direction, all frames, wait 2, y +1;
    wait: 4;
    anim: targets, effect;
    wait: 4;
    effect: self, targets, 100%;
    wait: 20;
    wait: pose;
    </action>
    
    # Pose for physical attacks
    <action: attack, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row direction, all frames, wait 2, y +1;
    icon: self, weapon, angle -90, x +12, y -16;
    icon: self, weapon, angle -45, x +6, y -16;
    icon: self, weapon, angle 0, x -6;
    anim: targets, weapon;
    icon: self, weapon, angle 45, x -10, y +8;
    effect: self, targets, 100%;
    wait: 20;
    icon: self, delete;
    </action>
    
    # Pose for physical attack with two weapons
    <action: dual attack, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row direction, all frames, wait 2, y +1;
    icon: self, weapon, angle -90, x +12, y -16;
    icon: self, weapon, angle -45, x +6, y -16;
    icon: self, weapon, angle 0, x -6;
    anim: targets, weapon;
    icon: self, weapon, angle 45, x -10, y +8;
    effect: self, targets 75%, weapon;
    wait: targets, animation;
    icon: self, delete;
    direction: self, subjects;
    pose: self, row direction, all frames, wait 2, revert, y +1;
    icon: self, weapon 2, angle -90, x +12, y -16;
    icon: self, weapon 2, angle -45, x +6, y -16;
    icon: self, weapon 2, angle 0;
    anim: targets, weapon;
    icon: self, weapon 2, angle 45, x -6, y +8;
    effect: self, targets 75%, weapon 2;
    wait: 20;
    icon: self, delete;
    </action>
    
    # Pose for using actions without type
    <action: use, reset>
    wait: targets, movement;
    action: self, step forward;
    pose: self, row direction, all frames, wait 4;
    wait: 4;
    anim: targets, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: 20;
    action: self, step backward;
    </action>
    
    # Pose for magical skill use
    <action: magic, reset>
    wait: targets, movement;
    action: self, step forward;
    wait: self, action;
    direction: self, subjects;
    pose: self, row direction, all frames, wait 4;
    wait: 4;
    anim: targets, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: 20;
    action: self, step backward;
    </action>
    
    # Pose for physical skill use
    <action: skill, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row direction, all frames, wait 2;
    icon: self, weapon, angle -90, x +12, y -16;
    icon: self, weapon, angle -45, x +6, y -16;
    icon: self, weapon, angle 0, x -6;
    anim: targets, effect;
    icon: self, weapon, angle 45, x -10, y +8;
    effect: self, targets, 100%;
    wait: 20;
    icon: self, delete;
    </action>
    
    # Pose for item use
    <action: item, reset>
    wait: targets, movement;
    action: self, step forward;
    wait: self, action;
    wait: 10;
    pose: self, row direction, frame 1;
    icon: action, x -8, above;
    wait: 4;
    pose: self, row direction, frame 2;
    icon: action, x -4, y -4, above;
    wait: 4;
    pose: self, row direction, frame 3;
    icon: action, y -8, above;
    wait: 4;
    pose: self, row direction, frame 2;
    icon: action, y -8, x +4, above;
    wait: 12;
    icon: self, delete;
    pose: self, row direction, frame 1;
    throw: targets, self, action, arc 10, init y -8;
    wait: targets, throw;
    anim: targets, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: 20;
    action: self, step backward;
    </action>

    # Pose for the skill 'Dual Attack'
    <action: dual attack skill, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row direction, all frames, wait 2, y +1;
    icon: self, weapon, angle -90, x +12, y -16;
    icon: self, weapon, angle -45, x +6, y -16;
    icon: self, weapon, angle 0, x -6;
    anim: targets, effect;
    icon: self, weapon, angle 45, x -10, y +8;
    effect: self, targets, 100%;
    wait: targets, animation;
    icon: self, delete;
    direction: self, subjects;
    pose: self, row direction, all frames, wait 2, revert, y +1;
    icon: self, weapon, angle -90, x +12, y -16;
    icon: self, weapon, angle -45, x +6, y -16;
    icon: self, weapon, angle 0;
    anim: targets, effect;
    icon: self, weapon, angle 45, x -6, y +8;
    effect: self, targets, 100%;
    wait: 20;
    icon: self, delete;
    </action>
    
    # Pose for the skills 'Life Drain' and 'Mana Drain'
    <action: drain, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row direction, all frames, wait 4;
    wait: 4;
    anim: targets, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: 20;
    action: targets, user drain;
    wait: targets, action;
    </action>

    # Pose for the targets of the skills 'Life Drain' and 'Mana Drain
    <action: user drain, reset>
    throw: self, user, icon 187, return, revert, init y -12, end y -12;
    wait: self, throw;
    drain: active;
    </action>    
    
    # Pose for the sample skill 'Throw Weapon'
    <action: throw weapon, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row direction, frame 1;
    pose: self, row direction, frame 2;
    action: targets, target throw;
    pose: self, row direction, frame 3;
    wait: targets, action;
    </action>
    
    # Pose for the targets of the sample skill 'Throw Weapon'
    <action: target throw, reset>
    throw: self, user, weapon, arc 12, spin +45, init y -12, end y -12;
    wait: self, throw;
    throw: self, user, weapon, arc 12, spin +45, return, revert, init y -12, end y -12;
    anim: self, weapon;
    wait: 8;
    effect: active, targets, 100%, clear;
    wait: self, throw;
    wait: animation;
    </action>
    
    # Pose for the sample skill 'Lightning Strike'
    <action: lightning strike, 5 times>
    direction: self, subjects;
    clear: targets, damage;
    move: targets, retreat, teleport;
    pose: self, row direction, frame 3, y +1;
    move: self, x -48, speed 50;
    icon: self, weapon, angle 45, x -12, y +8;
    anim: targets, effect;
    effect: self, targets 30%;
    icon: self, delete;
    </action>
    
    # Pose for the sample skill 'Tempest'
    <action: tempest, reset>
    wait: targets, movement;
    wait: animation;
    pose: self, row direction, all frames, wait 4;
    wait: 4;
    tone: black, high priority, duration 20;
    wait: tone;
    movie: name 'Tempest', white, high priority;
    tone: clear, high priority, duration 20;
    wait: 15;
    anim: targets, effect;
    flash: screen, duration 10; 
    effect: self, targets, 100%;
    wait: 20;
    </action>
    
    # Pose for the sample skill 'Meteor'
    <action: meteor, reset>
    wait: targets, movement;
    wait: animation;
    pose: self, row direction, all frames, wait 4;
    wait: 4;
    tone: black, high priority, duration 20;
    wait: tone;
    movie: name 'Meteor';
    tone: clear, high priority, duration 20;
    anim: targets, effect;
    wait: 20;
    effect: self, targets, 100%;
    wait: 20;
    </action>
    
    # Pose for that attack
    <action: bigbang, reset>
    wait: targets, movement;
    wait: animation;
    pose: self, row direction, all frames, wait 4;
    wait: 4;
    tone: black, high priority, duration 20;
    wait: tone;
    tone: clear, high priority, duration 20;
    anim: targets, effect;
    wait: 20;
    effect: self, targets, 100%;
    wait: 200;
    </action>
    
    
    # Pose for 'Claw' type weapons
    <action: claw, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row direction, all frames, wait 3, y +1;
    icon: self, weapon, angle -45, x +16, y -16;
    icon: self, weapon, angle -30, x +10, y -16;
    icon: self, weapon, angle -15, x -2;
    anim: targets, weapon;
    icon: self, weapon, angle 0, x -6, y +8;
    effect: self, targets, 100%;
    wait: 20;
    icon: self, delete;
    </action>
    
    # Pose for 'Spear' type weapons
    <action: spear, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row direction, all frames, wait 3, y +1;
    icon: self, weapon, angle 45, x +12, y +8;
    icon: self, weapon, angle 45, x +12, y +8;
    icon: self, weapon, angle 45, x 0, y +8;
    anim: targets, weapon;
    icon: self, weapon, angle 45, x -12, y +8;
    effect: self, targets, 100%;
    wait: 20;
    icon: self, delete;
    </action>
    
    # Pose for 'Gun' type weapons
    <action: gun, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row direction, all frames, wait 3;
    icon: self, weapon, angle -135, x +12, y -16;
    icon: self, weapon, angle -105, x +6, y -10;
    icon: self, weapon, angle -75, x 0, y -2;
    icon: self, weapon, angle -45, x -6, y +4;
    wait: 30;
    sound: name 'Gun1';
    pose: self, row direction, frame 3;
    icon: self, weapon, angle -75, x 0, y -2;
    pose: self, row direction, frame 2;
    icon: self, weapon, angle -105, x +6, y -10;
    pose: self, row direction, frame 1;
    anim: targets, weapon;
    icon: self, weapon, angle -135, x +12, y -16;
    effect: self, targets, 100%;
    wait: 20;
    icon: self, delete;
    </action>
    
    # Pose for 'Bow' type weapons
    <action: bow, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row 2, all frames, sufix _3, wait 4;
    icon: self, image 'Bow1', x +6, above;
    icon: self, image 'Bow2', x +6, above;
    icon: self, image 'Bow3', x +6, above;
    wait: 10;
    action: targets, arrow;
    icon: self, image 'Bow2', x +6, above;
    icon: self, image 'Bow1', x +6, above;
    wait: self, action;
    </action>

    # Pose for the targets of 'Bow' attack
    <action: arrow, reset>
    throw: self, user, image 'Arrow', arc 10, angle 45, init x -6, init y -12;
    wait: self, throw;
    anim: self, weapon;
    wait: 8;
    effect: active, targets, 100%;
    </action>

    # Pose for the skill 'Multi Attack'
    <action: multi attack, opponents_unit.targetable_members.size times>
    target: next;
    move: self, move to front;
    pose: self, row direction, all frames, return, wait 4, loop;
    wait: self, movement;
    direction: self, subjects;
    pose: self, row direction, all frames, wait 2, y +1;
    icon: self, weapon, angle -90, x +12, y -16;
    icon: self, weapon, angle -45, x +6, y -16;
    icon: self, weapon, angle 0, x -6;
    anim: last, effect;
    icon: self, weapon, angle 45, x -10, y +8;
    effect: self, last, 100%, clear;
    wait: 20;
    icon: self, delete;
    </action>
    
    # Pose for the skill 'Aura Spell'
    <action: aura spell, reset>
    wait: targets, movement;
    wait: animation;
    action: self, step forward;
    wait: self, action;
    direction: self, subjects;
    pose: self, row direction, all frames, wait 4;
    action: aura effect;
    wait: action
    action: self, step backward;
    </action>

    <action: aura effect, friends_unit.targetable_members.size times>
    wait: next;
    anim: last, effect;
    wait: 4;
    effect: self, last, 100%;
    wait: last, animation;
    </action>
    
    "
  #--------------------------------------------------------------------------
  # * Sample settings used for battlers tagged as 'kaduki' style
  #--------------------------------------------------------------------------
  VE_ACTION_SETTINGS[:kaduki] = "

    # Pose displayed for skip actions
    <action: do nothing, reset>
    </action>

    # Pose displayed when idle
    <action: idle, loop>
    pose: self, row 1, all frames, sufix _1, return, wait 16;
    wait: pose;
    </action>

    # Pose displayed when incapacited
    <action: dead, loop>
    pose: self, row 4, all frames, sufix _2, return, wait 8;
    wait: pose;
    </action>
  
    # Pose displayed when hp is low
    <action: danger, loop>
    pose: self, row 3, all frames, sufix _1, return, wait 16;
    wait: pose;
    </action>
  
    # Pose displayed when guarding
    <action: guard, loop>
    icon: self, shield, y +8, above;
    pose: self, row 4, frame 3, sufix _1;
    wait: 16;
    </action>
  
    # Pose displayed during the battle start
    <action: intro, reset>
    pose: self, row 1, frame 2, sufix _1;
    wait: 12;
    </action>
  
    # Pose displayed during battle victory
    <action: victory, wait>
    pose: self, row 1, all frames, sufix _2, wait 8;
    wait: pose;
    </action>
  
    # Pose displayed when escaping (for ATB)
    <action: escaping, loop>
    pose: self, row 4, all frames, sufix _1, return, loop, wait 8, invert;
    wait: pose;
    </action>

    # Pose displayed while waiting to perfom actions
    <action: ready, loop>
    pose: self, row 1, frame 2, sufix _1;
    wait: pose;
    </action>
    
    # Pose displayed while waiting to perfom item actions
    <action: item cast, loop>
    pose: self, row 1, frame 2, sufix _1;
    wait: pose;
    </action>
    
    # Pose displayed while waiting to perfom skill actions
    <action: skill cast, loop>
    pose: self, row 1, frame 2, sufix _1;
    wait: pose;
    </action>
    
    # Pose displayed while waiting to perfom magic actions
    <action: magic cast, loop>
    pose: self, row 4, all frames, sufix _3, loop, wait 8;
    wait: pose;
    </action>
    
    # Pose displayed before inputing commands
    <action: command, reset>
    action: self, step forward;
    wait: self, action;
    </action>
    
    # Pose displayed after inputing commands
    <action: input, reset>
    action: self, step backward;
    wait: self, action;
    </action>
    
    # Pose displayed when cancel inputing commands
    <action: cancel, reset>
    action: self, step backward;
    wait: self, action;
    </action>
        
    # Pose displayed when recive damage
    <action: hurt, reset>
    pose: self, row 2, all frames, sufix _1, wait 4;
    move: self, step backward, speed 4;
    wait: self, movement;
    pose: self, row direction, frame 2;
    wait: 4;
    pose: self, row 4, all frames, wait 4, return, sufix _1;
    move: self, step forward, speed 5;
    wait: self, movement;
    </action>
     
    # Pose displayed when hurt
    <action: hurt pose, reset>
    pose: self, row 2, frame 1, sufix _1;
    </action>

    # Pose displayed when evading attacks
    <action: evade, reset>
    pose: self, row 2, sufix _2, all frames, wait 4;
    move: self, step backward, speed 4;
    jump: self, move;
    wait: self, movement;
    pose: self, row 1, frame 2, sufix _2;
    wait: 4;
    pose: self, row 4, all frames, wait 4, return, sufix _1;
    move: self, step forward, speed 5;
    wait: self, movement;
    </action>
  
    # Pose displayed when a attack miss
    <action: miss, reset>
    </action>
  
    # Pose displayed when reviving
    <action: revive, reset>
    </action>
  
    # Pose displayed when dying
    <action: die, reset>
    </action>
    
    # Make the target inactive (important, avoid change)
    <action: inactive>
    countered;
    wait: self, counter;
    inactive;
    </action>
  
    # Finish offensive action (important, avoid change)
    <action: finish>
    finish;
    </action>
    
    # Reset to idle after action (important, avoid change)
    <action: clear, reset>
    </action>

    # Pose displayed during move reset (important, avoid change)
    <action: reset, reset>
    pose: self, row 1, all frames, sufix _1, return, wait 16, loop;
    </action>
    
    # Pose for counter attack preparation (important, avoid change)
    <action: prepare counter, reset>
    wait: self, action;
    wait: targets, countered;
    </action>
    
    # Pose for counter attack deactivation (important, avoid change)
    <action: counter off, reset>
    counter: targets;
    </action>
    
    # Pose for magic reflection (important, avoid change)
    <action: reflection, reset>
    wait: animation;
    wait: 4;
    anim: self, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: animation;
    </action>
    
    # Pose for substitution activation (important, avoid change)
    <action: substitution on, reset>
    pose: self, row 4, all frames, sufix _1, return, wait 8, loop;
    move: self, substitution, move over;
    wait: self, movement;
    </action>
    
    # Pose for substitution deactivation (important, avoid change)
    <action: substitution off, reset>
    pose: self, row 4, all frames, sufix _1, return, wait 8, loop;
    move: self, retreat, move over;
    wait: self, movement;
    </action>
    
    # Set action advance
    <action: advance, reset>
    action: self, move to target;
    wait: action;
    </action>
    
    # Movement to target
    <action: move to target, reset>
    wait: targets, movement;
    wait: animation;
    move: self, move to;
    direction: self, subjects;
    pose: self, row 4, all frames, sufix _1, return, wait 8, loop;
    wait: self, movement;
    </action>
    
    # Step forward movement
    <action: step forward, reset>
    wait: targets, movement;
    move: self, step forward, speed 6;
    pose: self, row 4, all frames, sufix _1, return, wait 8, loop;
    wait: self, movement;
    </action>

    # Step backward movement
    <action: step backward, reset>
    wait: animation;
    move: self, step backward, speed 6;
    pose: self, row 4, all frames, sufix _1, return, wait 8, loop;
    </action>
    
    # Return to original spot
    <action: retreat, reset>
    direction: self, return;
    move: self, retreat;
    pose: self, row 4, all frames, sufix _1, return, loop, wait 8;
    wait: self, movement;
    direction: self, default;
    </action>
    
    # Move outside of the screen
    <action: escape, reset>
    move: self, escape;
    pose: self, row 4, all frames, sufix _1, return, loop, wait 8, invert;
    wait: self, movement;
    </action>
    
    # Pose used for Defend command
    <action: defend, reset>
    pose: self, row 4, frame 2, sufix _1;
    icon: self, shield, y +8, above;
    pose: self, row 4, frame 3, sufix _1;
    wait: 4;
    anim: targets, effect;
    wait: 4;
    effect: self, targets, 100%;
    wait: 20;
    </action>
    
    # Pose for physical attacks
    <action: attack, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row 1, all frames, sufix _3, wait 3, y +1;
    icon: self, weapon, angle -90, x +12, y -16;
    icon: self, weapon, angle -45, x +6, y -16;
    icon: self, weapon, angle 0, x -6;
    anim: targets, weapon;
    icon: self, weapon, angle 45, x -10, y +8;
    effect: self, targets, 100%;
    wait: 20;
    icon: self, delete;
    </action>
    
    # Pose for physical attack with two weapons
    <action: dual attack, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row 1, all frames, sufix _3, wait 3, y +1;
    icon: self, weapon, angle -180, x +12, y -16;
    icon: self, weapon, angle -135, x +12, y -16;
    icon: self, weapon, angle -90, x +12, y -16;
    icon: self, weapon, angle -45, x +6, y -16;
    icon: self, weapon, angle 0, x -6;
    anim: targets, weapon 1;
    icon: self, weapon, angle 45, x -10, y +8;
    effect: self, targets 75%, weapon 1;
    wait: targets, animation;
    icon: self, delete;
    direction: self, subjects;
    pose: self, row 1, all frames, sufix _3, wait 3, y +1;
    icon: self, weapon 2, angle -180, x +12, y -16;
    icon: self, weapon 2, angle -135, x +12, y -16;
    icon: self, weapon 2, angle -90, x +12, y -16;
    icon: self, weapon 2, angle -45, x +6, y -16;
    icon: self, weapon 2, angle 0;
    anim: targets, weapon 2;
    icon: self, weapon 2, angle 45, x -6, y +8;
    effect: self, targets 75%, weapon 2;
    wait: 20;
    icon: self, delete;
    </action>
    
    # Pose for using actions without type
    <action: use, reset>
    wait: targets, movement;
    action: self, step forward;
    wait: self, action;
    pose: self, row 2, all frames, sufix _3, wait 3;
    wait: 4;
    anim: targets, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: 20;
    action: self, step backward;
    </action>
    
    # Pose for magical skill use
    <action: magic, reset>
    wait: targets, movement;
    action: self, step forward;
    wait: self, action;
    direction: self, subjects;
    pose: self, row 3, all frames, sufix _3, wait 3;
    anim: targets, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: 20;
    action: self, step backward;
    </action>

    # Pose for physical skill use
    <action: skill, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row 1, all frames, sufix _3, wait 3, y +1;
    icon: self, weapon, angle -90, x +12, y -16;
    icon: self, weapon, angle -45, x +6, y -16;
    icon: self, weapon, angle 0, x -6;
    anim: targets, effect;
    icon: self, weapon, angle 45, x -10, y +8;
    effect: self, targets, 100%;
    wait: 20;
    icon: self, delete;
    </action>

    # Pose for item use
    <action: item, reset>
    wait: targets, movement;
    action: self, step forward;
    wait: 10;
    pose: self, row 2, all frames, sufix _3, wait 3;
    icon: self, action, x -8, above;
    wait: 4;
    icon: self, action, x -4, y -4, above;
    wait: 4;
    icon: self, action, y -8, above;
    wait: 4;
    icon: self, action, y -8, x +4, above;
    wait: 12;
    pose: self, row 1, all frames, sufix _3, wait 2;
    icon: self, delete;
    throw: targets, self, action, arc 10, init y -8;
    wait: targets, throw;
    anim: targets, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: 20;
    action: self, step backward;
    </action>

    # Pose for the skill 'Dual Attack'
    <action: dual attack skill, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row 1, all frames, sufix _3, wait 3, y +1;
    icon: self, weapon, angle -180, x +12, y -16;
    icon: self, weapon, angle -135, x +12, y -16;
    icon: self, weapon, angle -90, x +12, y -16;
    icon: self, weapon, angle -45, x +6, y -16;
    icon: self, weapon, angle 0, x -6;
    anim: targets, id 7;
    icon: self, weapon, angle 45, x -10, y +8;
    effect: self, targets, 100%;
    wait: targets, animation;
    wait: self, animation;
    icon: self, delete;
    direction: self, subjects;
    pose: self, row 1, all frames, sufix _3, wait 3, y +1;
    icon: self, weapon, angle -180, x +12, y -16;
    icon: self, weapon, angle -135, x +12, y -16;
    icon: self, weapon, angle -90, x +12, y -16;
    icon: self, weapon, angle -45, x +6, y -16;
    icon: self, weapon, angle 0;
    anim: targets, id 7;
    icon: self, weapon, angle 45, x -6, y +8;
    effect: self, targets, 100%;
    wait: 20;
    icon: self, delete;
    </action>
    
    
    # Pose for the skills 'Life Drain' and 'Manda Drain'
    <action: drain, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row 3, all frames, sufix _3, wait 3;
    wait: 4;
    anim: targets, effect;
    wait: 8;
    effect: self, targets, 100%;
    wait: 20;
    action: targets, user drain;
    wait: action;
    </action>

    # Pose for the targets of the skills 'Life Drain' and 'Manda Drain'
    <action: user drain, reset>
    throw: self, user, icon 187, return, revert, init y -12, end y -12;
    wait: self, throw;
    drain: active;
    </action>    

    # Pose for the sample skill 'Throw Weapon'
    <action: throw weapon, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row 1, all frames, sufix _3, wait 3;
    wait: 4;
    action: targets, target throw;
    wait: targets, action;
    </action>
    
    # Pose for the targets of the sample skill 'Throw Weapon'
    <action: target throw, reset>
    throw: self, user, weapon, arc 12, spin +45, init y -12, end y -12;
    wait: self, throw;
    throw: self, user, weapon, arc 12, spin +45, return, revert, init y -12, end y -12;
    anim: self, weapon;
    wait: 8;
    effect: active, targets, 100%, clear;
    wait: self, throw;
    wait: self, animation;
    </action>
    
    # Pose for the sample skill 'Lightning Strike'
    <action: lightning strike, 5 times>
    direction: self, subjects;
    clear: targets, damage;
    move: targets, retreat, teleport;
    pose: self, row 1, frame 3, sufix _3, y +1;
    move: self, x -48, speed 50;
    icon: self, weapon, angle 45, x -12, y +8;
    anim: targets, effect;
    effect: self, targets 30%;
    icon: self, delete;
    </action>
    
    # Pose for the sample skill 'Tempest'
    <action: tempest, reset>
    wait: targets, movement;
    pose: self, row 3, all frames, sufix _3, wait 3;
    wait: 4;
    tone: black, high priority, duration 20;
    wait: tone;
    movie: name 'Tempest', white, high priority;
    tone: clear, high priority, duration 20;
    wait: 15;
    anim: targets, effect;
    flash: screen, duration 10; 
    effect: self, targets, 100%;
    wait: 20;
    </action>
    
    # Pose for the sample skill 'Meteor'
    <action: meteor, reset>
    wait: targets, movement;
    pose: self, row 3, all frames, sufix _3, wait 3;
    wait: 4;
    tone: black, high priority, duration 20;
    wait: tone;
    movie: name 'Meteor';
    tone: clear, high priority, duration 20;
    anim: targets, effect;
    wait: 20;
    effect: self, targets, 100%;
    wait: 20;
    </action>
    
    # Pose for 'Claw' type weapons
    <action: claw, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row 1, all frames, sufix _3, wait 3, y +1;
    icon: self, weapon, angle -45, x +16, y -16;
    icon: self, weapon, angle -30, x +10, y -16;
    icon: self, weapon, angle -15, x -2;
    anim: targets, weapon;
    icon: self, weapon, angle 0, x -6, y +8;
    effect: self, targets, 100%;
    wait: 20;
    icon: self, delete;
    </action>
    
    # Pose for 'Spear' type weapons
    <action: spear, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row 1, all frames, sufix _3, wait 3, y +1;
    icon: self, weapon, angle 45, x +12, y +8;
    icon: self, weapon, angle 45, x +12, y +8;
    icon: self, weapon, angle 45, x 0, y +8;
    anim: targets, weapon;
    icon: self, weapon, angle 45, x -12, y +8;
    effect: self, targets, 100%;
    wait: 20;
    icon: self, delete;
    </action>
    
    # Pose for 'Gun' type weapons
    <action: gun, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row 1, all frames, sufix _3, wait 3;
    icon: self, weapon, angle -135, x +12, y -16;
    icon: self, weapon, angle -105, x +6, y -10;
    icon: self, weapon, angle -75, x 0, y -2;
    icon: self, weapon, angle -45, x -6, y +4;
    wait: 30;
    sound: name 'Gun1';
    pose: self, row 1, frame 3, sufix _3;
    icon: self, weapon, angle -75, x -6, y -2;
    pose: self, row 1, frame 2, sufix _3;
    icon: self, weapon, angle -105, y -10;
    pose: self, row 1, frame 1, sufix _3;
    anim: targets, effect;
    effect: self, targets, 100%;
    wait: 20;
    icon: self, delete;
    </action>
    
    # Pose for 'Bow' type weapons
    <action: bow, reset>
    wait: targets, movement;
    direction: self, subjects;
    pose: self, row 2, all frames, sufix _3, wait 4;
    icon: self, image 'Bow1', x +6, above;
    icon: self, image 'Bow2', x +6, above;
    icon: self, image 'Bow3', x +6, above;
    wait: 10;
    action: targets, arrow;
    icon: self, image 'Bow2', x +6, above;
    icon: self, image 'Bow1', x +6, above;
    wait: targets, action;
    </action>
    
    # Pose for the targets of 'Bow' attack
    <action: arrow, reset>
    throw: self, user, image 'Arrow', arc 10, angle 45, init x -6, init y -12;
    wait: self, throw;
    anim: self, weapon;
    wait: 8;
    effect: active, targets, 100%;
    </action>

    # Movement to target for the skill 'Aura Blade'
    <action: aura blade move to, reset>
    wait: targets, movement;
    wait: self, animation;
    move: self, move to, x +52;
    direction: self, subjects;
    pose: self, row 4, all frames, sufix _1, return, wait 8;
    wait: self, movement;
    </action>
    
    # Pose for the skill 'Aura Blade'
    <action: aura blade, reset>
    wait: targets, movement;
    pose: self, row 4, sufix _3, all frames, wait 8, loop;
    anim: self, id 81;
    wait: self, animation;
    pose: self, row 2, sufix _3, all frames, wait 3, y +1;
    icon: self, weapon, angle 45, x -6, y +6;
    icon: self, weapon, angle 30, x -10, y +0;
    icon: self, weapon, angle 15, x -14, y -6;
    icon: self, weapon, angle 0, x -10, y -10;
    wait: 30;
    anim: self, id 110;
    wait: self, animation;
    wait: 30;
    afterimage: on, red 160, green 160, alpha 128;
    move: self, x -144, speed 15;
    pose: self, row 1, sufix _3, all frames, wait 3, y +1;
    icon: self, weapon, angle -90, x +12, y -16;
    icon: self, weapon, angle -45, x +6, y -16;
    icon: self, weapon, angle 0, x -6;
    icon: self, weapon, angle 45, x -10, y +8;
    anim: targets, effect;
    effect: self, targets, 100%;
    wait: self, movement;
    afterimage: self, off;
    wait: 20;
    icon: self, delete;
    </action>

    # Pose for the skill 'Multi Attack'
    <action: multi attack, opponents_unit.targetable_members.size times>
    target: next;
    afterimage: self, on;
    move: self, move to front;
    pose: self, row 4, all frames, sufix _1, return, wait 8, loop;
    wait: self, movement;
    afterimage: self, off;
    direction: self, subjects;
    pose: self, row 1, all frames, sufix _3, wait 3, y +1;
    icon: self, weapon, angle -90, x +12, y -16;
    icon: self, weapon, angle -45, x +6, y -16;
    icon: self, weapon, angle 0, x -6;
    anim: last, effect;
    icon: self, weapon, angle 45, x -10, y +8;
    effect: self, last, 100%, clear;
    wait: 20;
    icon: self, delete;
    </action>


    # Pose for the skill 'Aura Spell'
    <action: aura spell, reset>
    wait: targets, movement;
    action: self, step forward;
    wait: self, action;
    pose: self, row 3, all frames, sufix _3, wait 3;
    action: self, aura effect;
    wait: self, action
    action: self, step backward;
    </action>

    <action: aura effect, friends_unit.targetable_members.size times>
    target: next;
    anim: last, effect;
    wait: 4;
    effect: self, last, 100%;
    wait: last, animation;
    </action>
    
    "
  #--------------------------------------------------------------------------
  # * required
  #   This method checks for the existance of the basic module and other
  #   VE scripts required for this script to work, don't edit this
  #--------------------------------------------------------------------------
  def self.required(name, req, version, type = nil)
    if !$imported[:ve_basic_module]
      msg = "The script '%s' requires the script\n"
      msg += "'VE - Basic Module' v%s or higher above it to work properly\n"
      msg += "Go to http://victorscripts.wordpress.com/ to download this script."
      msgbox(sprintf(msg, self.script_name(name), version))
      exit
    else
      self.required_script(name, req, version, type)
    end
  end
  #--------------------------------------------------------------------------
  # * script_name
  #   Get the script name base on the imported value, don't edit this
  #--------------------------------------------------------------------------
  def self.script_name(name, ext = "VE")
    name = name.to_s.gsub("_", " ").upcase.split
    name.collect! {|char| char == ext ? "#{char} -" : char.capitalize }
    name.join(" ")
  end
end

$imported ||= {}
$imported[:ve_animated_battle] = 1.21
Victor_Engine.required(:ve_animated_battle, :ve_basic_module, 1.35, :above)
Victor_Engine.required(:ve_animated_battle, :ve_actor_battlers, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_animations_settings, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_passive_states, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_map_battle, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_state_cancel, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_tech_points, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_trait_control, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_mp_level, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_automatic_battlers, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_state_auto_apply, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_element_states, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_counter_options, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_state_aura, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_state_graphics, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_active_time_battle, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_damage_popup, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_action_streghten, 1.00, :bellow)
Victor_Engine.required(:ve_animated_battle, :ve_element_strenghten, 1.00, :bellow)

#==============================================================================
# ** Object
#------------------------------------------------------------------------------
#  This class is the superclass of all other classes.
#==============================================================================

class Object
  #--------------------------------------------------------------------------
  # * New method: custom_pose
  #--------------------------------------------------------------------------
  def custom_pose(type)
    note =~ /<#{type.upcase} POSE: (\w[\w ]+)>/i ? make_symbol($1) : nil
  end
end

#==============================================================================
# ** BattleManager
#------------------------------------------------------------------------------
#  This module handles the battle processing
#==============================================================================

class << BattleManager
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :old_tone
  #--------------------------------------------------------------------------
  # * Alias method: init_members
  #--------------------------------------------------------------------------
  alias :init_members_ve_animated_battle :init_members
  def init_members
    $game_party.members.each {|member| member.poses.clear_poses }
    init_members_ve_animated_battle
  end
  #--------------------------------------------------------------------------
  # * Alias method: battle_end
  #--------------------------------------------------------------------------
  alias :battle_end_ve_animated_battle :battle_end
  def battle_end(result)
    $game_party.members.each {|member| member.poses.clear_poses }
    $game_system.no_intro   = false
    $game_system.no_victory = false
    battle_end_ve_animated_battle(result)
  end
  #--------------------------------------------------------------------------
  # * Alias method: process_victory
  #--------------------------------------------------------------------------
  alias :process_victory_ve_animated_battle :process_victory
  def process_victory
    @phase = nil
    process_battle_end_pose($game_party)
    process_victory_ve_animated_battle
  end
  #--------------------------------------------------------------------------
  # * Alias method: process_defeat
  #--------------------------------------------------------------------------
  alias :process_defeat_ve_animated_battle :process_defeat
  def process_defeat
    @phase = nil
    process_battle_end_pose($game_troop)
    process_defeat_ve_animated_battle
  end
  #--------------------------------------------------------------------------
  # * Alias method: process_escape
  #--------------------------------------------------------------------------
  alias :process_escape_ve_animated_battle :process_escape
  def process_escape
    @escaping = true
    success   = process_escape_ve_animated_battle
    @escaping = false
    return success
  end
  #--------------------------------------------------------------------------
  # * Alias method: process_abort
  #--------------------------------------------------------------------------
  alias :process_abort_ve_animated_battle :process_abort
  def process_abort
    @phase = nil
    process_escape_pose if @escaping
    process_abort_ve_animated_battle
  end
  #--------------------------------------------------------------------------
  # * New method: process_battle_end_pose
  #--------------------------------------------------------------------------
  def process_battle_end_pose(party)
    SceneManager.scene.log_window_clear
    SceneManager.scene.update_basic while end_wait?(party)
    SceneManager.scene.update_basic
    party.movable_members.each do |member| 
      next if $game_system.no_victory || !member.victory_pose?
      member.poses.clear_loop
      member.poses.call_pose(:victory)
    end
  end
  #--------------------------------------------------------------------------
  # * New method: end_wait?
  #--------------------------------------------------------------------------
  def end_wait?(party)
    party.not_in_position? || party.active? || processing_collapse?
  end
  #--------------------------------------------------------------------------
  # * New method: processing_collapse?
  #--------------------------------------------------------------------------
  def processing_collapse?
    SceneManager.scene.spriteset.collapse?
  end
  #--------------------------------------------------------------------------
  # * New method: process_escape_pose
  #--------------------------------------------------------------------------
  def process_escape_pose
    $game_party.movable_members.each do |member| 
      member.poses.clear_loop
      member.poses.call_pose(:escape)
    end
    SceneManager.scene.abs_wait(5)
    SceneManager.scene.update_basic while $game_party.moving?
    SceneManager.scene.close_window
    Graphics.fadeout(30)
  end
  #--------------------------------------------------------------------------
  # * New method: clear_active_pose
  #--------------------------------------------------------------------------
  def clear_active_pose
    return unless actor && actor.poses.active_pose
    actor.poses.active_pose = nil
    actor.reset_pose
  end
  #--------------------------------------------------------------------------
  # * New method: active
  #--------------------------------------------------------------------------
  def active
    SceneManager.scene_is?(Scene_Battle) ? SceneManager.scene.active : nil
  end
  #--------------------------------------------------------------------------
  # * New method: targets
  #--------------------------------------------------------------------------
  def targets
    return [] unless active
    active.poses.current_action_targets
  end 
  #--------------------------------------------------------------------------
  # * New method: last_targets
  #--------------------------------------------------------------------------
  def last_targets
    return [] unless active
    active.poses.last_targets
  end
  #--------------------------------------------------------------------------
  # * New method: battler_active?
  #--------------------------------------------------------------------------
  def battler_active?
    return false unless active
    active.poses.active?
  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
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :no_intro
  attr_accessor :no_victory
  attr_accessor :intro_fade
  #--------------------------------------------------------------------------
  # * Alias method: initialize
  #--------------------------------------------------------------------------
  alias :initialize_ve_animated_battle :initialize
  def initialize
    initialize_ve_animated_battle
    @intro_fade = VE_BATTLE_INTRO_FADE
  end
end

#==============================================================================
# ** Game_Screen
#------------------------------------------------------------------------------
#  This class handles screen maintenance data, such as change in color tone,
# flashes, etc. It's used within the Game_Map and Game_Troop classes.
#==============================================================================

class Game_Screen
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :low_tone
  attr_reader   :high_tone
  attr_accessor :old_tone
  attr_accessor :old_low_tone
  attr_accessor :old_high_tone
  #--------------------------------------------------------------------------
  # * Alias method: clear_tone
  #--------------------------------------------------------------------------
  alias :clear_tone_ve_animated_battle :clear_tone
  def clear_tone
    clear_tone_ve_animated_battle
    @low_tone  = Tone.new
    @high_tone = Tone.new
    @low_tone_target  = Tone.new
    @high_tone_target = Tone.new
    @low_tone_duration  = 0
    @high_tone_duration = 0
  end
  #--------------------------------------------------------------------------
  # * Alias method: update
  #--------------------------------------------------------------------------
  alias :update_ve_animated_battle :update
  def update
    update_ve_animated_battle
    low_update_tone
    high_update_tone
  end
  #--------------------------------------------------------------------------
  # * New method: start_low_tone_change
  #--------------------------------------------------------------------------
  def start_low_tone_change(tone, duration)
    @low_tone_target = tone.clone
    @low_tone_duration = duration
    @low_tone = @low_tone_target.clone if @low_tone_duration == 0
  end
  #--------------------------------------------------------------------------
  # * New method: start_high_tone_change
  #--------------------------------------------------------------------------
  def start_high_tone_change(tone, duration)
    @high_tone_target = tone.clone
    @high_tone_duration = duration
    @high_tone = @high_tone_target.clone if @high_tone_duration == 0
  end
  #--------------------------------------------------------------------------
  # * New method: low_update_tone
  #--------------------------------------------------------------------------
  def low_update_tone
    if @low_tone_duration > 0
      d    = @low_tone_duration
      tone = @low_tone_target
      @low_tone.red   = (@low_tone.red   * (d - 1) + tone.red)   / d
      @low_tone.green = (@low_tone.green * (d - 1) + tone.green) / d
      @low_tone.blue  = (@low_tone.blue  * (d - 1) + tone.blue)  / d
      @low_tone.gray  = (@low_tone.gray  * (d - 1) + tone.gray)  / d
      @low_tone_duration -= 1
    end
  end  
  #--------------------------------------------------------------------------
  # * New method: high_update_tone
  #--------------------------------------------------------------------------
  def high_update_tone
    if @high_tone_duration > 0
      d    = @high_tone_duration
      tone = @high_tone_target
      @high_tone.red   = (@high_tone.red   * (d - 1) + tone.red)   / d
      @high_tone.green = (@high_tone.green * (d - 1) + tone.green) / d
      @high_tone.blue  = (@high_tone.blue  * (d - 1) + tone.blue)  / d
      @high_tone.gray  = (@high_tone.gray  * (d - 1) + tone.gray)  / d
      @high_tone_duration -= 1
    end
  end
  #--------------------------------------------------------------------------
  # * New method: tone_change?
  #--------------------------------------------------------------------------
  def tone_change?
    @tone_duration > 0 || @low_tone_duration > 0 || @high_tone_duration > 0
  end
end

#==============================================================================
# ** Game_ActionResult
#------------------------------------------------------------------------------
#  This class handles the results of actions. This class is used within the
# Game_Battler class.
#==============================================================================

class Game_ActionResult
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :hurt_pose
  #--------------------------------------------------------------------------
  # * New method: damage_adjust
  #--------------------------------------------------------------------------
  def damage_adjust(value, item)
    return unless value
    @hp_damage *= value
    @mp_damage *= value
    @hp_damage  = @hp_damage.to_i
    @mp_damage  = [@battler.mp, @mp_damage.to_i].min
    @hp_drain   = @hp_damage if item.damage.drain?
    @mp_drain   = @mp_damage if item.damage.drain?
    @hp_drain   = [@battler.hp, @hp_drain].min
  end
  #--------------------------------------------------------------------------
  # * New method: setup_drain
  #--------------------------------------------------------------------------
  def setup_drain(user)
    user.hp_drain += @hp_drain
    user.mp_drain += @mp_drain
#    @hp_drain = 0
#    @mp_drain = 0
  end
end

#==============================================================================
# ** Game_BattlerBase
#------------------------------------------------------------------------------
#  This class handles battlers. It's used as a superclass of the Game_Battler
# classes.
#==============================================================================

class Game_BattlerBase
  #--------------------------------------------------------------------------
  # * Overwrite method: refresh
  #--------------------------------------------------------------------------
  def refresh
    state_resist_set.each {|state_id| erase_state(state_id) }
    @hp = [[@hp, mhp].min, 0].max
    @mp = [[@mp, mmp].min, 0].max
    die if @dying && !immortal?
    return if @dying
    valid = @hp == 0 && !immortal?
    valid ? add_state(death_state_id) : remove_state(death_state_id)
  end
  #--------------------------------------------------------------------------
  # * Alias method: element_set
  #--------------------------------------------------------------------------
  alias :element_set_ve_animated_battle :element_set
  def element_set(item)
    element_set  = element_set_ve_animated_battle(item)
    element_set += poses.element_flag
    element_set.compact
  end
end

#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
#  This class deals with battlers. It's used as a superclass of the Game_Actor
# and Game_Enemy classes.
#==============================================================================

class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :poses
  attr_accessor :hp_drain
  attr_accessor :mp_drain
  #--------------------------------------------------------------------------
  # * Overwrite method: dead?
  #--------------------------------------------------------------------------
  def dead?
    super && !immortal?
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: item_element_rate
  #--------------------------------------------------------------------------
  def item_element_rate(user, item)
    elements = user.element_set(item)
    elements.empty? ? 1.0 : elements_max_rate(elements)
  end
  #--------------------------------------------------------------------------
  # * Alias method: initialize
  #--------------------------------------------------------------------------
  alias :initialize_ve_animated_battle :initialize
  def initialize
    @hp_drain = 0
    @mp_drain = 0
    @poses = Game_BattlerPose.new(self)
    initialize_ve_animated_battle
  end
  #--------------------------------------------------------------------------
  # * Alias method: item_apply
  #--------------------------------------------------------------------------
  alias :item_apply_ve_animated_battle :item_apply
  def item_apply(user, item)
    item_apply_ve_animated_battle(user, item)
    poses.call_damage_pose(item, user) if movable?
    poses.substitution     = false
    user.poses.result_flag = @result.hit? ? :hit : :miss
  end
  #--------------------------------------------------------------------------
  # * Alias method: make_damage_value
  #--------------------------------------------------------------------------
  alias :make_damage_value_ve_animated_battle :make_damage_value
  def make_damage_value(user, item)
    make_damage_value_ve_animated_battle(user, item)
    active_effect_make_damage(user, item)
    clear_elemental_flag(user, item)
    @result.damage_adjust(user.poses.damage_flag, item)
    @result.hurt_pose = !user.poses.no_hurt_flag
    @result.setup_drain(user)
  end
  #--------------------------------------------------------------------------
  # * Alias method: item_apply
  #--------------------------------------------------------------------------
  alias :execute_damage_ve_animated_battle :execute_damage
  def execute_damage(user)
    execute_damage_ve_animated_battle(user)
    poses.clear_immortal if self.hp <= 0 && poses.clear_flag
  end
  #--------------------------------------------------------------------------
  # * Alias method: regenerate_hp
  #--------------------------------------------------------------------------
  alias :regenerate_hp_ve_animated_battle :regenerate_hp
  def regenerate_hp
    regenerate_hp_ve_animated_battle
    if @result.hp_damage > 0 && movable? && $imported[:ve_damage_pop]
      poses.call_pose(:hurt, :clear)
    end
  end
  #--------------------------------------------------------------------------
  # * Alias method: die
  #--------------------------------------------------------------------------
  alias :die_ve_animated_battle :die
  def die
    return @dying = true if immortal?
    poses.call_pose(:die, :clear)
    @dying = false
    die_ve_animated_battle
  end
  #--------------------------------------------------------------------------
  # * Alias method: revive
  #--------------------------------------------------------------------------
  alias :revive_ve_animated_battle :revive
  def revive
#    call_pose(:revive)
    revive_ve_animated_battle
  end
  #--------------------------------------------------------------------------
  # * New method: get_all_poses
  #--------------------------------------------------------------------------
  def get_all_poses(note = "")
    note + get_all_notes + battler_settings + default_settings
  end
  #--------------------------------------------------------------------------
  # * New method: default_settings
  #--------------------------------------------------------------------------
  def default_settings
    VE_DEFAULT_ACTION
  end
  #--------------------------------------------------------------------------
  # * New method: battler_settings
  #--------------------------------------------------------------------------
  def battler_settings
    VE_ACTION_SETTINGS[battler_mode] ? VE_ACTION_SETTINGS[battler_mode] : ""
  end
  #--------------------------------------------------------------------------
  # * New method: battler_mode
  #--------------------------------------------------------------------------
  def battler_mode
    sprite_value(:action)
  end
  #--------------------------------------------------------------------------
  # * New method: sprite_value
  #--------------------------------------------------------------------------
  def sprite_value(n)
    sprite_settings[n].nil? ? VE_DEFAULT_SPRITE[n] : sprite_settings[n]
  end
  #--------------------------------------------------------------------------
  # * New method: sprite_settings
  #--------------------------------------------------------------------------
  def sprite_settings
    VE_SPRITE_SETTINGS[@battler_name] ? VE_SPRITE_SETTINGS[@battler_name] :
    VE_DEFAULT_SPRITE
  end
  #--------------------------------------------------------------------------
  # * New method: script_processing
  #--------------------------------------------------------------------------
  def script_processing(code)
    eval(code) rescue false
  end
  #--------------------------------------------------------------------------
  # * New method: set_pose_frames
  #--------------------------------------------------------------------------
  def set_pose_frames(value)
    if value =~ /(\d+) FRAMES/i
      [@pose[:frame] + $1.to_i, sprite_value(:frames)].min - 1
    else
      sprite_value(:frames) - 1
    end
  end
  #--------------------------------------------------------------------------
  # * New method: weapon_icon
  #--------------------------------------------------------------------------
  def weapon_icon(index)
    actor? ? actor_weapon_icon(index) : enemy_weapon_icon(index)
  end
  #--------------------------------------------------------------------------
  # * New method: actor_weapon_icon
  #--------------------------------------------------------------------------
  def actor_weapon_icon(index)
    weapons[index - 1] ? weapons[index - 1].icon_index : nil
  end
  #--------------------------------------------------------------------------
  # * New method: enemy_weapon_icon
  #--------------------------------------------------------------------------
  def enemy_weapon_icon(index)
    note =~ /<WEAPON #{index}: (\d+)>/i ? $1.to_i : 0
  end
  #--------------------------------------------------------------------------
  # * New method: armor_icon
  #--------------------------------------------------------------------------
  def armor_icon(index)
   actor? ? actor_armor_icon(index) : enemy_armor_icon(index)
  end
  #--------------------------------------------------------------------------
  # * New method: equip_list
  #--------------------------------------------------------------------------
  def actor_armor_icon(index)
    slot = equip_slots[index]
    return nil unless slot && slot != 0 && equip_list[slot]
    equip = equip_list[slot]
    equip.object ? equip.object.icon_index : nil
  end
  #--------------------------------------------------------------------------
  # * New method: equip_list
  #--------------------------------------------------------------------------
  def enemy_armor_icon(index)
    note =~ /<ARMOR #{index}: (\d+)>/i ? $1.to_i : 0
  end
  #--------------------------------------------------------------------------
  # * New method: equip_list
  #--------------------------------------------------------------------------
  def equip_list
    @equips
  end
  #--------------------------------------------------------------------------
  # * New method: action_icon
  #--------------------------------------------------------------------------
  def action_icon
    poses.current_item ? poses.current_item.icon_index : 0
  end
  #--------------------------------------------------------------------------
  # * New method: current_origin?
  #--------------------------------------------------------------------------
  def current_origin?
    current_x == screen_x && current_y == screen_y
  end
  #--------------------------------------------------------------------------
  # * New method: target_origin?
  #--------------------------------------------------------------------------
  def target_origin?
    target_x == screen_x && target_y == screen_y
  end
  #--------------------------------------------------------------------------
  # * New method: target_current?
  #--------------------------------------------------------------------------
  def target_current?
    current_x == target_x  && current_y == target_y
  end
  #--------------------------------------------------------------------------
  # * New method: not_origin?
  #--------------------------------------------------------------------------
  def not_origin?
    !origin?
  end
  #--------------------------------------------------------------------------
  # * New method: current_x
  #--------------------------------------------------------------------------
  def current_x
    poses.current_position[:x]
  end
  #--------------------------------------------------------------------------
  # * New method: current_y
  #--------------------------------------------------------------------------
  def current_y
    poses.current_position[:y]
  end
  #--------------------------------------------------------------------------
  # * New method: current_h
  #--------------------------------------------------------------------------
  def current_h
    poses.current_position[:h]
  end
  #--------------------------------------------------------------------------
  # * New method: current_j
  #--------------------------------------------------------------------------
  def current_j
    poses.current_position[:j]
  end
  #--------------------------------------------------------------------------
  # * New method: target_x
  #--------------------------------------------------------------------------
  def target_x
    poses.target_position[:x]
  end
  #--------------------------------------------------------------------------
  # * New method: target_y
  #--------------------------------------------------------------------------
  def target_y
    poses.target_position[:y]
  end
  #--------------------------------------------------------------------------
  # * New method: target_h
  #--------------------------------------------------------------------------
  def target_h
    poses.target_position[:h]
  end
  #--------------------------------------------------------------------------
  # * New method: target_j
  #--------------------------------------------------------------------------
  def target_j
    poses.target_position[:j]
  end
  #--------------------------------------------------------------------------
  # * New method: item_attack?
  #--------------------------------------------------------------------------
  def item_attack?(item)
    item.skill? && item.id == attack_skill_id
  end
  #--------------------------------------------------------------------------
  # * New method: item_defend?
  #--------------------------------------------------------------------------
  def item_defend?(item)
    item.skill? && item.id == guard_skill_id
  end
  #--------------------------------------------------------------------------
  # * New method: use_dual_attack?
  #--------------------------------------------------------------------------
  def use_dual_attack?(item)
    get_all_notes =~ /<USE DUAL ATTACK>/i && double_attack?(item)
  end
  # * New method: use_dual_attack?
  #--------------------------------------------------------------------------
  def use_double_attack?(item)
   double_attack?(item) && !use_dual_attack?(item)
  end
  #--------------------------------------------------------------------------
  # * New method: double_attack?
  #--------------------------------------------------------------------------
  def double_attack?(item)
    actor? && dual_wield? && weapons.size > 1 && (item_attack?(item) ||
    (item  && item.note =~ /<ALLOW DUAL ATTACK>/i))
  end
  #--------------------------------------------------------------------------
  # * New method: immortal?
  #--------------------------------------------------------------------------
  def immortal?
    poses.immortal?
  end
  #--------------------------------------------------------------------------
  # * New method: down?
  #--------------------------------------------------------------------------
  def down?
    poses.down?
  end
  #--------------------------------------------------------------------------
  # * New method: left?
  #--------------------------------------------------------------------------
  def left?
    poses.left?
  end
  #--------------------------------------------------------------------------
  # * New method: right?
  #--------------------------------------------------------------------------
  def right?
    poses.right?
  end
  #--------------------------------------------------------------------------
  # * New method: up?
  #--------------------------------------------------------------------------
  def up?
    poses.up?
  end
  #--------------------------------------------------------------------------
  # * New method: unmovable?
  #--------------------------------------------------------------------------
  def unmovable?
    get_all_notes =~ /<UNMOVABLE>/i
  end
  #--------------------------------------------------------------------------
  # * New method: hurt_pose?
  #--------------------------------------------------------------------------
  def hurt_pose?
    @result.hit? && @result.hp_damage > 0 && @result.hurt_pose
  end
  #--------------------------------------------------------------------------
  # * New method: command_pose
  #--------------------------------------------------------------------------
  def command_pose
    poses.call_pose(:command, :clear) if sprite_value(:command)
  end
  #--------------------------------------------------------------------------
  # * New method: input_pose
  #--------------------------------------------------------------------------
  def input_pose
    poses.call_pose(:input, :clear) if sprite_value(:input)
  end
  #--------------------------------------------------------------------------
  # * New method: cancel_pose
  #--------------------------------------------------------------------------
  def cancel_pose
    poses.call_pose(:cancel, :clear) if sprite_value(:cancel)
  end
  #--------------------------------------------------------------------------
  # * New method: setup_counter_targets
  #--------------------------------------------------------------------------
  def setup_counter_targets(target, item)
    [target]
  end
  #--------------------------------------------------------------------------
  # * New method: counter_action
  #--------------------------------------------------------------------------
  def counter_action
    $data_skills[attack_skill_id]
  end
  #--------------------------------------------------------------------------
  # * New method: drain_setup
  #--------------------------------------------------------------------------
  def drain_setup
    self.hp += @hp_drain
    self.mp += @mp_drain
    @result.hp_damage = -@hp_drain
    @result.mp_damage = -@mp_drain
    @hp_drain = 0
    @mp_drain = 0
    @damaged  = true if $imported[:ve_damage_pop]
  end
  #--------------------------------------------------------------------------
  # * New method: perform_damage_effect
  #--------------------------------------------------------------------------
  def perform_fast_collapse
    reset_pose
    @sprite_effect_type = :instant_collapse
  end
  #--------------------------------------------------------------------------
  # * New method: reset_pose
  #--------------------------------------------------------------------------
  def reset_pose
    return unless $game_party.in_battle
    sprite.reset_pose if sprite
  end
  #--------------------------------------------------------------------------
  # * New method: clear_flag=
  #--------------------------------------------------------------------------
  def clear_flag=(n)
    poses.clear_flag = n
  end
  #--------------------------------------------------------------------------
  # * New method: clear_elemental_flag
  #--------------------------------------------------------------------------
  def clear_elemental_flag(user, item)
    user.poses.element_flag.clear
    user.poses.active_effect.each {|member| member.poses.element_flag.clear }
    user.poses.active_effect.clear
  end
  #--------------------------------------------------------------------------
  # * New method: active_effect_make_damage
  #--------------------------------------------------------------------------
  def active_effect_make_damage(user, item)
    return if user.poses.active_effect.empty?
    setup_old_results
    apply_new_results(user, item)
    restore_old_results(item)
  end
  #--------------------------------------------------------------------------
  # * New method: cooperation_make_damage
  #--------------------------------------------------------------------------
  def setup_old_results
    @result_critical  = @result.critical
    @result_hp_damage = @result.hp_damage
    @result_mp_damage = @result.mp_damage
    @result_hp_drain  = @result.hp_drain
    @result_mp_drain  = @result.mp_drain
    @result_resist    = @result.resist if $imported[:ve_damage_pop]
  end
  #--------------------------------------------------------------------------
  # * New method: cooperation_make_damage
  #--------------------------------------------------------------------------
  def apply_new_results(user, item)
    user.poses.active_effect.each do |battler|
      next if battler == user
      make_damage_value_ve_animated_battle(battler, item)
      @result_critical  |= @result.critical
      @result_hp_damage += @result.hp_damage
      @result_mp_damage += @result.mp_damage
      @result_hp_drain  += @result.hp_drain
      @result_mp_drain  += @result.mp_drain
      @result_success   |= @result.success
      @result_resist    *= @result.resist if $imported[:ve_damage_pop]
    end
  end
  #--------------------------------------------------------------------------
  # * New method: cooperation_make_damage
  #--------------------------------------------------------------------------
  def restore_old_results(item)
    @result.critical  = @result_critical
    @result.hp_damage = @result_hp_damage
    @result.mp_damage = @result_mp_damage
    @result.hp_drain  = @result_hp_drain
    @result.mp_drain  = @result_mp_drain
    @result.resist    = @result_resist if $imported[:ve_damage_pop]
    @result.success   = item.damage.to_hp? || @result.mp_damage != 0
  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
  #--------------------------------------------------------------------------
  # * Overwrite method: perform_collapse_effect
  #--------------------------------------------------------------------------
  def perform_collapse_effect
    if $game_party.in_battle
      reset_pose
      case collapse_type
      when 0
        @sprite_effect_type = :collapse
        Sound.play_enemy_collapse
      when 1
        @sprite_effect_type = :boss_collapse
        Sound.play_boss_collapse1
      when 2
        @sprite_effect_type = :instant_collapse
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: perform_damage_effect
  #--------------------------------------------------------------------------
  def perform_damage_effect
    $game_troop.screen.start_shake(5, 5, 10) unless use_sprite?
    Sound.play_actor_damage
  end
  #--------------------------------------------------------------------------
  # * Alias method: param_plus
  #--------------------------------------------------------------------------
  alias :param_plus_ve_animated_battle :param_plus
  def param_plus(param_id)
    if param_id > 1 && @attack_flag
      atk_equips.compact.inject(super) {|r, item| r += item.params[param_id] }
    else
      param_plus_ve_animated_battle(param_id)
    end
  end
  #--------------------------------------------------------------------------
  # * New method: atk_feature_objects
  #--------------------------------------------------------------------------
  def atk_feature_objects
    list = @attack_flag ? atk_equips : equips.compact
    states + [actor] + [self.class] + list
  end
  #--------------------------------------------------------------------------
  # * New method: atk_all_features
  #--------------------------------------------------------------------------
  def atk_all_features
    atk_feature_objects.inject([]) {|r, obj| r + obj.features }
  end
  #--------------------------------------------------------------------------
  # * New method: atk_features
  #--------------------------------------------------------------------------
  def atk_features(code)
    atk_all_features.select {|ft| ft.code == code }
  end
  #--------------------------------------------------------------------------
  # * New method: atk_features_set
  #--------------------------------------------------------------------------
  def atk_features_set(code)
    atk_features(code).inject([]) {|r, ft| r |= [ft.data_id] }
  end
  #--------------------------------------------------------------------------
  # * New method: atk_elements
  #--------------------------------------------------------------------------
  def atk_elements
    set = atk_features_set(FEATURE_ATK_ELEMENT)
    set |= [1] if weapons.compact.empty?
    return set
  end
  #--------------------------------------------------------------------------
  # * New method: atk_states
  #--------------------------------------------------------------------------
  def atk_states
    atk_features_set(FEATURE_ATK_STATE)
  end
  #--------------------------------------------------------------------------
  # * New method: atk_equips
  #--------------------------------------------------------------------------
  def atk_equips
    ([weapons[@attack_flag - 1]] + armors).collect {|item| item }.compact
  end
  #--------------------------------------------------------------------------
  # * New method: screen_x
  #--------------------------------------------------------------------------
  def screen_x
    return 0
  end
  #--------------------------------------------------------------------------
  # * New method: screen_y
  #--------------------------------------------------------------------------
  def screen_y
    return 0
  end
  #--------------------------------------------------------------------------
  # * New method: character_hue
  #--------------------------------------------------------------------------
  def character_hue
    hue
  end
  #--------------------------------------------------------------------------
  # * New method: intro_pose?
  #--------------------------------------------------------------------------
  def intro_pose?
    !(note =~ /<NO INTRO>/i)
  end
  #--------------------------------------------------------------------------
  # * New method: victory_pose?
  #--------------------------------------------------------------------------
  def victory_pose?
    !(note =~ /<NO VICTORY>/i)
  end
end

#==============================================================================
# ** Game_Enemy
#------------------------------------------------------------------------------
#  This class handles enemy characters. It's used within the Game_Troop class
# ($game_troop).
#==============================================================================

class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # * Overwrite method: perform_damage_effect
  #--------------------------------------------------------------------------
  def perform_damage_effect
    Sound.play_enemy_damage
  end
  #--------------------------------------------------------------------------
  # * Alias method: perform_collapse_effect
  #--------------------------------------------------------------------------
  alias :perform_collapse_effect_ve_animated_battle :perform_collapse_effect
  def perform_collapse_effect
    reset_pose
    perform_collapse_effect_ve_animated_battle
  end
  #--------------------------------------------------------------------------
  # * New method: atk_animation_id1
  #--------------------------------------------------------------------------
  def atk_animation_id1
    return 0
  end
  #--------------------------------------------------------------------------
  # * New method: atk_animation_id2
  #--------------------------------------------------------------------------
  def atk_animation_id2
    return 0
  end
  #--------------------------------------------------------------------------
  # * New method: character_name
  #--------------------------------------------------------------------------
  def character_name
    @character_name = @battler_name
    @character_name
  end
  #--------------------------------------------------------------------------
  # * New method: character_hue
  #--------------------------------------------------------------------------
  def character_hue
    @character_hue = @battler_hue
    @character_hue
  end
  #--------------------------------------------------------------------------
  # * New method: character_index
  #--------------------------------------------------------------------------
  def character_index
    note =~ /<CHARACTER INDEX: (\d+)>/i ? $1.to_i - 1 : 0
  end
  #--------------------------------------------------------------------------
  # * New method: visual_items
  #--------------------------------------------------------------------------
  def visual_items
    [default_part]
  end
  #--------------------------------------------------------------------------
  # * New method: default_part
  #--------------------------------------------------------------------------
  def default_part
    {name: character_name, index1: character_index, index2: character_index,
     hue: character_hue, priority: 0}
  end
  #--------------------------------------------------------------------------
  # * New method: intro_pose?
  #--------------------------------------------------------------------------
  def intro_pose?
    note =~ /<INTRO POSE>/i
  end
  #--------------------------------------------------------------------------
  # * New method: victory_pose?
  #--------------------------------------------------------------------------
  def victory_pose?
    note =~ /<VICTORY POSE>/i
  end
end

#==============================================================================
# ** Game_Unit
#------------------------------------------------------------------------------
#  This class handles units. It's used as a superclass of the Game_Party and
# Game_Troop classes.
#==============================================================================

class Game_Unit
  #--------------------------------------------------------------------------
  # * New method: moving?
  #--------------------------------------------------------------------------
  def not_in_position?
    movable_members.any? {|member| member.poses.not_in_position? }
  end
  #--------------------------------------------------------------------------
  # * New method: moving?
  #--------------------------------------------------------------------------
  def moving?
    movable_members.any? {|member| member.poses.moving? }
  end
  #--------------------------------------------------------------------------
  # * New method: active?
  #--------------------------------------------------------------------------
  def active?
    movable_members.any? {|member| member.poses.active? }
  end
  #--------------------------------------------------------------------------
  # * New method: targetable_members
  #--------------------------------------------------------------------------  
  def targetable_members
    alive_members
  end
end

#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
#  An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # * Alias method: comment_call
  #--------------------------------------------------------------------------
  alias :comment_call_ve_animated_battle :comment_call
  def comment_call
    call_animated_battle_comments
    comment_call_ve_animated_battle
  end
  #--------------------------------------------------------------------------
  # * New method: call_animated_battle_comments
  #--------------------------------------------------------------------------
  def call_animated_battle_comments
    $game_system.no_intro   = true if note =~ /<NO INTRO>/i
    $game_system.no_victory = true if note =~ /<NO VICTORY>/i
  end
end

#==============================================================================
# ** Game_BattlerPose
#------------------------------------------------------------------------------
#  This class deals with battlers poses.
#==============================================================================

class Game_BattlerPose
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :row
  attr_accessor :spin
  attr_accessor :angle
  attr_accessor :sufix
  attr_accessor :frame
  attr_accessor :shake
  attr_accessor :reset
  attr_accessor :x_adj
  attr_accessor :y_adj
  attr_accessor :f_size
  attr_accessor :f_init
  attr_accessor :timing
  attr_accessor :freeze
  attr_accessor :active
  attr_accessor :jumping
  attr_accessor :targets
  attr_accessor :teleport
  attr_accessor :call_end
  attr_accessor :icon_list
  attr_accessor :invisible
  attr_accessor :direction
  attr_accessor :immortals
  attr_accessor :animation
  attr_accessor :countered
  attr_accessor :call_anim
  attr_accessor :dual_flag
  attr_accessor :pose_list
  attr_accessor :move_over
  attr_accessor :pose_loop
  attr_accessor :afterimage
  attr_accessor :move_speed
  attr_accessor :reset_move
  attr_accessor :throw_list
  attr_accessor :clear_flag
  attr_accessor :counter_on
  attr_accessor :call_effect
  attr_accessor :next_target
  attr_accessor :attack_flag
  attr_accessor :damage_flag
  attr_accessor :result_flag
  attr_accessor :active_pose
  attr_accessor :substitution
  attr_accessor :last_targets
  attr_accessor :anim_targets
  attr_accessor :element_flag
  attr_accessor :current_item
  attr_accessor :no_hurt_flag
  attr_accessor :active_effect
  attr_accessor :action_targets
  attr_accessor :counter_target
  attr_accessor :target_position
  attr_accessor :previous_action
  attr_accessor :current_position
  #--------------------------------------------------------------------------
  # * New method: initialize
  #--------------------------------------------------------------------------
  def initialize(battler)
    @battler = battler
    clear_poses
  end
  #--------------------------------------------------------------------------
  # * New method: clear_poses
  #--------------------------------------------------------------------------
  def clear_poses
    @sufix = ""
    @row   = 0
    @frame = 0
    @angle = 0
    @spin  = 0
    @x_adj = 0
    @y_adj = 0
    @f_init   = 0
    @hp_drain = 0
    @mp_drain = 0
    @direction  = 2
    @move_speed = 1.0
    @targets    = []
    @immortals  = []
    @throw_list = []
    @icon_list  = {}
    @timing     = {}
    @element_flag   = []
    @active_effect  = []
    @action_targets = []
    @pose_list = Game_PoseList.new(@battler)
    clear_shake
    clear_position
  end
  #--------------------------------------------------------------------------
  # * New method: immortal?
  #--------------------------------------------------------------------------
  def immortal?
    return false unless $game_party.in_battle
    members = BattleManager.all_battle_members
    members.any? {|member| member.poses.immortals.include?(@battler) }
  end
  #--------------------------------------------------------------------------
  # * New method: clear_shake
  #--------------------------------------------------------------------------
  def clear_shake
    @shake_power = 0
    @shake_speed = 0
    @shake_duration = 0
    @shake_direction = 1
    @shake = 0
  end
  #--------------------------------------------------------------------------
  # * New method: clear_position
  #--------------------------------------------------------------------------
  def clear_position
    @target_position  = {x: 0, y: 0, h: 0, j: 0}
    @current_position = {x: 0, y: 0, h: 0, j: 0}
    @default_position = {x: 0, y: 0, h: 0, j: 0}
  end
  #--------------------------------------------------------------------------
  # * New method: call_pose
  #--------------------------------------------------------------------------
  def call_pose(pose, insert = nil, item = nil, battler = nil)
    return if insert == :clear && pose_list.include?(pose)
    notes = @battler.get_all_poses(item ? item.note : "")
    setup_pose(pose, notes, make_string(pose), insert, battler)
  end
  #--------------------------------------------------------------------------
  # * New method: setup_pose
  #--------------------------------------------------------------------------
  def setup_pose(pose, notes, code, insert, battler)
    regexp = get_all_values("ACTION: *#{code}((?: *, *[^>]+)+)?", "ACTION")
    result = []
    if notes.gsub(/\r\n/i, "") =~ regexp
      value = $1
      setup = $2
      time  = value =~ /([^,]+) TIMES/i ? [script_processing($1), 1].max : 1
      last  = value =~ /(\w[\w ]+)/i    ? make_symbol($1) : nil
      layer = insert.numeric? ? insert : 1
      time.times { result.push(setup_value(setup, pose, last, layer, battler)) }
      insert_poses(insert, result)
    end
  end
  #--------------------------------------------------------------------------
  # * New method: script_processing
  #--------------------------------------------------------------------------
  def script_processing(value)
    @battler.script_processing(value)
  end
  #--------------------------------------------------------------------------
  # * New method: insert_poses
  #--------------------------------------------------------------------------
  def insert_poses(insert, next_pose)
    case insert
    when :clear, :insert then @pose_list.insert(1, 0, next_pose)
    when Numeric         then @pose_list.insert(insert, 0, next_pose)
    else @pose_list.insert(1, -1, next_pose)
    end
  end
  #--------------------------------------------------------------------------
  # * New method: setup_value
  #--------------------------------------------------------------------------
  def setup_value(setup, pose, last, layer, battler)
    values = Game_PoseAction.new(pose, last, layer, @battler)
    setup.scan(/(\w+)(?:: *([^;\n\r]+)[;\n\r])?/i) do |name, value|
      value = value ? value : ""
      values.push(Game_PoseValue.new(name, value, @battler, battler, layer))
    end
    values
  end
  #--------------------------------------------------------------------------
  # * New method: pose_name_list
  #--------------------------------------------------------------------------
  def pose_name_list
    pose_list.list[1]
  end
  #--------------------------------------------------------------------------
  # * New method: pose_name
  #--------------------------------------------------------------------------
  def pose_name
    pose_list.name[1]
  end
  #--------------------------------------------------------------------------
  # * New method: clear_loop
  #--------------------------------------------------------------------------
  def clear_loop
    @pose_list.clear_loop
  end
  #--------------------------------------------------------------------------
  # * New method: clear_damage
  #--------------------------------------------------------------------------
  def clear_damage
    @pose_list.clear_damage
  end
  #--------------------------------------------------------------------------
  # * New method: states_pose
  #--------------------------------------------------------------------------
  def states_pose
    $data_states.compact.collect {|state| state.custom_pose("STATE") }.compact
  end
  #--------------------------------------------------------------------------
  # * New method: current_action_targets
  #--------------------------------------------------------------------------
  def current_action_targets
    next_target ? [@action_targets[next_target]] : @action_targets
  end
  #--------------------------------------------------------------------------
  # * New method: active?
  #--------------------------------------------------------------------------
  def active?
    @active
  end
  #--------------------------------------------------------------------------
  # * New method: down?
  #--------------------------------------------------------------------------
  def down?
    @direction == 2
  end
  #--------------------------------------------------------------------------
  # * New method: left?
  #--------------------------------------------------------------------------
  def left?
    @direction == 4
  end
  #--------------------------------------------------------------------------
  # * New method: right?
  #--------------------------------------------------------------------------
  def right?
    @direction == 6
  end
  #--------------------------------------------------------------------------
  # * New method: up?
  #--------------------------------------------------------------------------
  def up?
    @direction == 8
  end
  #--------------------------------------------------------------------------
  # * New method: target_direction
  #--------------------------------------------------------------------------
  def target_direction(x, y)
    relative_x = @battler.current_x - x
    relative_y = @battler.current_y - y
    if isometric?
      @direction = 2 if relative_x > 0 && relative_y < 0
      @direction = 4 if relative_x > 0 && relative_y > 0
      @direction = 6 if relative_x < 0 && relative_y < 0
      @direction = 8 if relative_x < 0 && relative_y > 0
    elsif relative_x.abs >= relative_y.abs && !frontview?
      @direction = relative_x < 0 ? 6 : 4
    elsif relative_y.abs >= relative_x.abs && !sideview?
      @direction = relative_y < 0 ? 2 : 8
    end
  end
  #--------------------------------------------------------------------------
  # * New method: action_direction
  #--------------------------------------------------------------------------
  def action_direction(units)
    x = units.collect {|member| member.current_x }.average
    y = units.collect {|member| member.current_y }.average
    target_direction(x, y)
  end
  #--------------------------------------------------------------------------
  # * New method: active_direction
  #--------------------------------------------------------------------------
  def active_direction
    units = BattleManager.all_battle_members
    action_direction(units.select {|member| member.poses.active? })
  end
  #--------------------------------------------------------------------------
  # * New method: default_direction
  #--------------------------------------------------------------------------
  def default_direction
    action_direction(@battler.opponents_unit.members)
  end
  #--------------------------------------------------------------------------
  # * New method: targets_direction
  #--------------------------------------------------------------------------
  def targets_direction
    action_direction(BattleManager.targets)
  end
  #--------------------------------------------------------------------------
  # * New method: origin_direction
  #--------------------------------------------------------------------------
  def origin_direction
    target_direction(@battler.screen_x, @battler.screen_y)
  end
  #--------------------------------------------------------------------------
  # * New method: adjust_position
  #--------------------------------------------------------------------------
  def adjust_position(value)
    if isometric?
      x, y =  value, -value * 0.75 if down?
      x, y =  value,  value * 0.75 if left?
      x, y = -value, -value * 0.75 if right?
      x, y = -value,  value * 0.75 if up?
    else
      x, y = 0, -value if down?
      x, y =  value, 0 if left?
      x, y = -value, 0 if right?
      x, y = 0,  value if up?
    end
    @target_position[:x] += x.to_i
    @target_position[:y] += y.to_i
  end
  #--------------------------------------------------------------------------
  # * New method: sharing_position?
  #--------------------------------------------------------------------------
  def sharing_position?
    sharing_list.size > 1 && !move_over
  end
  #--------------------------------------------------------------------------
  # * New method: sharing_list
  #--------------------------------------------------------------------------
  def sharing_list
    BattleManager.all_battle_members.select {|other| position_overlap?(other) }
  end
  #--------------------------------------------------------------------------
  # * New method: position_overlap?(other)
  #--------------------------------------------------------------------------
  def position_overlap?(other)
    x = target_position[:x] - other.poses.target_position[:x]
    y = target_position[:y] - other.poses.target_position[:y]
    x.abs <= 12 && y.abs <= 12
  end
  #--------------------------------------------------------------------------
  # * New method: position_fix
  #--------------------------------------------------------------------------
  def position_fix
    sharing_list.each do |other|
      next if other == @battler || !position_overlap?(other)
      fix_vert(other) if left?  || right? 
      fix_horz(other) if down?  || up? 
    end
  end
  #--------------------------------------------------------------------------
  # * New method:  fix_vert
  #--------------------------------------------------------------------------
  def fix_vert(other)
    adjust = @battler.current_y > other.current_x ? 4 : -4
    @target_position[:y] += adjust
  end
  #--------------------------------------------------------------------------
  # * New method: fix_horz
  #--------------------------------------------------------------------------
  def fix_horz(other)
    adjust = @battler.current_x > other.current_x ? 4 : -4
    @target_position[:x] += adjust
  end
  #--------------------------------------------------------------------------
  # * New method: fix_position
  #--------------------------------------------------------------------------
  def fix_position
    @target_position = @current_position.dup
  end
  #--------------------------------------------------------------------------
  # * New method: sideview?
  #--------------------------------------------------------------------------
  def sideview?
    $imported[:ve_actor_battlers] && VE_BATTLE_FORMATION == :side
  end
  #--------------------------------------------------------------------------
  # * New method: frontview?
  #--------------------------------------------------------------------------
  def frontview?
    $imported[:ve_actor_battlers] && VE_BATTLE_FORMATION == :front
  end
  #--------------------------------------------------------------------------
  # * New method: isometric
  #--------------------------------------------------------------------------
  def isometric?
    $imported[:ve_actor_battlers] && VE_BATTLE_FORMATION == :iso
  end
  #--------------------------------------------------------------------------
  # * New method: target_distance
  #--------------------------------------------------------------------------
  def target_distance(symbol)
    @target_position[symbol] - @current_position[symbol]
  end
  #--------------------------------------------------------------------------
  # * New method: moving?
  #--------------------------------------------------------------------------
  def moving?
    @current_position != @target_position
  end
  #--------------------------------------------------------------------------
  # * New method: moving?
  #--------------------------------------------------------------------------
  def damage_pose?
    pose_list.damage_pose?
  end
  #--------------------------------------------------------------------------
  # * New method: no_pose?
  #--------------------------------------------------------------------------
  def pose?
    timing[:time]
  end
  #--------------------------------------------------------------------------
  # * New method: state_pose?
  #--------------------------------------------------------------------------
  def state_pose?
    state_pose
  end
  #--------------------------------------------------------------------------
  # * New method: state_pose
  #--------------------------------------------------------------------------
  def state_pose
    @battler.states.collect {|state| state.custom_pose("STATE") }.first
  end
  #--------------------------------------------------------------------------
  # * New method: state_pose
  #--------------------------------------------------------------------------
  def cast_pose
    call_active_pose(@battler.cast_action.item)
  end
  #--------------------------------------------------------------------------
  # * New method: activate
  #--------------------------------------------------------------------------
  def activate
    return unless current_action && current_action.item
    @active         = true
    @active_pose    = nil
    @action_targets = make_action_targets
    setup_immortals
  end
  #--------------------------------------------------------------------------
  # * New method: make_action_targets
  #--------------------------------------------------------------------------
  def make_action_targets
    targets = current_action.make_targets.compact.dup
    return targets.sort {|a, b| b.current_x <=> a.current_x } if frontview?
    return targets.sort {|a, b| b.current_y <=> a.current_y }
  end
  #--------------------------------------------------------------------------
  # * New method: setup_immortals
  #--------------------------------------------------------------------------
  def setup_immortals
    @action_targets.each {|target| @immortals.push(target) unless target.dead? }
    @immortals.uniq!
  end
  #--------------------------------------------------------------------------
  # * New method: deactivate
  #--------------------------------------------------------------------------
  def deactivate
    @active      = false
    @attack_flag = nil
    @result_flag = nil
    @next_target = nil
    @call_end    = true
    clear_immortals
    @action_targets.clear
  end
  #--------------------------------------------------------------------------
  # * New method: clear_immortals
  #--------------------------------------------------------------------------
  def clear_immortals
    members   = BattleManager.all_battle_members
    immortals = members.inject([]) {|r, member| r += member.poses.immortals }
    members.each   {|member| member.poses.immortals.clear }
    immortals.each {|member| member.refresh }
  end
  #--------------------------------------------------------------------------
  # * New method: action_pose
  #--------------------------------------------------------------------------
  def action_pose(item)
    @current_item = item
    call_action_poses
  end
  #--------------------------------------------------------------------------
  # * New method: call_action_poses
  #--------------------------------------------------------------------------
  def call_action_poses
    clear_loop
    set_action_pose
    call_pose(:inactive)
    call_custom_pose("RETREAT", :retreat, @current_item)
    call_pose(:clear)
  end
  #--------------------------------------------------------------------------
  # * New method: set_action_pose
  #--------------------------------------------------------------------------
  def set_action_pose
    set_attack_pose
    set_attack_pose(true) if use_double_attack?
    @attack_flag = use_double_attack? ? 1 : nil
  end
  #--------------------------------------------------------------------------
  # * New method: call_attack_pose
  #--------------------------------------------------------------------------
  def set_attack_pose(dual = false)
    item       = @current_item
    @dual_flag = dual
    call_move_pose("ADVANCE", :advance,   dual) if item && need_move?(item)
    call_pose(setup_pose_type(dual), nil, item) if item
    call_pose(:finish, nil)
  end
  #--------------------------------------------------------------------------
  # * New method: setup_pose_type
  #--------------------------------------------------------------------------
  def setup_pose_type(dual = false)
    pose = setup_basic_pose(dual)
    pose = :defend if item_defend?
    pose = setup_custom_pose(pose)
    pose
  end
  #--------------------------------------------------------------------------
  # * New method: setup_basic_pose
  #--------------------------------------------------------------------------
  def setup_basic_pose(dual)
    pose = weapons_pose("USE",    :use,    dual)
    pose = weapons_pose("ITEM",   :item,   dual) if @current_item.item?
    pose = weapons_pose("MAGIC",  :magic,  dual) if @current_item.magical?
    pose = weapons_pose("SKILL",  :skill,  dual) if @current_item.physical?
    pose = weapons_pose("ATTACK", :attack, dual) if item_attack?
    pose = weapons_pose("DUAL",   :dual_attack)  if use_dual_attack?
    pose
  end
  #--------------------------------------------------------------------------
  # * New method: 
  #--------------------------------------------------------------------------
  def item_attack?
    @battler.item_attack?(@current_item)
  end
  #--------------------------------------------------------------------------
  # * New method: 
  #--------------------------------------------------------------------------
  def item_defend?
    @battler.item_defend?(@current_item)
  end
  #--------------------------------------------------------------------------
  # * New method: 
  #--------------------------------------------------------------------------
  def use_double_attack?
    @battler.use_double_attack?(@current_item)
  end
  #--------------------------------------------------------------------------
  # * New method: 
  #--------------------------------------------------------------------------
  def use_dual_attack?
    @battler.use_dual_attack?(@current_item)
  end
  #--------------------------------------------------------------------------
  # * New method: 
  #--------------------------------------------------------------------------
  def current_action
    @battler.current_action
  end
  #--------------------------------------------------------------------------
  # * New method: frames
  #--------------------------------------------------------------------------
  def frames
    @battler.character_name[/\[F(\d+)\]/i] ? $1.to_i : 3
  end
  #--------------------------------------------------------------------------
  # * New method: not_in_position?
  #--------------------------------------------------------------------------
  def not_in_position?
    pose_list.first_name == :retreat
  end
  #--------------------------------------------------------------------------
  # * New method: setup_custom_pose
  #--------------------------------------------------------------------------
  def setup_custom_pose(pose)
    item = @current_item
    pose = battler_pose("ACTION", pose, item)
    pose = battler_pose("ITEM"  , pose, item) if item.item?
    pose = battler_pose("MAGIC" , pose, item) if item.magical?
    pose = battler_pose("SKILL" , pose, item) if item.physical?
    pose
  end
  #--------------------------------------------------------------------------
  # * New method: weapons_pose
  #--------------------------------------------------------------------------
  def weapons_pose(type, pose, dual = false)
    valid = @battler.actor? ? @battler.weapons + [@battler] : [@battler]
    list  = valid.collect {|item| item.custom_pose(type) }
    list.shift if dual
    list.empty? || !pose_exist?(list.first) ? pose : list.first
  end
  #--------------------------------------------------------------------------
  # * New method: battler_pose
  #--------------------------------------------------------------------------
  def battler_pose(type, pose, item)
    note   = item ? item.note : ""
    custom = item.custom_pose(type)
    custom && pose_exist?(custom, note) ? custom : pose
  end
  #--------------------------------------------------------------------------
  # * New method: pose_exist?
  #--------------------------------------------------------------------------
  def pose_exist?(pose, note = "")
    value  = "ACTION: #{make_string(pose)}(??: *, *[^>]+)+)?"
    regexp = get_all_values(value, "ACTION")
    @battler.get_all_poses(note) =~ regexp
  end
  #--------------------------------------------------------------------------
  # * New method: call_move_pose
  #--------------------------------------------------------------------------
  def call_move_pose(type, pose, dual)
    pose = weapons_pose(type, pose, dual) 
    pose = battler_pose(type, pose, @current_item)
    call_pose(pose, nil, @current_item)
  end
  #--------------------------------------------------------------------------
  # * New method: call_custom_pose
  #--------------------------------------------------------------------------
  def call_custom_pose(type, pose, item)
    pose = battler_pose(type, pose, item)
    call_pose(pose, nil, item)
  end
  #--------------------------------------------------------------------------
  # * New method: need_move?
  #--------------------------------------------------------------------------
  def need_move?(item)
    return false if @battler.unmovable?
    return true  if item.note =~ /<ACTION MOVEMENT>/i
    return true  if item.skill? && item.physical?
    return true  if item.skill? && item.id == @battler.attack_skill_id
    return false
  end
  #--------------------------------------------------------------------------
  # * New method: call_damage_pose
  #--------------------------------------------------------------------------
  def call_damage_pose(item, user)
    call_pose(:hurt,     :clear, item) if @battler.hurt_pose?
    call_pose(:miss,     :clear, item) if @battler.result.missed
    call_pose(:evade,    :clear, item) if @battler.result.evaded
    call_pose(:critical, :clear, item) if @battler.result.critical
    call_subsititution if @substitution
  end
  #--------------------------------------------------------------------------
  # * New method: call_damage_pose
  #--------------------------------------------------------------------------
  def clear_immortal
    @clear_flag = false
    BattleManager.all_battle_members.select do |member| 
      member.poses.immortals.delete(@battler)
      member.poses.action_targets.delete(@battler)
    end
    @battler.refresh
    @battler.result.added_states.delete(1)
  end
  #--------------------------------------------------------------------------
  # * New method: call_subsititution
  #--------------------------------------------------------------------------
  def call_subsititution
    call_pose(:substitution_on, :insert)
    @battler.sprite.update
  end
  #--------------------------------------------------------------------------
  # * New method: set_active_pose
  #--------------------------------------------------------------------------
  def set_active_pose
    return if !current_item && (!current_action || !current_action.item)
    item = current_action ? current_action.item : current_item
    setup_active_pose(item)
  end
  #--------------------------------------------------------------------------
  # * New method: setup_active_pose
  #--------------------------------------------------------------------------
  def setup_active_pose(item)
    @active_pose = call_active_pose(item)
    @battler.reset_pose if @active_pose
  end
  #--------------------------------------------------------------------------
  # * New method: call_active_pose
  #--------------------------------------------------------------------------
  def call_active_pose(item)
    pose = :ready      if @battler.sprite_value(:ready)
    pose = :item_cast  if item.item?     && @battler.sprite_value(:itemcast)
    pose = :magic_cast if item.magical?  && @battler.sprite_value(:magiccast)
    pose = :skill_cast if item.physical? && @battler.sprite_value(:skillcast)
    pose = battler_pose("ITEM CAST", pose, item)  if pose && item.item?
    pose = battler_pose("MAGIC CAST", pose, item) if pose && item.magical?
    pose = battler_pose("SKILL CAST", pose, item) if pose && item.physical?
    pose
  end
  #--------------------------------------------------------------------------
  # * New method: setup_counter
  #--------------------------------------------------------------------------
  def setup_counter(target, item)
    return if @counter_target
    target.poses.counter_on = true
    target.poses.countered  = true
    action          = @battler.counter_action
    @current_item   = action
    @action_targets = make_counter_targets(target, action)
    @counter_target = target
    setup_immortals
    @battler.use_item(action)
    call_pose(:prepare_counter)
    call_action_poses
    call_pose(:counter_off)
  end
  #--------------------------------------------------------------------------
  # * New method: make_counter_targets
  #--------------------------------------------------------------------------
  def make_counter_targets(target, item)
    targets = @battler.setup_counter_targets(target, item)
    return targets.sort {|a, b| b.current_x <=> a.current_x } if frontview?
    return targets.sort {|a, b| b.current_y <=> a.current_y }
  end
  #--------------------------------------------------------------------------
  # * New method: setup_reflect
  #--------------------------------------------------------------------------
  def setup_reflect(item)
    @action_targets = [@battler]
    setup_immortals
    @current_item = item
    call_pose(:reflection, :insert, item)
  end
  #--------------------------------------------------------------------------
  # * New method: setup_substitute
  #--------------------------------------------------------------------------
  def setup_substitute(target)
    @action_targets = [target]
    @substitution   = true
    call_pose(:substitution_off, :insert)
  end
  #--------------------------------------------------------------------------
  # * New method: start_shake
  #--------------------------------------------------------------------------
  def start_shake(power, speed, duration)
    @shake_power = power
    @shake_speed = speed
    @shake_duration = duration
  end
  #--------------------------------------------------------------------------
  # * New method: update_shake
  #--------------------------------------------------------------------------
  def update_shake
    return unless shaking?
    delta  = (@shake_power * @shake_speed * @shake_direction) / 10.0
    clear  = @shake_duration <= 1 && @shake * (@shake + delta) < 0
    @shake = clear ? 0 : @shake + delta
    @shake_direction = -1 if @shake > @shake_power * 2
    @shake_direction = 1  if @shake < - @shake_power * 2
    @shake_duration -= 1
  end
  #--------------------------------------------------------------------------
  # * New method: update_freeze
  #--------------------------------------------------------------------------
  def update_freeze
    return if @freeze == 0 || !@freeze.numeric?
    @freeze -= 1
  end
  #--------------------------------------------------------------------------
  # * New method: shaking?
  #--------------------------------------------------------------------------
  def shaking?
    @shake_duration > 0 || @shake != 0
  end
  #--------------------------------------------------------------------------
  # * New method: frozen?
  #--------------------------------------------------------------------------
  def frozen?
    (@freeze.numeric? && @freeze > 0) || @freeze == :lock || @battler.unmovable?
  end
  #--------------------------------------------------------------------------
  # * New method: frozen?
  #--------------------------------------------------------------------------
  def action?(layer)
    @pose_list.layer > layer
  end
  #--------------------------------------------------------------------------
  # * New method: setup_subject
  #--------------------------------------------------------------------------
  def setup_subject(subject)
    @immortals      = subject.poses.immortals.dup
    @current_item   = subject.poses.current_item
    @action_targets = subject.poses.action_targets.dup
  end
end

#==============================================================================
# ** Game_PoseValue
#------------------------------------------------------------------------------
#  This class deals with battlers pose values.
#==============================================================================

class Game_PoseValue
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :name
  attr_reader   :data
  attr_reader   :layer
  attr_reader   :battler
  attr_reader   :subjects
  attr_reader   :targets
  attr_reader   :active
  attr_reader   :icon_battler
  #--------------------------------------------------------------------------
  # * New method: initialize
  #--------------------------------------------------------------------------
  def initialize(name, value, battler, active, layer)
    @name     = make_symbol(name)
    @layer    = layer
    @battler  = battler
    @active   = active
    @subjects = set_subjects(value)
    @data     = {}
    @targets  = []
    setup_pose(value)
  end
  #--------------------------------------------------------------------------
  # * New method: []
  #--------------------------------------------------------------------------
  def [](value)
    @data[value]
  end
  #--------------------------------------------------------------------------
  # * New method: []=
  #--------------------------------------------------------------------------
  def []=(id, value)
    @data[id] = value
  end
  #--------------------------------------------------------------------------
  # * New method: poses
  #--------------------------------------------------------------------------
  def poses
    battler.poses
  end
  #--------------------------------------------------------------------------
  # * New method: setup_pose
  #--------------------------------------------------------------------------
  def setup_pose(value)
    case @name
    when :pose       then set_pose(value)
    when :wait       then set_wait(value)
    when :move       then set_move(value)
    when :jump       then set_jump(value)
    when :anim       then set_anim(value)
    when :icon       then set_icon(value)
    when :loop       then set_loop(value)
    when :tone       then set_tone(value)
    when :hide       then set_hide(value)
    when :throw      then set_throw(value)
    when :sound      then set_sound(value)
    when :plane      then set_plane(value)
    when :flash      then set_flash(value)
    when :shake      then set_shake(value)
    when :movie      then set_movie(value)
    when :count      then set_count(value)
    when :clear      then set_clear(value)
    when :state      then set_state(value)
    when :action     then set_action(value)
    when :freeze     then set_freeze(value)
    when :effect     then set_effect(value)
    when :script     then set_script(value)
    when :picture    then set_picture(value)
    when :counter    then set_counter(value)
    when :direction  then set_direction(value)
    when :condition  then set_condition(value)
    when :transform  then set_transform(value)
    when :afterimage then set_afterimage(value)
    when :transition then set_transition(value)
    end
  end
  #--------------------------------------------------------------------------
  # * New method: set_pose
  #--------------------------------------------------------------------------
  def set_pose(value)
    @data[:row]   = set_row(value)
    @data[:sufix] = set_sufix(value)
    @data[:frame] = value =~ /FRAME (\d+)/i      ? $1.to_i : 1
    @data[:angle] = value =~ /ANGLE ([+-]?\d+)/i ? $1.to_i : 0
    @data[:spin]  = value =~ /SPIN ([+-]?\d+)/i  ? $1.to_i : 0
    @data[:x]     = value =~ /X ([+-]?\d+)/i     ? $1.to_i : 0
    @data[:y]     = value =~ /Y ([+-]?\d+)/i     ? $1.to_i : 0
    @data[:size]  = value =~ /FRAME SIZE (\d+)/i ? $1.to_i : nil
    @data[:pose]  = setl_all_frames(value)
  end
  #--------------------------------------------------------------------------
  # * New method: set_wait
  #--------------------------------------------------------------------------
  def set_wait(value)
    value.scan(/\w+/i) {|result| set_wait_value(result) }
  end
  #--------------------------------------------------------------------------
  # * New method: set_move
  #--------------------------------------------------------------------------
  def set_move(value)
    @data[:value]    = make_symbol($1) if value =~ /(#{movement_words})/i
    @targets         = active_targets if @data[:value] == :move_to
    @targets         = active_targets if @data[:value] == :move_to_front
    @data[:x]        = value =~ /X ([+-]?\d+)/i ? $1.to_i : 0
    @data[:y]        = value =~ /Y ([+-]?\d+)/i ? $1.to_i : 0
    @data[:h]        = value =~ /HEIGHT (\d+)/i ? $1.to_i : 0
    @data[:speed]    = value =~ /SPEED (\d+)/i  ? $1.to_i / 10.0 : 1.0
    @data[:teleport] = true if value =~ /TELEPORT/i
    @data[:reset]    = true if value =~ /RESET/i
    @data[:over]     = true if value =~ /OVER/i
  end
  #--------------------------------------------------------------------------
  # * New method: set_jump
  #--------------------------------------------------------------------------
  def set_jump(value)
    @data[:move]   = true if value =~ /MOVE/i
    @data[:reset]  = true if value =~ /RESET/i
    @data[:height] = value =~ /HEIGHT (\d+)/i ? [$1.to_i, 1].max : nil
    @data[:speed]  = value =~ /SPEED (\d+)/i  ? [$1.to_i, 1].max : 10
  end
  #--------------------------------------------------------------------------
  # * New method: set_clear
  #--------------------------------------------------------------------------
  def set_clear(value)
    @data[:idle]   = true if value =~ /IDLE/i
    @data[:damage] = true if value =~ /DAMAGE/i
    @data[:pose]   = true if value =~ /POSE/i
  end
  #--------------------------------------------------------------------------
  # * New method: set_state
  #--------------------------------------------------------------------------
  def set_state(value)
    @data[:add]    = get_values(value, "ADD").compact
    @data[:remove] = get_values(value, "REMOVE").compact
  end
  #--------------------------------------------------------------------------
  # * New method: set_action
  #--------------------------------------------------------------------------
  def set_action(value)
    value.scan(/(\w[\w ]+)/) { @data[:action] = make_symbol($1) }
  end
  #--------------------------------------------------------------------------
  # * New method: set_freeze
  #--------------------------------------------------------------------------
  def set_freeze(value)
    @data[:duration] = value =~ /DURATION (\d+)/i ? [$1.to_i, 1].max : 1
  end
  #--------------------------------------------------------------------------
  # * New method: set_sound
  #--------------------------------------------------------------------------
  def set_sound(value)
    @data[:name]   = value =~ /NAME #{get_filename}/i ? $1 : ""
    @data[:volume] = value =~ /VOLUME (\d+)/i ? $1.to_i : 100
    @data[:pitch]  = value =~ /PITCH (\d+)/i  ? $1.to_i : 100
  end
  #--------------------------------------------------------------------------
  # * New method: set_hide
  #--------------------------------------------------------------------------
  def set_hide(value)
    @data[:all_battler] = true if value =~ /ALL BATTLERS/i
    @data[:all_enemies] = true if value =~ /ALL ENEMIES/i
    @data[:all_friends] = true if value =~ /ALL FRIENDS/i
    @data[:all_targets] = true if value =~ /ALL TARGETS/i
    @data[:not_targets] = true if value =~ /NOT TARGETS/i
    @data[:exc_user]    = true if value =~ /EXCLUDE USER/i
    @data[:inc_user]    = true if value =~ /INCLUDE USER/i
    @data[:unhide]      = true if value =~ /UNHIDE/i
  end
  #--------------------------------------------------------------------------
  # * New method: set_anim
  #--------------------------------------------------------------------------
  def set_anim(value)
    @data[:anim] = set_anim_id(value)
  end
  #--------------------------------------------------------------------------
  # * New method: set_icon
  #--------------------------------------------------------------------------
  def set_icon(value)
    @targets       = set_subjects(value, ",")
    @data[:index]  = value =~ /INDEX ([+-]?\d+)/i      ? $1.to_i : 0
    @data[:image]  = value =~ /IMAGE #{get_filename}/i ? $1.to_s : nil
    @data[:delete] = true if value =~ /DELETE/i
    @data[:above]  = true if value =~ /ABOVE/i
    return if @data[:delete]
    set_action_icon(value)
    @data[:x]    = value =~ /X ([+-]?\d+)/i     ? $1.to_i : 0
    @data[:y]    = value =~ /Y ([+-]?\d+)/i     ? $1.to_i : 0
    @data[:a]    = value =~ /ANGLE ([+-]?\d+)/i ? $1.to_i : 0
    @data[]    = value =~ /OPACITY (\d+)/i    ? $1.to_i : 255
    @data[:spin] = value =~ /SPIN ([+-]\d+)/i   ? $1.to_i : 0
    @data[:fin]  = value =~ /FADE IN (\d+)/i    ? $1.to_i : 0
    @data[:fout] = value =~ /FADE OUT (\d+)/i   ? $1.to_i : 0
    @data[:izm]  = value =~ /INIT ZOOM (\d+)/i  ? $1.to_i / 100.0 : 1.0
    @data[:ezm]  = value =~ /END ZOOM (\d+)/i   ? $1.to_i / 100.0 : 1.0
    @data[:szm]  = value =~ /ZOOM SPD (\d+)/i   ? $1.to_i / 100.0 : 0.1
  end
  #--------------------------------------------------------------------------
  # * New method: set_picture
  #--------------------------------------------------------------------------
  def set_picture(value)
    @data[:id]     = value =~ /ID (\d+)/i ? [$1.to_i, 1].max : 1
    @data[:delete] = true if value =~ /DELETE/i
    return if @data[:delete]
    nm = value =~ /NAME #{get_filename}/i ? $1.to_s : ""
    og = value =~ /CENTER/i            ? 1       : 0
    x  = value =~ /POS X ([+-]?\d+)/i  ? $1.to_i : 0
    y  = value =~ /POS Y ([+-]?\d+)/i  ? $1.to_i : 0
    zx = value =~ /ZOOM X ([+-]?\d+)/i ? $1.to_i : 100.0
    zy = value =~ /ZOOM X ([+-]?\d+)/i ? $1.to_i : 100.0
    op = value =~ /OPACITY (\d+)/i     ? $1.to_i : 255
    bt = value =~ /BLEND ([+-]\d+)/i   ? $1.to_i : 0
    dr = value =~ /DURATION (\d+)/i    ? $1.to_i : 0
    @data[:show] = [n, og, x, y, zx, zy, op, bt]  if value =~ /SHOW/i
    @data[:move] = [og, x, y, zx, zy, op, bt, dr] if value =~ /MOVE/i
  end
  #--------------------------------------------------------------------------
  # * New method: set_plane
  #--------------------------------------------------------------------------
  def set_plane(value)
    @data[:delete]   = value =~ /DELETE/i ? true : false
    @data[:duration] = value =~ /DURATION (\d+)/i ? $1.to_i : 0
    return if @data[:delete]
    name     = value =~ /NAME #{get_filename}/i ? $1.to_s : ""
    x        = value =~ /MOVE X ([+-]?\d+)/i    ? $1.to_i : 0
    y        = value =~ /MOVE Y ([+-]?\d+)/i    ? $1.to_i : 0
    z        = value =~ /Z ([+-]?\d+)/i         ? $1.to_i : 500
    zoom_x   = value =~ /ZOOM X (\d+)/i         ? $1.to_i : 100.0
    zoom_y   = value =~ /ZOOM Y (\d+)/i         ? $1.to_i : 100.0
    opacity  = value =~ /OPACITY (\d+)/i        ? $1.to_i : 160
    blend    = value =~ /BLEND (\d+)/i          ? $1.to_i : 0
    duration = @data[:duration]
    @data[:list] = [name, x, y, z, zoom_x, zoom_y, opacity, blend, duration]
  end
  #--------------------------------------------------------------------------
  # * New method: set_throw
  #--------------------------------------------------------------------------
  def set_throw(value)
    @targets       = set_subjects(value, ",")
    @data[:image]  = value =~ /IMAGE #{get_filename}/i ? $1.to_s : nil
    set_action_icon(value)
    @data[:revert] = true if value =~ /REVERT/i
    @data[:return] = true if value =~ /RETURN/i
    @data[:anim]   = value =~ /ANIM (\d+)/i        ? $1.to_i : nil
    @data[:init_x] = value =~ /INIT X ([+-]?\d+)/i ? $1.to_i : 0
    @data[:init_y] = value =~ /INIT Y ([+-]?\d+)/i ? $1.to_i : 0
    @data[:end_x]  = value =~ /END X ([+-]?\d+)/i  ? $1.to_i : 0
    @data[:end_y]  = value =~ /END Y ([+-]?\d+)/i  ? $1.to_i : 0
    @data[:arc]    = value =~ /ARC (\d+)/i         ? $1.to_i : 0
    @data[:spin]   = value =~ /SPIN ([+-]\d+)/i    ? $1.to_i : 0
    @data[:fin]    = value =~ /FADE IN (\d+)/i     ? $1.to_i : 0
    @data[:fout]   = value =~ /FADE OUT (\d+)/i    ? $1.to_i : 0
    @data[:a]      = value =~ /ANGLE (\d+)/i       ? $1.to_i : 0
    @data[]      = value =~ /OPACITY (\d+)/i     ? $1.to_i : 255
    @data[:speed]  = value =~ /SPEED (\d+)/i       ? $1.to_i / 10.0  : 1.0
    @data[:izm]    = value =~ /INIT ZOOM (\d+)/i   ? $1.to_i / 100.0 : 1.0
    @data[:ezm]    = value =~ /END ZOOM (\d+)/i    ? $1.to_i / 100.0 : 1.0
    @data[:szm]    = value =~ /ZOOM SPD (\d+)/i    ? $1.to_i / 100.0 : 0.1
  end
  #--------------------------------------------------------------------------
  # * New method: set_shake
  #--------------------------------------------------------------------------
  def set_shake(value)
    @data[:screen] = true if value =~ /SCREEN/i
    power    = value =~ /POWER (\d+)/i    ? [$1.to_i, 2].max : 5
    speed    = value =~ /SPEED (\d+)/i    ? [$1.to_i, 2].max : 5
    duration = value =~ /DURATION (\d+)/i ? [$1.to_i, 1].max : 10
    @data[:shake] = [power / 2.0, speed / 2.0, duration]
  end
  #--------------------------------------------------------------------------
  # * New method: set_movie
  #--------------------------------------------------------------------------
  def set_movie(value)
    @data[:name] = value =~ /NAME #{get_filename}/i ? $1.to_s : ""
    set_tone(value)
  end
  #--------------------------------------------------------------------------
  # * New method: set_tone
  #--------------------------------------------------------------------------
  def set_tone(value)
    r = value =~ /RED ([+-]?\d+)/i   ? $1.to_i : 0
    g = value =~ /GREEN ([+-]?\d+)/i ? $1.to_i : 0
    b = value =~ /BLUE ([+-]?\d+)/i  ? $1.to_i : 0
    a = value =~ /GRAY ([+-]?\d+)/i  ? $1.to_i : 0
    tone = [r, g, b, a]
    tone = [ 255,  255,  255, 0] if value =~ /WHITE/i
    tone = [-255, -255, -255, 0] if value =~ /BLACK/i
    @data[:tone]     = Tone.new(*tone)
    @data[:clear]    = true if value =~ /CLEAR/i
    @data[:duration] = value =~ /DURATION (\d+)/i ? $1.to_i : 0
    @data[:priority] = :normal
    @data[:priority] = :high if value =~ /HIGH PRIORITY/i
    @data[:priority] = :low  if value =~ /LOW PRIORITY/i
  end
  #--------------------------------------------------------------------------
  # * New method: set_flash
  #--------------------------------------------------------------------------
  def set_flash(value)
    @data[:screen] = true if value =~ /SCREEN/i
    r = value =~ /RED (\d+)/i   ? $1.to_i : 255
    g = value =~ /GREEN (\d+)/i ? $1.to_i : 255
    b = value =~ /BLUE (\d+)/i  ? $1.to_i : 255
    a = value =~ /ALPHA (\d+)/i ? $1.to_i : 160
    duration = value =~ /DURATION (\d+)/i ? [$1.to_i, 1].max : 10
    @data[:flash] = [Color.new(r, g, b, a), duration]
  end
  #--------------------------------------------------------------------------
  # * New method: set_loop
  #--------------------------------------------------------------------------
  def set_loop(value)
    @data[:loop_anim] = value =~ /ANIM (\d+)/i ? $1.to_i : 0
  end
  #--------------------------------------------------------------------------
  # * New method: set_effect
  #--------------------------------------------------------------------------
  def set_effect(value)
    @targets         = set_subjects(value, ",")
    @data[:damage]   = $1.to_i / 100.0  if value =~ /(\d+)%/i
    @data[:weapon]   = [$1.to_i, 1].max if value =~ /WEAPON (\d+)/i
    @data[:no_pose]  = true if value =~ /NO POSE/i
    @data[:clear]    = true if value =~ /CLEAR/i
    @data[:active]   = true if value =~ /ACTIVE/i
    @data[:elements] = get_values(value, "ELEMENTS").compact
  end
  #--------------------------------------------------------------------------
  # * New method: set_condition
  #--------------------------------------------------------------------------
  def set_condition(value)
    @data[:condition] = value =~ /^END/i ? :end : value.dup
  end
  #--------------------------------------------------------------------------
  # * New method: set_script
  #--------------------------------------------------------------------------
  def set_script(value)
    @data[:script]  = value.dup
  end
  #--------------------------------------------------------------------------
  # * New method: set_counter
  #--------------------------------------------------------------------------
  def set_counter(value)
    @data[:counter] = true  if value =~ /ON/i 
    @data[:counter] = false if value =~ /OFF/i 
  end
  #--------------------------------------------------------------------------
  # * New method: set_direction
  #--------------------------------------------------------------------------
  def set_direction(value)
    @targets          = battler.poses.last_targets if value =~ /SUBJECTS/i
    @data[:targets]   = true if value =~ /SUBJECTS/i
    @data[:active]    = true if value =~ /ACTIVE/i
    @data[:return]    = true if value =~ /RETURN/i
    @data[:default]   = true if value =~ /DEFAULT/i
    @data[:direction] = 2 if value =~ /DOWN/i
    @data[:direction] = 4 if value =~ /LEFT/i
    @data[:direction] = 6 if value =~ /RIGHT/i
    @data[:direction] = 8 if value =~ /UP/i
  end
  #--------------------------------------------------------------------------
  # * New method: set_transition
  #--------------------------------------------------------------------------
  def set_transition(value)
    @data[:prepare]  = true if value =~ /PREPARE/i
    @data[:execute]  = true if value =~ /EXECUTE/i
    @data[:duration] = value =~ /DURATION (\d+)/i ? $1.to_i : 40
    @data[:name]     = value =~ /NAME #{get_filename}/i ? $1.to_s : ""
  end
  #--------------------------------------------------------------------------
  # * New method: set_transform
  #--------------------------------------------------------------------------
  def set_transform(value)
    @data[:id] = $1.to_i if value =~ /ID (\d+)/i
  end
  #--------------------------------------------------------------------------
  # * New method: set_afterimage
  #--------------------------------------------------------------------------
  def set_afterimage(value)
    @data[:off]     = true if value =~ /OFF/i
    @data[:opacity] = value =~ /OPACITY (\d+)/i ? $1.to_i : 200
    @data[:blend]   = value =~ /BLEND (\d+)/i   ? $1.to_i : 0
    @data[:wait]    = value =~ /WAIT (\d+)/i    ? $1.to_i : 2
    @data[:fade]    = value =~ /FADE (\d+)/i   ? $1.to_i : 10
    r = value =~ /RED (\d+)/i   ? $1.to_i : 0
    g = value =~ /GREEN (\d+)/i ? $1.to_i : 0
    b = value =~ /BLUE (\d+)/i  ? $1.to_i : 0
    a = value =~ /ALPHA (\d+)/i ? $1.to_i : 0
    @data[:color] = [r, g, b, a]
  end
  #--------------------------------------------------------------------------
  # * New method: set_subjects
  #--------------------------------------------------------------------------
  def set_subjects(value, code = "^")
    case value
    when /#{code} *USER/i
      [active ? active : battler]
    when /#{code} *ACTIVE/i
      [BattleManager.active ? BattleManager.active : battler]
    when /#{code} *ACTOR ([^>,;]+)/i
      actor = $game_actors[battler.script_processing($1)]
      $game_party.battle_members.include?(actor) ? [actor] : []
    when /#{code} *FRIEND ([^>,;]+)/i
      [$game_party.battle_members[battler.script_processing($1) - 1]].compact
    when /#{code} *ENEMY ([^>,;]+)/i
      [$game_troop.members[battler.script_processing($1) - 1]].compact
    when /#{code} *RANDOM ENEMY/i
      poses.last_targets = [battler.opponents_unit.members.random]
      poses.last_targets
    when /#{code} *RANDOM FRIEND/i
      poses.last_targets = [battler.friends_unit.members.random]
      poses.last_targets
    when /#{code} *ALL ENEMIES/i
      poses.last_targets = battler.opponents_unit.members
      poses.last_targets
    when /#{code} *ALL FRIENDS/i
      poses.last_targets = battler.friends_unit.members
      poses.last_targets
    when /#{code} *TARGETS/i
      poses.last_targets = poses.action_targets.dup
      poses.last_targets
    when /#{code} *LAST/i
      poses.last_targets
    when /#{code} *NEXT/i
      poses.next_target  += 1 if poses.next_target
      poses.next_target ||= 0
      poses.next_target  %=  poses.action_targets.size
      poses.last_targets  = [poses.current_action_targets.first]
      poses.last_targets
    when /#{code} *PREVIOUS/i
      poses.next_target  -= 1 if battler.next_target
      poses.next_target ||= 0
      poses.next_target  %=  poses.action_targets.size
      poses.last_targets  = [poses.current_action_targets.first]
      poses.last_targets
    else
      [battler]
    end
  end
  #--------------------------------------------------------------------------
  # * New method: set_row
  #--------------------------------------------------------------------------
  def set_row(value)
    pose = battler.sprite_value(make_symbol($1)) if value =~ /ROW (\w+)/i
    pose = :direction if value =~ /ROW DIRECTION/i
    pose = $1.to_i    if value =~ /ROW (\d+)/i
    pose ? pose : 0
  end
  #--------------------------------------------------------------------------
  # * New method: set_sufix
  #--------------------------------------------------------------------------
  def set_sufix(value)
    pose = value =~ /SUFIX ([\[\]\w]+)/i ? $1.to_s : ""
    if pose.downcase == "[direction]"
      pose = case poses.direction
      when 2 then "[down]"
      when 4 then "[left]"
      when 6 then "[right]"
      when 8 then "[up]"
      end
    end
    pose
  end
  #--------------------------------------------------------------------------
  # * New method: set_action_icon
  #--------------------------------------------------------------------------
  def set_action_icon(value)
    id = battler.poses.dual_flag ? 2 : 1
    @icon_battler  = battler if value =~ /ACTIVE/i
    @data[:weapon] = id      if value =~ /WEAPON/i
    @data[:weapon] = $1.to_i if value =~ /WEAPON (\d+)/i
    @data[:armor]  = $1.to_i if value =~ /ARMOR (\d+)/i
    @data[:armor]  = 1       if value =~ /SHIELD/i
    @data[:custom] = $1.to_i if value =~ /ICON (\d+)/i
    @data[:action] = true    if value =~ /ACTION/i
  end
  #--------------------------------------------------------------------------
  # * New method: setl_all_frames
  #--------------------------------------------------------------------------
  def setl_all_frames(value)
    if value =~ /(?:\d+|ALL) FRAMES?/i
      w = value =~ /WAIT (\d+)/i ? [$1.to_i, 1].max : 1
      l = value =~ /LOOP/i   ? true : false
      r = value =~ /RETURN/i ? true : false
      v = value =~ /REVERT/i ? true : false
      i = value =~ /INVERT/i ? true : false
      f = battler.set_pose_frames(value) rescue 0
      {wait: w, time: w, frame: f, loop: l, return: r, revert: v, invert: i}
    else
      {invert: value =~ /INVERT/i ? true : false }
    end
  end
  #--------------------------------------------------------------------------
  # * New method: set_wait_value
  #--------------------------------------------------------------------------
  def set_wait_value(value)
    case value
    when /(\d+)/i
      @data[:time] = $1.to_i
      @data[:wait] = $1.to_i
    when /(#{wait_words})/i
      @data[:time] = 2
      @data[:wait] = make_symbol($1)
    end
  end
  #--------------------------------------------------------------------------
  # * New method: set_anim_id
  #--------------------------------------------------------------------------
  def set_anim_id(value)
    item = battler.poses.current_item
    case value
    when /CAST/i
      cast = item && $imported[:ve_cast_animation]
      anim = cast ? battler.cast_animation_id(item) : 0
      anim
    when /EFFECT/i
      item ? item.animation_id : 0
    when /ID (\d+)/i
      $1.to_i
    when /WEAPON(?: *(\d+)?)?/i
      dual = battler.poses.dual_flag || ($1 && $1.to_i == 2)
      dual ? battler.atk_animation_id2 : battler.atk_animation_id1
    else
      return 0
    end
  end
  #--------------------------------------------------------------------------
  # * New method: get_values
  #--------------------------------------------------------------------------
  def get_values(value, code)
    regexp = /#{code} *((?:\d+%?|, *\d+%?)+)/i
    value.scan(regexp).inject([]) do |r, obj| 
      r += obj.first.scan(/\d+%?/i).collect {|i| i[/%/i] ? nil : i.to_i}
    end
  end
  #--------------------------------------------------------------------------
  # * New method: wait_words
  #--------------------------------------------------------------------------
  def wait_words
    words  = 'ANIMATION|ACTIVE|ACTION|MOVEMENT|ORIGIN|COUNTERED|COUNTER|'
    words += 'SUBSTITUTION|TONE|THROW|POSE|FREEZE|LOG'
    words
  end
  #--------------------------------------------------------------------------
  # * New method: movement_words
  #--------------------------------------------------------------------------
  def movement_words
    'MOVE TO(?: FRONT)?|STEP (?:FORWARD|BACKWARD)|RETREAT|ESCAPE|SUBSTITUTION'
  end
  #--------------------------------------------------------------------------
  # * New method: active_targets
  #--------------------------------------------------------------------------
  def active_targets
    battler.poses.current_action_targets
  end
end

#==============================================================================
# ** Game_PoseAction
#------------------------------------------------------------------------------
#  This class deals with battlers pose actions.
#==============================================================================

class Game_PoseAction
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :name
  attr_reader   :next
  attr_reader   :data
  attr_reader   :layer
  attr_reader   :battler
  #--------------------------------------------------------------------------
  # * New method: initialize
  #--------------------------------------------------------------------------
  def initialize(name, last, layer, battler)
    @name    = name
    @next    = last
    @layer   = layer
    @battler = battler
    @data    = []
    @current = []
  end
  #--------------------------------------------------------------------------
  # * New method: []
  #--------------------------------------------------------------------------
  def [](id)
    @data[id]
  end
  #--------------------------------------------------------------------------
  # * New method: []=
  #--------------------------------------------------------------------------
  def []=(id, value)
    @data[id] = value
  end
  #--------------------------------------------------------------------------
  # * New method: push
  #--------------------------------------------------------------------------
  def push(value)
    @data.push(value)
  end
  #--------------------------------------------------------------------------
  # * New method: empty?
  #--------------------------------------------------------------------------
  def empty?
    @data.empty?
  end
  #--------------------------------------------------------------------------
  # * New method: poses
  #--------------------------------------------------------------------------
  def poses
    @battler.poses
  end
  #--------------------------------------------------------------------------
  # * New method: pose_list
  #--------------------------------------------------------------------------
  def pose_list
    @battler.poses.pose_list
  end
  #--------------------------------------------------------------------------
  # * New method: update
  #--------------------------------------------------------------------------
  def update
    setup_pose
    update_pose
  end
  #--------------------------------------------------------------------------
  # * New method: setup_pose
  #--------------------------------------------------------------------------
  def setup_pose
    return unless @data.first && changed_pose?
    @current = @data.dup
    @pose    = @current.first
  end
  #--------------------------------------------------------------------------
  # * New method: changed_pose?
  #--------------------------------------------------------------------------
  def changed_pose?
    @current.size != @data.size || @current.first.name != @data.first.name
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose
  #--------------------------------------------------------------------------
  def update_pose
    if @pose && @pose.name.symbol?
      update_current_pose
      next_pose unless waiting?
    else
      next_pose
    end
  end
  #--------------------------------------------------------------------------
  # * New method: next_pose
  #--------------------------------------------------------------------------
  def next_pose
    return unless @data
    case @next
    when :loop
      @data.next_item
    when :wait
      @data.shift if @data.size > 1
    when :reset
      @data.shift
    when Symbol
      @data.shift
      poses.pose_list.setup_pose(layer, false) if @data.empty?
      poses.call_pose(@next, :clear)           if @data.empty?
    else
      last = @data.shift
      poses.pose_list.setup_pose(layer) if !@data.empty?
      @data.unshift(last) if @data.empty? && pose_list[@layer].empty?
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_type
  #--------------------------------------------------------------------------
  def update_current_pose
    @wait = false
    send("update_pose_#{@pose.name}")
  end
  #--------------------------------------------------------------------------
  # * New method: get_subjects
  #--------------------------------------------------------------------------
  def get_subjects
    @pose ? @pose.subjects.compact : [active]
  end
  #--------------------------------------------------------------------------
  # * New method: active
  #--------------------------------------------------------------------------
  def active
    @pose.active ? @pose.active : @battler
  end
  #--------------------------------------------------------------------------
  # * New method: pose_list
  #--------------------------------------------------------------------------
  def pose_list
    poses.pose_list
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_wait
  #--------------------------------------------------------------------------
  def update_pose_wait
    case @pose[:wait]
    when :animation
      @pose[:time] -= 1
      anim  = get_subjects.any? {|subject| subject.sprite.animation? }
      @wait = anim || @pose[:time] > 0
    when :active
      @wait = get_subjects.any? {|subject| subject.poses.active? }
    when :action
      @wait = get_subjects.any? {|subject| subject.poses.action?(@layer) }
    when :movement
      @wait = get_subjects.any? {|subject| subject.poses.moving? }
    when :origin
      @wait = get_subjects.any? {|subject| subject.poses.not_origin? }
    when :counter
      @wait = get_subjects.any? {|subject| subject.poses.counter_on }
    when :countered
      @wait = get_subjects.any? {|subject| subject.poses.countered }
    when :substitution
      @wait = get_subjects.any? {|subject| subject.poses.substitution }
    when :throw
      @wait = get_subjects.any? {|subject| subject.sprite.throwing? }
    when :pose
      @wait = get_subjects.any? {|subject| subject.poses.pose? }
    when :freeze
      @wait = get_subjects.any? {|subject| subject.poses.frozen? }
    when :tone
      @wait = $game_troop.screen.tone_change?
    when :log
      @wait = SceneManager.scene.log_window_wait?
    when Numeric
      @pose[:time] -= 1
      @pose[:time]  = @pose[:wait] if @pose[:time] == 0
      @wait         = @pose[:time] != @pose[:wait]
    end
  end
  #--------------------------------------------------------------------------
  # * New method: waiting?
  #--------------------------------------------------------------------------
  def waiting?
    @wait
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_clear
  #--------------------------------------------------------------------------
  def update_pose_clear
    get_subjects.each do |subject|
      subject.poses.clear_loop   if @pose[:idle]
      subject.poses.clear_damage if @pose[:damage]
      subject.poses.reset = true if @pose[:pose]
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_action
  #--------------------------------------------------------------------------
  def update_pose_action
    get_subjects.each do |subject|
      item  = poses.current_item
      layer = subject.poses.pose_list.layer + 1
      subject.poses.clear_loop
      subject.poses.call_pose(@pose[:action], layer, item, @battler) 
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_finish
  #--------------------------------------------------------------------------
  def update_pose_finish
    poses.attack_flag += 1 if poses.attack_flag
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_state
  #--------------------------------------------------------------------------
  def update_pose_state
    get_subjects.each do |subject|
      @pose[:add].each    {|id| subject.add_state(id) }
      @pose[:remove].each {|id| subject.remove_state(id) }
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_appear
  #--------------------------------------------------------------------------
  def update_pose_appear
    get_subjects.each do |subject|
      next if subject.actor?
      subject.appear
      $game_troop.make_unique_names
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_transform
  #--------------------------------------------------------------------------
  def update_pose_transform
    get_subjects.each do |subject|
      next if subject.actor? || !@pose[:id]
      subject.transform(@pose[:id])
      $game_troop.make_unique_names
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_anim
  #--------------------------------------------------------------------------
  def update_pose_anim
    active.poses.anim_targets ||= []
    active.poses.anim_targets += get_subjects.dup
    active.poses.anim_targets.uniq!
    active.poses.call_anim = true
    active.poses.animation = @pose[:anim]
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_effect
  #--------------------------------------------------------------------------
  def update_pose_effect
    battler = get_subjects.include?(active) ? active : get_subjects.first
    battler.poses.call_effect = true if battler
    get_subjects.each do |subject|
      battler.poses.active_effect.push(subject) if battler != subject
      subject.poses.setup_subject(battler)      if battler != subject
      subject.poses.damage_flag  = @pose[:damage]
      subject.poses.attack_flag  = @pose[:weapon] if @pose[:weapon]
      subject.poses.no_hurt_flag = @pose[:no_pose]
      subject.poses.element_flag = @pose[:elements]
      if @pose.targets.empty?
        subject.poses.targets = subject.poses.action_targets
      else
        subject.poses.targets = @pose.targets.dup
      end
      subject.poses.targets.each {|target| target.clear_flag = @pose[:clear] }
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_loop
  #--------------------------------------------------------------------------
  def update_pose_loop
    get_subjects.each {|subject| subject.pose_loop = @pose[:loop_anim] }
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_plane
  #--------------------------------------------------------------------------
  def update_pose_plane
    if @pose[:delete]
      SceneManager.scene.spriteset.delete_plane(@pose[:duration])
    elsif @pose[:list]
      SceneManager.scene.spriteset.action_plane(*@pose[:list])
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_sound
  #--------------------------------------------------------------------------
  def update_pose_sound
    se = RPG::SE.new(@pose[:name], @pose[:volume], @pose[:pitch])
    se.play
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_pose
  #--------------------------------------------------------------------------
  def update_pose_pose
    get_subjects.each do |subject|
      poses = subject.poses
      poses.row    = @pose[:row] - 1          if @pose[:row].numeric?
      poses.row    = poses.direction / 2  - 1 if @pose[:row].symbol?
      poses.sufix  = @pose[:sufix]
      poses.angle  = @pose[:angle]
      poses.spin   = @pose[:spin]
      poses.x_adj  = @pose[:x]
      poses.y_adj  = @pose[:y]
      poses.timing = @pose[:pose]
      poses.f_size = @pose[:size]
      poses.frame  = (@pose[:frame] - 1) % subject.sprite_value(:frames)
      poses.f_init = (@pose[:frame] - 1) % subject.sprite_value(:frames)
      poses.frame  = poses.timing[:frame] if poses.timing[:revert]
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_move
  #--------------------------------------------------------------------------
  def update_pose_move
    get_subjects.each do |subject|
      subject.poses.teleport   = @pose[:teleport]
      subject.poses.reset_move = @pose[:reset]
      subject.poses.move_over  = @pose[:over]
      setup_target_position(subject)
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_counter
  #--------------------------------------------------------------------------
  def update_pose_counter
    subject = poses.counter_target ? poses.counter_target : @battler
    subject.poses.counter_on = false
    poses.counter_target     = nil
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_substitution
  #--------------------------------------------------------------------------
  def update_pose_substitution
    substitution = @pose[:substitution]
    get_subjects.each {|subject| subject.poses.substitution = substitution }
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_jump
  #--------------------------------------------------------------------------
  def update_pose_jump
    get_subjects.each do |subject|
      poses  = subject.poses
      height = @pose[:height] ? @pose[:height] : 5
      if @pose[:move]
        x_plus = (poses.target_distance(:x) / 32.0).abs
        y_plus = (poses.target_distance(:y) / 32.0).abs
        speed = Math.sqrt((x_plus ** 2) + (y_plus ** 2)) / poses.move_speed
        poses.jumping[:speed] = height * 5.0 / [speed, 1].max
      else
        poses.jumping[:speed] = @pose[:speed]
      end
      if @pose[:height]
        poses.jumping[:reset]  = @pose[:reset]
        poses.jumping[:height] = @pose[:height]
        poses.jumping[:count]  = poses.jumping[:height] * 2
      end
    end    
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_inactive
  #--------------------------------------------------------------------------
  def update_pose_inactive
    @battler.poses.deactivate
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_inactive
  #--------------------------------------------------------------------------
  def update_pose_countered
    @battler.poses.countered = false
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_target
  #--------------------------------------------------------------------------
  def update_pose_target
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_direction
  #--------------------------------------------------------------------------
  def update_pose_direction
    get_subjects.each do |subject|
      subject.poses.origin_direction  if @pose[:return]
      subject.poses.active_direction  if @pose[:active]
      subject.poses.default_direction if @pose[:default]
      subject.poses.action_direction(@pose.targets) if @pose[:targets]
      subject.poses.direction = @pose[:direction]   if @pose[:direction]
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_condition
  #--------------------------------------------------------------------------
  def update_pose_condition
    return if condition_met || @pose[:condition] == :end
    loop do
      next_pose
      setup_pose
      break if @current.empty? || [@pose && @pose[:condition] == :end]
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_script
  #--------------------------------------------------------------------------
  def update_pose_script
    @battler.script_processing(@pose[:script])
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_icon
  #--------------------------------------------------------------------------
  def update_pose_icon
    get_subjects.each do |subject|
      if @pose[:delete]
        subject.poses.icon_list.delete(@pose[:index])
      else
        icon = Game_PoseIcon.new(@pose, subject, subject)
        subject.poses.icon_list[@pose[:index]] = icon
      end
      subject.sprite.update_icon
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_picture
  #--------------------------------------------------------------------------
  def update_pose_picture
    if @pose[:show]
      $game_troop.screen.pictures[@pose[:id]].show(*@pose[:show])
    elsif @pose[:move]
      $game_troop.screen.pictures[@pose[:id]].move(*@pose[:move])
    elsif @pose[:delete]
     $game_troop.screen.pictures[@pose[:id]].erase
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_throw
  #--------------------------------------------------------------------------
  def update_pose_throw
    get_subjects.each do |subject|
      @pose.targets.each do |target|
        icon = Game_PoseIcon.new(@pose.data.dup, target, subject)
        subject.poses.throw_list.push(icon)
      end
      subject.sprite.update_throw
    end   
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_shake
  #--------------------------------------------------------------------------
  def update_pose_shake
    if @pose[:screen]
      $game_troop.screen.start_shake(*@pose[:shake])
    else
      get_subjects.each {|subject| subject.poses.start_shake(*@pose[:shake]) }
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_flash
  #--------------------------------------------------------------------------
  def update_pose_flash
    if @pose[:screen]
      $game_troop.screen.start_flash(*@pose[:flash])
    else
      get_subjects.each {|subject| subject.sprite.flash(*@pose[:flash]) }
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_freeze
  #--------------------------------------------------------------------------
  def update_pose_freeze
    get_subjects.each {|subject| subject.poses.freeze = @pose[:duration] }
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_movie
  #--------------------------------------------------------------------------
  def update_pose_movie
    Graphics.play_movie("Movies/" + @pose[:name]) if @pose[:name] != ""
    update_pose_tone
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_drain
  #--------------------------------------------------------------------------
  def update_pose_drain
    get_subjects.each do |subject|
      subject.drain_setup if subject.hp_drain != 0 || subject.mp_drain != 0
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_transition
  #--------------------------------------------------------------------------
  def update_pose_transition
    if @pose[:prepare]
      Graphics.freeze
    elsif @pose[:execute]
      time  = @pose[:duration]
      name  = "Graphics/System/" + @pose[:name]
      value = @pose[:name] == "" ? [time] : [time, name]
      Graphics.transition(*value)
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_hide
  #--------------------------------------------------------------------------
  def update_pose_hide
    hidden_list.each {|subject| subject.poses.invisible = !@pose[:unhide] }
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_tone
  #--------------------------------------------------------------------------
  def update_pose_tone
    send("update_#{@pose[:priority]}_tone")
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_afterimage
  #--------------------------------------------------------------------------
  def update_pose_afterimage
    get_subjects.each do |subject|
      if @pose[:off]
        subject.poses.afterimage = nil
      else
        subject.poses.afterimage = {}
        subject.poses.afterimage[:wait]    = @pose[:wait]
        subject.poses.afterimage[:opacity] = @pose[:opacity]
        subject.poses.afterimage[:color]   = @pose[:color]
        subject.poses.afterimage[:fade]    = @pose[:fade]
        subject.poses.afterimage[:blend]   = @pose[:blend]
      end
    end
  end
  #--------------------------------------------------------------------------
  # * New method: hidden_list
  #--------------------------------------------------------------------------
  def hidden_list
    list = []
    if @pose[:all_battler]
      list += BattleManager.all_battle_members
    elsif @pose[:all_enemies]
      list += @battler.opponents_unit
    elsif @pose[:all_friends]
      list += @battler.friends_unit
    elsif @pose[:all_targets]
      list += @battler.poses.action_targets
    elsif @pose[:not_targets]
      list += BattleManager.all_battle_members - @battler.poses.action_targets
    end
    if @pose[:exc_user]
      list -= [active]
    elsif @pose[:inc_user]
      list += [active]
    end
    list = get_subjects.dup if list.empty?
    list
  end
  #--------------------------------------------------------------------------
  # * New method: update_low_tone
  #--------------------------------------------------------------------------
  def update_low_tone
    screen = $game_troop.screen
    screen.old_low_tone = screen.low_tone.dup unless screen.old_low_tone
    tone = @pose[:clear] ? screen.old_low_tone.dup : @pose[:tone] 
    $game_troop.screen.old_low_tone = nil if @pose[:clear]
    $game_troop.screen.start_low_tone_change(tone, @pose[:duration])
  end
  #--------------------------------------------------------------------------
  # * New method: update_normal_tone
  #--------------------------------------------------------------------------
  def update_normal_tone
    screen = $game_troop.screen
    screen.old_tone = screen.tone.dup unless screen.old_tone
    tone = @pose[:clear] ? $game_troop.screen.old_tone.dup : @pose[:tone] 
    $game_troop.screen.old_tone = nil if @pose[:clear]
    $game_troop.screen.start_tone_change(tone, @pose[:duration])
  end
  #--------------------------------------------------------------------------
  # * New method: update_high_tone
  #--------------------------------------------------------------------------  
  def update_high_tone
    screen = $game_troop.screen
    screen.old_high_tone = screen.high_tone.dup unless screen.old_high_tone
    tone = @pose[:clear] ? screen.old_high_tone.dup : @pose[:tone] 
    $game_troop.screen.old_high_tone = nil if @pose[:clear]
    $game_troop.screen.start_high_tone_change(tone, @pose[:duration])
  end
  #--------------------------------------------------------------------------
  # * New method: condition_met
  #--------------------------------------------------------------------------
  def condition_met
    @pose[:condition].string? && @battler.script_processing(@pose[:condition])
  end
  #--------------------------------------------------------------------------
  # * New method: setup_target_position
  #--------------------------------------------------------------------------
  def setup_target_position(subject)
    return unless @battler.use_sprite?
    if @pose[:value] == :move_to
      setup_move_to_target_position(subject)
    elsif @pose[:value] == :move_to_front
      setup_move_to_front_position(subject)
    elsif @pose[:value] == :step_forward
      setup_step_forward_position(subject)
    elsif @pose[:value] == :step_backward
      setup_step_backward_position(subject)
    elsif @pose[:value] == :escape
      setup_escape_position(subject)
    elsif @pose[:value] == :retreat
      setup_retreat_position(subject)
    elsif @pose[:value] == :substitution
      setup_substitution_position(subject)
    end
    return if waiting?
    subject.poses.position_fix while subject.poses.sharing_position?
    subject.poses.move_over = false
    setup_final_target_position(subject)
    subject.poses.fix_position if subject.unmovable?
  end
  #--------------------------------------------------------------------------
  # * New method: setup_move_to_target_position
  #--------------------------------------------------------------------------
  def setup_move_to_target_position(subject)
    targets = @pose.targets.select {|member| member.use_sprite? }
    return if targets.empty?
    return @wait = true if targets.any? {|member| member.poses.moving? }
    return @wait = true if targets.any? {|member| member.poses.damage_pose? }
    x = targets.collect {|member| member.current_x}.average
    y = targets.collect {|member| member.current_y}.average
    subject.poses.target_position[:x] = x
    subject.poses.target_position[:y] = y
    return if subject.target_current?
    subject.poses.target_direction(x, y)
    subject.poses.adjust_position(32)
  end
  #--------------------------------------------------------------------------
  # * New method: setup_move_to_target_position
  #--------------------------------------------------------------------------
  def setup_move_to_front_position(subject)
    targets = @pose.targets.select {|member| member.use_sprite? }
    return if targets.empty?
    return @wait = true if targets.any? {|member| member.poses.moving?}
    return @wait = true if targets.any? {|member| member.poses.damage_pose? }
    battler = targets.first
    adjustx = battler.poses.right? ? 32 : battler.poses.left? ? -32 : 0
    adjusty = battler.poses.down?  ? 32 : battler.poses.up?   ? -32 : 0
    x = battler.current_x + adjustx
    y = battler.current_y + adjusty
    subject.poses.target_position[:x] = x
    subject.poses.target_position[:y] = y
    return if subject.target_current?
    subject.poses.target_direction(x, y)
  end
  #--------------------------------------------------------------------------
  # * New method: setup_step_forward_position
  #--------------------------------------------------------------------------
  def setup_step_forward_position(subject)
    subject.poses.adjust_position(-48)
  end
  #--------------------------------------------------------------------------
  # * New method: setup_step_backward_position
  #--------------------------------------------------------------------------
  def setup_step_backward_position(subject)
    subject.poses.adjust_position(48)
  end
  #--------------------------------------------------------------------------
  # * New method: setup_escape_position
  #--------------------------------------------------------------------------
  def setup_escape_position(subject)
    subject.poses.adjust_position(320)
    subject.poses.target_direction(subject.target_x, subject.target_y)
  end
  #--------------------------------------------------------------------------
  # * New method: setup_retreat_position
  #--------------------------------------------------------------------------
  def setup_retreat_position(subject)
    return if subject.target_origin? || subject.current_origin?
    x = subject.poses.target_position[:x] = subject.screen_x
    y = subject.poses.target_position[:y] = subject.screen_y
    subject.poses.target_direction(x, y)
  end
  #--------------------------------------------------------------------------
  # * New method: setup_substitution_position
  #--------------------------------------------------------------------------
  def setup_substitution_position(subject)
    battler = subject.poses.action_targets.first
    subject.poses.target_position = battler.poses.current_position.dup
    x = battler.left? ? -16 : battler.right? ? 16 : 0
    y = battler.up?   ? -16 : battler.down?  ? 16 : 1
    subject.poses.target_position[:x] += x
    subject.poses.target_position[:y] += y
  end
  #--------------------------------------------------------------------------
  # * New method: setup_final_target_positio
  #--------------------------------------------------------------------------
  def setup_final_target_position(subject)
    poses = subject.poses
    if subject.left?  || subject.right?
      poses.target_position[:x] += subject.left? ? @pose[:x] : -@pose[:x]
      poses.target_position[:y] += @pose[:y]
    elsif subject.up? || subject.down?
      poses.target_position[:y] += subject.up?   ? @pose[:x] : -@pose[:x]
      poses.target_position[:x] += @pose[:y]
    end
    poses.target_position[:h] += @pose[:h]
    poses.move_speed           = @pose[:speed]
  end
end

#==============================================================================
# ** Game_PoseIcon
#------------------------------------------------------------------------------
#  This class deals with pose icons.
#==============================================================================

class Game_PoseIcon
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :user
  attr_reader   :data
  attr_reader   :icon
  attr_reader   :target
  #--------------------------------------------------------------------------
  # * New method: initialize
  #--------------------------------------------------------------------------
  def initialize(data, user, target)
    @user   = user
    @target = target
    @data   = data
    @icon   = setup_pose_icon(user)
  end
  #--------------------------------------------------------------------------
  # * New method: setup_pose_icon
  #--------------------------------------------------------------------------
  def setup_pose_icon(subject)
    icon = subject.weapon_icon(@data[:weapon]) if @data[:weapon]
    icon = subject.armor_icon(@data[:armor])   if @data[:armor]
    icon = subject.action_icon if @data[:action]
    icon = @data[:custom]      if @data[:custom]
    icon = @data[:image]       if @data[:image]
    icon ? icon : 0
  end
end

#==============================================================================
# ** Game_PoseList
#------------------------------------------------------------------------------
#  This class deals with battlers pose list.
#==============================================================================

class Game_PoseList
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :data
  attr_reader   :pose
  attr_reader   :list
  attr_reader   :name
  #--------------------------------------------------------------------------
  # * New method: initialize
  #--------------------------------------------------------------------------
  def initialize(battler)
    @battler = battler
    @data    = {}
    @pose    = {}
    @list    = {}
    @name    = {}
  end
  #--------------------------------------------------------------------------
  # * New method: []
  #--------------------------------------------------------------------------
  def [](id)
    @data[id] ||= []
  end
  #--------------------------------------------------------------------------
  # * New method: []=
  #--------------------------------------------------------------------------
  def []=(id, value)
    @data[id] = value
  end
  #--------------------------------------------------------------------------
  # * New method: insert
  #--------------------------------------------------------------------------
  def insert(id, index, value)
    self[id].insert(index, *value)
  end
  #--------------------------------------------------------------------------
  # * New method: shift
  #--------------------------------------------------------------------------
  def shift(id)
    self[id].shift
  end
  #--------------------------------------------------------------------------
  # * New method: delete
  #--------------------------------------------------------------------------
  def delete(value)
    @data.delete(value)
  end
  #--------------------------------------------------------------------------
  # * New method: include?
  #--------------------------------------------------------------------------
  def include?(pose)
    all_names.include?(pose)
  end
  #--------------------------------------------------------------------------
  # * New method: keys
  #--------------------------------------------------------------------------
  def keys
    @data.keys.compact.collect {|key| yield key } if block_given?
  end
  #--------------------------------------------------------------------------
  # * New method: any?
  #--------------------------------------------------------------------------
  def any?
    @data.keys.compact.any? {|key| yield key } if block_given?
  end
  #--------------------------------------------------------------------------
  # * New method: update
  #--------------------------------------------------------------------------
  def update
    @data.keys.compact.each do |key|
      setup_pose(key)  if @pose[key] != self[key].first
      update_pose(key) if @pose[key]
      self.delete(key) if self[key].empty? && key != 1
    end
  end
  #--------------------------------------------------------------------------
  # * New method: setup_pose
  #--------------------------------------------------------------------------
  def setup_pose(key, update = true)
    @pose[key] = self[key].first
    @name[key] = @pose[key] ? @pose[key].name : nil
    @list[key] = self[key].collect {|value| value.name }
    @battler.poses.icon_list.clear if !inactive_pose?(@name[key])
    @pose[key].update if @pose[key] && update
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose
  #--------------------------------------------------------------------------
  def update_pose(key)
    @pose[key].update
    return if @pose[key].waiting? || !@pose[key].empty?
    self[key].shift
    self[key].shift if no_retreat?(first_name(key))
    @battler.reset_pose if @pose[key].next == :reset
    @battler.poses.afterimage = nil
  end
  #--------------------------------------------------------------------------
  # * New method: first_name
  #--------------------------------------------------------------------------
  def first_name(key = 1)
    self[key].first ? self[key].first.name : nil
  end
  #--------------------------------------------------------------------------
  # * New method: all_names
  #--------------------------------------------------------------------------
  def all_names
    @data.keys.compact.inject([]) {|r, key| r += get_names(key) }
  end
  #--------------------------------------------------------------------------
  # * New method: get_names
  #--------------------------------------------------------------------------
  def get_names(key)
    self[key].collect {|value| value.name }
  end
  #--------------------------------------------------------------------------
  # * New method: setup_all_poses
  #--------------------------------------------------------------------------
  def setup_all_poses
    @data.keys.compact.reverse.each do |key|
      self[key].first.setup_pose if self[key].first
    end
  end
  #--------------------------------------------------------------------------
  # * New method: layer
  #--------------------------------------------------------------------------
  def layer
    @data.keys.compact.size
  end
  #--------------------------------------------------------------------------
  # * New method: clear_loop
  #--------------------------------------------------------------------------
  def clear_loop
    keys {|key| self[key].delete_if {|pose| pose.next == :loop } }
  end
  #--------------------------------------------------------------------------
  # * New method: clear_damage
  #--------------------------------------------------------------------------
  def clear_damage
    keys {|key| self[key].delete_if {|pose| is_damage_pose?(pose.name)} }
  end
  #--------------------------------------------------------------------------
  # * New method: is_damage_pose?
  #--------------------------------------------------------------------------
  def is_damage_pose?(name)
    name == :hurt || name == :miss || name == :evade || name == :critical
  end
  #--------------------------------------------------------------------------
  # * New method: damage_pose?
  #--------------------------------------------------------------------------
  def damage_pose?
    any? {|key| self[key].first && is_damage_pose?(self[key].first.name) }
  end
  #--------------------------------------------------------------------------
  # * New method: inactive_pose?
  #--------------------------------------------------------------------------
  def inactive_pose?(name)
    name.nil? || name == :inactive || name == :finish || name == :retreat
  end
  #--------------------------------------------------------------------------
  # * New method: no_retreat?
  #--------------------------------------------------------------------------
  def no_retreat?(name)
    name == :retreat && @battler.current_origin?
  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
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :battler
  attr_reader   :battler_name
  #--------------------------------------------------------------------------
  # * Overwrite method: update_bitmap
  #--------------------------------------------------------------------------
  def update_bitmap
    setup_bitmap if graphic_changed?
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: init_visibility
  #--------------------------------------------------------------------------
  def init_visibility
    @battler_visible = !@battler.hidden?
    self.opacity = 0 unless @battler_visible
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: update_origin
  #--------------------------------------------------------------------------
  def update_origin
    update_rect if bitmap
  end
  #--------------------------------------------------------------------------
  # * Alias method: initialize
  #--------------------------------------------------------------------------
  alias :initialize_ve_animated_battle :initialize
  def initialize(viewport, battler = nil)
    initialize_ve_animated_battle(viewport, battler)
    init_variables
  end
  #--------------------------------------------------------------------------
  # * Alias method: update_effect
  #--------------------------------------------------------------------------
  alias :update_effect_ve_animated_battle :update_effect
  def update_effect
    setup_collapse
    update_effect_ve_animated_battle
    update_pose
    update_afterimage
    update_pose_loop if $imported[:ve_loop_animation]
  end
  #--------------------------------------------------------------------------
  # * Alias method: revert_to_normal
  #--------------------------------------------------------------------------
  alias :revert_to_normal_ve_animated_battle :revert_to_normal
  def revert_to_normal
    revert_to_normal_ve_animated_battle
    update_rect if bitmap
  end
  #--------------------------------------------------------------------------
  # * Alias method: setup_new_effect
  #--------------------------------------------------------------------------
  alias :setup_new_effect_ve_animated_battle :setup_new_effect
  def setup_new_effect
    if @battler_visible && !@invisible && @battler.poses.invisible
      @invisible = true
      @effect_type = :disappear
      @effect_duration = 12
    elsif @battler_visible && @invisible && !@battler.poses.invisible
      @invisible = false
      @effect_type = :appear
      @effect_duration = 12
    end
    setup_new_effect_ve_animated_battle
  end
  #--------------------------------------------------------------------------
  # * New method: init_variables
  #--------------------------------------------------------------------------
  def init_variables
    @spin  = 0
    @frame = 0
    @sufix = ""
    @pose_sufix = ""
    @anim_sufix = VE_SPRITE_SUFIX
    @returning    = 0
    @frame_width  = 0
    @frame_height = 0
    @icon_list    = {}
    @throw_list   = []
    @afterimage_wait    = 0
    @afterimage_sprites = []
    start_effect(:appear) if $game_system.intro_fade && !@battler.hidden?
    poses.clear_poses
    setup_positions
  end
  #--------------------------------------------------------------------------
  # * New method: setup_collapse
  #--------------------------------------------------------------------------
  def setup_collapse
    if @battler.dead? && !@dead
      @battler.perform_collapse_effect if !@fast_collapse
      @battler.perform_fast_collapse   if  @fast_collapse
      @fast_collapse = false
      @dead = true
    elsif @dead && !@battler.dead?
      @dead = false
    end
  end
  #--------------------------------------------------------------------------
  # * New method: subject
  #--------------------------------------------------------------------------
  def subject
    @pose_battler ? @pose_battler : @battler
  end
  #--------------------------------------------------------------------------
  # * New method: poses
  #--------------------------------------------------------------------------
  def poses
    @battler.poses
  end
  #--------------------------------------------------------------------------
  # * New method: sprite_value
  #--------------------------------------------------------------------------
  def sprite_value(value)
    @battler.sprite_value(value)
  end
  #--------------------------------------------------------------------------
  # * New method: graphic_changed?
  #--------------------------------------------------------------------------
  def graphic_changed?
    actor_name_change? || battler_name_change? || misc_change?
  end
  #--------------------------------------------------------------------------
  # * New method: actor_name_change?
  #--------------------------------------------------------------------------
  def actor_name_change?
    use_charset? && (@battler_name != @battler.character_name ||
    @battler_index != @battler.character_index ||
    @battler_hue   != @battler.character_hue)
  end
  #--------------------------------------------------------------------------
  # * New method: battler_name_change?
  #--------------------------------------------------------------------------
  def battler_name_change?
    !use_charset? && (@battler_name != @battler.battler_name ||
    @battler_hue  != @battler.battler_hue)
  end
  #--------------------------------------------------------------------------
  # * New method: misc_change?
  #--------------------------------------------------------------------------
  def misc_change?
    (visual_equip? && @visual_items != @battler.visual_items) ||
     @direction != poses.direction || @frame_size != poses.f_size ||
     @sufix != poses.sufix
  end
  #--------------------------------------------------------------------------
  # * New method: use_charset?
  #--------------------------------------------------------------------------
  def use_charset?
    sprite_value(:mode) == :charset
  end
  #--------------------------------------------------------------------------
  # * New method: visual_equip?
  #--------------------------------------------------------------------------
  def visual_equip?
    $imported[:ve_visual_equip]
  end
  #--------------------------------------------------------------------------
  # * New method: collapse?
  #--------------------------------------------------------------------------
  def collapse?
    @effect_type == :collapse || @effect_type == :custom_collapse
  end
  #--------------------------------------------------------------------------
  # * New method: setup_bitmap
  #--------------------------------------------------------------------------
  def setup_bitmap
    if use_charset?
      @battler_name  = @battler.character_name
      @battler_hue   = @battler.character_hue
      @battler_index = @battler.character_index
    else
      @battler_name  = @battler.battler_name
      @battler_hue   = @battler.battler_hue
    end
    @frame_size   = poses.f_size
    @sufix        = poses.sufix
    @direction    = poses.direction
    @visual_items = @battler.visual_items.dup if visual_equip?
    init_bitmap
    init_frame
    init_visibility
  end
  #--------------------------------------------------------------------------
  # * New method: init_bitmap
  #--------------------------------------------------------------------------
  def init_bitmap
    self.bitmap = setup_bitmap_sprite
  end
  #--------------------------------------------------------------------------
  # * New method: setup_bitmap_sprite
  #--------------------------------------------------------------------------
  def setup_bitmap_sprite
    case sprite_value(:mode)
    when :charset
      if visual_equip?
        args = [@battler_name, @battler_hue, @visual_items, sufix]
        Cache.character(*args)
      else
        Cache.character(get_character_name, @battler_hue)
      end
    when :single
      Cache.battler(get_battler_name, @battler_hue)
    when :sprite
      Cache.battler(get_battler_name, @battler_hue)
    else
      Cache.battler(@battler_name, @battler_hue)
    end
  end
  #--------------------------------------------------------------------------
  # * New method: sufix
  #--------------------------------------------------------------------------
  def sufix
    case sprite_value(:mode)
    when :charset then @sufix
    when :sprite  then @anim_sufix + @sufix
    else @sufix
    end
  end
  #--------------------------------------------------------------------------
  # * New method: get_battler_name
  #--------------------------------------------------------------------------
  def get_battler_name
    name = @battler_name + sufix
    battler_exist?(name) ? name : @battler_name
  end
  #--------------------------------------------------------------------------
  # * New method: get_character_name
  #--------------------------------------------------------------------------
  def get_character_name
    name = @battler_name + sufix
    character_exist?(name) ? name : @battler_name
  end
  #--------------------------------------------------------------------------
  # * New method: init_frame
  #--------------------------------------------------------------------------
  def init_frame
    @frame_width  = bitmap.width  / frame_number
    @frame_height = bitmap.height / row_number
  end
  #--------------------------------------------------------------------------
  # * New method: frame_number
  #--------------------------------------------------------------------------
  def frame_number
    return poses.frames     if single_char?
    return poses.frames * 4 if multi_char?
    return 1 unless battler_exist?(@battler_name + sufix)
    return poses.f_size     if poses.f_size
    return sprite_value(:frames) if sprite_value(:mode) == :sprite
    return 1
  end
  #--------------------------------------------------------------------------
  # * New method: row_number
  #--------------------------------------------------------------------------
  def row_number
    return 4 if single_char?
    return 8 if multi_char?
    return 1 unless battler_exist?(@battler_name + sufix)
    return sprite_value(:rows) if sprite_value(:mode) == :sprite
    return 1
  end
  #--------------------------------------------------------------------------
  # * New method: single_char?
  #--------------------------------------------------------------------------
  def single_char?
    use_charset? && (single_normal? && !visual_equip?)
  end
  #--------------------------------------------------------------------------
  # * New method: multi_char?
  #--------------------------------------------------------------------------
  def multi_char?
    use_charset? && (multi_normal? || visual_equip?)
  end
  #--------------------------------------------------------------------------
  # * New method: single_normal?
  #--------------------------------------------------------------------------
  def single_normal?
    !visual_equip? && @battler_name[/^[!]?[$]./]
  end
  #--------------------------------------------------------------------------
  # * New method: multi_normal?
  #--------------------------------------------------------------------------
  def multi_normal?
    !visual_equip? && !@battler_name[/^[!]?[$]./]
  end
  #--------------------------------------------------------------------------
  # * New method: get_sign
  #--------------------------------------------------------------------------
  def get_sign
    @visual_items.any? {|part| !part[:name][/^[!]?[$]./] }
  end
  #--------------------------------------------------------------------------
  # * New method: update_rect
  #--------------------------------------------------------------------------
  def update_rect
    setup_frame2
    setup_rect
    self.ox = @frame_width / 2
    self.oy = @frame_height
    self.mirror = pose_mirror
    reset_frame if poses.reset
  end
  #--------------------------------------------------------------------------
  # * New method: pose_mirror
  #--------------------------------------------------------------------------
  def pose_mirror
    mirror = sprite_value(:invert)
    mirror = !mirror if timing && timing[:invert]
    mirror = !mirror if right? && sprite_value(:mirror)
    mirror
  end
  #--------------------------------------------------------------------------
  # * New method: down?
  #--------------------------------------------------------------------------
  def down?
    poses.down?
  end
  #--------------------------------------------------------------------------
  # * New method: left?
  #--------------------------------------------------------------------------
  def left?
    poses.left?
  end
  #--------------------------------------------------------------------------
  # * New method: right?
  #--------------------------------------------------------------------------
  def right?
    poses.right?
  end
  #--------------------------------------------------------------------------
  # * New method: up?
  #--------------------------------------------------------------------------
  def up?
    poses.up?
  end
  #--------------------------------------------------------------------------
  # * New method: timing
  #--------------------------------------------------------------------------
  def timing
    poses.timing
  end
  #--------------------------------------------------------------------------
  # * New method: setup_frame
  #--------------------------------------------------------------------------
  def setup_frame2
    return if !poses.pose?
    timing[:time] -= 1
    timing[:time]  = timing[:wait] if timing[:time] == 0
    return if timing[:time] != timing[:wait]
    return if poses.reset
    update_frame
  end
  #--------------------------------------------------------------------------
  # * New method: update_frame
  #--------------------------------------------------------------------------
  def update_frame
    @max_frame = timing[:frame]
    @min_frame = poses.f_init
    update_frame_return if  timing[:return] && !timing[:revert]
    update_frame_revert if !timing[:return] &&  timing[:revert]
    update_frame_normal if !timing[:return] && !timing[:revert]
    poses.frame = [@frame, sprite_value(:frames) - 1].min
  end
  #--------------------------------------------------------------------------
  # * New method: update_frame_return
  #--------------------------------------------------------------------------
  def update_frame_return
    @returning += 1
    @frame = returning_value(@returning, @max_frame)
    poses.reset = true if !timing[:loop] && @returning > @max_frame * 2 - 1
  end
  #--------------------------------------------------------------------------
  # * New method: update_frame_revert
  #--------------------------------------------------------------------------
  def update_frame_revert
    @frame -= 1 
    @frame  = @max_frame if @frame < @min_frame
    poses.reset = true   if !timing[:loop] && @frame < @min_frame
  end
  #--------------------------------------------------------------------------
  # * New method: update_frame_normal
  #--------------------------------------------------------------------------
  def update_frame_normal
    @frame += 1
    @frame  = @min_frame if @frame < @min_frame || @frame > @max_frame + 1
    poses.reset = true   if !timing[:loop] && @frame > @max_frame
  end
  #--------------------------------------------------------------------------
  # * New method: reset_frame
  #--------------------------------------------------------------------------
  def reset_frame
    invert       = timing[:invert]
    poses.timing = {invert: invert}
    poses.reset  = false
    @returning   = 0
    @frame       = 0
    @spin        = 0
  end
  #--------------------------------------------------------------------------
  # * New method: setup_rect
  #--------------------------------------------------------------------------
  def setup_rect
    sign = @battler_name[/^[$]./]
    if use_charset? && !sign
      index = @battler_index
      frame = (index % 4 * poses.frames + poses.frame) * @frame_width
      row   = (index / 4 * 4 + poses.row) * @frame_height
    else
      frame = [[poses.frame, 0].max, frame_number - 1].min * @frame_width
      row   = [[poses.row,   0].max,   row_number - 1].min * @frame_height
    end
    self.src_rect.set(frame, row, @frame_width, @frame_height)
  end  
  #--------------------------------------------------------------------------
  # * New method: update_pose
  #--------------------------------------------------------------------------
  def update_pose
    poses.pose_list.update
  end
  #--------------------------------------------------------------------------
  # * New method: reset_pose
  #--------------------------------------------------------------------------
  def reset_pose
    next_pose = get_idle_pose
    return if next_pose == poses.pose_list.name
    reset_frame
    poses.clear_loop
    poses.call_pose(next_pose)
    poses.pose_list.setup_all_poses
  end
  #--------------------------------------------------------------------------
  # * New method: get_idle_pose
  #--------------------------------------------------------------------------
  def get_idle_pose
    value = :idle
    value = :danger if @battler.danger?
    value = :guard  if @battler.guard?
    value = poses.state_pose  if poses.state_pose?
    value = poses.active_pose if poses.active_pose
    value = poses.cast_pose   if cast_pose?
    value = :sleeping    if @battler.state?(6)
    value = :poisoned    if @battler.state?(2)
    value = :burning    if @battler.state?(26)
    value = :burning    if @battler.state?(28)
    value = :stunned    if @battler.state?(5)
    value = :stunned    if @battler.state?(8)
    value = :escaping if escaping? && @battler.actor?
    value = :dead     if @battler.dead?
    value
  end
  #--------------------------------------------------------------------------
  # * New method: cast_pose?
  #--------------------------------------------------------------------------
  def cast_pose?
    $imported[:ve_active_time_battle] && @battler.cast_action &&
    @battler.cast_action.item
  end
  #--------------------------------------------------------------------------
  # * New method: escaping?
  #--------------------------------------------------------------------------
  def escaping?
    $imported[:ve_active_time_battle] && BattleManager.escaping? &&
    VE_ATB_ESCAPING_ANIM
  end
  #--------------------------------------------------------------------------
  # * New method: setup_positions
  #--------------------------------------------------------------------------
  def setup_positions
    positions   = {x: @battler.screen_x, y: @battler.screen_y, h: 0, j: 0}
    poses.target_position  = positions.dup
    poses.current_position = positions.dup
    poses.jumping   = {count: 0, height: 0, speed: 10}
    @fast_collapse = true if @battler.dead? && @battler.collapse_type != 3
    reset_pose
  end
  #--------------------------------------------------------------------------
  # * New method: position
  #--------------------------------------------------------------------------
  def position
    poses.current_position
  end
  #--------------------------------------------------------------------------
  # * New method: update_position
  #--------------------------------------------------------------------------
  def update_position
    update_misc
    update_movement
    update_jumping
    self.x  = position[:x] + adjust_x
    self.y  = position[:y] + adjust_y
    self.z  = [[self.y / (Graphics.height / 100.0), 1].max, 100].min
    self.ox = @frame_width / 2
    self.oy = @frame_height + position[:h] + position[:j] 
    @spin += 1 if Graphics.frame_count % 2 == 0
    self.angle = poses.angle + poses.spin * @spin
    update_ajust
    update_icon
    update_throw
  end
  #--------------------------------------------------------------------------
  # * New method: update_movement
  #--------------------------------------------------------------------------
  def update_ajust
    angle_move(:x, sprite_value(:ox)) if sprite_value(:ox)
    angle_move(:y, sprite_value(:oy)) if sprite_value(:oy)
  end
  #--------------------------------------------------------------------------
  # * New method: angle_move
  #--------------------------------------------------------------------------
  def angle_move(axis, amount)
    a = (360 - angle) * Math::PI / 180
    cos = Math.cos(a)
    sin = Math.sin(a)
    self.ox += (axis == :x ? -cos : -sin) * amount
    self.oy += (axis == :x ?  sin : -cos) * amount
  end
  #--------------------------------------------------------------------------
  # * New method: update_misc
  #--------------------------------------------------------------------------
  def update_misc
    poses.update_shake
    poses.update_freeze
  end
  #--------------------------------------------------------------------------
  # * New method: adjust_x
  #--------------------------------------------------------------------------
  def adjust_x
    poses.x_adj + [1, -1].random * rand(poses.shake + 1)
  end
  #--------------------------------------------------------------------------
  # * New method: adjust_y
  #--------------------------------------------------------------------------
  def adjust_y
    poses.y_adj + [1, -1].random * rand(poses.shake + 1)
  end
  #--------------------------------------------------------------------------
  # * New method: update_movement
  #--------------------------------------------------------------------------
  def update_movement
    return if poses.frozen? || !poses.moving?
    poses.teleport ? update_teleport_movement : update_normal_movement
  end
  #--------------------------------------------------------------------------
  # * New method: update_teleport_movement
  #--------------------------------------------------------------------------
  def update_teleport_movement
    poses.current_position[:x] = poses.target_position[:x]
    poses.current_position[:y] = poses.target_position[:y]
    poses.current_position[:h] = [poses.target_position[:h], 0].max
    poses.teleport = false
  end
  #--------------------------------------------------------------------------
  # * New method: update_afterimage
  #--------------------------------------------------------------------------  
  def update_afterimage
    update_afterimage_sprites
    setup_afterimage_sprites if poses.afterimage && @afterimage_wait <= 0
  end
  #--------------------------------------------------------------------------
  # * New method: update_afterimage_sprites
  #--------------------------------------------------------------------------  
  def update_afterimage_sprites
    @afterimage_wait -= 1 if @afterimage_wait > 0
    @afterimage_sprites.each do |sprite| 
      sprite.update
      next if sprite.opacity > 0
      sprite.dispose
      @afterimage_sprites.delete(sprite)
    end
  end
  #--------------------------------------------------------------------------
  # * New method: setup_afterimage_sprites
  #--------------------------------------------------------------------------  
  def setup_afterimage_sprites
    @afterimage_sprites.push(Sprite_AfterImage.new(self))
    @afterimage_wait = poses.afterimage[:wait]
  end
  #--------------------------------------------------------------------------
  # * New method: update_normal_movement
  #--------------------------------------------------------------------------
  def update_normal_movement
    distance = set_distance
    move     = {x: 1.0, y: 1.0, h: 1.0}
    if distance[:x].abs < distance[:y].abs
      move[:x] = 1.0 / (distance[:y].abs.to_f / distance[:x].abs)
    elsif distance[:y].abs < distance[:x].abs
      move[:y] = 1.0 / (distance[:x].abs.to_f / distance[:y].abs)
    elsif distance[:h].abs < distance[:x].abs
      move[:h] = 1.0 / (distance[:x].abs.to_f / distance[:h].abs)
    end
    speed = set_speed(distance)
    x = move[:x] * speed[:x]
    y = move[:y] * speed[:y]
    h = move[:h] * speed[:h]
    set_movement(x, y, h)
  end
  #--------------------------------------------------------------------------
  # * New method: set_distance
  #--------------------------------------------------------------------------
  def set_distance
    x = poses.target_distance(:x)
    y = poses.target_distance(:y)
    h = poses.target_distance(:h)
    {x: x, y: y, h: h}
  end
  #--------------------------------------------------------------------------
  # * New method: set_speed
  #--------------------------------------------------------------------------
  def set_speed(distance)
    move_speed = poses.move_speed
    x = move_speed * (distance[:x] == 0 ? 0 : (distance[:x] > 0 ? 8 : -8))
    y = move_speed * (distance[:y] == 0 ? 0 : (distance[:y] > 0 ? 8 : -8))
    h = move_speed * (distance[:h] == 0 ? 0 : (distance[:h] > 0 ? 8 : -8))
    {x: x, y: y, h: h}
  end
  #--------------------------------------------------------------------------
  # * New method: set_movement
  #--------------------------------------------------------------------------
  def set_movement(x, y, h)
    target  = poses.target_position
    current = poses.current_position
    current[:x] += x
    current[:y] += y
    current[:h] += h
    current[:x] = target[:x] if in_distance?(current[:x], target[:x], x)
    current[:y] = target[:y] if in_distance?(current[:y], target[:y], y)
    current[:h] = target[:h] if in_distance?(current[:h], target[:h], h)
    reset_move if poses.reset_move && !poses.moving?
  end
  #--------------------------------------------------------------------------
  # * New method: reset_move
  #--------------------------------------------------------------------------
  def reset_move
    poses.reset_move = nil
    poses.call_pose(:reset, :clear)
    poses.targets_direction
  end
  #--------------------------------------------------------------------------
  # * New method: in_distance?
  #--------------------------------------------------------------------------
  def in_distance?(x, y, z)
    x.between?(y - z - 1, y + z + 1)
  end
  #--------------------------------------------------------------------------
  # * New method: update_jumping
  #--------------------------------------------------------------------------
  def update_jumping
    return if poses.jumping[:count] == 0 || poses.frozen?
    jump = poses.jumping
    jump[:count] = [jump[:count] - (1 * jump[:speed] / 10.0), 0].max.to_f
    count  = jump[:count]
    speed  = jump[:speed]
    peak   = jump[:height]
    result = (peak ** 2 - (count - peak).abs ** 2) / 2
    poses.current_position[:j] = [result, 0].max
    if poses.current_position[:j] == 0
      jump[:count] = 0
      reset_move if jump[:reset]
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_icon
  #--------------------------------------------------------------------------
  def update_icon
    poses.icon_list.each do |key, value|
      @icon_list[key] = Sprite_Icon.new(value) unless @icon_list[key]
      @icon_list[key].refresh(value) if @icon_list[key].changed_icon?(value)
    end
    @icon_list.each do |key, value|
      value.update
      delete_icon(key) if value && !poses.icon_list[key]
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_throw
  #--------------------------------------------------------------------------
  def update_throw
    poses.throw_list.each do |value|
      @throw_list.push(Sprite_Throw.new(value))
      poses.throw_list.delete(value)
    end
    @throw_list.each_with_index do |value, index|
      value.update
      delete_throw(index) if value.disposing?
    end
    @throw_list.compact!
  end
  #--------------------------------------------------------------------------
  # * New method: delete_icon
  #--------------------------------------------------------------------------
  def delete_icon(key)
    @icon_list[key].dispose
    @icon_list.delete(key)
  end
  #--------------------------------------------------------------------------
  # * New method: delete_throw
  #--------------------------------------------------------------------------
  def delete_throw(index)
    @throw_list[index].dispose
    @throw_list.delete_at(index)
  end
  #--------------------------------------------------------------------------
  # * New method: throwing?
  #--------------------------------------------------------------------------
  def throwing?
    @throw_list.any? {|value| value.target == @battler }
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose_loop
  #--------------------------------------------------------------------------
  def update_pose_loop
    if poses.pose_loop && !loop_anim?(:pose_anim)
      @pose_name = poses.pose_name
      animation  = {type: :pose_anim, anim: poses.pose_loop, loop: 1}     
      add_loop_animation(animation)
    end
    if poses.pose_loop && loop_anim?(:pose_anim) && 
       @pose_name_list != poses.pose_name.first
      @pose_loop = nil
      poses.pose_loop = nil
      end_loop_anim(:pose_anim)
    end
  end
end

#==============================================================================
# ** Spriteset_Battle
#------------------------------------------------------------------------------
#  This class brings together battle screen sprites. It's used within the
# Scene_Battle class.
#==============================================================================

class Spriteset_Battle
  #--------------------------------------------------------------------------
  # * Overwrite method: create_actors
  #--------------------------------------------------------------------------
  def create_actors
    @actor_sprites = $game_party.battle_members.reverse.collect do |actor|
      Sprite_Battler.new(@viewport1, actor)
    end
    @actors_party = $game_party.battle_members.dup
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: update_actors
  #--------------------------------------------------------------------------
  def update_actors
    update_party if $game_party.battle_members != @actors_party
    @actor_sprites.each {|sprite| sprite.update }
  end
  #--------------------------------------------------------------------------
  # * Alias method: initialize
  #--------------------------------------------------------------------------
  alias :initialize_ve_animated_battle :initialize
  def initialize
    init_action_plane
    initialize_ve_animated_battle
  end
  #--------------------------------------------------------------------------
  # * Alias method: update
  #--------------------------------------------------------------------------
  alias :update_ve_animated_battle :update
  def update
    update_ve_animated_battle
    update_action_plane
  end
  #--------------------------------------------------------------------------
  # * Alias method: dispose
  #--------------------------------------------------------------------------
  alias :dispose_ve_animated_battle :dispose
  def dispose
    dispose_ve_animated_battle
    dispose_action_plane
  end
  #--------------------------------------------------------------------------
  # * Alias method: create_pictures
  #--------------------------------------------------------------------------
  alias :create_pictures_ve_animated_battle :create_pictures
  def create_pictures
    battler_sprites.each {|battler| battler.setup_positions }
    create_pictures_ve_animated_battle
  end
  #--------------------------------------------------------------------------
  # * Alias method: create_viewports
  #--------------------------------------------------------------------------
  alias :create_viewports_ve_animated_battle :create_viewports
  def create_viewports
    create_viewports_ve_animated_battle
    @viewport4   = Viewport.new
    @viewport4.z = 200
  end
  #--------------------------------------------------------------------------
  # * Alias method: update_viewports
  #--------------------------------------------------------------------------
  alias :update_viewports_ve_animated_battle :update_viewports
  def update_viewports
    update_viewports_ve_animated_battle
    @viewport1.ox = [1, -1].random * rand($game_troop.screen.shake)
    @viewport1.oy = [1, -1].random * rand($game_troop.screen.shake)
    @back1_sprite.tone.set($game_troop.screen.low_tone) if @back1_sprite
    @back2_sprite.tone.set($game_troop.screen.low_tone) if @back2_sprite
    @viewport4.tone.set($game_troop.screen.high_tone)
  end
  #--------------------------------------------------------------------------
  # * New method: update_party
  #--------------------------------------------------------------------------
  def update_party
    @actor_sprites.each_index do |i|
      next if $game_party.battle_members.include?(@actor_sprites[i].battler)
      @actor_sprites[i].dispose
      @actor_sprites[i] = nil
    end
    $game_party.battle_members.collect do |actor|
      next if @actors_party.include?(actor)
      @actor_sprites.push(Sprite_Battler.new(@viewport1, actor))
    end
    @actor_sprites.compact!
    @actors_party = $game_party.battle_members.dup
  end
  #--------------------------------------------------------------------------
  # * New method: collapse?
  #--------------------------------------------------------------------------
  def collapse?
    battler_sprites.compact.any? {|sprite| sprite.collapse? }
  end
  #--------------------------------------------------------------------------
  # * New method: init_action_plane
  #--------------------------------------------------------------------------
  def init_action_plane
    @action_plane = Plane_ActionPlane.new(@viewport1)
  end
  #--------------------------------------------------------------------------
  # * New method: update_action_plane
  #--------------------------------------------------------------------------
  def update_action_plane
    @action_plane.update
  end
  #--------------------------------------------------------------------------
  # * New method: dispose_action_plane
  #--------------------------------------------------------------------------
  def dispose_action_plane
    @action_plane.dispose
  end
  #--------------------------------------------------------------------------
  # * New method: action_plane
  #--------------------------------------------------------------------------
  def action_plane(name, x, y, z, zx, zy, opacity, blend, duration)
    @action_plane.setup(name, x, y, z, zx, zy, opacity, blend, duration)
  end
  #--------------------------------------------------------------------------
  # * New method: delete_plane
  #--------------------------------------------------------------------------
  def delete_plane(duration)
    @action_plane.delete(duration)
  end
end

#==============================================================================
# ** Window_BattleLog
#------------------------------------------------------------------------------
#  This window shows the battle progress. Do not show the window frame.
#==============================================================================

class Window_BattleLog < Window_Selectable
  #--------------------------------------------------------------------------
  # * Overwrite method: wait_and_clear
  #--------------------------------------------------------------------------
  def wait_and_clear
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: wait
  #--------------------------------------------------------------------------
  def wait
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: back_to
  #--------------------------------------------------------------------------
  def back_to(line_number)
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: back_one
  #--------------------------------------------------------------------------
  def back_one
    return unless last_text.empty?
    @lines.pop
    refresh
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: display_added_states
  #--------------------------------------------------------------------------
  def display_added_states(target)
    target.result.added_state_objects.each do |state|
      state_msg = target.actor? ? state.message1 : state.message2
      next if state_msg.empty?
      replace_text(target.name + state_msg)
    end
  end
  #--------------------------------------------------------------------------
  # * Alias method: wait_and_clear
  #--------------------------------------------------------------------------
  alias :add_text_ve_animated_battle :add_text
  def add_text(text)
    skip_second_line while @lines.size > max_line_number
    add_text_ve_animated_battle(text)
  end
  #--------------------------------------------------------------------------
  # * New method: skip_second_line
  #--------------------------------------------------------------------------
  def skip_second_line
    first_line = @lines.shift
    @lines.shift
    @lines.unshift(first_line)
  end
  #--------------------------------------------------------------------------
  # * New method: wait_message_end
  #--------------------------------------------------------------------------
  def wait_message_end
    @method_wait.call(message_speed) if @method_wait && line_number > 0
    clear
  end
end

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

class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # * Overwrite method: abs_wait_short
  #--------------------------------------------------------------------------
  def abs_wait_short
    update_for_wait
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: apply_item_effects
  #--------------------------------------------------------------------------
  def apply_item_effects(target, item)
    target.item_apply(@subject, item)
    refresh_status
    @log_window.display_action_results(target, item)
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: execute_action
  #--------------------------------------------------------------------------
  def execute_action
    @subject.poses.activate
    use_item
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: use_item
  #--------------------------------------------------------------------------
  def use_item
    item = @subject.current_action.item
    @log_window.display_use_item(@subject, item)
    @subject.poses.action_pose(item)
    @subject.use_item(item)
    refresh_status
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: show_animation
  #--------------------------------------------------------------------------
  def show_animation(targets, animation_id)
    if animation_id < 0
      show_animated_battle_attack_animation(targets)
    else
      show_normal_animation(targets, animation_id)
    end
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: invoke_counter_attack
  #--------------------------------------------------------------------------
  def invoke_counter_attack(target, item)
    if target == @subject || target.poses.counter_on
      return if retaliation_counter?(target, item)
      target.counter = false if $imported[:ve_damage_pop]
      apply_item_effects(apply_substitute(target, item), item)
      return
    end
    target.poses.setup_counter(@subject, item)
    @counter_flag.push(target)
  end
  #--------------------------------------------------------------------------
  # * New method: retaliation_counter?(target, item)
  #--------------------------------------------------------------------------
  def retaliation_counter?(target, item)
    $imported[:ve_retaliation_damage] && damage_on_counter?(target, item)
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: invoke_magic_reflection
  #--------------------------------------------------------------------------
  def invoke_magic_reflection(target, item)
    if target == @subject
      target.reflect = false if $imported[:ve_damage_pop]
      apply_item_effects(apply_substitute(target, item), item)
      return
    end
    @subject.poses.setup_reflect(item)
    @reflect_flag.push(target)
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: apply_substitute
  #--------------------------------------------------------------------------
  def apply_substitute(target, item)
    if check_substitute(target, item)
      substitute = target.friends_unit.substitute_battler
      if substitute && target != substitute
        @substitution = {target: target, substitute: substitute}
        substitute.poses.setup_substitute(target)
        return substitute
      end
    end
    target
  end
  #--------------------------------------------------------------------------
  # * Alias method: create_spriteset
  #--------------------------------------------------------------------------
  alias :create_spriteset_ve_animated_battle :create_spriteset
  def create_spriteset
    create_spriteset_ve_animated_battle
    setup_spriteset
  end
  #--------------------------------------------------------------------------
  # * Alias method: update_basic
  #--------------------------------------------------------------------------
  alias :update_basic_ve_animated_battle :update_basic
  def update_basic
    update_basic_ve_animated_battle
    update_sprite_action
  end
  #--------------------------------------------------------------------------
  # * Alias method: process_action
  #--------------------------------------------------------------------------
  alias :process_action_ve_animated_battle :process_action
  def process_action
    return if active?
    process_action_ve_animated_battle
  end
  #--------------------------------------------------------------------------
  # * Alias method: turn_end
  #--------------------------------------------------------------------------
  alias :turn_end_ve_animated_battle :turn_end
  def turn_end
    turn_end_ve_animated_battle
    @spriteset.battler_sprites.each {|sprite| sprite.reset_pose }
  end
  #--------------------------------------------------------------------------
  # * Alias method: next_command
  #--------------------------------------------------------------------------
  alias :next_command_ve_animated_battle :next_command
  def next_command
    previous =  BattleManager.actor
    BattleManager.actor.input_pose   if BattleManager.actor
    next_command_ve_animated_battle
    previous.poses.set_active_pose   if previous 
    BattleManager.actor.command_pose if BattleManager.actor
  end
  #--------------------------------------------------------------------------
  # * Alias method: prior_command
  #--------------------------------------------------------------------------
  alias :prior_command_ve_animated_battle :prior_command
  def prior_command
    BattleManager.actor.cancel_pose  if BattleManager.actor
    prior_command_ve_animated_battle
    BattleManager.clear_active_pose
    BattleManager.actor.command_pose if BattleManager.actor
  end
  #--------------------------------------------------------------------------
  # * New method: close_window
  #--------------------------------------------------------------------------
  def close_window
    abs_wait(10)
    update_for_wait while @message_window.openness > 0
    $game_message.clear
  end
  #--------------------------------------------------------------------------
  # * New method: setup_spriteset
  #--------------------------------------------------------------------------
  def setup_spriteset
    all_battle_members.each {|member| member.poses.default_direction }
    BattleManager.all_movable_members.each do |member| 
      next if $game_system.no_intro || !member.intro_pose?
      member.poses.call_pose(:intro, :clear)
    end
    2.times { @spriteset.update }
  end
  #--------------------------------------------------------------------------
  # * New method: log_window_wait?
  #--------------------------------------------------------------------------
  def log_window_wait?
    @log_window.line_number > 0
  end
  #--------------------------------------------------------------------------
  # * New method: log_window_clear
  #--------------------------------------------------------------------------
  def log_window_clear
    @log_window.clear
  end
  #--------------------------------------------------------------------------
  # * New method: show_animated_battle_attack_animation
  #--------------------------------------------------------------------------
  def show_animated_battle_attack_animation(targets)
    if @subject.actor? || $imported[:ve_actor_battlers]
      show_normal_animation(targets, @subject.atk_animation_id1, false)
    else
      Sound.play_enemy_attack
      abs_wait_short
    end
  end
  #--------------------------------------------------------------------------
  # * New method: next_subject?
  #--------------------------------------------------------------------------
  def next_subject?
    !@subject || !@subject.current_action
  end
  #--------------------------------------------------------------------------
  # * New method: active?
  #--------------------------------------------------------------------------
  def active?
    all_battle_members.any? {|member| member.poses.active? }
  end
  #--------------------------------------------------------------------------
  # * New method: active
  #--------------------------------------------------------------------------
  def active
    all_battle_members.select {|member| member.poses.active? }.first
  end
  #--------------------------------------------------------------------------
  # * New method: update_sprite_action
  #--------------------------------------------------------------------------
  def update_sprite_action
    @old_subject = @subject
    all_battle_members.each do |subject|
      @subject = subject
      call_animation if @subject.poses.call_anim
      call_effect    if @subject.poses.call_effect
      call_end       if @subject.poses.call_end
    end
    @subject = @old_subject
  end
  #--------------------------------------------------------------------------
  # * New method: call_animation
  #--------------------------------------------------------------------------
  def call_animation
    @subject.poses.call_anim = false
    animation = @subject.poses.animation
    targets   = @subject.poses.anim_targets.dup
    @subject.poses.animation = 0
    @subject.poses.anim_targets.clear
    show_animation(targets, animation)
  end
  #--------------------------------------------------------------------------
  # * New method: call_effect
  #--------------------------------------------------------------------------
  def call_effect
    @counter_flag = []
    @reflect_flag = []
    @substitution = nil
    @subject.poses.call_effect = false
    targets = @subject.poses.targets.dup
    item    = @subject.poses.current_item
    @subject.poses.targets.clear
    targets.each {|target| item.repeats.times { invoke_item(target, item) } }
    @counter_flag.each {|target| @log_window.display_counter(target, item) }
    @reflect_flag.each {|target| @log_window.display_reflection(target, item) }
    if @substitution
      substitute = @substitution[:substitute]
      target     = @substitution[:target]
      @log_window.display_substitute(substitute, target) 
    end
  end
  #--------------------------------------------------------------------------
  # * New method: call_end
  #--------------------------------------------------------------------------
  def call_end
    @subject.poses.call_end = false
    process_action_end if @subject.alive? && @old_subject == @subject
    @log_window.wait_message_end
  end
end

#==============================================================================
# ** Sprite_AfterImag
#------------------------------------------------------------------------------
#  This sprite is used to display battlers afterimages.
#==============================================================================

class Sprite_AfterImage < Sprite_Battler
  #--------------------------------------------------------------------------
  # * New method: initialize
  #--------------------------------------------------------------------------
  def initialize(sprite)
    info = sprite.battler.poses.afterimage
    @afterimage_opacity  = [info[:opacity], sprite.opacity].min
    @afterimage_fade     = info[:fade]
    @afterimage_color    = info[:color]
    @afterimage_blend    = info[:blend]
    @original_battler    = sprite.battler
    @battler_icons       = @original_battler.poses.icon_list.dup
    @poses               = @original_battler.poses.clone
    super(sprite.viewport, @original_battler.dup)
    update_icon
  end
  #--------------------------------------------------------------------------
  # * New method: poses
  #--------------------------------------------------------------------------
  def poses
    @poses 
  end
  #--------------------------------------------------------------------------
  # * New method: update
  #--------------------------------------------------------------------------
  def update
    super
    self.color.set(*@afterimage_color)
    self.blend_type      = @afterimage_blend
    self.opacity         = @afterimage_opacity
    @afterimage_opacity -= @afterimage_fade
    update_icon
  end
  #--------------------------------------------------------------------------
  # * New method: init_bitmap
  #--------------------------------------------------------------------------
  def init_bitmap
    self.bitmap = setup_bitmap_sprite.clone
  end
  #--------------------------------------------------------------------------
  # * New method: setup_positions
  #--------------------------------------------------------------------------
  def setup_positions
    poses.current_position       = @original_battler.poses.current_position.dup
    poses.target_position        = poses.current_position 
    @sufix     = poses.sufix     = @original_battler.poses.sufix
    @frame     = poses.frame     = @original_battler.poses.frame
    @direction = poses.direction = @original_battler.poses.direction
    poses.jumping = {count: 0, height: 0, speed: 10}
  end
  #--------------------------------------------------------------------------
  # * New method: update_icon
  #--------------------------------------------------------------------------
  def update_icon
    @battler_icons.each do |key, value|
      @icon_list[key] = Sprite_Icon.new(value) unless @icon_list[key]
      @icon_list[key].refresh(value) if @icon_list[key].changed_icon?(value)
    end
    @icon_list.each do |key, value|
      value.update
      value.opacity    = self.opacity
      value.blend_type = self.blend_type
      value.color.set(*@afterimage_color)
      delete_icon(key) if value && !@battler_icons[key]
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_pose
  #--------------------------------------------------------------------------
  def update_pose
  end
  #--------------------------------------------------------------------------
  # * New method: update_afterimage
  #--------------------------------------------------------------------------
  def update_afterimage
  end
end

#==============================================================================
# ** Sprite_IconBase
#------------------------------------------------------------------------------
#  This the base sprite used to display icons and throw animations.
#==============================================================================

class Sprite_IconBase < Sprite_Base
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :data
  attr_reader   :user
  attr_reader   :icon
  attr_reader   :value
  attr_reader   :target
  #--------------------------------------------------------------------------
  # * New method: initialize
  #--------------------------------------------------------------------------
  def initialize(viewport)
    super(viewport)
    @right    = user.right?
    @left     = user.left?
    @down     = user.down?
    @up       = user.up?
    @spin     = 0
    @zooming  = 0
    @fade_in  = 0
    @fade_out = 0
    self.zoom_x = @data[:izm]
    self.zoom_y = @data[:izm]
  end
  #--------------------------------------------------------------------------
  # * New method: refresh
  #-------------------------------------------------------------------------- 
  def refresh(value)
    @user   = value.user
    @target = value.target
    @icon   = value.icon
    @data   = value.data.dup
  end
  #--------------------------------------------------------------------------
  # * New method: changed_icon?
  #--------------------------------------------------------------------------
  def changed_icon?(value)
    @user != value.user || @target != value.target || @icon != value.icon ||
    @data != value.data
  end
  #--------------------------------------------------------------------------
  # * New method: update
  #--------------------------------------------------------------------------
  def update
    super
    update_zoom
    update_angle
    update_opacity
    update_position
  end
  #--------------------------------------------------------------------------
  # * New method: update_opacity
  #--------------------------------------------------------------------------
  def update_opacity
    if @data[:fin] > 0
      @fade_in += 1
      self.opacity = [@fade_in * @data[:fin], @data[]].min
    elsif @data[:fout] > 0
      @fade_out += 1
      self.opacity = [@data[] - @fade_out * @data[:fin], 0].max
    else
      self.opacity =  @data[]
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_angle
  #--------------------------------------------------------------------------
  def update_angle
    @spin      += 1 if Graphics.frame_count % 2 == 0
    self.angle  = @data[:a] + @data[:spin] * @spin
    self.angle *= -1 if @right 
    self.angle -= 90 if @up
    self.angle += 90 if @down
    self.angle  = 360 + self.angle if self.angle < 0
  end
  #--------------------------------------------------------------------------
  # * New method: update_zoom
  #--------------------------------------------------------------------------
  def update_zoom
    if self.zoom_x < @data[:ezm]
      @zooming += 1
      self.zoom_x = [@data[:izm] + @zooming * @data[:szm], @data[:ezm]].min
      self.zoom_y = [@data[:izm] + @zooming * @data[:szm], @data[:ezm]].min
    elsif self.zoom_x > @data[:ezm]
      @zooming += 1
      self.zoom_x = [@data[:izm] - @zooming * @data[:szm], @data[:ezm]].max
      self.zoom_y = [@data[:izm] - @zooming * @data[:szm], @data[:ezm]].max
    end
  end
  #--------------------------------------------------------------------------
  # * New method: setup_icon
  #--------------------------------------------------------------------------
  def setup_icon
    @current_icon = @icon
    if @icon.string?
      self.bitmap = Cache.picture(icon)
      self.src_rect.set(0, 0, bitmap.width, bitmap.height)
      @icon_ox = bitmap.width  / 2
      @icon_oy = bitmap.height / 2
    else
      self.bitmap = Cache.system("Iconset")
      size = bitmap.width / 16
      self.src_rect.set(icon % 16 * size, icon / 16 * size, size, size)
      @icon_ox = size / 2
      @icon_oy = size / 2
    end
  end  
end

#==============================================================================
# ** Sprite_Icon
#------------------------------------------------------------------------------
#  This sprite is used to display icons.
#==============================================================================

class Sprite_Icon < Sprite_IconBase
  #--------------------------------------------------------------------------
  # * New method: initialize
  #--------------------------------------------------------------------------
  def initialize(value)
    refresh(value)
    super(target.sprite.viewport)
    setup_icon
  end
  #--------------------------------------------------------------------------
  # * New method: update_position
  #--------------------------------------------------------------------------
  def update_position
    setup_icon if @current_icon != @icon
    self.x      = user.sprite.x
    self.y      = user.sprite.y - 1
    self.z      = user.sprite.z + (@data[:above] ? 1 : 0)
    self.ox     = @icon_ox
    self.oy     = @icon_oy
    self.mirror = @right
    update_movement
  end
  #--------------------------------------------------------------------------
  # * New method: update_movement
  #--------------------------------------------------------------------------
  def update_movement
    if @right || @left
      angle_move(:x, (@right ? adjust_x : -adjust_x))
      angle_move(:y, adjust_y)
    elsif @up || @down
      angle_move(:x, (@down ? adjust_y : -adjust_y))
      angle_move(:y, (@down ? adjust_x : -adjust_x) - 8)
    end
  end
  #--------------------------------------------------------------------------
  # * New method: angle_move
  #--------------------------------------------------------------------------
  def angle_move(axis, amount)
    a = (360 - angle) * Math::PI / 180
    cos = Math.cos(a)
    sin = Math.sin(a)
    self.ox += (axis == :x ? -cos : -sin) * amount
    self.oy += (axis == :x ?  sin : -cos) * amount
  end
  #--------------------------------------------------------------------------
  # * New method: adjust_x
  #--------------------------------------------------------------------------
  def adjust_x
    user.sprite.ox / 2 - @data[:x] 
  end
  #--------------------------------------------------------------------------
  # * New method: adjust_y
  #--------------------------------------------------------------------------
  def adjust_y
    @data[:y] - (position[:h] + position[:j] + user.sprite.oy) / 2
  end
  #--------------------------------------------------------------------------
  # * New method: position
  #--------------------------------------------------------------------------
  def position
    user.sprite.position
  end
end

#==============================================================================
# ** Sprite_Throw
#------------------------------------------------------------------------------
#  This sprite is used to display throw animations.
#==============================================================================

class Sprite_Throw < Sprite_IconBase
  #--------------------------------------------------------------------------
  # * New method: initialize
  #--------------------------------------------------------------------------
  def initialize(value)
    refresh(value)
    super(target.sprite.viewport)
    setup_throw
  end
  #--------------------------------------------------------------------------
  # * New method: setup_throw
  #--------------------------------------------------------------------------
  def setup_throw
    set_initial_position
    setup_arc
    setup_icon
    setup_animation if $imported[:ve_loop_animation] && @data[:anim]
  end
  #--------------------------------------------------------------------------
  # * New method: set_initial_position
  #--------------------------------------------------------------------------
  def set_initial_position
    value = set_initial_values(user, target) 
    value = set_initial_values(target, user) if @data[:return]
    @current_position[:x] += @data[:init_x] + value[:init_ox]
    @current_position[:y] += @data[:init_y] + value[:init_oy]
    @target_position[:x]  += @data[:end_x]  + value[:end_ox]
    @target_position[:y]  += @data[:end_y]  + value[:end_oy]
    @initial_position = @current_position.dup
  end
  #--------------------------------------------------------------------------
  # * New method: set_initial_values
  #--------------------------------------------------------------------------
  def set_initial_values(battler1, battler2)
    @current_position = battler1.sprite.position.dup
    @target_position  = battler2.sprite.position.dup
    x1 = battler1.right? ? -@data[:init_x] : @data[:init_x]
    y1 = battler1.up?    ? -@data[:init_x] : @data[:init_x]
    x2 = battler2.right? ? -@data[:end_x]  : @data[:end_x]
    y2 = battler2.up?    ? -@data[:end_y]  : @data[:end_y]
    {init_ox:  x1, init_oy: y1, end_ox: x2, end_oy: y2}
  end
  #--------------------------------------------------------------------------
  # * New method: setup_arc
  #--------------------------------------------------------------------------
  def setup_arc
    @arc   = {}
    x_plus = (target_distance(:x) / 32.0).abs
    y_plus = (target_distance(:y) / 32.0).abs
    speed  = Math.sqrt((x_plus ** 2) + (y_plus ** 2)) / @data[:speed]
    @arc[:speed]  = @data[:arc] * 5.0 / [speed, 1].max
    @arc[:height] = @data[:arc]
    @arc[:count]  = @data[:arc] * 2
    @current_position[:a] = 0
  end
  #--------------------------------------------------------------------------
  # * New method: setup_icon
  #--------------------------------------------------------------------------
  def setup_icon
    super
    self.angle = @data[:a]
  end
  #--------------------------------------------------------------------------
  # * New method: setup_animation
  #--------------------------------------------------------------------------
  def setup_animation
    animation = {type: :throw, anim: @data[:anim], loop: 1}
    add_loop_animation(animation)
  end
  #--------------------------------------------------------------------------
  # * New method: update
  #--------------------------------------------------------------------------
  def update
    super
    update_move
    update_arc
  end
  #--------------------------------------------------------------------------
  # * New method: update_move
  #--------------------------------------------------------------------------
  def update_move
    distance = set_distance
    move     = {x: 1.0, y: 1.0}
    if distance[:x].abs < distance[:y].abs
      move[:x] = 1.0 / (distance[:y].abs.to_f / distance[:x].abs)
    elsif distance[:y].abs < distance[:x].abs
      move[:y] = 1.0 / (distance[:x].abs.to_f / distance[:y].abs)
    end
    speed = set_speed(distance)
    x = move[:x] * speed[:x]
    y = move[:y] * speed[:y]
    set_movement(x, y)
  end
  #--------------------------------------------------------------------------
  # * New method: set_distance
  #--------------------------------------------------------------------------
  def set_distance
    {x: target_distance(:x), y: target_distance(:y)}
  end
  #--------------------------------------------------------------------------
  # * New method: target_distance
  #--------------------------------------------------------------------------
  def target_distance(symbol)
    @target_position[symbol] - @current_position[symbol]
  end
  #--------------------------------------------------------------------------
  # * New method: set_speed
  #--------------------------------------------------------------------------
  def set_speed(distance)
    x = @data[:speed] * (distance[:x] == 0 ? 0 : (distance[:x] > 0 ? 8 : -8))
    y = @data[:speed] * (distance[:y] == 0 ? 0 : (distance[:y] > 0 ? 8 : -8))
    {x: x, y: y}
  end
  #--------------------------------------------------------------------------
  # * New method: set_movement
  #--------------------------------------------------------------------------
  def set_movement(x, y)
    target  = @target_position
    current = @current_position
    current[:x] += x
    current[:y] += y
    current[:x] = target[:x] if in_distance?(current[:x], target[:x], x)
    current[:y] = target[:y] if in_distance?(current[:y], target[:y], y)
  end
  #--------------------------------------------------------------------------
  # * New method: in_distance?
  #--------------------------------------------------------------------------
  def in_distance?(x, y, z)
    x.between?(y - z - 1, y + z + 1)
  end
  #--------------------------------------------------------------------------
  # * New method: update_arc
  #--------------------------------------------------------------------------
  def update_arc
    return if @arc[:count] == 0
    @arc[:count] = [@arc[:count] - (1 * @arc[:speed] / 10.0), 0].max.to_f
    count = @arc[:count]
    speed = @arc[:speed]
    peak  = @arc[:height]   
    result = (peak ** 2 - (count - peak).abs ** 2) / 2
    @current_position[:a] = @data[:revert] ? -result : result
  end
  #--------------------------------------------------------------------------
  # * New method: update_position
  #--------------------------------------------------------------------------
  def update_position
    setup_icon if @current_icon != @icon
    self.x      = current[:x]
    self.y      = current[:y] - current[:h] - current[:a]
    self.z      = [target.sprite.z, user.sprite.z].max
    self.ox     = @icon_ox
    self.oy     = @icon_oy
    self.mirror = @right || @up
  end
  #--------------------------------------------------------------------------
  # * New method: current
  #--------------------------------------------------------------------------
  def current
    @current_position
  end
  #--------------------------------------------------------------------------
  # * New method: disposing?
  #--------------------------------------------------------------------------
  def disposing?
    current[:x] == @target_position[:x] && current[:y] == @target_position[:y]
  end
end

#==============================================================================
# ** Plane_ActionPlane
#------------------------------------------------------------------------------
#  This is the plane used to display action plane images
#==============================================================================

class Plane_ActionPlane < Plane
  #--------------------------------------------------------------------------
  # * New method: initialize
  #--------------------------------------------------------------------------
  def initialize(viewport)
    super(viewport)
    @settings = {x: 0, y: 0, opacity: 0, zoom_x: 1.0, zoom_y: 1.0}
    @duration = 1
  end
  #--------------------------------------------------------------------------
  # * New method: dispose
  #--------------------------------------------------------------------------
  def dispose
    bitmap.dispose if bitmap
    super
  end
  #--------------------------------------------------------------------------
  # * New method: setup
  #--------------------------------------------------------------------------
  def setup(name, x, y, z, zoom_x, zoom_y, opacity, blend, duration)
    self.bitmap = Cache.picture(name)
    self.z = z
    @settings[:x] = x
    @settings[:y] = y
    @settings[:zoom_x]  = zoom_x / 100.0
    @settings[:zoom_y]  = zoom_y / 100.0
    @settings[:opacity] = opacity
    @blend_type = blend
    @delete     = false
    @duration   = [duration, 1].max
  end
  #--------------------------------------------------------------------------
  # * New method: delete
  #--------------------------------------------------------------------------
  def delete(duration = 60)
    @settings[:opacity] = 0
    @duration = [duration, 1].max
    @delete   = true
  end
  #--------------------------------------------------------------------------
  # * New method: value
  #--------------------------------------------------------------------------
  def value
    @settings
  end
  #--------------------------------------------------------------------------
  # * New method: update
  #--------------------------------------------------------------------------
  def update
    update_position
    update_opacity
    update_zoom
    update_delete
    @duration -= 1 if @duration > 0
  end
  #--------------------------------------------------------------------------
  # * New method: update_position
  #--------------------------------------------------------------------------
  def update_position
    self.ox += value[:x]
    self.oy += value[:y]
  end
  #--------------------------------------------------------------------------
  # * New method: update_opacity
  #--------------------------------------------------------------------------
  def update_opacity
    return if @duration == 0
    d = @duration
    self.opacity = (self.opacity * (d - 1) + value[:opacity]) / d
  end
  #--------------------------------------------------------------------------
  # * New method: update_zoom
  #--------------------------------------------------------------------------
  def update_zoom
    return if @duration == 0
    d = @duration
    self.zoom_x = (self.zoom_x * (d - 1) + value[:zoom_x]) / d
    self.zoom_y = (self.zoom_y * (d - 1) + value[:zoom_y]) / d
  end
  #--------------------------------------------------------------------------
  # * New method: update_delete
  #--------------------------------------------------------------------------
  def update_delete
    return if !@delete || @duration > 0
    self.bitmap.dispose
    self.bitmap = nil
    @settings   = {x: 0, y: 0, opacity: 0, zoom_x: 100.0, zoon_y: 100.0}
    @blend_type = 0
    @delete = false
  end
end

 

 

 

Victor's Actors battlers:

 

 

#==============================================================================
# ** Victor Engine - Actors Battlers
#------------------------------------------------------------------------------
# Author : Victor Sant
#
# Version History:
#  v 1.00 - 2011.12.19 > First release
#  v 1.01 - 2011.12.30 > Faster Regular Expressions
#  v 1.02 - 2012.01.15 > Compatibility with Target Arrow
#  v 1.03 - 2012.01.28 > Compatibility with Animated Battle
#  v 1.04 - 2012.03.11 > Added position distance settings
#  v 1.05 - 2012.03.17 > Fixed battle test glitch
#  v 1.06 - 2012.05.20 > Compatibility with Map Turn Battle
#  v 1.07 - 2012.12.13 > Compatibility with State Graphics
#  v 1.08 - 2012.12.30 > Compatibility with Leap Attack
#  v 1.09 - 2013.01.07 > Fixed issue with custom formation and big parties
#------------------------------------------------------------------------------
#  This script adds visible battler graphics for the party actors actors
# during combat. With the visible battlers, new options will be available
# like setting actor's battlers positions and attack animations.
#------------------------------------------------------------------------------
# Compatibility
#   Requires the script 'Victor Engine - Basic Module' v 1.11 or higher.
#   If used with 'Victor Engine - Animated Battle' place this bellow it.
# 
# * Overwrite methods
#   class Spriteset_Battle
#      def create_actors
#     def update_actors
#
#   class Scene_Battle < Scene_Base
#     def show_attack_animation(targets)
#
# * Alias methods 
#   class << DataManager
#     def setup_new_game
#     def create_game_objects
#     def make_save_contents
#     def extract_save_contents(contents)
#
#   class Game_Actor < Game_Battler
#     def setup(actor_id)
#
#   class Game_Interpreter
#     def comment_call
#
#   class Scene_Battle < Scene_Base
#     def start
#
#------------------------------------------------------------------------------
# Instructions:
#  To instal the script, open you script editor and paste this script on
#  a new section bellow the Materials section. This script must also
#  be bellow the script 'Victor Engine - Basic'
#
#------------------------------------------------------------------------------
# Comment calls note tags:
#  Tags to be used in events comment box, works like a script call.
#  
#  <battler name id: x>
#   This tag allows to change the actor battler graphic.
#    id : actor ID
#    x  : battler graphic filename
#
#  <battler hue id: x>
#   This tag allows to change the actor battler graphic.
#    id : actor ID
#    x  : battler graphic hue (0-360)
#
#  <battler position i: x, y>
#   This tag allows to change the battler position during combat.
#   only valid if VE_BATTLE_FORMATION = :custom
#     i : position index
#     x : new coorditante X
#     y : new coorditante X
#
#------------------------------------------------------------------------------
# Actors and Enemies note tags:
#   Tags to be used on the Actors and Enemies note box in the database
#
#  <battler name: x>
#   This tag allows to set the initial battler graphic filename for the actor.
#    x : battler graphic filename
#
#  <battler hue: x>
#   This tag allows to set the initial battler graphic hur for the actor.
#    x : battler graphic hue (0-360)
#
#------------------------------------------------------------------------------
# Enemies note tags:
#   Tags to be used on the Enemies note box in the database
#
#  <attack animation: x>
#   This tag allows to set the normal attack animation for the enemy
#    x : animation ID
#  
#==============================================================================

#==============================================================================
# ** Victor Engine
#------------------------------------------------------------------------------
#   Setting module for the Victor Engine
#==============================================================================

module Victor_Engine
  #--------------------------------------------------------------------------
  # * Set the battle formation
  #    Choose here how the actors battlers will be placed on the combat.
  #    :front  : horizontal placement
  #    :side   : vertical placement
  #    :iso    : isometric placement
  #    :custom : custom placement
  #--------------------------------------------------------------------------
  VE_BATTLE_FORMATION = :custom
  #--------------------------------------------------------------------------
  # * Set battler centralization
  #    When true, battlers are centralized automatically.
  #    Not valid if VE_BATTLE_FORMATION = :custom
  #--------------------------------------------------------------------------
  VE_BATTLE_CENTRALIZE = false
  #--------------------------------------------------------------------------
  # * Set battlers custom positions
  #    Only if VE_BATTLE_FORMATION = :custom, allows to set the position of
  #    all party actors, don't forget to add values for all positions
  #    available if using a party bigger than the default.
  #--------------------------------------------------------------------------
  VE_CUSTOM_POSITION = {
  # Position
    1 => {x: 420, y: 234}, # Position for the first actor.
    2 => {x: 450, y: 258}, # Position for the second actor.
    3 => {x: 480, y: 282}, # Position for the thrid actor.
    4 => {x: 450, y: 306}, # Position for the fourth actor.
  } # Don't remove
  #--------------------------------------------------------------------------
  # * Actors battlers position adjust
  #    Used to adjust the position of all actors battlers.
  #--------------------------------------------------------------------------
  VE_POSITION_ADJUST = {x: 0, y: 0}
  #--------------------------------------------------------------------------
  # * Actors battlers position adjust
  #    Used to adjust the position of all actors battlers.
  #--------------------------------------------------------------------------
  VE_DISTANCE_ADJUST = {x: 8, y: 24}
  #--------------------------------------------------------------------------
  # * required
  #   This method checks for the existance of the basic module and other
  #   VE scripts required for this script to work, don't edit this
  #--------------------------------------------------------------------------
  def self.required(name, req, version, type = nil)
    if !$imported[:ve_basic_module]
      msg = "The script '%s' requires the script\n"
      msg += "'VE - Basic Module' v%s or higher above it to work properly\n"
      msg += "Go to http://victorscripts.wordpress.com/ to download this script."
      msgbox(sprintf(msg, self.script_name(name), version))
      exit
    else
      self.required_script(name, req, version, type)
    end
  end
  #--------------------------------------------------------------------------
  # * script_name
  #   Get the script name base on the imported value, don't edit this
  #--------------------------------------------------------------------------
  def self.script_name(name, ext = "VE")
    name = name.to_s.gsub("_", " ").upcase.split
    name.collect! {|char| char == ext ? "#{char} -" : char.capitalize }
    name.join(" ")
  end
end

$imported ||= {}
$imported[:ve_actor_battlers] = 1.09
Victor_Engine.required(:ve_actor_battlers, :ve_basic_module, 1.11, :above)
Victor_Engine.required(:ve_actor_battlers, :ve_map_battle, 1.00, :bellow)
Victor_Engine.required(:ve_actor_battlers, :ve_state_graphics, 1.00, :bellow)

#==============================================================================
# ** DataManager
#------------------------------------------------------------------------------
#  This module handles the game and database objects used in game.
# Almost all global variables are initialized on this module
#==============================================================================

class << DataManager
  #--------------------------------------------------------------------------
  # * Alias method: setup_new_game
  #--------------------------------------------------------------------------
  alias :setup_new_game_ve_actor_battlers :setup_new_game
  def setup_new_game
    setup_new_game_ve_actor_battlers
    $game_custom_positions = VE_CUSTOM_POSITION.dup
    $game_custom_formation = VE_BATTLE_FORMATION
    $game_position_adjust  = VE_POSITION_ADJUST.dup
  end
  #--------------------------------------------------------------------------
  # * Alias method: setup_battle_test
  #--------------------------------------------------------------------------
  alias :setup_battle_test_ve_actor_battlers :setup_battle_test
  def setup_battle_test
    setup_battle_test_ve_actor_battlers
    $game_custom_positions = VE_CUSTOM_POSITION.dup
    $game_custom_formation = VE_BATTLE_FORMATION
    $game_position_adjust  = VE_POSITION_ADJUST.dup
  end
  #--------------------------------------------------------------------------
  # * Alias method: create_game_objects
  #--------------------------------------------------------------------------
  alias :create_game_objects_ve_actor_battlers :create_game_objects
  def create_game_objects
    create_game_objects_ve_actor_battlers
    $game_custom_positions = {}
    $game_custom_formation = VE_BATTLE_FORMATION
    $game_position_adjust  = VE_POSITION_ADJUST.dup
  end
  #--------------------------------------------------------------------------
  # * Alias method: make_save_contents
  #--------------------------------------------------------------------------
  alias :make_save_contents_ve_actor_battlers  :make_save_contents
  def make_save_contents
    contents = make_save_contents_ve_actor_battlers
    contents[:positions_ve]  = $game_custom_positions
    contents[:formation_ve]  = $game_custom_formation
    contents[:pos_adjust_ve] = $game_position_adjust
    contents
  end
  #--------------------------------------------------------------------------
  # * Alias method: extract_save_contents
  #--------------------------------------------------------------------------
  alias :extract_save_contents_ve_actor_battlers :extract_save_contents
  def extract_save_contents(contents)
    extract_save_contents_ve_actor_battlers(contents)
    $game_custom_positions = contents[:positions_ve]
    $game_custom_formation = contents[:formation_ve]
    $game_position_adjust  = contents[:pos_adjust_ve]
  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                 # Coordenada X na tela
  attr_accessor :screen_y                 # Coordenada Y na tela
  #--------------------------------------------------------------------------
  # * Alias method: setup
  #--------------------------------------------------------------------------
  alias :setup_ve_actor_battlers :setup
  def setup(actor_id)
    setup_ve_actor_battlers(actor_id)
    @battler_name = actor_battler_name
    @battler_hue  = actor_battler_hue
  end
  #--------------------------------------------------------------------------
  # * Aquisição do índice do herói
  #--------------------------------------------------------------------------
  def index
    $game_party.members.index($game_actors[@actor_id])
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: use_sprite?
  #--------------------------------------------------------------------------
  def use_sprite?
    return true
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: screen_z
  #--------------------------------------------------------------------------
  def screen_z
    return 100
  end
  #--------------------------------------------------------------------------
  # * New method: actor_battler_name
  #--------------------------------------------------------------------------
  def actor_battler_name
    actor.note =~ /<BATTLER NAME: ([^><]*)>/i ? $1.to_s : ""
  end
  #--------------------------------------------------------------------------
  # * New method: actor_battler_hue
  #--------------------------------------------------------------------------
  def actor_battler_hue
    actor.note =~ /<BATTLER HUE: (\d+)>/i ? $1.to_i : 0
  end
  #--------------------------------------------------------------------------
  # * New method: battler_name
  #--------------------------------------------------------------------------
  def battler_name=(name)
    @battler_name = name if name.is_a?(String)
  end
  #--------------------------------------------------------------------------
  # * New method: battler_hue
  #--------------------------------------------------------------------------
  def battler_hue=(hue)
    @battler_hue = hue if hue.numeric?
  end
  #--------------------------------------------------------------------------
  # * New method: screen_x
  #--------------------------------------------------------------------------
  def screen_x
    setup_x
  end
  #--------------------------------------------------------------------------
  # * New method: screen_y
  #--------------------------------------------------------------------------
  def screen_y
    setup_y
  end
  #--------------------------------------------------------------------------
  # * New method: setup_x
  #--------------------------------------------------------------------------
  def setup_x
    case $game_custom_formation
    when :front  then position = get_frontal_x
    when :side   then position = get_sideview_x
    when :iso    then position = get_isometric_x
    when :custom then position = $game_custom_positions[index + 1][:x]
    end
    position + $game_position_adjust[:x]
  end
  #--------------------------------------------------------------------------
  # * New method: setup_y
  #--------------------------------------------------------------------------
  def setup_y
    case $game_custom_formation
    when :front  then position = get_frontal_y
    when :side   then position = get_sideview_y
    when :iso    then position = get_isometric_y
    when :custom then position = $game_custom_positions[index + 1][:y]
    end
    position + $game_position_adjust[:y]
  end
  #--------------------------------------------------------------------------
  # * New method: get_frontal_x
  #--------------------------------------------------------------------------
  def get_frontal_x
    if VE_BATTLE_CENTRALIZE
      size = $game_party.battle_members.size
      position = (index + 1) * Graphics.width / (size + 1)
    else
      size = $game_party.max_battle_members
      position = index * Graphics.width / size + 64
    end
    position
  end
  #--------------------------------------------------------------------------
  # * New method: get_frontal_y
  #--------------------------------------------------------------------------
  def get_frontal_y
    Graphics.height - 16
  end
  #--------------------------------------------------------------------------
  # * New method: get_sideview_x
  #--------------------------------------------------------------------------
  def get_sideview_x
    if VE_BATTLE_CENTRALIZE
      size = $game_party.max_battle_members
      x    = dist[:x] / 8
      position = -index * (index * x - x * size) + Graphics.width - 160
    else
      position = index * dist[:x] + Graphics.width - 192
    end
    position
  end
  #--------------------------------------------------------------------------
  # * New method: get_sideview_y
  #--------------------------------------------------------------------------
  def get_sideview_y
    if VE_BATTLE_CENTRALIZE
      size   = $game_party.battle_members.size
      height = Graphics.height
      position = (index - size) * dist[:y] + size * dist[:y] / 2 + height - 160
    else
      position = index * dist[:y] +  Graphics.height - 200
    end
    position
  end
  #--------------------------------------------------------------------------
  # * New method: get_isometric_x
  #--------------------------------------------------------------------------
  def get_isometric_x
    if VE_BATTLE_CENTRALIZE
      position = -index * (index * dist[:x] - 32) + Graphics.width - 160
    else
      position = index * dist[:x] +  Graphics.width - 192
    end
    position
  end
  #--------------------------------------------------------------------------
  # * New method: get_isometric_y
  #--------------------------------------------------------------------------
  def get_isometric_y
    if VE_BATTLE_CENTRALIZE
      position = index * (dist[:y] - index * 6) + Graphics.height - 160
    else
      position = Graphics.height - 96 - index * dist[:y]
    end
    position
  end
  #--------------------------------------------------------------------------
  # * New method: dist
  #--------------------------------------------------------------------------
  def dist
    VE_DISTANCE_ADJUST
  end
end

#==============================================================================
# ** Game_Enemy
#------------------------------------------------------------------------------
#  This class handles enemy characters. It's used within the Game_Troop class
# ($game_troop).
#==============================================================================

class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # * Alias method: initialize
  #--------------------------------------------------------------------------
  alias :initialize_ve_actor_battlers :initialize
  def initialize(index, enemy_id)
    initialize_ve_actor_battlers(index, enemy_id)
    @battler_name = enemy_battler_name if enemy_battler_name
    @battler_hue  = enemy_battler_hue  if enemy_battler_hue
  end
  #--------------------------------------------------------------------------
  # * New method: enemy_battler_name
  #--------------------------------------------------------------------------
  def enemy_battler_name
    enemy.note =~ /<BATTLER NAME: ([^><]*)>/i ? $1.to_s : nil
  end
  #--------------------------------------------------------------------------
  # * New method: enemy_battler_hue
  #--------------------------------------------------------------------------
  def enemy_battler_hue
    enemy.note =~ /<BATTLER HUE: (\d+)>/i ? $1.to_i : nil
  end
  #--------------------------------------------------------------------------
  # * New method: atk_animation_id1
  #--------------------------------------------------------------------------
  def atk_animation_id1
    enemy.note =~ /<ATTACK ANIM(?:ATION): (\d+)>/i ? $1.to_i : 1
  end
  #--------------------------------------------------------------------------
  # * New method: atk_animation_id2
  #--------------------------------------------------------------------------
  def atk_animation_id2
    return 0
  end
end

#==============================================================================
# ** Game_Unit
#------------------------------------------------------------------------------
#  This class handles units. It's used as a superclass of the Game_Party and
# Game_Troop classes.
#==============================================================================

class Game_Unit
  #--------------------------------------------------------------------------
  # * New method: setup_in_battle
  #--------------------------------------------------------------------------
  def setup_in_battle
    @in_battle = true
  end
end

#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
#  An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # * Alias method: comment_call
  #--------------------------------------------------------------------------
  alias :comment_call_ve_actor_battlers :comment_call
  def comment_call
    change_battler_name
    change_battler_hue
    change_position
    comment_call_ve_actor_battlers
  end
  #--------------------------------------------------------------------------
  # * New method: change_battler_name
  #--------------------------------------------------------------------------
  def change_battler_name
    note.scan(/<BATTLER NAME (\d+): ([^><]*)>/i) do |id, name|
      $game_actors[id.to_i].battler_name = name
    end
  end
  #--------------------------------------------------------------------------
  # * New method: change_battler_hue
  #--------------------------------------------------------------------------
  def change_battler_hue
    note.scan(/<BATTLER HUE (\d+): (\d+)>/i) do |id, hue|
      $game_actors[id.to_i].battler_hue = hue
    end
  end
  #--------------------------------------------------------------------------
  # * New method: change_position
  #--------------------------------------------------------------------------
  def change_position
    regexp = /<BATTLER POSITION (\d+): (\d+) *, *(\d+)>/i
    note.scan(regexp) do |i, x, y|
      $game_custom_positions[i.to_i][:x] = x.to_i
      $game_custom_positions[i.to_i][:y] = y.to_i
    end
  end
end

#==============================================================================
# ** Spriteset_Battle
#------------------------------------------------------------------------------
#  This class brings together battle screen sprites. It's used within the
# Scene_Battle class.
#==============================================================================

class Spriteset_Battle
  #--------------------------------------------------------------------------
  # * Overwrite method: create_actors
  #--------------------------------------------------------------------------
  def create_actors
    @actor_sprites = $game_party.battle_members.reverse.collect do |actor|
      Sprite_Battler.new(@viewport1, actor)
    end
    @actors_party = $game_party.battle_members.dup
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: update_actors
  #--------------------------------------------------------------------------
  def update_actors
    update_party if $game_party.battle_members != @actors_party
    @actor_sprites.each {|sprite| sprite.update }
  end
  #--------------------------------------------------------------------------
  # * New method: update_party
  #--------------------------------------------------------------------------
  def update_party
    @actor_sprites.each_index do |i|
      next if $game_party.battle_members.include?(@actor_sprites[i].battler)
      @actor_sprites[i].dispose
      @actor_sprites[i] = nil
    end
    $game_party.battle_members.collect do |actor|
      next if @actors_party.include?(actor)
      @actor_sprites.push(Sprite_Battler.new(@viewport1, actor))
    end
    @actor_sprites.compact!
    @actors_party = $game_party.battle_members.dup
    $game_party.battle_members.each do |actor|
      old_position = [actor.screen_x, actor.screen_y]
#      actor.default_direction if $imported[:ve_animated_battle]
      if old_position != [actor.screen_x, actor.screen_y]
        sprite(actor).start_effect(:appear) 
      end
    end
  end
end

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

class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # * Alias method: start
  #--------------------------------------------------------------------------
  alias :start_ve_actor_battlers :start
  def start
    $game_party.setup_in_battle
    start_ve_actor_battlers
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: show_attack_animation
  #--------------------------------------------------------------------------
  def show_attack_animation(targets)
    show_normal_animation(targets, @subject.atk_animation_id1, false)
    show_normal_animation(targets, @subject.atk_animation_id2, true)
  end
end

 

 

 

And Moghunter's Advanced Battle Hud:

 

 

#==============================================================================
# +++ MOG - Advanced Battle Hud (v2.6) +++
#==============================================================================
# By Moghunter 
# http://www.atelier-rgss.com/
#==============================================================================
# Sistema de hud avançado de batalha.
#==============================================================================

#==============================================================================
# ◠Histórico (Version History)
#==============================================================================
# v 2.6 - Melhor codificação
# v 2.5 - Melhoria na performance
#       - Correção de bugs.
#==============================================================================
#
# Battle_AT_Layout.png
# Battle_AT_Meter.png
#
#==============================================================================
# â–  - FACE ANIMADAS DOS PERSONAGENS - (Opcional)
#==============================================================================
# 1 - Grave as imagens das faces dos personagens na pasta.
#
# GRAPHICS/BATTLERS/
#
# 2 - Nomeie a imagem com o mesmo nome do personagem. (EG - Hertor.png)
# 3 - A largura da imagem deverá ser dividido por 5. (A escolha do tamanho
#     da face é livre desde que a lagura dividido pela altura seja igual a 5 )
#
#==============================================================================

#==============================================================================
# â–  BATTLE HUD SETTING
#==============================================================================
module MOG_BATTLE_HUD
  # Ativar Battlers dos personagens em faces, deixe desativado em caso de haver
  # outros scripts que usam battlers dos personagens em seu projeto.
  BATTLER_FACE_ENABLE = true
  #Definição geral da posição da HUD.
  HUD_POSITION = [5,315]
  #Definição da posição da face
  FACE_POSITION = [60,30]
  #Definição da posição do numero de HP.
  HP_NUMBER_POSITION = [85,28]
  #Definição da posição do medidor de HP.
  HP_METER_POSITION = [27,37]
  #Definição da posição do numero de MP.
  MP_NUMBER_POSITION = [101,46]
  #Definição da posição do medidor de MP.
  MP_METER_POSITION = [43,55]  
  #Definição da posição do numero de TP.
  TP_NUMBER_POSITION = [85,64]
  #Definição da posição do medidor de TP.
  TP_METER_POSITION = [27,73]   
  #Definição da posição das condições
  STATES_POSITION = [5,1]
  #Definição da posição do comando de batalha.
  COMMAND_POSITION = [0,-145]  
  #Definição da posição do espaço da HUD entre os membros do grupo.
  MEMBERS_SPACE = [136,0]
  #Definição da prioridade da HUD.
  BATTLE_HUD_Z = 0
  #Definição da velocidade de animação dos medidores.
  METER_FLOW_SPEED = 2
  #Ativa o layout mais limpo nas janelas de item e skill. 
  ITEM_SKILL_WINDOWS_CLEAN_STYLE = true
  #Definição da opacidade das janelas.
  ITEM_SKILL_WINDOW_OPACITY = 0
  
end

#==============================================================================
# â–  Game Temp
#==============================================================================
class Game_Temp
  
  attr_accessor :cache_battle_hud
  
  #--------------------------------------------------------------------------
  # â— Initialize
  #--------------------------------------------------------------------------    
  alias mog_battle_hud_initialize initialize
  def initialize
      mog_battle_hud_initialize
      pre_cache_battle_hud
  end
  
  #--------------------------------------------------------------------------
  # â— Pre Cache Battle Hud
  #--------------------------------------------------------------------------  
  def pre_cache_battle_hud
      @cache_battle_hud = []
      @cache_battle_hud.push(Cache.system("Battle_Hud_Number"))
      @cache_battle_hud.push(Cache.system("Battle_Hud_Meter"))
      @cache_battle_hud.push(Cache.system("Iconset"))
      @cache_battle_hud.push(Cache.system("Battle_Hud_Layout"))
  end
  
end

#==============================================================================
# â–  Battle_Hud
#==============================================================================
class Battle_Hud
  include MOG_BATTLE_HUD
  
  #--------------------------------------------------------------------------
  # â— Initialize
  #--------------------------------------------------------------------------    
  def initialize(actor)      
      @actor = actor
      @x = HUD_POSITION[0] + (MEMBERS_SPACE[0] * @actor.index)
      @y = HUD_POSITION[1] + (MEMBERS_SPACE[1] * @actor.index)
      @flow_speed = 0
      pre_cache
      create_layout
      create_hp_number
      create_hp_meter
      create_mp_number
      create_mp_meter
      create_tp_number
      create_tp_meter
      create_states
  end
  
  #--------------------------------------------------------------------------
  # â— Pre Cache
  #--------------------------------------------------------------------------      
  def pre_cache
      $game_temp.pre_cache_battle_hud
      @number = $game_temp.cache_battle_hud[0]
      @number_cw = @number.width / 10
      @number_ch = @number.height / 4
      @meter = $game_temp.cache_battle_hud[1]
      @meter_cw = @meter.width / 3
      @meter_ch = @meter.height / 3
      @icon = $game_temp.cache_battle_hud[2]
  end
  
  #--------------------------------------------------------------------------
  # â— Create Layout
  #--------------------------------------------------------------------------      
  def create_layout
      @layout = Sprite.new
      @layout.bitmap = $game_temp.cache_battle_hud[3]
      @layout.z = BATTLE_HUD_Z
      @layout.x = @x
      @layout.y = @y
  end
  
  #--------------------------------------------------------------------------
  # â— Create HP Number
  #--------------------------------------------------------------------------        
  def create_hp_number
      @hp = @actor.hp
      @hp_old = @actor.hp
      @hp_ref = @hp_old
      @hp_refresh = false
      @hp_number = Sprite.new
      @hp_number.bitmap = Bitmap.new((@number_cw * 6),@number_ch)
      @hp_number.z = BATTLE_HUD_Z + 2
      @hp_number.x = @x + HP_NUMBER_POSITION[0]
      @hp_number.y = @y + HP_NUMBER_POSITION[1]
      refresh_hp_number
  end
  
  #--------------------------------------------------------------------------
  # â— Create HP Meter
  #--------------------------------------------------------------------------      
  def create_hp_meter
      @hp_meter = Sprite.new
      @hp_meter.bitmap = Bitmap.new(@meter_cw,@meter_ch)
      @hp_meter.z =  BATTLE_HUD_Z + 1
      @hp_meter.x = @x + HP_METER_POSITION[0]
      @hp_meter.y = @y + HP_METER_POSITION[1] 
      @hp_flow = rand(@meter_cw * 2)
      @hp_width_old = @meter_cw * @actor.hp / @actor.mhp 
      hp_flow_update
  end  
  
  #--------------------------------------------------------------------------
  # â— Hp Flow Update
  #--------------------------------------------------------------------------
  def hp_flow_update
      @hp_meter.bitmap.clear
      hp_width = @meter_cw * @actor.hp / @actor.mhp
      hp_src_rect = Rect.new(@hp_flow, 0,hp_width, @meter_ch)
      @hp_meter.bitmap.blt(0,0, @meter, hp_src_rect)
      @hp_flow += METER_FLOW_SPEED
      @hp_flow = 0 if @hp_flow >=  @meter_cw * 2      
  end
    
  #--------------------------------------------------------------------------
  # â— Execute Damage Flow
  #-------------------------------------------------------------------------- 
  def execute_damage_flow(hp_width)
     n = (@hp_width_old - hp_width).abs * 3 / 100
     damage_flow = [[n, 2].min,0.5].max
     @hp_width_old -= damage_flow         
     @hp_width_old = hp_width if @hp_width_old < hp_width 
     src_rect_old = Rect.new(@hp_flow, @meter_ch * 3,@hp_width_old, @meter_ch)
     @hp_meter.bitmap.blt(0,0, @meter, src_rect_old)       
  end  
 
  #--------------------------------------------------------------------------
  # â— Update HP Number
  #--------------------------------------------------------------------------      
  def update_hp_number
      @hp_refresh = true
      n =  2 * (@actor.hp - @hp_old).abs / 100
      hp_ref = [[n, 100].min,1].max
      if @hp_old < @actor.hp
          @hp += hp_ref     
          if @hp >= @actor.hp
             @hp_old = @actor.hp 
             @hp = @actor.hp   
             @hp_ref = 0
          end              
        elsif @hp_old > @actor.hp   
           @hp -= hp_ref                
           if @hp <= @actor.hp
              @hp_old = @actor.hp 
              @hp = @actor.hp   
              @hp_ref = 0
           end            
        end          
  end  
  
  #--------------------------------------------------------------------------
  # â— Refresh HP Number
  #--------------------------------------------------------------------------      
  def refresh_hp_number
      @flow_speed = METER_FLOW_SPEED
      @hp_number.bitmap.clear
      number_value = @hp.abs.to_s.split(//)
      hp_color = @hp < @actor.mhp * 30 / 100 ? @number_ch : 0
      center_x = 0
      for r in 0..number_value.size - 1         
         number_value_abs = number_value[r].to_i 
         src_rect = Rect.new(@number_cw * number_value_abs, hp_color, @number_cw, @number_ch)
         @hp_number.bitmap.blt((@number_cw + 1) *  r, 0, @number, src_rect) 
         center_x += 1
      end
      @hp_number.x = @x + HP_NUMBER_POSITION[0] - (center_x * (@number_cw + 1))
      @hp_refresh = false if @hp == @actor.hp      
  end  
  
  #--------------------------------------------------------------------------
  # â— Create MP Number
  #--------------------------------------------------------------------------        
  def create_mp_number
      @mp = @actor.mp
      @mp_old = @actor.mp
      @mp_ref = @mp_old
      @mp_refresh = false
      @mp_number = Sprite.new
      @mp_number.bitmap = Bitmap.new((@number_cw * 6),@number_ch)
      @mp_number.z = BATTLE_HUD_Z + 2
      @mp_number.x = @x + MP_NUMBER_POSITION[0]
      @mp_number.y = @y + MP_NUMBER_POSITION[1]
      refresh_mp_number
  end
  
  #--------------------------------------------------------------------------
  # â— Create MP Meter
  #--------------------------------------------------------------------------      
  def create_mp_meter
      @mp_meter = Sprite.new
      @mp_meter.bitmap = Bitmap.new(@meter_cw,@meter_ch)
      @mp_meter.z =  BATTLE_HUD_Z + 1
      @mp_meter.x = @x + MP_METER_POSITION[0]
      @mp_meter.y = @y + MP_METER_POSITION[1] 
      @mp_flow = rand(@meter_cw * 2)
      @mp_width_old = @meter_cw * @actor.mp / @actor.mmp rescue 0
      mp_flow_update
  end  
  
  #--------------------------------------------------------------------------
  # â— Mp Flow Update
  #--------------------------------------------------------------------------
  def mp_flow_update
      return if @actor.mmp == 0
      @mp_meter.bitmap.clear
      mp_width = @meter_cw * @actor.mp / @actor.mmp rescue 0
      src_rect = Rect.new(@mp_flow, @meter_ch,mp_width, @meter_ch)
      @mp_meter.bitmap.blt(0,0, @meter, src_rect)
      @mp_flow += METER_FLOW_SPEED
      @mp_flow = 0 if @mp_flow >=  @meter_cw * 2      
    end
    
  #--------------------------------------------------------------------------
  # â— Update MP Number
  #--------------------------------------------------------------------------      
  def update_mp_number
      @mp_refresh = true
      n =  2 * (@actor.mp - @mp_old).abs / 100
      mp_ref = [[n, 100].min,1].max
      if @mp_old < @actor.mp
          @mp += mp_ref     
          if @mp >= @actor.mp
             @mp_old = @actor.mp 
             @mp = @actor.mp   
             @mp_ref = 0
          end              
        elsif @mp_old > @actor.mp   
           @mp -= mp_ref                
           if @mp <= @actor.mp
              @mp_old = @actor.mp 
              @mp = @actor.mp   
              @mp_ref = 0
           end            
        end          
  end  
  
  #--------------------------------------------------------------------------
  # â— Refresh MP Number
  #--------------------------------------------------------------------------      
  def refresh_mp_number
      @flow_speed = METER_FLOW_SPEED
      @mp_number.bitmap.clear
      number_value = @mp.abs.to_s.split(//)
      center_x = 0
      for r in 0..number_value.size - 1         
         number_value_abs = number_value[r].to_i 
         src_rect = Rect.new(@number_cw * number_value_abs, @number_ch * 2, @number_cw, @number_ch)
         @mp_number.bitmap.blt((@number_cw + 1) *  r, 0, @number, src_rect) 
         center_x += 1
      end
      @mp_number.x = @x + MP_NUMBER_POSITION[0] - (center_x * (@number_cw + 1))
      @mp_refresh = false if @mp == @actor.mp      
  end  
  
  #--------------------------------------------------------------------------
  # â— Create TP Number
  #--------------------------------------------------------------------------        
  def create_tp_number
      @tp = @actor.tp
      @tp_old = @actor.tp
      @tp_ref = @tp_old
      @tp_refresh = false
      @tp_number = Sprite.new
      @tp_number.bitmap = Bitmap.new((@number_cw * 6),@number_ch)
      @tp_number.z = BATTLE_HUD_Z + 2
      @tp_number.x = @x + TP_NUMBER_POSITION[0]
      @tp_number.y = @y + TP_NUMBER_POSITION[1]
      refresh_tp_number
  end
  
  #--------------------------------------------------------------------------
  # â— Create TP Meter
  #--------------------------------------------------------------------------      
  def create_tp_meter
      @tp_meter = Sprite.new
      @tp_meter.bitmap = Bitmap.new(@meter_cw,@meter_ch)
      @tp_meter.z =  BATTLE_HUD_Z + 1
      @tp_meter.x = @x + TP_METER_POSITION[0]
      @tp_meter.y = @y + TP_METER_POSITION[1] 
      @tp_flow = rand(@meter_cw * 2)
      @tp_width_old = @meter_cw * @actor.tp / @actor.max_tp rescue 0 
      tp_flow_update
  end  
  
  #--------------------------------------------------------------------------
  # â— TP Flow Update
  #--------------------------------------------------------------------------
  def tp_flow_update
      return if @actor.max_tp == 0
      @tp_meter.bitmap.clear
      tp_width = @meter_cw * @actor.tp / @actor.max_tp rescue 0
      src_rect = Rect.new(@tp_flow, @meter_ch * 2,tp_width, @meter_ch)
      @tp_meter.bitmap.blt(0,0, @meter, src_rect)
      @tp_flow += METER_FLOW_SPEED
      @tp_flow = 0 if @tp_flow >=  @meter_cw * 2      
  end
    
  #--------------------------------------------------------------------------
  # â— Update TP Number
  #--------------------------------------------------------------------------      
  def update_tp_number
      @tp_refresh = true
      n =  2 * (@actor.tp - @tp_old).abs / 100
      tp_ref = [[n, 100].min,1].max
      if @tp_old < @actor.tp
          @tp += tp_ref     
          if @tp >= @actor.tp
             @tp_old = @actor.tp 
             @tp = @actor.tp   
             @tp_ref = 0
          end              
        elsif @tp_old > @actor.tp   
           @tp -= tp_ref                
           if @tp <= @actor.tp
              @tp_old = @actor.tp 
              @tp = @actor.tp   
              @tp_ref = 0
           end           
         end            
  end      
    
  #--------------------------------------------------------------------------
  # â— Refresh TP Number
  #--------------------------------------------------------------------------      
  def refresh_tp_number
      @flow_speed = METER_FLOW_SPEED
      @tp_number.bitmap.clear
      number_value = @tp.truncate.to_s.split(//)
      center_x = 0
      for r in 0..number_value.size - 1        
         number_value_abs = number_value[r].to_i 
         src_rect = Rect.new(@number_cw * number_value_abs, @number_ch * 3, @number_cw, @number_ch)
         @tp_number.bitmap.blt((@number_cw + 1) *  r, 0, @number, src_rect) 
         center_x += 1
      end
      @tp_number.x = @x + TP_NUMBER_POSITION[0] - (center_x * (@number_cw + 1))
      @tp_refresh = false if @tp == @actor.tp
  end    
  
  #--------------------------------------------------------------------------
  # â— Create_States
  #--------------------------------------------------------------------------      
  def create_states
      refresh_states
      @status = Sprite.new
      @status.bitmap = Bitmap.new(24,24)
      @status.x = @x + STATES_POSITION[0]
      @status.y = @y + STATES_POSITION[1]      
      @status_flow = -24
      @states_speed = 50
      @status.z = BATTLE_HUD_Z + 2
      @old_states = @actor.states
      flow_states
  end  
  
  #--------------------------------------------------------------------------
  # â— Flow_Status
  #--------------------------------------------------------------------------          
  def flow_states
      return if @actor.states.size == 0 and !@status.visible
      @states_speed = 0
      @status.bitmap.clear
      src_rect = Rect.new(@status_flow,0, 24,24)
      @status.bitmap.blt(0,0, @actor_status, src_rect)
      @status.visible = @actor.states.size == 0 ? false : true
      @status_flow += 1
      @status_flow = -24 if @status_flow >= @states_size - 24
  end    
  
  #--------------------------------------------------------------------------
  # â— Refresh States
  #--------------------------------------------------------------------------        
  def refresh_states
      @old_states = @actor.states
      @actor_status.dispose if @actor_status != nil
      @states_size = @actor.states.size > 0 ? (48 * @actor.states.size) : 24 
      @actor_status = Bitmap.new(@states_size,24)
      index = 0
      for i in  @actor.states
         rect = Rect.new(i.icon_index % 16 * 24, i.icon_index / 16 * 24, 24, 24)
         @actor_status.blt(48 * index , 0, @icon, rect)
         index += 1
      end
  end  
  
  #--------------------------------------------------------------------------
  # â— Dispose
  #--------------------------------------------------------------------------    
  def dispose
      return if @layout == nil
      @layout.dispose
      @hp_number.bitmap.dispose
      @hp_number.dispose
      @hp_meter.bitmap.dispose
      @hp_meter.dispose
      @mp_number.bitmap.dispose
      @mp_number.dispose
      @mp_meter.bitmap.dispose
      @mp_meter.dispose      
      @tp_number.bitmap.dispose
      @tp_number.dispose
      @tp_meter.bitmap.dispose
      @tp_meter.dispose
      @status.bitmap.dispose
      @status.dispose
      @actor_status.dispose if @actor_status != nil
      @layout = nil
  end
  
  #--------------------------------------------------------------------------
  # â— Update
  #--------------------------------------------------------------------------    
  def update
      return if @meter == nil
      update_hp_number if @hp_old != @actor.hp
      refresh_hp_number if @hp_refresh
      update_mp_number if @mp_old != @actor.mp
      refresh_mp_number if @mp_refresh
      update_tp_number if @tp_old != @actor.tp
      refresh_tp_number if @tp_refresh
      refresh_states if @old_states != @actor.states
      @flow_speed += 1
      if @flow_speed >= METER_FLOW_SPEED
         @flow_speed = 0
         hp_flow_update
         tp_flow_update
         mp_flow_update
      end
      flow_states
  end
  
end

#==============================================================================
# â–  Game_System
#==============================================================================
class Game_System
  
  attr_accessor :battler_hud
  
  #--------------------------------------------------------------------------
  # â— Initialize
  #--------------------------------------------------------------------------    
  alias mog_adv_battle_hud_initialize initialize
  def initialize       
      @battler_hud = false
      mog_adv_battle_hud_initialize
  end  
  
end

#==============================================================================
# â–  Spriteset Battle
#==============================================================================
class Spriteset_Battle
  
  #--------------------------------------------------------------------------
  # â— Initialize
  #--------------------------------------------------------------------------  
  alias mog_battle_hud_initialize initialize
  def initialize
      mog_battle_hud_initialize
      create_battle_hud      
  end
  
  #--------------------------------------------------------------------------
  # â— Create Battle Hud
  #--------------------------------------------------------------------------    
  def create_battle_hud
      @battle_hud = []
      for i in $game_party.battle_members
          @battle_hud.push(Battle_Hud.new(i))
      end
  end
  
  #--------------------------------------------------------------------------
  # â— Dispose
  #--------------------------------------------------------------------------      
  alias mog_battle_hud_dispose dispose
  def dispose
      mog_battle_hud_dispose
      dispose_battle_hud
  end  
  
  #--------------------------------------------------------------------------
  # â— Dispose Battle Hud
  #--------------------------------------------------------------------------        
  def dispose_battle_hud
      return if @battle_hud == nil
      @battle_hud.each {|sprite| sprite.dispose }
      @battle_hud = nil
  end
  
  #--------------------------------------------------------------------------
  # â— Update
  #--------------------------------------------------------------------------        
  alias mog_battle_hud_update update
  def update
      mog_battle_hud_update
      update_battle_hud
  end
  
  #--------------------------------------------------------------------------
  # â— Update Battle Hud
  #--------------------------------------------------------------------------          
  def update_battle_hud
      return if @battle_hud == nil
      @battle_hud.each {|sprite| sprite.update }
  end
    
end

#==============================================================================
# â–  Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
  include MOG_BATTLE_HUD
   
   attr_accessor :hud_x
   attr_accessor :hud_y

  #--------------------------------------------------------------------------
  # â— HUD X
  #--------------------------------------------------------------------------     
  def hud_x
      return HUD_POSITION[0] + (MEMBERS_SPACE[0] * index)
  end
  
  #--------------------------------------------------------------------------
  # â— HUD Y
  #--------------------------------------------------------------------------    
  def hud_y
      return HUD_POSITION[1] + (MEMBERS_SPACE[1] * index)
  end
    
end  

#==============================================================================
# â–  Scene Battle
#==============================================================================
class Scene_Battle < Scene_Base
  
  #--------------------------------------------------------------------------
  # â— Create Party Command Window
  #--------------------------------------------------------------------------    
  alias mog_battle_hud_create_party_command_window create_party_command_window
  def create_party_command_window
      mog_battle_hud_create_party_command_window
      set_party_window_position 
  end  
  
  #--------------------------------------------------------------------------
  # â— Set Party Window Position
  #--------------------------------------------------------------------------      
  def set_party_window_position
      @party_command_window.viewport = nil  
      return if $mog_rgss3_at_system != nil
      a_index = []
      for actor in $game_party.alive_members
          a_index = [actor.hud_x, actor.hud_y]
          break
      end
      return if a_index.empty? 
      @party_command_window.x = MOG_BATTLE_HUD::COMMAND_POSITION[0] + a_index[0]
      @party_command_window.y = MOG_BATTLE_HUD::COMMAND_POSITION[1] + a_index[1]      
  end  
  
  #--------------------------------------------------------------------------
  # â— Set Party Window Position
  #--------------------------------------------------------------------------        
  alias mog_battle_hud_start_party_command_selection start_party_command_selection
  def start_party_command_selection
      set_party_window_position 
      mog_battle_hud_start_party_command_selection
  end  
  
  #--------------------------------------------------------------------------
  # â— Update
  #--------------------------------------------------------------------------  
  alias mog_battle_hud_update_basic update_basic
  def update_basic
      mog_battle_hud_update_basic
      update_command_window_visible
  end  
  
  #--------------------------------------------------------------------------
  # â— Update Command Window Visible
  #--------------------------------------------------------------------------    
  def update_command_window_visible
      @status_window.visible = @status_window.active ? true : false
      @actor_command_window.visible = @actor_command_window.active ? true : false
      @skill_window.visible = @skill_window.active ? true : false
      @item_window.visible = @item_window.active ? true : false      
  end
  
  #--------------------------------------------------------------------------
  # â— Start Actor Command Selection
  #--------------------------------------------------------------------------    
  alias mog_battle_hud_start_actor_command_selection start_actor_command_selection
  def start_actor_command_selection
      mog_battle_hud_start_actor_command_selection
      @actor_command_window.viewport = nil
      @actor_command_window.x = MOG_BATTLE_HUD::COMMAND_POSITION[0] + $game_party.members[BattleManager.actor.index].hud_x
      @actor_command_window.y = MOG_BATTLE_HUD::COMMAND_POSITION[1] + $game_party.members[BattleManager.actor.index].hud_y
      @party_command_window.x = @actor_command_window.x
      @party_command_window.y = @actor_command_window.y  
  end  

end

#==============================================================================
# â–  Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
  include MOG_BATTLE_HUD
  
  attr_accessor :battler_face
  attr_accessor :battler_face_name
  attr_accessor :screen_x
  attr_accessor :screen_y
  attr_accessor :screen_z
  
  #--------------------------------------------------------------------------
  # â— Initialize
  #--------------------------------------------------------------------------
  alias mog_battle_hud_initialize setup
  def setup(actor_id)
      mog_battle_hud_initialize(actor_id)
      battler_sprite_setup
  end  
    
  #--------------------------------------------------------------------------
  # â— Battler Sprite Setup
  #--------------------------------------------------------------------------  
  def battler_sprite_setup
      @battler_face = [0,0,0]
      @battler_face_name = @name + "_Face"
  end

  if BATTLER_FACE_ENABLE
  #--------------------------------------------------------------------------
  # â— Use Sprite?
  #--------------------------------------------------------------------------
  def use_sprite?
      return true
  end
  end
  
end

#==============================================================================
# â–  Sprite_Battler
#==============================================================================
class Sprite_Battler < Sprite_Base
  include MOG_BATTLE_HUD
  
  #--------------------------------------------------------------------------
  # â— Dispose
  #--------------------------------------------------------------------------    
  alias mog_battler_face_dispose dispose
  def dispose
      mog_battler_face_dispose
      dispose_battler_face
  end  
  
  #--------------------------------------------------------------------------
  # â— Update
  #--------------------------------------------------------------------------   
  alias mog_battler_face_update update
  def update
      refresh_face_battler
      mog_battler_face_update
      update_battler_face
  end
    
  #--------------------------------------------------------------------------
  # â— Refresh Face Battler
  #--------------------------------------------------------------------------     
  def refresh_face_battler
      return if @face_sprite != nil 
      return if @battler == nil 
      return if @battler.is_a?(Game_Enemy)
      setup_battler_screen if @battler.screen_x == nil or $game_system.battler_hud
      @face_sprite = Battler_Face_Sprite.new(self.viewport, @battler)
  end  
  
  #--------------------------------------------------------------------------
  # â— Setup Battler Screen
  #--------------------------------------------------------------------------       
  def setup_battler_screen
      $game_system.battler_hud = true
      @battler.screen_x = FACE_POSITION[0] + HUD_POSITION[0] + (MEMBERS_SPACE[0] * @battler.index)
      @battler.screen_y = FACE_POSITION[1] + HUD_POSITION[1] + (MEMBERS_SPACE[1] * @battler.index)
      @battler.screen_z = 103 if @battler.screen_z == nil
  end  
  
  #--------------------------------------------------------------------------
  # â— Dispose Battler Face
  #--------------------------------------------------------------------------       
  def dispose_battler_face
      return if @face_sprite == nil 
      @face_sprite.dispose  
  end
  
  #--------------------------------------------------------------------------
  # â— Update Battler Face
  #--------------------------------------------------------------------------       
  def update_battler_face
      return if @face_sprite == nil
      @face_sprite.update_actor_battler
  end  
  
  #--------------------------------------------------------------------------
  # â— Update Posiion
  #--------------------------------------------------------------------------         
  alias mog_battler_face_update_position update_position
  def update_position
      mog_battler_face_update_position
      update_face_z
  end  
  
  #--------------------------------------------------------------------------
  # â— Update Face Z
  #--------------------------------------------------------------------------         
  def update_face_z
      return if @face_sprite == nil
      @face_sprite.update_face_z(self.z)
  end

  #--------------------------------------------------------------------------
  # â— Update Collapse
  #--------------------------------------------------------------------------                          
   alias mog_battle_hud_update_collapse update_collapse
   def update_collapse
       if face_can_cancel_method?
         self.opacity = 255
         self.visible = true
         return
      end
       mog_battle_hud_update_collapse
   end  
   
  #--------------------------------------------------------------------------
  # â— Update Instant Collapse
  #--------------------------------------------------------------------------                             
   alias mog_battle_hud_update_instant_collapse update_instant_collapse
   def update_instant_collapse
      if face_can_cancel_method?
         self.opacity = 255
         self.visible = true
         return
      end
       mog_battle_hud_update_instant_collapse
   end  
  
  #--------------------------------------------------------------------------
  # â— Init Visibility
  #--------------------------------------------------------------------------                                
  alias mog_battle_face_init_visibility init_visibility
  def init_visibility
      if face_can_cancel_method?
         self.opacity = 255
         self.visible = true
         return
      end
      mog_battle_face_init_visibility
  end
   
  #--------------------------------------------------------------------------
  # â— Face Can Cancel Method
  #--------------------------------------------------------------------------                                  
  def face_can_cancel_method?
      return false if !BATTLER_FACE_ENABLE
      return false if @battler.is_a?(Game_Enemy)
      return false if !$game_system.battler_hud
      return true
  end  
  
end

#==============================================================================
# â–  Battler Face Sprite
#==============================================================================
class Battler_Face_Sprite < Sprite
  include MOG_BATTLE_HUD
  
  #--------------------------------------------------------------------------
  # â— Initialize
  #--------------------------------------------------------------------------                
   def initialize(viewport = nil,battler)
       super(viewport)
       @battler = battler
       @f_im = Cache.battler(@battler.battler_face_name, 0)
       @f_cw = @f_im.width / 5
       @f_ch = @f_im.height
       self.bitmap = Bitmap.new(@f_cw,@f_ch)
       x = -(@f_cw / 2) + FACE_POSITION[0] + HUD_POSITION[0] + (MEMBERS_SPACE[0] * @battler.index)
       y = -@f_ch + FACE_POSITION[1] + HUD_POSITION[1] + (MEMBERS_SPACE[1] * @battler.index)
       @org_pos = [x,y]
       @battler.battler_face = [0,0,0]
       @battler_visible = true
       @low_hp = @battler.mhp * 30 / 100
       @old_face_index = 0
       self.z = @battler.screen_z
       make_face(true)
   end
   
  #--------------------------------------------------------------------------
  # â— Dispose
  #--------------------------------------------------------------------------                       
  def dispose
      super
      dispose_battler_face_sprite 
  end    

  #--------------------------------------------------------------------------
  # â— Dispose Battler Face Sprite
  #--------------------------------------------------------------------------                    
  def dispose_battler_face_sprite 
       self.bitmap.dispose
       @f_im.dispose
  end  
   
  #--------------------------------------------------------------------------
  # â— Update
  #--------------------------------------------------------------------------  
  def update_face_sprite(battler)
      @battler = battler
      update_face_reset_time
      update_face_effect
  end
   
  #--------------------------------------------------------------------------
  # â— Face Base Setting
  #--------------------------------------------------------------------------                 
  def face_base_setting 
      self.x = @org_pos[0]
      self.y = @org_pos[1]
      self.zoom_x = 1
      self.zoom_y = 1
      self.mirror = false   
  end
  
  #--------------------------------------------------------------------------
  # â— Check Base Face
  #--------------------------------------------------------------------------              
   def check_base_face(reset)
       face_base_setting
       return if @battler.battler_face[2] > 0 
       @battler.battler_face = [0,0,0] if reset and @battler.battler_face[1] != 2  
       @battler.battler_face[0] = 3 if @battler.hp < @low_hp
       @battler.battler_face[0] = 4 if @battler.hp == 0
   end  
   
  #--------------------------------------------------------------------------
  # â— Make Face
  #--------------------------------------------------------------------------              
   def make_face(reset = false)
       self.bitmap.clear
       check_base_face(reset)
       src_rect_back = Rect.new(@f_cw * @battler.battler_face[0], 0, @f_cw, @f_ch)
       self.bitmap.blt(0,0, @f_im, src_rect_back)
       @old_face_index = @battler.battler_face[0] 
   end  

  #--------------------------------------------------------------------------
  # â— Update Actor Battler
  #--------------------------------------------------------------------------           
   def update_actor_battler
       return if self.bitmap == nil
       update_face_effect
       update_face_reset_time
       make_face if @old_face_index != @battler.battler_face[0]              
   end
   
  #--------------------------------------------------------------------------
  # â— Update Face Z
  #--------------------------------------------------------------------------                 
  def update_face_z(value)
      self.z = value + 2
  end  
   
  #--------------------------------------------------------------------------
  # â— Update Face Reset Time 
  #--------------------------------------------------------------------------              
   def update_face_reset_time
       return if @battler.battler_face[2] == 0
       @battler.battler_face[2] -= 1
       if @battler.battler_face[2] == 0 or 
         (@battler.hp < @low_hp and @battler.battler_face[0] == 0)
          make_face(true) 
       end   
   end

  #--------------------------------------------------------------------------
  # â— Update Face Effect
  #--------------------------------------------------------------------------                 
   def update_face_effect
       return if @battler.battler_face[2] == 0
       case @battler.battler_face[1]
          when 0
             face_damage
          when 1..2
             face_heal
          when 3
             face_action
       end
   end  
   
  #--------------------------------------------------------------------------
  # â— Face Damage
  #--------------------------------------------------------------------------                    
   def face_damage
       self.x = (@org_pos[0] - (@battler.battler_face[2] /2)) + rand(@battler.battler_face[2])
   end  
   
  #--------------------------------------------------------------------------
  # â— Face Heal
  #--------------------------------------------------------------------------                    
   def face_heal
       case  @battler.battler_face[2]
         when 20..40
             self.zoom_x += 0.01
             self.zoom_y = self.zoom_x
         when 0..20
             self.zoom_x -= 0.01
             self.zoom_y = self.zoom_x       
       end
   end     
   
  #--------------------------------------------------------------------------
  # â— Face Action
  #--------------------------------------------------------------------------                    
   def face_action
       case  @battler.battler_face[2]
         when 25..50
             self.zoom_x += 0.01 
             self.zoom_y = self.zoom_x
             self.mirror = true
         when 0..25
             self.zoom_x -= 0.01
             self.zoom_y = self.zoom_x
             self.mirror = false
       end
       self.zoom_x = self.zoom_x > 1.5 ? self.zoom_x = 1.5 : self.zoom_x < 1 ? 1 : self.zoom_x
       self.zoom_y = self.zoom_y > 1.5 ? self.zoom_y = 1.5 : self.zoom_y < 1 ? 1 : self.zoom_y
   end
      
 end
 
  #==============================================================================
# â–  Battle Manager
#==============================================================================
class << BattleManager
  
  #--------------------------------------------------------------------------
  # â— Battle End
  #--------------------------------------------------------------------------                    
  alias mog_battle_hud_battle_process_victory process_victory
  def process_victory
      execute_face_effect    
      mog_battle_hud_battle_process_victory
  end
  
  #--------------------------------------------------------------------------
  # â— Prepare
  #--------------------------------------------------------------------------                  
  def execute_face_effect
      for i in $game_party.members
          i.battler_face = [1,2,40] if i.hp > 0   
      end  
  end
  
end

#==============================================================================
# â–  Game Action
#==============================================================================
class Scene_Battle < Scene_Base
  
  #--------------------------------------------------------------------------
  # â— Show Animations
  #--------------------------------------------------------------------------     
  alias mog_battle_hud_show_animation show_animation
  def show_animation(targets, animation_id)
      make_face_action_battle 
      mog_battle_hud_show_animation(targets, animation_id)
  end
  
  #--------------------------------------------------------------------------
  # â— Make Face Action
  #--------------------------------------------------------------------------                  
  def make_face_action_battle
      return if !@subject.is_a?(Game_Actor) 
      @subject.battler_face = [2,3,50]
  end    
  
end  

#==============================================================================
# â–  Game Battler
#==============================================================================
class Game_Battler < Game_BattlerBase
  
  #--------------------------------------------------------------------------
  # â— Item Apply
  #--------------------------------------------------------------------------                
  alias mog_battle_hud_item_apply item_apply 
  def item_apply(user, item)
      old_hp = self.hp
      old_mp = self.mp
      mog_battle_hud_item_apply(user, item)
      check_face_effect(old_hp,old_mp) if can_check_face_effect?(old_hp,old_mp)
  end
  
  #--------------------------------------------------------------------------
  # â— Check Face Effect
  #--------------------------------------------------------------------------  
  def check_face_effect(old_hp,old_mp)
      if self.hp > old_hp or self.mp > old_mp
         self.battler_face = [1,1,40]
      elsif self.hp < old_hp
         self.battler_face = [3,0,40]
      end  
  end  
  
  #--------------------------------------------------------------------------
  # â— Added New State
  #--------------------------------------------------------------------------  
  alias mog_battle_hud_add_new_state add_new_state
  def add_new_state(state_id)
      mog_battle_hud_add_new_state(state_id)
      if self.is_a?(Game_Actor)
         self.battler_face = [1,1,40] if $data_states[state_id].note =~ /<Good State>/
         self.battler_face = [3,0,40] if $data_states[state_id].note =~ /<Bad State>/
      end   
  end    
  
  #--------------------------------------------------------------------------
  # â— Regenerate HP
  #--------------------------------------------------------------------------
  alias mog_battle_hud_regenerate_hp regenerate_hp
  def regenerate_hp
      old_hp = self.hp
      old_mp = self.mp    
      mog_battle_hud_regenerate_hp
      check_face_effect(old_hp,old_mp) if can_check_face_effect?(old_hp,old_mp)
  end

  #--------------------------------------------------------------------------
  # â— Regenerate MP
  #--------------------------------------------------------------------------
  alias mog_battle_hud_regenerate_mp regenerate_mp
  def regenerate_mp
      old_hp = self.hp
      old_mp = self.mp    
      mog_battle_hud_regenerate_mp
      check_face_effect(old_hp,old_mp) if can_check_face_effect?(old_hp,old_mp)
  end  

  #--------------------------------------------------------------------------
  # â— Can Check Face Effect
  #--------------------------------------------------------------------------                  
  def can_check_face_effect?(old_hp,old_mp)
      return false if self.is_a?(Game_Enemy)
      return true if old_hp != self.hp
      return true if old_mp != self.mp
      return false
  end
  
end

#==============================================================================
# â–  Scene_Battle
#==============================================================================
class Scene_Battle < Scene_Base
  
  #--------------------------------------------------------------------------
  # â— Invoke Counter Attack
  #--------------------------------------------------------------------------        
  alias mog_battle_hud_invoke_counter_attack invoke_counter_attack
  def invoke_counter_attack(target, item)
      mog_battle_hud_invoke_counter_attack(target, item)
      if target.is_a?(Game_Actor) and target.battler_face[0] != 2        
         target.battler_face = [2,3,50]
      end  
  end  
  
  #--------------------------------------------------------------------------
  # â— Invoke Magic Reflection
  #--------------------------------------------------------------------------        
  alias mog_battle_hud_invoke_magic_reflection invoke_magic_reflection
  def invoke_magic_reflection(target, item)
      mog_battle_hud_invoke_magic_reflection(target, item)
      if target.is_a?(Game_Actor) and target.battler_face[0] != 2        
         target.battler_face = [2,3,50]
      end  
  end    
  
end

#==============================================================================
# â–  Scene Battle
#==============================================================================  
class Scene_Battle < Scene_Base
  
  #--------------------------------------------------------------------------
  # â— select_enemy_selection
  #--------------------------------------------------------------------------
  alias mog_battle_cursor_select_enemy_selection select_enemy_selection
  def select_enemy_selection
      mog_battle_cursor_select_enemy_selection
      if $mog_rgss3_battle_cursor != nil 
         @enemy_window.visible = false
         @info_viewport.rect.width = 0
      end   
  end
  
  #--------------------------------------------------------------------------
  # â— select_enemy_selection
  #--------------------------------------------------------------------------
  alias mog_battle_cursor_select_actor_selection select_actor_selection
  def select_actor_selection
      mog_battle_cursor_select_actor_selection
      if $mog_rgss3_battle_cursor != nil
         @actor_window.visible = false
         @info_viewport.rect.width = 0
      end   
  end
  
end  

$mog_rgss3_battle_hud = true

 

 

 

But I can't seem to find where the conflict arrises, there's no crashes from what I can see, just the player's actions

not triggering the facial animation/battle cry effects. Does anyone know if there's some way to properly combine these?

If not I'll likely opt out of using Moghunter's HUD and go back to the old setup.

Edited by KayakoChan

Share this post


Link to post
Share on other sites

I'm sorry, but to be honest I don't even know how to obtain the script normally! The only reason I managed to get it was by downloading the "Ace master demo" The layout of Moghunter's site is confusing as hell, even if it weren't in Japanese and, I think Portuguese?

 

Anyway, Time to try getting it this way, I found a download link at the bottom, hope that's it!

 

Okay, I have managed to put the script where it belongs, overwriting the old one but it did not fix

the part about player moves not calling the portrait animations.

 

It did however result in a much fancier battle hud!

 

ioBbClQ.png

 

 

Okay, the weirdest thing seems to have happened right now, everything works, but since switching to

an active battle system being poisoned causes your character to effectively skip their turn!

Edited by KayakoChan

Share this post


Link to post
Share on other sites

The only thing I can think of at the moment is where you have placed the script?

 

I placed mine at the top above everything else for my own game

Share this post


Link to post
Share on other sites

Okay, everything seems to have been fixed, with the exception of one thing

That is the fact that when someone is poisoned their turn will end prematurely.

I think this is because Victor's active battle script does not like this part I added to the states in the animated battlers script:

    # Pose displayed when poisoned
    <action: poisoned, loop>
    pose: self, row danger, all frames, wait 12;
    #wait: self, pose;
    anim: id 120;
    </action>

Which loops when a character is poisoned. I think the animation effect is what causes the turn-end effect.
But since I can't read scripts I can't tell for sure. Or rather, how to keep that animation without breaking the turn?

I figured the effect doesn't occur when it's not the active character under the effect.

 

 

 

#==============================================================================
# ** Victor Engine - Active Time Battle
#------------------------------------------------------------------------------
# Author : Victor Sant
#
# Version History:
#  v 1.00 - 2012.12.16 > First release
#  v 1.01 - 2012.12.24 > Fixed issue with changing party during battle
#                      > Fixed ATB value during Surprise and Pre Emptive
#                      > Fixed Command Window position to not cover the ATB
#                      > Fixed issue with freezes after events
#                      > Fixed issue with state timings
#                      > Fixed issue with cast time at battle start
#                      > Fixed issue with escape at battle start
#                      > Added notetags <timed trigger: x> <cast protection: x>
#                        and <delay protection>
#                      > Fixed issue with command window not closing when
#                        the actor is becomes unable to select action
#  v 1.02 - 2012.12.30 > Compatibility with Leap Attack
#                      > Fixed issue with Guard command and ATB Reverse
#  v 1.03 - 2013.01.07 > Fixed issue with selection when all enemies are dead
#  v 1.04 - 2013.01.24 > Fixed issue with skill, item and target windows not
#                        closing when the actor is becomes unable to act
#  v 1.05 - 2013.02.13 > Added notetag <atb speed: x%>
#                      > Added setup for play a SE when the ATB is full
#------------------------------------------------------------------------------
#  This scripts changes the turn management of battles. The default turn based
# system is replaced by an active time system, where the order of actions
# are decided by individual time bars
#------------------------------------------------------------------------------
# Compatibility
#   Requires the script 'Victor Engine - Basic Module' v 1.32 or higher
#   If used with 'Victor Engine - Animated Battle' place this bellow it.
#   If used with 'Victor Engine - Skip Battle Log' place this bellow it.
#
# * Overwrite methods
#   class << BattleManager
#     def next_command
#     def prior_command
#     def turn_start
#     def turn_end
#     def make_action_orders
#
#   class Game_Enemy < Game_Battler
#     def conditions_met_turns?(param1, param2)
#
#   class Window_BattleStatus < Window_Selectable
#     def window_width
#     def draw_basic_area(rect, actor)
#     def draw_gauge_area_with_tp(rect, actor)
#     def draw_gauge_area_without_tp(rect, actor)
#     def update
# 
# * Alias methods
#   class << BattleManager
#     def init_members
#     def battle_start
#     def process_escape
#
#   class Game_System
#     def initialize
#
#   class Game_Action
#     def prepare
#
#   class Game_BattlerBase
#     def inputable?
#
#   class Game_Battler < Game_BattlerBase
#     def item_user_effect(user, item)
#
#   class Game_Enemy < Game_Battler
#     def initialize(index, enemy_id)
#
#   class Spriteset_Battle
#     def update_actors
#
#   class Window_BattleLog < Window_Selectable
#     def last_text
#
#   class Window_ActorCommand < Window_Command
#     def make_command_list
#
#------------------------------------------------------------------------------
# Instructions:
#  To instal the script, open you script editor and paste this script on
#  a new section bellow the Materials section. This script must also
#  be bellow the script 'Victor Engine - Basic'
#
#------------------------------------------------------------------------------
# Actors, Classes, Enemies, Weapons, Armors, States, Skills and Items note tags:
#   Tags to be used on Actors, Classes, Enemies, Weapons, Armors, States,
#   Skills and Items note boxes.
# 
#  <cast cancel: x%>
#   Actions will have a chance of canceling spell casting of the targets.
#     x : success rate
# 
#  <atb delay: x%, y%>
#   Actions will have a chance of delaying the ATB of the targets.
#     x : success rate
#     y : delay rate
#
#------------------------------------------------------------------------------
# Actors, Classes, Enemies, Weapons, Armors and States note tags:
#   Tags to be used on Actors, Classes, Enemies, Weapons, Armors and States
#   note boxes.
# 
#  <cast protection: x%>
#   Reduce the success rate of a cast cancel action.
#     x : reduction
# 
#  <delay protection: x%>
#   Reduce the success rate of a atb delay action.
#     x : reduction
# 
#  <atb speed: x%>
#   Changes the rate of a atb fill speed. if the value is higher then 100%
#   the bar fills faster, if it's lower than 100% the bar fills slower.
#     x : speed rate
#
#------------------------------------------------------------------------------
# Skills note tags:
#   Tags to be used on Skills note boxes.
#
#  <cast time: x>
#  <cast time: x, y>
#   Actions with this will have a cast time before executing, you can add
#   opitionally wich stat will be used to define the speed.
#     x : cast speed (100 = default speed)
#     y : stat (any valid battler stat)
#
#  <atb cost: x%>
#   Changes the total ATB spent after executing an action. By default all
#   actions cost 100% of the ATB. Can't be lower than 1%
#     x : ATB cost rate
#
#------------------------------------------------------------------------------
# States note tags:
#   Tags to be used on States note boxes.
#
#  <timed trigger: x>
#   There is two options for state auto-removal on the database: Action End
#   and Turn End. This tag creates a third option, to make the state end
#   and trigger after a set time.
#     x : time for the trigger.
#
#------------------------------------------------------------------------------
# Additional instructions:
#
#  The <cast cancel: x%> and <atb delay: x%, y%> will have effect only on
#  physical actions when added to any object beside Skills and Items.
#
#  The <cast protection: x%> and <delay protection: x%> are multiplied by
#  the cast cancel/atb delay rate. So if an action have 30% cast cancel, and
#  the target have 50% cast protection, the cast cancel will be reduced to 15%
#  Multiple cast cancel effects are added separately. So an action with 40%
#  cast cancel and a target with 50%, 50% and 30% cast protection from different
#  sourcers (let's say 3 different equips) will have the chance reduced to 7%
#  (40 - 50% = 20%, 20% - 50% = 10%, 10% - 30% = 7%)
#
#  The <atb speed: x%> can be used to change the rate of a battler ATB speed
#  without the need of changing the AGI of the battler. Can be used to create
#  effect such as "Haste" and "Slow".
#
#  You can use script calls to change the wait mode and the atb speed
#  $game_system.wait_mode = X
#     :full_wait : time stop to select commands and actions
#     :semi_wait : time stop to select actions 
#     :active    : time don't stop
#
#  $game_system.atb_speed = X
#    1.0 = default speed
#
#==============================================================================

#==============================================================================
# ** Victor Engine
#------------------------------------------------------------------------------
#   Setting module for the Victor Engine
#==============================================================================

module Victor_Engine
  #--------------------------------------------------------------------------
  # * Wait mode
  #   :full_wait : time stop to select commands and actions
  #   :semi_wait : time stop to select actions 
  #   :active    : time don't stop
  #--------------------------------------------------------------------------
  VE_ATB_WAIT_MODE = :full_wait
  #--------------------------------------------------------------------------
  # * Action wait
  #   if true, time will stop while executing actions
  #--------------------------------------------------------------------------
  VE_ATB_WAIT_ACTION = true
  #--------------------------------------------------------------------------
  # * Reverse ATB
  #   This setting revert how the ATB works, instead waiting the bar to fill
  #   up to select actions, you first select the action, the the bar start
  #   to fill and the action is executed once it's full.
  #--------------------------------------------------------------------------
  VE_ATB_REVERSE = false
  #--------------------------------------------------------------------------
  # * Move status window
  #   Setup this true to move the status window when the actor command
  #   window or part command window shows up. If false, both windows will
  #   be displayed above the status window.
  #--------------------------------------------------------------------------
  VE_MOVE_STATUS_WINDOW = true
  #--------------------------------------------------------------------------
  # * ATB Full Sound
  #   Play a sound when the actor command window open. Leave nil for no sound
  #   RPG::SE.new(filename, volume, pitch)
  #--------------------------------------------------------------------------
  VE_ATB_SOUND = RPG::SE.new("Decision2", 100, 100)
  #--------------------------------------------------------------------------
  # * Escape type
  #   :party   : open party menu by pressing the cancel key
  #   :command : add the "Escape" option to actors command list
  #   :key     : press the set keys for a while to escape
  #--------------------------------------------------------------------------
  VE_ATB_ESCAPE_TYPE = :key
  #--------------------------------------------------------------------------
  # * Setup the key that must be pressed for escaping
  #    :A >> keyboard Shift  :B >> keyboard X      :C >> keyboard Z
  #    :X >> keyboard A      :Y >> keyboard S      :Z >> keyboard D
  #    :L >> keyboard Q      :R >> keyboard W
  #   adding more than one key makes need to press all of them at same time
  #--------------------------------------------------------------------------
  VE_ATB_ESCAPE_KEYS = [:R, :L]
  #--------------------------------------------------------------------------
  # * Escape time
  #  Average escape time in frames to escape if VE_ATB_ESCAPE_TYPE = :key
  #  This value vary based on the battlers stats and the ATB speed
  #--------------------------------------------------------------------------
  VE_ATB_ESCAPE_TIME = 200
  #--------------------------------------------------------------------------
  # * Escape text
  #   Display escape text when trying to escape if VE_ATB_ESCAPE_TYPE = :key
  #--------------------------------------------------------------------------
  VE_ATB_ESCAPE_TEXT = true
  #--------------------------------------------------------------------------
  # * Turn count control
  #  This is used to control how the turn count will increase, the turn count
  #  control the battle event conditions
  #   :time     : control by time (in frames)
  #   :battlers : control by the number of alive battlers
  #   :actions  : control by the number of actions executed
  #--------------------------------------------------------------------------
  VE_ATB_TURN_COUNT = :time
  #--------------------------------------------------------------------------
  # * Time count
  #   Valid only if VE_ATB_TURN_COUNT = :time, setup the number of frames
  #   needed to increase the turn count. Is influenced by the ATB speed
  #--------------------------------------------------------------------------
  VE_ATB_TIME_COUNT = 200
  #--------------------------------------------------------------------------
  # * Action count
  #   Valid only if VE_ATB_TURN_COUNT = :actions, setup the number of actions
  #   needed to increase the turn count
  #--------------------------------------------------------------------------
  VE_ATB_ACTION_COUNT = 10
  #--------------------------------------------------------------------------
  # * ATB speed
  #   Multiplier that controls the speed of the ATB bars
  #--------------------------------------------------------------------------
  VE_ATB_SPEED = 1.0
  #--------------------------------------------------------------------------
  # * Speed modifier
  #   Value used to control the influence of the stats on the ATB speed
  #   Higher values reduce the influence of the stats on the speed.
  #--------------------------------------------------------------------------
  VE_speed_modifier = 50
  #--------------------------------------------------------------------------
  # * Start rate
  #   Initial ATB value on battle start, a random value between 0 and X%
  #--------------------------------------------------------------------------
  VE_ATB_START_RATE = 15
  #--------------------------------------------------------------------------
  # * Reverse ATB Guard Time
  #   With VE_ATB_REVERSE = true the guard time is set by this value, not
  #   by the value set on the database
  #--------------------------------------------------------------------------
  VE_ATB_REVERSE_GUARD_TIME = 150
  #--------------------------------------------------------------------------
  # * Default magic cast
  #   Setup a default cast speed for all magic skills. 
  #   Leave nil for no cast time.
  #     100 = default speed (same as the default wait time for actions)
  #--------------------------------------------------------------------------
  VE_ATB_DEFAULT_CAST = nil
  #--------------------------------------------------------------------------
  # * Damage wait
  #   Stop battler wait time during hurt animation. Available only for
  #   Animated Battle
  #--------------------------------------------------------------------------
  VE_ATB_DAMAGE_WAIT = true
  #--------------------------------------------------------------------------
  # * Escaping animation
  #   Add a steping animation while holding the escape key. Available only for
  #   Animated Battle and if VE_ATB_ESCAPE_TYPE = :key
  #--------------------------------------------------------------------------
  VE_ATB_ESCAPING_ANIM = true
  #--------------------------------------------------------------------------
  # * Regenerarion Trigger
  #  All regen effects triggers at same time no matter of the source, here
  #  you can set when the regen trigger
  #    :turn   : at the turn end
  #    :action : at the action end
  #    :timing : at fixed intervals
  #   It's highly recomended to setup all regen and poison states with the
  #   same auto-removal condition to ensure the duration match the trigger
  #--------------------------------------------------------------------------
  VE_ATB_REGEN_TRIGGER = :action
  #--------------------------------------------------------------------------
  # * Regenerarion Timing
  #  Time for regen effects to apply if VE_ATB_REGEN_TRIGGER = :timing
  #  Is influenced by the ATB speed
  #--------------------------------------------------------------------------
  VE_ATB_REGEN_TIMING = 300
  #--------------------------------------------------------------------------
  # * required
  #   This method checks for the existance of the basic module and other
  #   VE scripts required for this script to work, don't edit this
  #--------------------------------------------------------------------------
  def required(name, req, version, type = nil)
    if !$imported[:ve_basic_module]
      msg = "The script '%s' requires the script\n"
      msg += "'VE - Basic Module' v%s or higher above it to work properly\n"
      msg += "Go to http://victorscripts.wordpress.com/ to download this script."
      msgbox(sprintf(msg, self.script_name(name), version))
      exit
    else
      self.required_script(name, req, version, type)
    end
  end
  #--------------------------------------------------------------------------
  # * script_name
  #   Get the script name base on the imported value
  #--------------------------------------------------------------------------
  def script_name(name, ext = "VE")
    name = name.to_s.gsub("_", " ").upcase.split
    name.collect! {|char| char == ext ? "#{char} -" : char.capitalize }
    name.join(" ")
  end
end

$imported ||= {}
$imported[:ve_active_time_battle] = 1.05
Victor_Engine.required(:ve_active_time_battle, :ve_basic_module, 1.32, :above)
Victor_Engine.required(:ve_active_time_battle, :ve_state_auto_apply, 1.00, :bellow)
Victor_Engine.required(:ve_active_time_battle, :ve_damage_pop, 1.00, :bellow)
Victor_Engine.required(:ve_active_time_battle, :ve_leap_attack, 1.00, :bellow)
Victor_Engine.required(:ve_active_time_battle, :ve_cooperation_skill, 1.00, :bellow)

#==============================================================================
# ** Vocab
#------------------------------------------------------------------------------
#  This module defines terms and messages. It defines some data as constant
# variables. Terms in the database are obtained from $data_system.
#==============================================================================

module Vocab
  
  # ATB stat name show above atb bar
  VE_ATB_Name = "ATB"

  # Message displayed when trying to escape using VE_ATB_ESCAPE_TYPE = :key
  VE_Escaping = "Escaping..."
  
  # Message displayed when can't escape using VE_ATB_ESCAPE_TYPE = :key
  VE_CantEscape = "Can't escape!"
  
end

#==============================================================================
# ** class RPG::BaseItem
#------------------------------------------------------------------------------
#  Superclass of actor, class, skill, item, weapon, armor, enemy, and state.
#==============================================================================

class RPG::BaseItem
  #--------------------------------------------------------------------------
  # * New method: atb_speed
  #--------------------------------------------------------------------------
  def atb_speed
    return @atb_speed if @atb_speed
    @atb_speed = note =~ /<ATB SPEED: *(\d+)%?>/i ? [$1.to_f, 1].max / 100 : 1
    @atb_speed
  end
end

#==============================================================================
# ** RPG::UsableItem
#------------------------------------------------------------------------------
#  This is the superclass for skills and items.
#==============================================================================

class RPG::UsableItem < RPG::BaseItem
  #--------------------------------------------------------------------------
  # * New method: castable?
  #--------------------------------------------------------------------------
  def castable?
    (cast_speed && not_cooperation?) ? true : false
  end
  #--------------------------------------------------------------------------
  # * New method: not_cooperation?
  #--------------------------------------------------------------------------
  def not_cooperation?
    !$imported[:ve_cooperation_skill] || !cooperation?
  end
  #--------------------------------------------------------------------------
  # * New method: cast_speed
  #--------------------------------------------------------------------------
  def cast_speed
    regexp = /<CAST TIME: (\d+)(?:, *(\w+))?>/i
    note   =~ regexp ? {spd: $1.to_i, stat: ($2 ? $2 : "agi")} : default_cast
  end
  #--------------------------------------------------------------------------
  # * New method: default_cast
  #--------------------------------------------------------------------------
  def default_cast
    speed = VE_ATB_DEFAULT_CAST
    ((magical? && speed) || VE_ATB_REVERSE) ? {spd: speed, stat: "agi"} : nil
  end
  #--------------------------------------------------------------------------
  # * New method: atb_cost
  #--------------------------------------------------------------------------
  def atb_cost
    regexp = /<ATB COST: (\d+)%?>/i
    note  =~ regexp ? [1.0 - ($1.to_f / 100), 0].max : 0
  end
  #--------------------------------------------------------------------------
  # * New method: cast_cancel
  #--------------------------------------------------------------------------
  def cast_cancel
    regexp = /<CAST CANCEL: (\d+)%?>/i
    note  =~ regexp ? $1.to_f / 100 : 0
  end
  #--------------------------------------------------------------------------
  # * New method: atb_delay
  #--------------------------------------------------------------------------
  def guard_skill?
    effects.any? {|effect| effect.code == 21 && effect.data_id == 9 }
  end
  #--------------------------------------------------------------------------
  # * New method: atb_delay
  #--------------------------------------------------------------------------
  def atb_delay
    regexp = /<ATB DELAY: (\d+)%?, *([+-]?\d+)%?>/i
    note   =~ regexp ? {rate: $1.to_f / 100, delay: $2.to_f / 100} : 
                       {rate: 0, delay: 0}
  end
end

#==============================================================================
# ** RPG::State
#------------------------------------------------------------------------------
#  This is the data class for states
#==============================================================================

class RPG::State < RPG::BaseItem
  #--------------------------------------------------------------------------
  # * Alias method: auto_removal_timing
  #--------------------------------------------------------------------------
  alias :auto_removal_timing_ve_active_time_battle :auto_removal_timing
  def auto_removal_timing
    timed_trigger ? 3 : auto_removal_timing_ve_active_time_battle
  end
  #--------------------------------------------------------------------------
  # * New method: timed_trigger
  #--------------------------------------------------------------------------
  def timed_trigger
    return @timed_trigger if @timed_trigger
    return VE_ATB_REVERSE_GUARD_TIME if guard_state?
    @timed_trigger = note =~ /<TIMED TRIGGER: (\d+)>/i ? $1.to_i : nil
  end
  #--------------------------------------------------------------------------
  # * New method: guard_state?
  #--------------------------------------------------------------------------
  def guard_state?
    features.any? {|ft| ft.code == 62 && ft.data_id == 1 }
  end
end

#==============================================================================
# ** BattleManager
#------------------------------------------------------------------------------
#  This module handles the battle processing
#==============================================================================

class << BattleManager
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :input_battlers
  #--------------------------------------------------------------------------
  # * Overwrite method: next_command
  #--------------------------------------------------------------------------
  def next_command
    begin
      return false if !actor || !actor.next_command
    end until actor.inputable?
    return true
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: prior_command
  #--------------------------------------------------------------------------
  def prior_command
    begin
      if !actor || !actor.prior_command
        old_actor = actor
        @actor_index -= 1
        @actor_index %= $game_party.members.size
        return false if old_actor == actor
      end
    end until actor.inputable?
    return true
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: turn_start
  #--------------------------------------------------------------------------
  def turn_start
    @phase = :turn
    make_action_orders
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: turn_end
  #--------------------------------------------------------------------------
  def turn_end
    @phase = :turn_end
    $game_troop.increase_turn
    @atb_turn_count = 0
    @abt_turn_speed = setup_atb_turn_speed
    all_battle_members.each do |battler|
      battler.on_turn_end
      next if scene_changing?
      SceneManager.scene.refresh_status
      SceneManager.scene.log_window.display_auto_affected_status(battler)
      SceneManager.scene.log_window.wait_and_clear
    end
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: make_action_orders
  #--------------------------------------------------------------------------
  def make_action_orders
    @action_battlers += @active_members
    @active_members.clear
  end
  #--------------------------------------------------------------------------
  # * Alias method: init_members
  #--------------------------------------------------------------------------
  alias :init_members_ve_active_time_battle :init_members
  def init_members
    init_members_ve_active_time_battle    
    @abt_turn_speed   = setup_atb_turn_speed
    @escape_time      = 0
    @atb_turn_count   = 0
    @key_escape_count = 0
    @input_battlers   = []
    @active_members   = []
    @action_battlers  = []
  end
  #--------------------------------------------------------------------------
  # * Alias method: battle_start
  #--------------------------------------------------------------------------
  alias :battle_start_ve_active_time_battle :battle_start
  def battle_start
    battle_start_ve_active_time_battle
    setup_initial_atb
    @phase = :turn
  end
  #--------------------------------------------------------------------------
  # * Alias method: process_escape
  #--------------------------------------------------------------------------
  alias :process_escape_ve_active_time_battle :process_escape
  def process_escape
    @preemptive = true if @escape_success
    @escape_success = false
    process_escape_ve_active_time_battle
  end
  #--------------------------------------------------------------------------
  # * New method: update_atb
  #--------------------------------------------------------------------------
  def update_atb
    clear_dead_atb
    return if scene_changing?
    return if $game_troop.interpreter.running? 
    return if SceneManager.scene.party_window?
    return if $imported[:ve_animated_battle] && @escaping
    update_timing
    update_turn
    update_all_atb
    update_input
    update_escaping 
  end
  #--------------------------------------------------------------------------
  # * New method: setup_initial_atb
  #--------------------------------------------------------------------------
  def setup_initial_atb
    @escape_success = false
    @key_escaping   = false
    @escap_pose     = false
    @party_escaping = false
    all_battle_members.each {|battler| battler.cast_action = nil }
    if @preemptive
      $game_party.members.each {|battler| battler.atb = battler.max_atb }
      $game_troop.members.each {|battler| battler.atb = 0 }
    elsif @surprise
      $game_party.members.each {|battler| battler.atb = 0 }
      $game_troop.members.each {|battler| battler.atb = battler.max_atb }
    else
      all_battle_members.each {|battler| battler.preset_atb }
    end
  end
  #--------------------------------------------------------------------------
  # * New method: scene_changing?
  #--------------------------------------------------------------------------
  def scene_changing?
    !SceneManager.scene_is?(Scene_Battle)
  end
  #--------------------------------------------------------------------------
  # * New method: update_all_atb
  #--------------------------------------------------------------------------
  def update_all_atb
    return if wating?
    all_battle_members.each {|member| member.atb_update }
  end
  #--------------------------------------------------------------------------
  # * New method: wating?
  #--------------------------------------------------------------------------
  def wating?
    return true if scene_changing?
    return true if $game_troop.interpreter.running? 
    return true if SceneManager.scene.full_wait?
    return true if SceneManager.scene.semi_wait?
    return true if wait_action?
    return false
  end
  #--------------------------------------------------------------------------
  # * New method: update_escaping
  #--------------------------------------------------------------------------
  def update_escaping
    open_party_command   if VE_ATB_ESCAPE_TYPE == :party
    process_party_escape if VE_ATB_ESCAPE_TYPE == :party && party_escape?
    key_press_escape     if VE_ATB_ESCAPE_TYPE == :key
    process_escape       if VE_ATB_ESCAPE_TYPE == :key   && key_escape?
  end
  #--------------------------------------------------------------------------
  # * New method: open_party_command
  #--------------------------------------------------------------------------
  def open_party_command
    return if scene_changing?
    return if SceneManager.scene.windows_active?
    SceneManager.scene.open_party_command_selection if Input.trigger?(:
  end
  #--------------------------------------------------------------------------
  # * New method: party_escape?
  #--------------------------------------------------------------------------
  def party_escape?
    $game_party.alive_members.all? {|actor| actor.atb_full? } &&
    all_battle_members.all? {|battler| !active_battler?(battler) }
  end 
  #--------------------------------------------------------------------------
  # * New method: process_party_escape
  #--------------------------------------------------------------------------
  def process_party_escape
    $game_party.members.each do |battler| 
      battler.atb = 0
      battler.cast_action = nil
      battler.clear_actions
    end
    @party_escaping = false
    return if process_escape
    turn_start 
    SceneManager.scene.battle_start_open_window unless scene_changing?
  end
  #--------------------------------------------------------------------------
  # * New method: key_press_escape
  #--------------------------------------------------------------------------
  def key_press_escape
    @key_escaping = VE_ATB_ESCAPE_KEYS.all? {|key| Input.press?(key)}
    update_escape_time
  end
  #--------------------------------------------------------------------------
  # * New method: key_escape?
  #--------------------------------------------------------------------------
  def key_escape?
    all_battle_members.all? {|battler| !active?(battler) } && @escape_success
  end 
  #--------------------------------------------------------------------------
  # * New method: update_escape_time
  #--------------------------------------------------------------------------
  def update_escape_time
    return if @escape_success
    escaping? ? increase_escape_time : decrease_escape_time
  end
  #--------------------------------------------------------------------------
  # * New method: increase_escape_time
  #--------------------------------------------------------------------------
  def increase_escape_time
    reset_escape_pose if !reset_escape_pose?
    @escap_pose = true
    if BattleManager.can_escape?
      @escape_time   = [@escape_time + 5 + rand, max_escape_time].min
      @escape_success = @escape_time == max_escape_time
    end
  end
  #--------------------------------------------------------------------------
  # * New method: decrease_escape_time
  #--------------------------------------------------------------------------
  def decrease_escape_time
    reset_escape_pose if reset_escape_pose?
    @escap_pose  = false
    @escape_time = [@escape_time - 1, 0].max
  end
  #--------------------------------------------------------------------------
  # * New method: reset_escape_pose
  #--------------------------------------------------------------------------
  def reset_escape_pose
    $game_party.alive_members.each {|actor| actor.reset_pose if !actor.active? }
  end
  #--------------------------------------------------------------------------
  # * New method: reset_escape_pose?
  #--------------------------------------------------------------------------
  def reset_escape_pose?
    $imported[:ve_animated_battle] && @escap_pose && VE_ATB_ESCAPING_ANIM
  end
  #--------------------------------------------------------------------------
  # * New method: max_escape_time
  #--------------------------------------------------------------------------
  def max_escape_time
    10.0 * VE_ATB_ESCAPE_TIME * @escape_ratio * $game_system.atb_speed
  end
  #--------------------------------------------------------------------------
  # * New method: wait_action? 
  #--------------------------------------------------------------------------
  def wait_action?
    $imported[:ve_animated_battle]  && !scene_changing? && 
    SceneManager.scene.wait_action? && SceneManager.scene.active?
  end
  #--------------------------------------------------------------------------
  # * New method: update_turn
  #--------------------------------------------------------------------------
  def update_turn
    return if wating?
    increase_atb_turn_count(:time)
    SceneManager.scene.turn_ending if @atb_turn_count >= @abt_turn_speed
  end
  #--------------------------------------------------------------------------
  # * New method: update_timing
  #--------------------------------------------------------------------------
  def update_timing
    return if wating?
    all_battle_members.each {|battler| battler.on_timing }
  end
  #--------------------------------------------------------------------------
  # * New method: update_input
  #--------------------------------------------------------------------------
  def update_input
    all_battle_members.reverse.each do |battler|
      next if (@party_escaping && battler.actor?) || !battler.ready?
      @input_battlers.push(battler)
      battler.on_action_start
      skill_window.refresh if skill_window.active
      item_window.refresh  if item_window.active
    end
    shift_input unless @input_battlers.empty?
  end
  #--------------------------------------------------------------------------
  # * New method: skill_window
  #--------------------------------------------------------------------------
  def skill_window
    SceneManager.scene.skill_window
  end
  #--------------------------------------------------------------------------
  # * New method: item_window
  #--------------------------------------------------------------------------
  def item_window
    SceneManager.scene.item_window
  end
  #--------------------------------------------------------------------------
  # * New method: shift_input
  #--------------------------------------------------------------------------
  def shift_input
    battler = @input_battlers.last
    battler.actor? ? setup_action(battler) : setup_no_selection(battler)
  end
  #--------------------------------------------------------------------------
  # * New method: setup_action
  #--------------------------------------------------------------------------
  def setup_action(battler)
    return if scene_changing?
    return if SceneManager.scene.windows_active? && battler.inputable?
    return if battler.guard? && VE_ATB_REVERSE
    battler.inputable? ? setup_selection(battler) : setup_no_selection(battler) 
  end
  #--------------------------------------------------------------------------
  # * New method: setup_selection
  #--------------------------------------------------------------------------
  def setup_selection(battler)
    @actor_index = battler.index
    battler.make_actions
    SceneManager.scene.start_actor_command_selection
    VE_ATB_SOUND.play if VE_ATB_SOUND
  end
  #--------------------------------------------------------------------------
  # * New method: setup_no_selection
  #--------------------------------------------------------------------------
  def setup_no_selection(battler)
    battler.turn_count += 1 if !battler.actor? && !battler.cast_action?
    battler.make_actions
    battler.setup_cast_action if battler.cast_action?
    @input_battlers.delete(battler)
    @active_members.push(battler)
    turn_start
  end
  #--------------------------------------------------------------------------
  # * New method: add_actor
  #--------------------------------------------------------------------------
  def add_actor(battler)
    return unless input_battlers?(battler)
    @input_battlers.delete(battler)
    @active_members.push(battler)
  end
  #--------------------------------------------------------------------------
  # * New method: active_battler?
  #--------------------------------------------------------------------------
  def active_battler?(battler)
    @active_members.include?(battler) || @action_battlers.include?(battler) ||
    @input_battlers.include?(battler) || battler.current_actor? ||
    active?(battler)
  end
  #--------------------------------------------------------------------------
  # * New method: input_battlers?
  #--------------------------------------------------------------------------
  def input_battlers?(battler)
    @input_battlers.include?(battler)
  end
  #--------------------------------------------------------------------------
  # * New method: all_battle_members
  #--------------------------------------------------------------------------
  def all_battle_members
    $game_party.members + $game_troop.members
  end
  #--------------------------------------------------------------------------
  # * New method: all_dead_members
  #--------------------------------------------------------------------------
  def all_dead_members
    $game_party.dead_members + $game_troop.dead_members
  end
  #--------------------------------------------------------------------------
  # * New method: delete_input
  #--------------------------------------------------------------------------
  def delete_input(battler)
    @input_battlers.delete(battler)
  end
  #--------------------------------------------------------------------------
  # * New method: clear_battler
  #--------------------------------------------------------------------------
  def clear_battler(battler)
    @input_battlers.delete(battler)
    @active_members.delete(battler)
  end
  #--------------------------------------------------------------------------
  # * New method: escaping?
  #--------------------------------------------------------------------------
  def escaping?
    @key_escaping
  end
  #--------------------------------------------------------------------------
  # * New method: party_escaping?
  #--------------------------------------------------------------------------
  def party_escaping?
    @party_escaping
  end
  #--------------------------------------------------------------------------
  # * New method: active?
  #--------------------------------------------------------------------------
  def active?(battler)
    $imported[:ve_animated_battle] && battler.poses.active?
  end
  #--------------------------------------------------------------------------
  # * New method: setup_atb_turn_speed
  #--------------------------------------------------------------------------
  def setup_atb_turn_speed
    case VE_ATB_TURN_COUNT
    when :battlers then all_dead_members.size
    when :actions  then VE_ATB_ACTION_COUNT
    when :time     then VE_ATB_TIME_COUNT
    end
  end
  #--------------------------------------------------------------------------
  # * New method: clear_dead_atb
  #--------------------------------------------------------------------------
  def clear_dead_atb
    all_dead_members.each do |battler|
      next unless active_battler?(battler)
      battler.atb = 0
      @active_members.delete(battler)
      @input_battlers.delete(battler)
      @action_battlers.delete(battler)
    end
  end
  #--------------------------------------------------------------------------
  # * New method: increase_atb_turn_count
  #--------------------------------------------------------------------------
  def increase_atb_turn_count(type)
    @atb_turn_count += $game_system.atb_speed if VE_ATB_TURN_COUNT == type
  end
  #--------------------------------------------------------------------------
  # * New method: setup_escape
  #--------------------------------------------------------------------------
  def setup_escape
    $game_party.members.each {|battler| delete_input(battler) }
    @party_escaping = true
  end
  #--------------------------------------------------------------------------
  # * New method: undo_escape
  #--------------------------------------------------------------------------
  def undo_escape
    @party_escaping = false
  end
  #--------------------------------------------------------------------------
  # * New method: turn_phase
  #--------------------------------------------------------------------------
  def turn_phase
    @phase = :turn
  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
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :wait_mode
  attr_accessor :atb_speed
  #--------------------------------------------------------------------------
  # * Alias method: initialize
  #--------------------------------------------------------------------------
  alias :initialize_ve_active_time_battle :initialize
  def initialize
    initialize_ve_active_time_battle
    @wait_mode = VE_ATB_WAIT_MODE
    @atb_speed = VE_ATB_SPEED
  end
end

#==============================================================================
# ** Game_Action
#------------------------------------------------------------------------------
#  This class handles battle actions. This class is used within the
# Game_Battler class.
#==============================================================================

class Game_Action
  #--------------------------------------------------------------------------
  # * Alias method: prepare
  #--------------------------------------------------------------------------
  alias :prepare_ve_active_time_battle :prepare
  def prepare
    subject.atb = item ? subject.atb * item.atb_cost : 0
    if item && item.castable? && !subject.cast_action? &&
       !subject.confusion? && !forcing
      subject.cast_action = self.clone
      subject.skip_actions
      subject.reset_pose if $imported[:ve_animated_battle]
    else
      subject.cast_action = nil if !forcing
      prepare_ve_active_time_battle
    end
  end
end

#==============================================================================
# ** Game_BattlerBase
#------------------------------------------------------------------------------
#  This class handles battlers. It's used as a superclass of the Game_Battler
# classes.
#==============================================================================

class Game_BattlerBase
  #--------------------------------------------------------------------------
  # * Alias method: inputable?
  #--------------------------------------------------------------------------
  alias :inputable_ve_active_time_battle? :inputable?
  def inputable?
    inputable_ve_active_time_battle? && atb_full? && input? && !cast_action? 
  end
  #--------------------------------------------------------------------------
  # * Alias method: clear_states
  #--------------------------------------------------------------------------  
  alias :clear_states_ve_active_time_battle :clear_states
  def clear_states
    clear_states_ve_active_time_battle
    @state_timing = {}
  end
  #--------------------------------------------------------------------------
  # * Alias method: erase_state
  #--------------------------------------------------------------------------
  alias :erase_state_ve_active_time_battle :erase_state
  def erase_state(state_id)
    erase_state_ve_active_time_battle(state_id)
    @state_timing.delete(state_id)
  end
end

#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
#  This class deals with battlers. It's used as a superclass of the Game_Actor
# and Game_Enemy classes.
#==============================================================================

class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :cast_action
  #--------------------------------------------------------------------------
  # * Overwite method: on_action_end
  #--------------------------------------------------------------------------
  def on_action_end
    @result.clear
    regenerate_all if VE_ATB_REGEN_TRIGGER == :action
    @result.clear  if VE_ATB_REGEN_TRIGGER == :action
    remove_states_auto(1)
    update_buff_turns
    remove_buffs_auto
  end
  #--------------------------------------------------------------------------
  # * Overwite method: on_turn_end
  #--------------------------------------------------------------------------
  def on_turn_end
    @result.clear
    remove_states_auto(2)
  end
  #--------------------------------------------------------------------------
  # * Alias method: remove_states_auto
  #--------------------------------------------------------------------------
  alias :remove_states_auto_ve_active_time_battle :remove_states_auto
  def remove_states_auto(timing)
    update_state_auto(timing)
    remove_states_auto_ve_active_time_battle(timing)
  end
  #--------------------------------------------------------------------------
  # * Alias method: item_user_effect
  #--------------------------------------------------------------------------
  alias :item_user_effect_ve_active_time_battle :item_user_effect
  def item_user_effect(user, item)
    item_user_effect_ve_active_time_battle(user, item)
    setup_cast_cancel(user, item)
    setup_atb_delay(user, item)
  end
  #--------------------------------------------------------------------------
  # * Alias method: reset_state_counts
  #--------------------------------------------------------------------------
  alias :reset_state_counts_ve_active_time_battle :reset_state_counts
  def reset_state_counts(state_id)
    reset_state_counts_ve_active_time_battle(state_id)
    state = $data_states[state_id]
    @state_timing[state_id] = state.timed_trigger if state.timed_trigger
  end
  #--------------------------------------------------------------------------
  # * New method: max_atb
  #--------------------------------------------------------------------------
  def max_atb
    @max_atb ||= 1000
  end
  #--------------------------------------------------------------------------
  # * New method: atb
  #--------------------------------------------------------------------------
  def atb
    @atb ||= 0
  end
  #--------------------------------------------------------------------------
  # * New method: atb=
  #--------------------------------------------------------------------------
  def atb=(n)
    @atb = [[n, 0].max, max_atb].min
  end
  #--------------------------------------------------------------------------
  # * New method: atb_freeze
  #--------------------------------------------------------------------------
  def atb_freeze
    @atb_freeze
  end
  #--------------------------------------------------------------------------
  # * New method: regen_timing
  #--------------------------------------------------------------------------
  def regen_timing
    @regen_timing ||= 0
  end
  #--------------------------------------------------------------------------
  # * New method: regen_timing=
  #--------------------------------------------------------------------------
  def regen_timing=(n)
    @regen_timing = [[n, 0].max, VE_ATB_REGEN_TIMING].min
  end
  #--------------------------------------------------------------------------
  # * New method: regen_timing_full?
  #--------------------------------------------------------------------------
  def regen_timing_full?
    regen_timing == VE_ATB_REGEN_TIMING
  end
  #--------------------------------------------------------------------------
  # * New method: atb_freeze=
  #--------------------------------------------------------------------------
  def atb_freeze=(n)
    @atb_freeze = n
  end
  #--------------------------------------------------------------------------
  # * New method: atb_full?
  #--------------------------------------------------------------------------
  def atb_full?
    @atb == max_atb
  end
  #--------------------------------------------------------------------------
  # * New method: atb_rate
  #--------------------------------------------------------------------------
  def atb_rate
    atb.to_f / max_atb
  end
  #--------------------------------------------------------------------------
  # * New method: ready?
  #--------------------------------------------------------------------------
  def ready?
    movable? && atb_full? && !active_battler?
  end
  #--------------------------------------------------------------------------
  # * New method: cast_action?
  #--------------------------------------------------------------------------
  def cast_action?
    cast_action ? true : false
  end
  #--------------------------------------------------------------------------
  # * New method: preset_atb
  #--------------------------------------------------------------------------
  def preset_atb
    self.atb = max_atb * VE_ATB_START_RATE * rand / 100
  end
  #--------------------------------------------------------------------------
  # * New method: total_agi
  #--------------------------------------------------------------------------
  def total_agi
    SceneManager.scene.all_battle_members.inject(0.0) {|r, obj| r += obj.agi }
  end
  #--------------------------------------------------------------------------
  # * New method: atb_update
  #--------------------------------------------------------------------------
  def atb_update
    update_atb_freeze if atb_freeze?
    return if atb_wait?
    self.atb_freeze = nil
    self.atb += update_atb
    self.atb  = max_atb if VE_ATB_REVERSE && !cast_action?
  end
  #--------------------------------------------------------------------------
  # * New method: atb_freeze?
  #--------------------------------------------------------------------------
  def atb_freeze?
    !movable?
  end
  #--------------------------------------------------------------------------
  # * New method: update_atb
  #--------------------------------------------------------------------------
  def update_atb
    speed = cast_action? ? cast_speed : agi
    20.0 * $game_system.atb_speed * atb_speed_mod(speed) * speed_modifier
  end
  #--------------------------------------------------------------------------
  # * New method: atb_wait?
  #--------------------------------------------------------------------------
  def atb_wait?
    atb_full? || atb_freeze? || pause_damage? || current_actor? ||
    (actor? && BattleManager.escaping?)
  end
  #--------------------------------------------------------------------------
  # * New method: update_atb_freeze
  #--------------------------------------------------------------------------
  def update_atb_freeze
    self.cast_action = nil
    self.atb_freeze ||= self.atb
    self.atb_freeze  += update_atb
    atb_freeze_result unless @atb_freeze < max_atb
  end
  #--------------------------------------------------------------------------
  # * New method: atb_freeze_result
  #--------------------------------------------------------------------------
  def atb_freeze_result
    @result.clear
    remove_states_auto(1)
    regenerate_all if VE_ATB_REGEN_TRIGGER == :action
    self.atb_freeze = 0
  end
  #--------------------------------------------------------------------------
  # * New method: pause_damage?
  #--------------------------------------------------------------------------
  def pause_damage?
    VE_ATB_DAMAGE_WAIT && $imported[:ve_animated_battle] && poses.damage_pose?
  end
  #--------------------------------------------------------------------------
  # * New method: cast_speed
  #--------------------------------------------------------------------------
  def cast_speed
    return agi if !cast_action
    speed = cast_action.item.cast_speed
    speed[:spd] * send(make_symbol(speed[:stat])) / 100.0 
  end
  #--------------------------------------------------------------------------
  # * New method: atb_speed_mod
  #--------------------------------------------------------------------------
  def atb_speed_mod(speed)
    (speed + [VE_speed_modifier, 0].max) / total_agi
  end
  #--------------------------------------------------------------------------
  # * New method: setup_cast_action
  #--------------------------------------------------------------------------
  def setup_cast_action
    @actions = [cast_action]
  end
  #--------------------------------------------------------------------------
  # * New method: setup_cast_cancel
  #--------------------------------------------------------------------------
  def setup_cast_cancel(user, item)
    rate  = item.cast_cancel
    rate += user.cast_cancel if item.physical?
    rate *= cast_protection
    execute_cast_cancel      if rand < rate && cast_action?
  end
  #--------------------------------------------------------------------------
  # * New method: setup_atb_delay
  #--------------------------------------------------------------------------
  def setup_atb_delay(user, item)
    rate  = item.atb_delay[:rate]
    rate += user.atb_delay[:rate] if item.physical?
    rate *= delay_protection
    execute_atb_delay(user, item) if rand < rate
  end
  #--------------------------------------------------------------------------
  # * New method: execute_cast_cancel
  #--------------------------------------------------------------------------
  def execute_cast_cancel
    skip_actions
    self.atb = 0
    self.cast_action = nil
  end
  #--------------------------------------------------------------------------
  # * New method: execute_atb_delay
  #--------------------------------------------------------------------------
  def execute_atb_delay(user, item)
    rate  = item.atb_delay[:delay]
    rate += user.atb_delay[:delay] if item.physical?
    self.atb -= max_atb * rate
  end
  #--------------------------------------------------------------------------
  # * New method: cast_cancel
  #--------------------------------------------------------------------------
  def cast_cancel
    regexp = /<CAST CANCEL: (\d+)%?>/i
    get_all_notes.scan(regexp).inject(0.0) {|r| r += ($1.to_f / 100) }
  end
  #--------------------------------------------------------------------------
  # * New method: atb_delay
  #--------------------------------------------------------------------------
  def atb_delay
    result = {}
    notes  = get_all_notes.dup
    regexp = /<ATB DELAY: (\d+)%?, *(\d+)%?>/i
    result[:rate]  = notes.scan(regexp).inject(0.0) {|r| r += ($1.to_f / 100) }
    result[:delay] = notes.scan(regexp).inject(0.0) {|r| r += ($1.to_f / 100) }
    result
  end
  #--------------------------------------------------------------------------
  # * New method: cast_protection
  #--------------------------------------------------------------------------
  def cast_protection
    regexp = /<CAST PROTECTION: (\d+)%?>/i
    get_all_notes.scan(regexp).inject(1.0) {|r| r *= 1 - ($1.to_f / 100) }
  end
  #--------------------------------------------------------------------------
  # * New method: delay_protection
  #--------------------------------------------------------------------------
  def delay_protection
    regexp = /<DELAY PROTECTION: (\d+)%?>/i
    get_all_notes.scan(regexp).inject(1.0) {|r| r *= 1 - ($1.to_f / 100) }
  end
  #--------------------------------------------------------------------------
  # * New method: update_state_auto
  #--------------------------------------------------------------------------
  def update_state_auto(timing)
    states.each do |state|
      if @state_turns[state.id] > 0 && state.auto_removal_timing == timing
        @state_turns[state.id] -= 1
      end
    end
  end
  #--------------------------------------------------------------------------
  # * New method: on_timing
  #--------------------------------------------------------------------------
  def on_timing
    timing_regen
    remove_timing_states
  end
  #--------------------------------------------------------------------------
  # * New method: timing_regen
  #--------------------------------------------------------------------------
  def timing_regen
    return unless VE_ATB_REGEN_TRIGGER == :timing
    self.regen_timing += $game_system.atb_speed if regen?
    @result.clear     if regen_timing_full?
    regenerate_all    if regen_timing_full?
    @regen_timing = 0 if regen_timing_full? || !regen?
  end
  #--------------------------------------------------------------------------
  # * New method: remove_timing_states
  #--------------------------------------------------------------------------
  def remove_timing_states
    states.each do |state|
      next if state.auto_removal_timing != 3 
      next if state.guard_state? && !VE_ATB_REVERSE
      @state_timing[state.id] -= $game_system.atb_speed
      if @state_turns[state.id] > 0 && @state_timing[state.id] <= 0
        @state_turns[state.id] -= 1
        @state_timing[state.id] = state.timed_trigger
      end
      remove_state(state.id) if @state_turns[state.id] == 0
    end
  end
  #--------------------------------------------------------------------------
  # * New method: regen?
  #--------------------------------------------------------------------------
  def regen?
    hrg != 0 || mrg != 0 || trg != 0
  end
  #--------------------------------------------------------------------------
  # * Overwite method: on_action_end
  #--------------------------------------------------------------------------
  def on_action_start
    make_actions
    remove_guard_state
  end
  #--------------------------------------------------------------------------
  # * Overwite method: remove_guard_state
  #--------------------------------------------------------------------------
  def remove_guard_state
    return if VE_ATB_REVERSE
    states.each do |state|
      next unless state.guard_state?
      remove_state(state.id)
      @damaged = true
    end
  end
  #--------------------------------------------------------------------------
  # * New method: skip_actions
  #--------------------------------------------------------------------------
  def skip_actions
    clear_actions
    @actions = [Game_Action.new(self)]
  end
  #--------------------------------------------------------------------------
  # * New method: active_battler?
  #--------------------------------------------------------------------------
  def active_battler?
    BattleManager.active_battler?(self)
  end
  #--------------------------------------------------------------------------
  # * New method: input?
  #--------------------------------------------------------------------------
  def input?
    BattleManager.input_battlers?(self)
  end
  #--------------------------------------------------------------------------
  # * New method: current_actor?
  #--------------------------------------------------------------------------
  def current_actor?
    SceneManager.scene_is?(Scene_Battle) && SceneManager.scene.subject == self
  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
  #--------------------------------------------------------------------------
  # * New method: speed_modifier
  #--------------------------------------------------------------------------
  def speed_modifier
    list = [self.actor] + [self.class] + states + equips
    list.compact.inject(1.0) {|r, obj| r *= obj.atb_speed }
  end
end

#==============================================================================
# ** Game_Enemy
#------------------------------------------------------------------------------
#  This class handles enemy characters. It's used within the Game_Troop class
# ($game_troop).
#==============================================================================

class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :turn_count
  #--------------------------------------------------------------------------
  # * Overwrite method: conditions_met_turns?
  #--------------------------------------------------------------------------
  def conditions_met_turns?(param1, param2)
    n = @turn_count
    if param2 == 0
      n == param1
    else
      n > 0 && n >= param1 && n % param2 == param1 % param2
    end
  end
  #--------------------------------------------------------------------------
  # * Alias method: initialize
  #--------------------------------------------------------------------------
  alias :initialize_ve_active_time_battle :initialize
  def initialize(index, enemy_id)
    initialize_ve_active_time_battle(index, enemy_id)
    @turn_count = 0
  end
  #--------------------------------------------------------------------------
  # * New method: speed_modifier
  #--------------------------------------------------------------------------
  def speed_modifier
    enemy.atb_speed * states.inject(1.0) {|r, state| r *= state.atb_speed }
  end
end

#==============================================================================
# ** Spriteset_Battle
#------------------------------------------------------------------------------
#  This class brings together battle screen sprites. It's used within the
# Scene_Battle class.
#==============================================================================

class Spriteset_Battle
  #--------------------------------------------------------------------------
  # * Alias method: update_actors
  #--------------------------------------------------------------------------
  alias :update_actors_ve_active_time_battle :update_actors
  def update_actors
    uptate_actors_atb
    update_actors_ve_active_time_battle
  end
  #--------------------------------------------------------------------------
  # * New method: uptate_actors_atb
  #--------------------------------------------------------------------------
  def uptate_actors_atb
    return if @atb_actors == $game_party.members
    $game_party.members.each do |actor|
      actor.preset_atb if @atb_actors && !@atb_actors.include?(actor)
    end
    @atb_actors = $game_party.members.dup
  end
end

#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
#  This is a superclass of all windows in the game.
#==============================================================================

class Window_Base < Window
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :hidden
end

#==============================================================================
# ** Window_BattleLog
#------------------------------------------------------------------------------
#  This window shows the battle progress. Do not show the window frame.
#==============================================================================

class Window_BattleLog < Window_Selectable
  #--------------------------------------------------------------------------
  # * Alias method: last_text
  #--------------------------------------------------------------------------
  alias :last_text_ve_active_time_battle :last_text
  def last_text
    last_text_ve_active_time_battle ? last_text_ve_active_time_battle : ""
  end
end

#==============================================================================
# ** Window_ActorCommand
#------------------------------------------------------------------------------
#  This window is used to select actor commands, such as "Attack" or "Skill".
#==============================================================================

class Window_ActorCommand < Window_Command
  #--------------------------------------------------------------------------
  # * Alias method: make_command_list
  #--------------------------------------------------------------------------
  alias :make_command_list_ve_active_time_battle :make_command_list
  def make_command_list
    make_command_list_ve_active_time_battle
    add_escape_command if VE_ATB_ESCAPE_TYPE == :command
  end
  #--------------------------------------------------------------------------
  # * New method: add_escape_command
  #--------------------------------------------------------------------------
  def add_escape_command
    add_command(Vocab::escape, :escape, BattleManager.can_escape?)
  end
end

#==============================================================================
# ** Window_BattleStatus
#------------------------------------------------------------------------------
#  Esta janela exibe as condições de todos membros do grupo na tela de batalha.
#==============================================================================

class Window_BattleStatus < Window_Selectable
  #--------------------------------------------------------------------------
  # * Overwrite method: window_width
  #--------------------------------------------------------------------------
  def window_width
    Graphics.width - ($data_system.opt_display_tp ? 0 : 128)
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: draw_basic_area
  #--------------------------------------------------------------------------
  def draw_basic_area(rect, actor)
    width = $data_system.opt_display_tp ? 180 : 104
    draw_actor_name(actor, rect.x + 0, rect.y, 100)
    draw_actor_icons(actor, rect.x + 104, rect.y, [rect.width - width, 24].max)
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: draw_gauge_area_with_tp
  #--------------------------------------------------------------------------
  def draw_gauge_area_with_tp(rect, actor)
    draw_actor_hp(actor, rect.x - 82, rect.y, 72)
    draw_actor_mp(actor, rect.x + 0, rect.y, 64)
    draw_actor_tp(actor, rect.x + 74, rect.y, 64)
    update_atb
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: draw_gauge_area_without_tp
  #--------------------------------------------------------------------------
  def draw_gauge_area_without_tp(rect, actor)
    draw_actor_hp(actor, rect.x + 0, rect.y, 72)
    draw_actor_mp(actor, rect.x + 82, rect.y, 64)
    update_atb
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: update
  #--------------------------------------------------------------------------
  def update
    super
    update_atb
  end
  #--------------------------------------------------------------------------
  # * New method: update_atb
  #--------------------------------------------------------------------------
  def update_atb
    @count ||= 0
    @count  += 1
    return if @count % 2 != 0
    update_atb_bars
  end
  #--------------------------------------------------------------------------
  # * New method: update_atb_bars
  #--------------------------------------------------------------------------
  def update_atb_bars
    tp_adjust = $data_system.opt_display_tp ? 148 : 156
    item_max.times do |i| 
      actor = $game_party.battle_members[i]
      rect  = gauge_area_rect(i)
      rect.x += tp_adjust
      contents.clear_rect(rect)
      draw_actor_atb(actor, rect.x, rect.y, 64)
    end
  end
  #--------------------------------------------------------------------------
  # * New method: draw_actor_atb
  #--------------------------------------------------------------------------
  def draw_actor_atb(actor, x, y, width = 124)
    color1 = setup_atb_color1(actor)
    color2 = setup_atb_color2(actor)
    draw_gauge(x, y, width, actor.atb_rate, color1, color2)
    change_color(system_color)
    draw_text(x, y, 30, line_height, Vocab::VE_ATB_Name)
  end
  #--------------------------------------------------------------------------
  # * New method: setup_atb_color1
  #--------------------------------------------------------------------------
  def setup_atb_color1(actor)
    return text_color(2) if actor.cast_action?
    return text_color(6) if BattleManager.party_escaping?
    return text_color(5) 
  end
  #--------------------------------------------------------------------------
  # * New method: setup_atb_color2
  #--------------------------------------------------------------------------
  def setup_atb_color2(actor)
    return text_color(10) if actor.cast_action?
    return text_color(14) if BattleManager.party_escaping?
    return text_color(13)
  end
end

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

class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :log_window
  attr_reader   :item_window
  attr_reader   :skill_window
  #--------------------------------------------------------------------------
  # * Overwrite method: update_info_viewport
  #--------------------------------------------------------------------------
  def update_all_windows
    update_active_windows
    super
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: update_info_viewport
  #--------------------------------------------------------------------------
  def update_info_viewport
    if VE_MOVE_STATUS_WINDOW
      @move_info_wait  = 4 if @moved_info != windows_active?
      @move_info_wait -= 1
      move_info_viewport(0) if @party_command_window.active
      move_info_viewport(right_status_window)  if right_info_viewport
      move_info_viewport(center_status_window) if center_info_viewport
      @moved_info = windows_active?
    else
      move_info_viewport(128)
    end
    update_close_command_window
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: turn_start
  #--------------------------------------------------------------------------
  def turn_start
    BattleManager.add_actor(BattleManager.actor)
    @close_command_wait   = 2
    @close_command_window = true
    @status_window.unselect
    BattleManager.turn_start
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: start_party_command_selection
  #--------------------------------------------------------------------------
  def start_party_command_selection
  end
  #--------------------------------------------------------------------------
  # * Overwrite method: turn_end
  #--------------------------------------------------------------------------
  def turn_end
  end
  #--------------------------------------------------------------------------
  # * Alias method: battle_start
  #--------------------------------------------------------------------------
  alias :battle_start_ve_active_time_battle :battle_start
  def battle_start
    battle_start_ve_active_time_battle
    battle_start_open_window
  end
  #--------------------------------------------------------------------------
  # * Alias method: create_all_windows
  #--------------------------------------------------------------------------
  alias :create_all_windows_ve_active_time_battle :create_all_windows
  def create_all_windows
    create_all_windows_ve_active_time_battle
    create_escape_window
    @close_command_wait = 0
    @move_info_wait     = 4
  end
  #--------------------------------------------------------------------------
  # * Alias method: reate_party_command_window
  #--------------------------------------------------------------------------
  alias :create_party_command_window_ve_active_time_battle :create_party_command_window
  def create_party_command_window
    create_party_command_window_ve_active_time_battle
    unless VE_MOVE_STATUS_WINDOW
      @party_command_window.x = @party_command_window.width
    end
    @info_viewport.ox = center_status_window
  end
  #--------------------------------------------------------------------------
  # * Alias method: create_actor_command_window
  #--------------------------------------------------------------------------
  alias :create_command_window_ve_active_time_battle :create_actor_command_window
  def create_actor_command_window
    create_command_window_ve_active_time_battle
    @actor_command_window.set_handler(:escape,  method(:command_escape))
    if !VE_MOVE_STATUS_WINDOW
      @actor_command_window.x = @actor_command_window.width
    elsif $data_system.opt_display_tp
      @actor_command_window.x = Graphics.width + 128
    end
  end
  #--------------------------------------------------------------------------
  # * Alias method: update
  #--------------------------------------------------------------------------
  alias :update_ve_active_time_battle :update
  def update
    result = update_ve_active_time_battle
    BattleManager.update_atb unless result
    result
  end
  #--------------------------------------------------------------------------
  # * Alias method: update_basic
  #--------------------------------------------------------------------------
  alias :update_basic_ve_active_time_battle :update_basic
  def update_basic
    update_basic_ve_active_time_battle
    update_escape_window if VE_ATB_ESCAPE_TYPE == :key
  end
  #--------------------------------------------------------------------------
  # * Alias method: update_for_wait
  #--------------------------------------------------------------------------
  alias :update_for_wait_ve_active_time_battle :update_for_wait
  def update_for_wait
    update_for_wait_ve_active_time_battle
    BattleManager.update_atb if BattleManager.in_turn? && !wait_action?
  end
  #--------------------------------------------------------------------------
  # * Alias method: wait_for_message
  #--------------------------------------------------------------------------
  alias :wait_for_message_ve_active_time_battle :wait_for_message
  def wait_for_message
    wait_for_message_ve_active_time_battle
    open_windows
  end
  #--------------------------------------------------------------------------
  # * Atualização da mensagem aberta
  #--------------------------------------------------------------------------
  alias :update_message_open_ve_active_time_battle :update_message_open
  def update_message_open
    close_windows
    update_message_open_ve_active_time_battle
  end
  #--------------------------------------------------------------------------
  # * Alias method: start_actor_command_selection
  #--------------------------------------------------------------------------
  alias :start_actor_command_selection_ve_active_time_battle :start_actor_command_selection
  def start_actor_command_selection
    start_actor_command_selection_ve_active_time_battle
    @close_command_window = false
  end
  #--------------------------------------------------------------------------
  # * Alias method: process_action_end
  #--------------------------------------------------------------------------
  alias :process_action_end_ve_active_time_battle :process_action_end
  def process_action_end
    return if $imported[:ve_animated_battle] && @subject.poses.active?
    BattleManager.increase_atb_turn_count(:battlers)
    BattleManager.increase_atb_turn_count(:actions)
    process_action_end_ve_active_time_battle
  end
  #--------------------------------------------------------------------------
  # * Alias method: command_fight
  #--------------------------------------------------------------------------
  alias :command_fight_end_ve_active_time_battle :command_fight
  def command_fight
    command_fight_end_ve_active_time_battle
    @party_command_window.close
    BattleManager.undo_escape
  end
  #--------------------------------------------------------------------------
  # * Alias method: command_escape
  #--------------------------------------------------------------------------
  alias :command_escape_end_ve_active_time_battle :command_escape
  def command_escape
    if VE_ATB_ESCAPE_TYPE == :command
      BattleManager.actor.atb = 0 
      command_escape_end_ve_active_time_battle
      battle_start_open_window
    else
      @party_command_window.close
      BattleManager.setup_escape
    end
  end
  #--------------------------------------------------------------------------
  # * Alias method: prior_command
  #--------------------------------------------------------------------------
  alias :prior_command_ve_active_time_battle :prior_command
  def prior_command
    prior_command_ve_active_time_battle
    open_party_command_selection if !BattleManager.actor.prior_command
  end
  #--------------------------------------------------------------------------
  # * Alias method: on_enemy_ok
  #--------------------------------------------------------------------------
  alias :on_enemy_ok_ve_active_time_battle :on_enemy_ok
  def on_enemy_ok
    return if !@enemy_window.enemy
    on_enemy_ok_ve_active_time_battle
  end
  #--------------------------------------------------------------------------
  # * Alias method: refresh_status
  #--------------------------------------------------------------------------
  alias :refresh_status_ve_active_time_battle :refresh_status
  def refresh_status
    refresh_status_ve_active_time_battle
    @skill_window.refresh if @skill_window.active
    @item_window.refresh  if @item_window.active
  end
  #--------------------------------------------------------------------------
  # * New method: update_close_command_window
  #--------------------------------------------------------------------------
  def update_close_command_window
    @close_command_wait -= 1
    if @close_command_wait == 0 && @close_command_window
      @actor_command_window.close
      @close_command_window = false
    end
  end
  #--------------------------------------------------------------------------
  # * New method: update_active_windows
  #--------------------------------------------------------------------------
  def update_active_windows
    @enemy_window.hide if @enemy_window.active && @enemy_window.item_max == 0
    @actor_window.hide if @actor_window.active && @actor_window.item_max == 0
    close_command_windows
  end
  #--------------------------------------------------------------------------
  # * New method: close_command_windows
  #--------------------------------------------------------------------------
  def close_command_windows
    return if !BattleManager.actor || BattleManager.actor.inputable?
    on_enemy_cancel if @enemy_window.active
    on_actor_cancel if @actor_window.active
    on_skill_cancel if @skill_window.active
    on_item_cancel  if @item_window.active
    @actor_command_window.close.deactivate
    @skill_window.deactivate
    @item_window.deactivate
    @actor_window.deactivate
    @enemy_window.deactivate
    BattleManager.clear_actor
    next_command
  end
  #--------------------------------------------------------------------------
  # * New method: create_escape_window
  #--------------------------------------------------------------------------
  def create_escape_window
    @escape_window = Window_Help.new(1)
    @escape_window.openness = 0
  end
  #--------------------------------------------------------------------------
  # * New method: update_escape_window
  #--------------------------------------------------------------------------
  def update_escape_window
    escaping = BattleManager.escaping?
    open_escape_window   if  escaping && @escape_window.openness == 0
    @escape_window.close if !escaping && @escape_window.openness != 0
  end
  #--------------------------------------------------------------------------
  # * New method: open_escape_window
  #--------------------------------------------------------------------------
  def open_escape_window
    return if BattleManager.can_escape? && !VE_ATB_ESCAPE_TEXT
    txt = BattleManager.can_escape? ? Vocab::VE_Escaping : Vocab::VE_CantEscape
    @escape_window.set_text(txt)
    @escape_window.open
  end
  #--------------------------------------------------------------------------
  # * New method: on_turn_end
  #--------------------------------------------------------------------------
  def on_turn_end
  end
  #--------------------------------------------------------------------------
  # * New method: close_windows
  #--------------------------------------------------------------------------
  def close_windows
    if $game_message.busy? && !@status_window.close?
      command_windows.each {|window| window.hidden ||= window.open?  }
      @help_window.close
      @item_window.close
      @skill_window.close
      @actor_window.close
      @enemy_window.close
    end
  end
  #--------------------------------------------------------------------------
  # * New method: open_windows
  #--------------------------------------------------------------------------
  def open_windows
    command_windows.each do |window| 
      window.open if window.hidden
      window.hidden = false
    end
  end
  #--------------------------------------------------------------------------
  # * New method: command_windows
  #--------------------------------------------------------------------------
  def command_windows
    [@party_command_window, @actor_command_window, @help_window, @skill_window,
     @item_window, @actor_window, @enemy_window, @status_window]
  end
  #--------------------------------------------------------------------------
  # * New method: battle_start_open_window
  #--------------------------------------------------------------------------
  def battle_start_open_window
    unless scene_changing?
      refresh_status
      @status_window.unselect
      @status_window.open
    end
  end
  #--------------------------------------------------------------------------
  # * New method: open_party_command_selection
  #--------------------------------------------------------------------------
  def open_party_command_selection
    return if scene_changing? || VE_ATB_ESCAPE_TYPE != :party
    BattleManager.delete_input(BattleManager.actor)
    refresh_status
    @status_window.unselect
    @status_window.open
    @actor_command_window.close.deactivate
    @party_command_window.setup
  end
  #--------------------------------------------------------------------------
  # * New method: wait_action?
  #--------------------------------------------------------------------------
  def wait_action?
    VE_ATB_WAIT_ACTION
  end
  #--------------------------------------------------------------------------
  # * New method: full_wait?
  #--------------------------------------------------------------------------
  def full_wait?
    $game_system.wait_mode == :full_wait && windows_active?(true)
  end
  #--------------------------------------------------------------------------
  # * New method: semi_wait?
  #--------------------------------------------------------------------------
  def semi_wait?
    $game_system.wait_mode == :semi_wait && windows_active?(false)
  end
  #--------------------------------------------------------------------------
  # * New method: party_window?
  #--------------------------------------------------------------------------
  def party_window?
    @party_command_window.active
  end
  #--------------------------------------------------------------------------
  # * New method: windows_active?
  #--------------------------------------------------------------------------
  def windows_active?(command = true)
    (command && @actor_command_window.active)   || @skill_window.active ||
    @item_window.active || @actor_window.active || @enemy_window.active
  end
  #--------------------------------------------------------------------------
  # * New method: turn_ending
  #--------------------------------------------------------------------------
  def turn_ending
    BattleManager.turn_end
    process_event
    BattleManager.turn_phase
  end
  #--------------------------------------------------------------------------
  # * New method: right_status_window
  #--------------------------------------------------------------------------
  def right_status_window
    256 - (Graphics.width - @status_window.width)
  end
  #--------------------------------------------------------------------------
  # * New method: center_status_window
  #--------------------------------------------------------------------------
  def center_status_window
    128 - (Graphics.width - @status_window.width) / 2
  end
  #--------------------------------------------------------------------------
  # * New method: right_info_viewport
  #--------------------------------------------------------------------------
  def right_info_viewport
    !@party_command_window.active && windows_active? && @move_info_wait < 0
  end
  #--------------------------------------------------------------------------
  # * New method: center_info_viewport
  #--------------------------------------------------------------------------
  def center_info_viewport
    !@party_command_window.active && !windows_active? && @move_info_wait < 0
  end
end

 

 

Edited by KayakoChan

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted