Guest User

Untitled

a guest
Dec 10th, 2017
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 122.94 KB | None | 0 0
  1. #==============================================================================
  2. # ** Custom Battle System (CTB) by Charlie Fleed  
  3. #
  4. # Version:          3.2
  5. # Author:    Charlie Fleed
  6. #==============================================================================
  7.  
  8. #==============================================================================
  9. # ** Scene_Battle (part 1)
  10. #------------------------------------------------------------------------------
  11. #  This class performs battle screen processing.
  12. #==============================================================================
  13.  
  14. class Scene_Battle
  15.   #--------------------------------------------------------------------------
  16.   # * Public Instance Variables
  17.   #--------------------------------------------------------------------------
  18.   attr_accessor   :action_times
  19.   attr_reader     :active_battler_copy
  20.   attr_accessor   :wait_count
  21.   attr_reader     :target_battlers
  22.  
  23.   #--------------------------------------------------------------------------
  24.   # * Main Processing
  25.   #--------------------------------------------------------------------------
  26.   def main
  27.     # Initialize each kind of temporary battle data
  28.     $game_temp.in_battle = true
  29.     $game_temp.battle_turn = 0
  30.     $game_temp.battle_event_flags.clear
  31.     $game_temp.battle_abort = false
  32.     $game_temp.battle_main_phase = false
  33.     $game_temp.battleback_name = $game_map.battleback_name
  34.     $game_temp.forcing_battler = nil
  35.  
  36.     @wait_count = 0
  37.     @battlers_queue = []
  38.     @battlers_array = []
  39.     @action_times = []
  40.     $game_temp.battle_time = 0
  41.     @prev_actor_command = ""
  42.     ## REFLECT SUPPORT ##
  43.     @reflected_battler = nil
  44.     @reflecters = []
  45.     ## REACTION SUPPORT ##
  46.     @target_of_reaction = nil
  47.     @reacting_battler = nil
  48.     @reacting = false
  49.     ## AUTO PHOENIX SUPPORT ##
  50.     @phoenix_users = []
  51.     @using_phoenix = false
  52.     @phoenix_targets = []
  53.     ## AUTO LIFE SUPPORT ##
  54.     @auto_life_targets = []
  55.     @auto_life = false
  56.     @using_auto_life = false
  57.     ## FORCED ACTION SUPPORT
  58.     @active_battler_saved_forced_action=Game_BattleAction.new
  59.     ## Extended party support
  60.     $game_party.update_size
  61.     @switch_common_event = false
  62.     @retire_common_event = false
  63.     @new_battle_turn = true
  64.     # @battle_event_to_setup is used as a flag when delaying the execution of
  65.     # battle events when animating the hp/sp bars
  66.     @battle_event_to_setup = false
  67.     @old_party = []
  68.  
  69.     # Initialize battle event interpreter
  70.     $game_system.battle_interpreter.setup(nil, 0)
  71.     # Prepare troop
  72.     @troop_id = $game_temp.battle_troop_id
  73.     $game_troop.setup(@troop_id)
  74.  
  75.     # Support for hp bars
  76.     for enemy in $game_troop.enemies
  77.       if $game_system.killed_enemies_ids.include?(enemy.id)
  78.         enemy.show_hp_bar = true
  79.       end
  80.     end
  81.  
  82.     # Make actor command window
  83.     s1 = $data_system.words.attack
  84.     s2 = $data_system.words.skill
  85.     s3 = $data_system.words.guard
  86.     s4 = $data_system.words.item
  87.  
  88.     @actor_command_window = Window_Command_Plus.new(ACTOR_COMMAND_WINDOW_WIDTH,
  89.       112, [s1, s2, s3, s4, "Skip", "Status", "Escape"], 20)
  90.     @actor_command_window.x = ACTOR_COMMAND_WINDOW_X
  91.     @actor_command_window.target_x = ACTOR_COMMAND_WINDOW_X
  92.     @actor_command_window.y = 368
  93.     @actor_command_window.z = 200
  94.     @actor_command_window.back_opacity = 255
  95.     @actor_command_window.opacity = ACTOR_COMMAND_WINDOW_WINDOWSKIN_OPACITY
  96.     @actor_command_window.active = false
  97.     @actor_command_window.visible = false
  98.     @actor_command_window.custom_normal_color = ACTOR_COMMAND_WINDOW_TEXT_COLOR
  99.     @actor_command_window.custom_normal_b_color = ACTOR_COMMAND_WINDOW_TEXT_BG_COLOR
  100.     @actor_command_window.set_font_size(20 + ACTOR_COMMAND_WINDOW_TEXT_SIZE_OFFSET)
  101.     @actor_command_window.refresh
  102.  
  103.     # Make other windows
  104.  
  105.     @turn_window = Window_BattleTurns.new
  106.     @turn_window.visible = false
  107.     @turn_window.set_action_times(@action_times)
  108.     @enemy_attacks_window = Window_Enemy_Attacks.new
  109.     @all_enemies_window = Window_All_Enemies.new
  110.     @all_allies_window = Window_All_Allies.new
  111.     @battler_window = Window_Battler.new
  112.     @escape_window = Window_Failed_Escape.new
  113.     @reaction_window = Window_Reaction.new(nil)
  114.     @auto_phoenix_window = Window_AutoPhoenix.new(nil)
  115.     @actor_select_window = Window_Actor_Select.new
  116.     @left_actor_command_window = Window_Command_Plus.new(ACTOR_COMMAND_WINDOW_WIDTH,
  117.       112, [s3, "Skip", "Status", "Escape"], 20)
  118.     @left_actor_command_window.custom_normal_color=ACTOR_COMMAND_WINDOW_TEXT_COLOR
  119.     @left_actor_command_window.custom_normal_b_color=ACTOR_COMMAND_WINDOW_TEXT_BG_COLOR
  120.     begin
  121.       if LEFT_ACTOR_COMMAND_WINDOWSKIN_NAME != ""
  122.         @left_actor_command_window.windowskin =
  123.           RPG::Cache.windowskin(LEFT_ACTOR_COMMAND_WINDOWSKIN_NAME)
  124.       end
  125.     rescue
  126.       p LEFT_ACTOR_COMMAND_WINDOWSKIN_NAME + " not found."
  127.     end
  128.     @left_actor_command_window.opacity = LEFT_ACTOR_COMMAND_WINDOWSKIN_OPACITY
  129.     @left_actor_command_window.set_font_size(20 + ACTOR_COMMAND_WINDOW_TEXT_SIZE_OFFSET)
  130.     @left_actor_command_window.refresh
  131.     @left_actor_command_window.visible = false
  132.     @left_actor_command_window.active = false
  133.     @left_actor_command_window.set_x(ACTOR_COMMAND_WINDOW_X)
  134.     @left_actor_command_window.set_y(368)
  135.     @left_actor_command_window.z = 204
  136.     @battler_window.visible = false
  137.     @battler_window.z = 200
  138.     @status_on_battle_window = Window_Status_On_Battle.new
  139.     @status_on_battle_window.visible = false
  140.  
  141.     @help_window = Window_Help_Tiny.new
  142.     @help_window.back_opacity = 160
  143.     @help_window.visible = false
  144.  
  145.     @help_window.back_opacity = 200 #255
  146.     @help_window.z = 205
  147.     battle_data_hard_reset
  148.  
  149.     @status_window = Window_BattleStatus.new
  150.     @message_window = Window_Message.new
  151.  
  152.     # Make other windows
  153.     @grandia_bar_window = Window_GrandiaBar.new if GRANDIA_MODE
  154.  
  155.     # Make sprite set
  156.     @spriteset = Spriteset_Battle.new
  157.  
  158.     @actor_command_bg=Sprite.new(@spriteset.viewport2)
  159.     begin
  160.       @actor_command_bg.bitmap = RPG::Cache.picture(ACTOR_COMMAND_BG_PICTURE_NAME)
  161.     rescue
  162.       if ACTOR_COMMAND_BG_PICTURE_NAME != ""
  163.         p ACTOR_COMMAND_BG_PICTURE_NAME + " not found."
  164.       end
  165.     end
  166.     @actor_command_bg.x = ACTOR_COMMAND_WINDOW_X + ACTOR_COMMAND_BG_PICTURE_X
  167.     @actor_command_bg.z = 2502
  168.     @actor_command_bg.y = @actor_command_window.y + ACTOR_COMMAND_BG_PICTURE_Y
  169.     @actor_command_bg.visible = false
  170.  
  171.     # Initialize wait count
  172.     @wait_count = 0
  173.     # Execute transition
  174.     if $data_system.battle_transition == ""
  175.       Graphics.transition(20)
  176.     else
  177.       Graphics.transition(40, "Graphics/Transitions/" +
  178.         $data_system.battle_transition)
  179.     end
  180.     # Start pre-battle phase
  181.     start_phase1
  182.     # Main loop
  183.     loop do
  184.       # Update game screen
  185.       Graphics.update
  186.       # Update input information
  187.       Input.update
  188.       # Frame update
  189.       update
  190.       # Abort loop if screen is changed
  191.       if $scene != self
  192.         break
  193.       end
  194.     end
  195.     # Refresh map
  196.     $game_map.refresh
  197.     # Prepare for transition
  198.     Graphics.freeze
  199.     # Dispose of windows
  200.     @actor_command_window.dispose
  201.  
  202.     @enemy_attacks_window.dispose
  203.     @all_enemies_window.dispose
  204.     @all_allies_window.dispose
  205.     @escape_window.dispose
  206.     @battler_window.dispose
  207.     @reaction_window.dispose
  208.     @auto_phoenix_window.dispose
  209.     @turn_window.dispose
  210.     @actor_select_window.dispose
  211.     @status_on_battle_window.dispose
  212.     @actor_command_bg.dispose if @actor_command_bg != nil
  213.     @left_actor_command_window.dispose
  214.     @grandia_bar_window.dispose if GRANDIA_MODE
  215.    
  216.     @help_window.dispose
  217.     @status_window.dispose
  218.     @message_window.dispose
  219.     if @skill_window != nil
  220.       @skill_window.dispose
  221.     end
  222.     if @item_window != nil
  223.       @item_window.dispose
  224.     end
  225.     if @result_window != nil
  226.       @result_window.dispose
  227.     end
  228.     if @result_window2 != nil
  229.       @result_window2.dispose
  230.     end
  231.     # Dispose of sprite set
  232.     @spriteset.dispose
  233.     # If switching to title screen
  234.     if $scene.is_a?(Scene_Title)
  235.       # Fade out screen
  236.       Graphics.transition
  237.       Graphics.freeze
  238.     end
  239.     # If switching from battle test to any screen other than game over screen
  240.     if $BTEST and not $scene.is_a?(Scene_Gameover)
  241.       $scene = nil
  242.     end
  243.   end
  244.  
  245.   # def battle_end(result)            [unchanged]
  246.   # def setup_battle_event            [unchanged]
  247.  
  248.   #--------------------------------------------------------------------------
  249.   # * Judge
  250.   #--------------------------------------------------------------------------
  251.   alias ctb_judge judge
  252.   def judge
  253.     # If all dead determinant is true, or number of members in party is 0
  254.     if $game_party.all_dead? or $game_party.actors.size == 0
  255.       for actor in $game_party.actors
  256.         if actor.state?($auto_life_state_id)
  257.           $outfile.write "judge: dead actor is in auto life\n" if $outfile
  258.           return false
  259.         end
  260.       end
  261.     end
  262.     if ($charlie_fleed_summons!=nil) and
  263.     $game_party.removed_actors.size == 0
  264.       regular_actor_alive = false
  265.       for actor in $game_party.actors
  266.         if ($charlie_fleed_summons != nil) and
  267.         not $game_party.aeons_ids.include?(actor.id) and
  268.         ((not actor.dead?) or actor.state?($auto_life_state_id))
  269.           regular_actor_alive = true
  270.         end
  271.       end
  272.       unless regular_actor_alive
  273.         # If possible to lose
  274.         if $game_temp.battle_can_lose
  275.           # Return to BGM before battle starts
  276.           $game_system.bgm_play($game_temp.map_bgm)
  277.           # Battle ends
  278.           battle_end(2)
  279.           # Return true
  280.           $outfile.write "judge battle_end(2)\n" if $outfile
  281.           return true
  282.         end
  283.         $game_temp.gameover = true
  284.       end
  285.     end
  286.     return ctb_judge
  287.   end
  288.  
  289.   #--------------------------------------------------------------------------
  290.   # * Frame Update
  291.   #--------------------------------------------------------------------------
  292.   def update
  293.     $outfile.write "update\n" if $outfile
  294.     if @battle_event_to_setup == true
  295.       $outfile.write "update there is a @battle_event_to_setup\n" if $outfile
  296.       if $game_temp.forcing_battler == nil
  297.         if not @status_window.animate_bars and not @spriteset.effect?
  298.           $outfile.write "@status_window.animate_bars = false\n" if $outfile
  299.           # Rerun battle event set up if battle continues
  300.           $outfile.write "executing judge\n" if $outfile
  301.           if not judge
  302.             $outfile.write "update setup_battle_event @battle_event_to_setup\n" if $outfile
  303.             setup_battle_event
  304.             @battle_event_to_setup = false
  305.           else
  306.             $outfile.write "judge! cancel @battle_event_to_setup\n" if $outfile
  307.             @battle_event_to_setup = false
  308.           end
  309.         end
  310.       end
  311.     end
  312.    
  313.     # If battle event is running
  314.     if $game_system.battle_interpreter.running?
  315.       $outfile.write "update battle_interpreter.running\n" if $outfile
  316.       # Update interpreter
  317.       $outfile.write "$game_system.battle_interpreter.update\n" if $outfile
  318.       $game_system.battle_interpreter.update
  319.       $outfile.write "after battle_interpreter.update - gameover = " +
  320.         $game_temp.gameover.to_s + "\n" if $outfile
  321.       if not @status_window.animate_bars
  322.         $outfile.write "set animate_bars\n" if $outfile
  323.         @status_window.animate_bars = true
  324.       end
  325.       # If a battler which is forcing actions doesn't exist
  326.       if $game_temp.forcing_battler == nil
  327.         # If battle event has finished running
  328.         unless $game_system.battle_interpreter.running?
  329.           $outfile.write "battle event has finished running\n" if $outfile
  330.           @status_window.refresh_hp
  331.           @status_window.refresh_sp
  332.           @status_window.update_animate_bars
  333.           if not @status_window.animate_bars and not @spriteset.effect?
  334.             # Rerun battle event set up if battle continues
  335.             $outfile.write "executing judge\n" if $outfile
  336.             unless judge
  337.               $outfile.write "update setup_battle_event\n" if $outfile
  338.               setup_battle_event
  339.             end
  340.           else
  341.             $outfile.write "set @battle_event_to_setup\n" if $outfile
  342.             @battle_event_to_setup = true
  343.           end
  344.         end
  345.       end
  346.     end
  347.    
  348.     # Update system (timer) and screen
  349.     $game_system.update
  350.     $game_screen.update
  351.     # If timer has reached 0
  352.     if $game_system.timer_working and $game_system.timer == 0
  353.       # Abort battle
  354.       $game_temp.battle_abort = true
  355.     end
  356.    
  357.     # Update windows
  358.     @turn_window.update if (@phase == 3 or @phase == 2)
  359.     @battler_window.update if (@phase == 3 or @phase == 2)
  360.     @help_window.update if (@phase != 4)
  361.     if @message_window.visible
  362.       @actor_command_window.update_xy if (@phase == 3)
  363.       @left_actor_command_window.update_xy if (@phase == 3 and @left_actor_command_window.active)
  364.     else
  365.       @actor_command_window.update if (@phase == 3)
  366.       @left_actor_command_window.update if (@phase == 3 and @left_actor_command_window.active)
  367.     end
  368.     @actor_command_bg.visible = (@actor_command_window.visible or @left_actor_command_window.visible)
  369.     @status_window.update
  370.     if @phase != 4 and @status_window.counter == 0
  371.       for enemy in $game_troop.enemies
  372.         enemy.toggle_shown_state()
  373.       end
  374.     end
  375.     # Always refresh the status window upon party changes
  376.     if @old_party != $game_party.actors
  377.       # Set actor to non-selecting
  378.       @status_window.index =- 1
  379.       @status_window.refresh
  380.     end
  381.     @old_party = $game_party.actors.clone
  382.     @status_window.refresh_hp if (@phase == 4 and @status_window.animate_bars)
  383.     @status_window.refresh_sp if (@phase == 4 and @status_window.animate_bars)
  384.     @result_window.update if @result_window != nil
  385.     # Floating status on battle window
  386.     if @help_window.visible or @message_window.visible
  387.       @status_on_battle_window.target_y =- 80
  388.     else
  389.       @status_on_battle_window.target_y = 0
  390.     end
  391.     @status_on_battle_window.update
  392.     #lo stato non si aggiorna finchè non termina l'animazione
  393.     @message_window.update
  394.     if @stolen_item_window != nil
  395.       update_stolen_item_window
  396.       @wait_count = 1
  397.     end
  398.  
  399.     # Update sprite set
  400.     @spriteset.update
  401.     # If transition is processing
  402.     if $game_temp.transition_processing
  403.       # Clear transition processing flag
  404.       $game_temp.transition_processing = false
  405.       # Execute transition
  406.       if $game_temp.transition_name == ""
  407.         Graphics.transition(20)
  408.       else
  409.         Graphics.transition(40, "Graphics/Transitions/" +
  410.           $game_temp.transition_name)
  411.       end
  412.     end
  413.     # If message window is showing
  414.     if $game_temp.message_window_showing
  415.       $outfile.write "update message_window_showing\n" if $outfile
  416.       return
  417.     end
  418.     # If effect is showing
  419.     if @spriteset.effect?
  420.       $outfile.write "update @spriteset.effect\n" if $outfile
  421.       return
  422.     end
  423.     # If game over
  424.     if $game_temp.command_353
  425.       # Switch to game over screen
  426.       $scene = Scene_Gameover.new
  427.       $outfile.write "Gameover by command 353\n" if $outfile
  428.       return
  429.     elsif $game_temp.gameover
  430.       if not @status_window.animate_bars and not @spriteset.effect?
  431.         # If there are not removed actors
  432.         if ($charlie_fleed_summons == nil) or $game_party.removed_actors.size == 0
  433.           $outfile.write "phase " + @phase.to_s + " gameover\n" if $outfile
  434.           # Switch to game over screen
  435.           $scene = Scene_Gameover.new
  436.           return
  437.         end
  438.         $outfile.write "no gameover, there are removed actors\n" if $outfile
  439.         $game_temp.gameover = false
  440.       else
  441.         $outfile.write "update @status_window.animate_bars\n" if $outfile
  442.       end
  443.     end
  444.     # If returning to title screen
  445.     if $game_temp.to_title
  446.       # Switch to title screen
  447.       $scene = Scene_Title.new
  448.       return
  449.     end
  450.     # If battle is aborted
  451.     if $game_temp.battle_abort
  452.       # Return to BGM used before battle started
  453.       $game_system.bgm_play($game_temp.map_bgm)
  454.       # Battle ends
  455.       battle_end(1)
  456.       $outfile.write "update battle_end(1)\n" if $outfile
  457.       return
  458.     end
  459.     # If waiting
  460.     if @wait_count > 0
  461.       # Decrease wait count
  462.       @wait_count -= 1
  463.       $outfile.write "update @wait_count > 0\n" if $outfile
  464.       return
  465.     end
  466.     # If battler forcing an action doesn't exist,
  467.     # and battle event is running
  468.     if $game_temp.forcing_battler == nil and
  469.       $game_system.battle_interpreter.running?
  470.       return
  471.     end
  472.     # Branch according to phase
  473.     case @phase
  474.     when 1  # pre-battle phase
  475.       update_phase1
  476.     when 2  # party command phase
  477.       update_phase2
  478.     when 3  # actor command phase
  479.       update_phase3
  480.     when 4  # main phase
  481.       update_phase4
  482.     when 5  # after battle phase
  483.       update_phase5
  484.     end
  485.   end
  486.  
  487.   #--------------------------------------------------------------------------
  488.   # * Start Pre-Battle Phase
  489.   #--------------------------------------------------------------------------
  490.   def start_phase1
  491.     # Shift to phase 1
  492.     @phase = 1
  493.     # Clear all party member actions
  494.     $game_party.clear_actions
  495.   end
  496.  
  497.   # def update_phase1             [unchanged]
  498.  
  499.   #--------------------------------------------------------------------------
  500.   # * Start Party Command Phase
  501.   #--------------------------------------------------------------------------
  502.  
  503.   def start_phase2
  504.     # print("start_phase2")
  505.     $outfile.write "*** start_phase2 ***\n" if $outfile
  506.     # This method now updates the queue and determines the new active battler
  507.    
  508.     # Shift to phase 2
  509.     @phase = 2
  510.  
  511.     @reflected_battler = nil
  512.     @reflecters= []
  513.     @reacting = false
  514.     @return_guarding = false
  515.     @return_to_forced_action = false
  516.     @using_phoenix = false
  517.     @using_auto_life = false
  518.     @hits_count = 0
  519.  
  520.     # Set actor to non-selecting
  521.     @actor_index = -1
  522.     @active_battler = nil
  523.    
  524.    
  525.     # @end_turn == true is now used as the condition to end the turn
  526.     # in update_phase4_step1 instead of @active_battler == nil
  527.     @end_turn = false
  528.    
  529.     @status_window.refresh
  530.     $outfile.write "start_phase2 animate bars\n" if $outfile
  531.     @status_window.animate_bars = true
  532.     @status_window.index = @actor_index
  533.  
  534.     # remove phoenix targets if not in the party
  535.     # and reset phoenix data if no target is in the party
  536.     @phoenix_targets = @phoenix_targets & $game_party.actors
  537.     if @phoenix_targets.empty?
  538.       # reset phoenix data
  539.       @auto_phoenix = false
  540.       @phoenix_users = []
  541.       @phoenix_targets = []
  542.     end
  543.  
  544.     # Reset casting for dead actors
  545.     for actor in $game_party.actors
  546.       if actor.dead?
  547.         actor.randomize_next_action_time
  548.         actor.cf_casting = false
  549.         actor.casting_action.clear
  550.       end
  551.     end
  552.    
  553.     make_auto_life_targets
  554.  
  555.     # In case of not playable reaction the active battler is not selected as
  556.     # the first of the queue, the queue and the battle time are not updated
  557.     if $game_temp.reaction and not PLAYABLE_REACTION
  558.       $outfile.write "start_phase2: not playable reaction\n" if $outfile
  559.       @active_battler = @reacting_battler
  560.     elsif @auto_life
  561.       $outfile.write "start_phase2: auto life\n" if $outfile
  562.       @active_battler = @auto_life_targets[0]
  563.     elsif @auto_phoenix
  564.       $outfile.write "start_phase2: auto phoenix\n" if $outfile
  565.       @active_battler = @phoenix_users.pop
  566.       @auto_phoenix_window.actor = @active_battler
  567.       @auto_phoenix_window.refresh
  568.     else
  569.       # calculates the queue of actions so that it can be shown
  570.       $outfile.write "start_phase2: regular turn\n" if $outfile
  571.       update_battlers_queue(UPDATE_DELAYS)
  572.       @active_battler = @battlers_queue.first
  573.       @active_battler_copy = @active_battler
  574.       # set the actor index
  575.       for i in 0 ... $game_party.actors.size
  576.         if @active_battler == $game_party.actors[i]
  577.           @actor_index = i
  578.         end
  579.       end
  580.       # regular_turn_ended is now used to make sure that
  581.       # action_executed is executed just once
  582.       @active_battler.regular_turn_ended = false
  583.       @turn_window.set_active_battler(@active_battler)
  584.       @turn_window.set_battlers_queue(@battlers_queue)
  585.       @min_time_interval =
  586.         (@active_battler.next_action_time - $game_temp.battle_time) / 40.0
  587.       if ATB_MODE or GRANDIA_MODE
  588.         @atb_grandia_wait = true
  589.       else
  590.         $game_temp.battle_time = @active_battler.next_action_time
  591.         @atb_grandia_wait = false
  592.       end
  593.       #########################
  594.       # SUPPORT FOR ALTRUISMO #
  595.       #########################
  596.       @active_battler.reset_altruismo
  597.      
  598.       # @new_battle_turn is set by end_regular_turn
  599.       # the battle turn must be updated at the beginning of a regular turn
  600.       # this excludes not-playable reaction, auto-life, auto-phoenix, switching
  601.       if @new_battle_turn
  602.         $game_temp.battle_turn += 1
  603.         @new_battle_turn = false
  604.         # Search all battle event pages
  605.         for index in 0 ... $data_troops[@troop_id].pages.size
  606.           # Get event page
  607.           page = $data_troops[@troop_id].pages[index]
  608.           # If this page span is [turn]
  609.           if page.span == 1
  610.             # Clear action completed flags
  611.             $game_temp.battle_event_flags[index] = false
  612.           end
  613.         end
  614.       end    
  615.     end
  616.  
  617.     # Disable actor command window
  618.     @actor_command_window.active = false
  619.     @actor_command_window.visible = false
  620.     @actor_command_bg.visible = false
  621.  
  622.     # Disable left actor command window
  623.     @left_actor_command_window.active = false
  624.     @left_actor_command_window.visible = false
  625.     @battler_window.visible = false
  626.     @escape_window.visible = false
  627.  
  628.     # Clear main phase flag
  629.     $game_temp.battle_main_phase = false
  630.  
  631.     # DON'T Clear all party member actions because it would cancel guarding
  632.     # and forced actions
  633.     # Clear action if not guarding or forced action
  634.     for actor in $game_party.actors
  635.       if not (actor.current_action.kind == 0 and actor.current_action.basic == 1) and
  636.         not actor.current_action.forcing
  637.         actor.current_action.clear
  638.       end
  639.     end
  640.  
  641.     # If impossible to input command
  642.     unless (@active_battler.inputable? or @active_battler.is_a? Game_Enemy or
  643.       @auto_life)
  644.       if not GRANDIA_MODE and not ATB_MODE
  645.         # Start main phase
  646.         $outfile.write "start_phase2: impossible to input command, start_phase4\n" if $outfile
  647.         start_phase4
  648.       end
  649.     end
  650.  
  651.     # set @enemy turn and manage windows
  652.     if @active_battler.is_a? Game_Enemy
  653.       @enemy_turn = true
  654.       @enemy_attacks_window.boss = @battlers_queue.first.index
  655.       @enemy_attacks_window.refresh
  656.       # show the turn window until the enemy begins the attack
  657.       @turn_window.visible = TURNS_WINDOW_VISIBLE
  658.       @turn_window.refresh(@battlers_queue)
  659.     else
  660.       @enemy_turn = false
  661.       if not @auto_life
  662.         @status_on_battle_window.actor = @active_battler
  663.         @status_on_battle_window.refresh
  664.         @status_on_battle_window.visible = $game_system.status_on_battle unless
  665.           (($game_temp.reaction and not PLAYABLE_REACTION) or @atb_grandia_wait)
  666.       end
  667.     end
  668.     if $game_temp.reaction
  669.       $game_temp.reaction = false
  670.       @reacting = true
  671.       $outfile.write "start_phase2: @reacting = true\n" if $outfile
  672.       if @active_battler.movable?
  673.         @reaction_window.visible = REACTION_WINDOW_VISIBLE
  674.         @wait_count = REACTION_WINDOW_DURATION
  675.         begin
  676.           Audio.se_play(REACTION_SE)
  677.         rescue
  678.           if REACTION_SE != ""
  679.             p REACTION_SE + " not found."
  680.           end
  681.         end
  682.       end
  683.     elsif @auto_life
  684.       $outfile.write "start_phase2: @using_auto_life = true\n" if $outfile
  685.       @using_auto_life = true
  686.     elsif @auto_phoenix
  687.       @using_phoenix = true
  688.       $outfile.write "start_phase2: @using_phoenix = true\n" if $outfile
  689.       if @active_battler.movable?
  690.         @auto_phoenix_window.visible = AUTO_PHOENIX_WINDOW_VISIBLE
  691.         @wait_count = AUTO_PHOENIX_WINDOW_DURATION
  692.       end
  693.     end
  694.     if @phase != 2
  695.       $outfile.write "start_phase2 setup_battle_event, turn = " + $game_temp.battle_turn.to_s + "\n" if $outfile
  696.       $outfile.write "@active_battler_copy = " + @active_battler_copy.to_s + "\n" if $outfile
  697.       # Setup a battle event only if update_phase2 is going to be skipped
  698.       setup_battle_event
  699.     end
  700.   end
  701.  
  702.   #--------------------------------------------------------------------------
  703.   # * Frame Update (party command phase)
  704.   #--------------------------------------------------------------------------
  705.   def update_phase2
  706.     $outfile.write "update_phase2\n" if $outfile
  707.     # This method has been totally redefined because the escape option
  708.     # is available in the actor command window now
  709.     # Goes directly to start_phase3
  710.    
  711.     @reaction_window.visible = false
  712.     @auto_phoenix_window.visible = false
  713.  
  714.     if ATB_MODE and not (@reacting or @using_auto_life or @using_phoenix)
  715.       $game_temp.battle_time = [@active_battler.next_action_time,
  716.         $game_temp.battle_time + [10, @min_time_interval].max].min
  717.       return unless $game_temp.battle_time == @active_battler.next_action_time
  718.       $game_system.se_play($data_system.decision_se) unless @active_battler.is_a?(Game_Enemy)
  719.     end
  720.     if GRANDIA_MODE and not (@reacting or @using_auto_life or @using_phoenix)
  721.       $game_temp.battle_time = [@active_battler.next_action_time,
  722.         $game_temp.battle_time + [10, @min_time_interval].max].min
  723.       @grandia_bar_window.update(@battlers_array)
  724.       return unless $game_temp.battle_time == @active_battler.next_action_time
  725.       $game_system.se_play($data_system.decision_se) unless @active_battler.is_a?(Game_Enemy)
  726.     end
  727.     # Setup battle event skipped in start_phase2
  728.     setup_battle_event
  729.     @atb_grandia_wait = false
  730.     unless @enemy_turn
  731.       @status_on_battle_window.visible = $game_system.status_on_battle unless
  732.         ((@reacting and not PLAYABLE_REACTION))
  733.     end
  734.     start_phase3
  735.   end
  736.  
  737.   #--------------------------------------------------------------------------
  738.   # * Frame Update (party command phase: escape)
  739.   #--------------------------------------------------------------------------
  740.   def update_phase2_escape
  741.     # Calculate enemy agility average
  742.     enemies_agi = 0
  743.     enemies_number = 0
  744.     for enemy in $game_troop.enemies
  745.       if enemy.exist?
  746.         enemies_agi += enemy.agi
  747.         enemies_number += 1
  748.       end
  749.     end
  750.     if enemies_number > 0
  751.       enemies_agi /= enemies_number
  752.     end
  753.     # Calculate actor agility average
  754.     actors_agi = 0
  755.     actors_number = 0
  756.     for actor in $game_party.actors
  757.       if actor.exist?
  758.         actors_agi += actor.agi
  759.         actors_number += 1
  760.       end
  761.     end
  762.     if actors_number > 0
  763.       actors_agi /= actors_number
  764.     end
  765.     # Determine if escape is successful
  766.     success = rand(100) < 50 * actors_agi / enemies_agi
  767.     # If escape is successful
  768.     if success
  769.       # Play escape SE
  770.       $game_system.se_play($data_system.escape_se)
  771.       # Return to BGM before battle started
  772.       $game_system.bgm_play($game_temp.map_bgm)
  773.       # Battle ends
  774.       battle_end(1)
  775.     # If escape is failure
  776.     else
  777.       # escape failed
  778.       @escape_window.visible = true
  779.       @wait_count = 45
  780.       #$game_party.clear_actions
  781.       #clear action if not guarding
  782.       for actor in $game_party.actors
  783.         if !(actor.current_action.kind == 0 and actor.current_action.basic == 1) and
  784.           !actor.current_action.forcing
  785.           actor.current_action.clear
  786.         end
  787.       end
  788.  
  789.     end
  790.   end
  791.  
  792.   #--------------------------------------------------------------------------
  793.   # * Start After Battle Phase
  794.   #--------------------------------------------------------------------------
  795.   def start_phase5
  796.     $outfile.write "start_phase5\n" if $outfile
  797.     # Shift to phase 5
  798.     @phase = 5
  799.     if $game_temp.map_bgm != nil
  800.       # Play battle end ME
  801.       $game_system.me_play($game_system.battle_end_me)
  802.       # Return to BGM before battle started
  803.       $game_system.bgm_play($game_temp.map_bgm)
  804.     end
  805.     # Initialize EXP, amount of gold, and treasure
  806.     exp = 0
  807.     gold = 0
  808.     treasures = []
  809.     # Loop
  810.     for enemy in $game_troop.enemies
  811.       # If enemy is not hidden
  812.       unless enemy.hidden
  813.         # Add EXP and amount of gold obtained
  814.         exp += enemy.exp
  815.         gold += enemy.gold
  816.         if ENEMY_TREASURES[enemy.id]
  817.           for treasure in ENEMY_TREASURES[enemy.id]
  818.             if rand(100) < treasure[2]
  819.               case treasure[0]
  820.               when 0 # item
  821.                 treasures.push($data_items[treasure[1]])
  822.               when 1 # weapon
  823.                 treasures.push($data_weapons[treasure[1]])
  824.               when 2 # armor
  825.                 treasures.push($data_armors[treasure[1]])
  826.               end
  827.             end
  828.           end
  829.         else
  830.           # Determine if treasure appears
  831.           if rand(100) < enemy.treasure_prob
  832.             if enemy.item_id > 0
  833.               treasures.push($data_items[enemy.item_id])
  834.             end
  835.             if enemy.weapon_id > 0
  836.               treasures.push($data_weapons[enemy.weapon_id])
  837.             end
  838.             if enemy.armor_id > 0
  839.               treasures.push($data_armors[enemy.armor_id])
  840.             end
  841.           end
  842.         end
  843.       end
  844.     end
  845.     # Treasure is limited to a maximum of 6 items (NOT ANYMORE)
  846.     # treasures = treasures[0..5]
  847.     # Obtaining EXP
  848.     for i in 0...$game_party.actors.size
  849.       actor = $game_party.actors[i]
  850.       # Store current stats for the report screen
  851.       actor.old_exp = actor.exp
  852.       actor.old_maxhp = actor.maxhp
  853.       actor.old_maxsp = actor.maxsp
  854.       actor.old_str = actor.str
  855.       actor.old_int = actor.int
  856.       actor.old_agi = actor.agi
  857.       actor.old_dex = actor.dex
  858.       if actor.cant_get_exp? == false
  859.         last_level = actor.level
  860.         actor.exp += exp
  861.        
  862.         if (actor.state?($expx2_state_id))
  863.           actor.exp += exp
  864.         end
  865.        
  866.         if actor.level > last_level
  867.           @status_window.level_up(i)
  868.         end
  869.       end
  870.     end
  871.  
  872.     # Obtaining gold
  873.     $game_party.gain_gold(gold)
  874.     for i in 0 ... $game_party.actors.size
  875.       actor = $game_party.actors[i]
  876.       if (actor.state?($goldx2_state_id))
  877.         $game_party.gain_gold(gold)
  878.         break
  879.       end
  880.     end
  881.    
  882.     # Obtaining treasure
  883.     for item in treasures
  884.       case item
  885.       when RPG::Item
  886.         $game_party.gain_item(item.id, 1)
  887.       when RPG::Weapon
  888.         $game_party.gain_weapon(item.id, 1)
  889.       when RPG::Armor
  890.         $game_party.gain_armor(item.id, 1)
  891.       end
  892.     end
  893.     # Make battle result window
  894.     @result_window = Window_BattleReport.new
  895.     @result_window.active = true
  896.     @result_window.index = 0
  897.  
  898.     @result_window2 = Window_BattleResult.new(exp, gold, treasures)
  899.     # Set wait count
  900.     @phase5_wait_count = 100
  901.     @status_on_battle_window.visible = false
  902.     @status_window.visible = STATUS_WINDOW_VISIBLE_DURING_REPORT
  903.     @grandia_bar_window.visible = false if GRANDIA_MODE
  904.   end
  905.  
  906.  
  907.   #--------------------------------------------------------------------------
  908.   # * Frame Update (after battle phase)
  909.   #--------------------------------------------------------------------------
  910.   def update_phase5
  911.     $outfile.write "update_phase5\n" if $outfile
  912.     # If wait count is larger than 0
  913.     if @phase5_wait_count > 0
  914.       # Decrease wait count
  915.       @phase5_wait_count -= 1
  916.       # If wait count reaches 0
  917.       if @phase5_wait_count == 0
  918.         # Clear main phase flag
  919.         $game_temp.battle_main_phase = false
  920.         # Refresh status window
  921.         @status_window.refresh
  922.       end
  923.       return
  924.     end
  925.     # If C button was pressed
  926.     if Input.trigger?(Input::C)
  927.       battle_end(0)
  928.     end
  929.   end
  930.  
  931.  
  932.   # Added to speed up annoying phase 5  
  933.   alias fast_update_phase5 update_phase5
  934.   def update_phase5
  935.     if @phase5_wait_count > 0
  936.       @phase5_wait_count -= 1
  937.     end
  938.     fast_update_phase5
  939.   end
  940.  
  941.   #--------------------------------------------------------------------------
  942.   # * Start Actor Command Phase
  943.   #--------------------------------------------------------------------------
  944.  
  945.   def start_phase3
  946.     $outfile.write "*** start_phase3 ***\n" if $outfile
  947.     # This method launches the input command phase,
  948.     # by calling phase3_setup_command_window, in case the active battler is
  949.     # an actor.
  950.     # It decides the action in case the active battler is an enemy
  951.    
  952.     # Shift to phase 3
  953.     @phase = 3
  954.  
  955.     #######################
  956.     # UNPLAYABLE REACTION #
  957.     #######################
  958.     if @reacting and not PLAYABLE_REACTION
  959.       # print("start_phase3 UNPLAYABLE REACTION set current action")
  960.       if @active_battler.guarding? and GUARD_AFTER_REACTION
  961.         @return_guarding = true
  962.       end
  963.       if @active_battler.current_action.forcing
  964.         @active_battler_saved_forced_action =
  965.           @active_battler.current_action.dup
  966.         @return_to_forced_action = true
  967.       end
  968.       # test if a reaction skill is configured
  969.       reaction_skill_id = REACTION_SKILLS[@active_battler.id]
  970.       if reaction_skill_id != nil and @active_battler.skill_learn?(reaction_skill_id)
  971.         @active_battler.current_action.kind = 1
  972.         @active_battler.current_action.skill_id = reaction_skill_id
  973.       else
  974.         @active_battler.current_action.kind = 0
  975.         @active_battler.current_action.basic = 0
  976.       end
  977.       phase3_next_actor
  978.       return
  979.     elsif @using_auto_life
  980.     #######################
  981.     #      AUTO LIFE      #
  982.     #######################
  983.       # print("start_phase3 AUTO LIFE")
  984.       # Set action
  985.       @item = $data_items[AUTO_LIFE_ITEM_ID]
  986.       phase3_next_actor
  987.       return
  988.     elsif @using_phoenix
  989.     #######################
  990.     #    AUTO PHOENIX     #
  991.     #######################
  992.       # print("start_phase3 AUTO PHOENIX set current action")
  993.       if @active_battler.guarding?
  994.         @return_guarding = true
  995.       end
  996.       if @active_battler.current_action.forcing
  997.         @active_battler_saved_forced_action =
  998.           @active_battler.current_action.dup
  999.         @return_to_forced_action = true
  1000.       end
  1001.       # Set action
  1002.       @active_battler.current_action.kind = 2
  1003.       @active_battler.current_action.item_id = PHOENIX_ITEM_ID
  1004.       @item = $data_items[PHOENIX_ITEM_ID]
  1005.       phase3_next_actor
  1006.       return
  1007.     end
  1008.    
  1009.     #######################
  1010.     # NORMAL TURN         #
  1011.     #######################
  1012.     # set row positions in the battle status window for the actors
  1013.     i = 0
  1014.     for actor in $game_party.actors
  1015.           actor.battle_status_row_pos = i
  1016.           i += 1
  1017.     end
  1018.     # Stop blinking the active battler
  1019.     @active_battler.blink = false
  1020.  
  1021.     # launch the input command phase for the actor  
  1022.     # actor case
  1023.     if @active_battler.is_a? Game_Actor
  1024.       # Forced actions support
  1025.       if @active_battler.current_action.forcing
  1026.         @active_battler.action_decided($game_temp.battle_time,
  1027.           @active_battler.current_action)
  1028.         phase3_next_actor
  1029.       # Casting delay support
  1030.       elsif @active_battler.cf_casting
  1031.         @active_battler.current_action = @active_battler.casting_action.dup
  1032.         $game_temp.selecting_all_allies =
  1033.           @active_battler.current_action.selecting_all_allies
  1034.         $game_temp.selecting_all_enemies =
  1035.           @active_battler.current_action.selecting_all_enemies
  1036.         if ($game_temp.selecting_all_allies or $game_temp.selecting_all_enemies)
  1037.           @single_all_scope = true
  1038.         end
  1039.         @active_battler.action_decided($game_temp.battle_time,
  1040.           @active_battler.current_action)
  1041.         @active_battler.cf_casting = false
  1042.         @active_battler.casting_action.clear
  1043.         @active_battler.after_cast = true
  1044.         phase3_next_actor
  1045.       else
  1046.         if @active_battler.inputable?
  1047.           @active_battler.blink = true
  1048.           # set the index of the highlighted row in the status window
  1049.           @status_window.index = @active_battler.battle_status_row_pos
  1050.           @status_window.refresh
  1051.           phase3_setup_command_window
  1052.         else
  1053.           phase3_next_actor
  1054.         end
  1055.       end
  1056.     end
  1057.  
  1058.     # if the active battler is an enemy, decide its action
  1059.     # enemy case
  1060.     if @active_battler.is_a? Game_Enemy
  1061.       # Forced actions support
  1062.       if !@active_battler.current_action.forcing
  1063.         # Casting delay support
  1064.         if @active_battler.cf_casting
  1065.           @active_battler.current_action = @active_battler.casting_action.dup
  1066.           @active_battler.action_decided($game_temp.battle_time, @active_battler.current_action)
  1067.           @active_battler.cf_casting = false
  1068.           @active_battler.casting_action.clear
  1069.           @active_battler.after_cast = true
  1070.           phase3_next_actor
  1071.           return
  1072.         else
  1073.           @active_battler.make_action
  1074.         end
  1075.       end
  1076.       @active_battler.action_decided($game_temp.battle_time, @active_battler.current_action)
  1077.       phase3_next_actor
  1078.     end
  1079.   end
  1080.  
  1081.   #--------------------------------------------------------------------------
  1082.   # *
  1083.   #--------------------------------------------------------------------------
  1084.   alias single_all_start_phase3 start_phase3
  1085.   def start_phase3
  1086.     @single_all_scope = false
  1087.     $game_temp.selecting_all_enemies = false
  1088.     $game_temp.selecting_all_allies = false
  1089.     single_all_start_phase3
  1090.   end
  1091.  
  1092.   #--------------------------------------------------------------------------
  1093.   # * The action has been decided, ACTION!!!
  1094.   #--------------------------------------------------------------------------
  1095.   def phase3_next_actor
  1096.     unless (@reacting and !PLAYABLE_REACTION)
  1097.       if @active_battler.cf_casting
  1098.         @active_battler.casting_action = @active_battler.current_action.dup
  1099.         @active_battler.casting_action.selecting_all_allies =
  1100.           $game_temp.selecting_all_allies
  1101.         @active_battler.casting_action.selecting_all_enemies =
  1102.           $game_temp.selecting_all_enemies
  1103.         @active_battler.current_action.clear
  1104.       end
  1105.     end
  1106.     if @enemy_turn and @active_battler.current_action.valid?
  1107.       @enemy_attacks_window.visible = ENEMY_ATTACKS_WINDOW_VISIBLE
  1108.       @wait_count = ENEMY_ATTACKS_WINDOW_DURATION
  1109.       @status_on_battle_window.visible = false
  1110.       $outfile.write "@enemy_attacks_window.visible = ENEMY_ATTACKS_WINDOW_VISIBLE\n" if $outfile
  1111.     end
  1112.     phase3_next_actor_step2
  1113.   end  
  1114.  
  1115.   #--------------------------------------------------------------------------
  1116.   # * The action has been decided, ACTION!!!
  1117.   #--------------------------------------------------------------------------
  1118.   def phase3_next_actor_step2
  1119.     start_phase4
  1120.   end
  1121.  
  1122.   #--------------------------------------------------------------------------
  1123.   # * Actor Command Window Setup
  1124.   #--------------------------------------------------------------------------
  1125.   def phase3_setup_command_window
  1126.     s1 = $data_system.words.attack
  1127.     s2 = $data_system.words.skill
  1128.     s3 = $data_system.words.guard
  1129.     s4 = $data_system.words.item
  1130.     @active_battler.refresh_commands
  1131.     if SWITCHING and
  1132.     ( ($charlie_fleed_summons==nil) or (($charlie_fleed_summons!=nil) and
  1133.     not $game_party.aeons_ids.include?(@active_battler.id)) ) and
  1134.     ( ($charlie_fleed_party_change==nil) or (($charlie_fleed_party_change!=nil) and
  1135.     not $game_party.fixed_actors.include?(@active_battler.id)) ) and
  1136.     ( ($charlie_fleed_summons==nil) or (($charlie_fleed_summons!=nil) and
  1137.     ($charlie_fleed_party_change!=nil) and
  1138.     not $game_party.fixed_actors.include?(@active_battler.original_form_id)) )
  1139.       if CANNOT_USE_ITEMS.include?(@active_battler.id)
  1140.         @individual_battle_commands=[s1]+["Switch"]+@active_battler.individual_commands
  1141.       else
  1142.         @individual_battle_commands=[s1]+["Switch"]+@active_battler.individual_commands+[s4]
  1143.       end
  1144.     else
  1145.       if CANNOT_USE_ITEMS.include?(@active_battler.id)
  1146.         @individual_battle_commands=[s1]+@active_battler.individual_commands
  1147.       else
  1148.         @individual_battle_commands=[s1]+@active_battler.individual_commands+[s4]
  1149.       end
  1150.     end
  1151.     phase3_setup_command_window2
  1152.   end
  1153.  
  1154.   #--------------------------------------------------------------------------
  1155.   # *
  1156.   #--------------------------------------------------------------------------
  1157.   def phase3_setup_command_window2
  1158.     @actor_command_window.dispose
  1159.     @actor_command_window = Window_Command_Plus.new(ACTOR_COMMAND_WINDOW_WIDTH,
  1160.       112, @individual_battle_commands, 20)
  1161.     @actor_command_window.custom_normal_color=ACTOR_COMMAND_WINDOW_TEXT_COLOR
  1162.     @actor_command_window.custom_normal_b_color=ACTOR_COMMAND_WINDOW_TEXT_BG_COLOR
  1163.     @actor_command_window.set_font_size(20+ACTOR_COMMAND_WINDOW_TEXT_SIZE_OFFSET)
  1164.     @actor_command_window.refresh
  1165.     if ($charlie_fleed_party_change==nil) or $game_party.backup_actors.empty?
  1166.       index = @individual_battle_commands.index("Switch")
  1167.       if index!=nil
  1168.         @actor_command_window.disable_item(index)
  1169.       end
  1170.     end      
  1171.     @actor_command_window.x = ACTOR_COMMAND_WINDOW_X
  1172.     @actor_command_window.target_x = ACTOR_COMMAND_WINDOW_X
  1173.     @actor_command_window.y = 480
  1174.     @actor_command_window.target_y = 368
  1175.     @actor_command_window.z = 200
  1176.     @actor_command_window.back_opacity = 255
  1177.     begin
  1178.       if ACTOR_COMMAND_WINDOWSKIN_NAME != ""
  1179.         @actor_command_window.windowskin =
  1180.           RPG::Cache.windowskin(ACTOR_COMMAND_WINDOWSKIN_NAME)
  1181.       end
  1182.     rescue
  1183.       p ACTOR_COMMAND_WINDOWSKIN_NAME + " not found."
  1184.     end
  1185.     @actor_command_window.opacity = ACTOR_COMMAND_WINDOW_WINDOWSKIN_OPACITY
  1186.     @actor_command_window.active = true
  1187.     @actor_command_window.visible = true
  1188.     @battler_window.visible = true
  1189.     @battler_window.battler = @active_battler
  1190.     @battler_window.refresh
  1191.     @actor_command_window.index = (ACTOR_COMMAND_CURSOR_MEMORY)?(@active_battler.last_command):(0)
  1192.     @left_actor_command_window.index = (ACTOR_COMMAND_CURSOR_MEMORY)?(@active_battler.last_left_command):(0)
  1193.     if ACTOR_COMMAND_CURSOR_MEMORY
  1194.       #The queue must be updated in case the last selected command was not attack
  1195.       #Set the action first
  1196.       set_initial_action
  1197.       update_battlers_queue
  1198.       @turn_window.set_battlers_queue(@battlers_queue)
  1199.     end
  1200.     # show the turn window (shown in start phase 2 only when the enemy attacks)
  1201.     @turn_window.visible = TURNS_WINDOW_VISIBLE
  1202.     # set the proper animation phase for the turn window
  1203.     @turn_window.enter()
  1204.     @prev_actor_command = @actor_command_window.commands[@actor_command_window.index]
  1205.     if BATTLE_CRIES.keys.include?(@active_battler.id)
  1206.       # Determine how many cries
  1207.       size = BATTLE_CRIES[@active_battler.id].size
  1208.       cry = RPG::AudioFile.new(BATTLE_CRIES[@active_battler.id][rand(size)])
  1209.       $game_system.se_play(cry)
  1210.     end
  1211.   end
  1212.  
  1213.   #--------------------------------------------------------------------------
  1214.   # * Frame Update (actor command phase)
  1215.   #--------------------------------------------------------------------------
  1216.   def update_phase3
  1217.     $outfile.write "update_phase3\n" if $outfile
  1218.     # If enemy arrow is enabled
  1219.     if @enemy_arrow != nil
  1220.       update_phase3_enemy_select
  1221.  
  1222.     elsif $game_temp.selecting_all_enemies
  1223.       update_phase3_all_enemies_select
  1224.     elsif $game_temp.selecting_all_allies
  1225.       update_phase3_all_allies_select
  1226.      
  1227.     # If actor arrow is enabled
  1228.     elsif @actor_arrow != nil
  1229.       update_phase3_actor_select
  1230.     # If skill window is enabled
  1231.     elsif @skill_window != nil
  1232.       update_phase3_skill_select
  1233.     elsif @switch_window != nil
  1234.       update_phase3_switch_select
  1235.     # If item window is enabled
  1236.     elsif @item_window != nil
  1237.       update_phase3_item_select
  1238.     # If actor command window is enabled
  1239.     elsif @actor_command_window.active
  1240.       update_phase3_basic_command
  1241.     # If left actor command window is enabled
  1242.     elsif @left_actor_command_window.active
  1243.       update_phase3_left_command
  1244.     end
  1245.   end
  1246.  
  1247.   #--------------------------------------------------------------------------
  1248.   # * Frame Update (actor command phase : basic command)
  1249.   #--------------------------------------------------------------------------
  1250.   def update_phase3_basic_command
  1251.     # LEFT
  1252.     if Input.trigger?(Input::LEFT)
  1253.       $game_system.se_play($data_system.decision_se)
  1254.       @left_actor_command_window.visible=true
  1255.       @left_actor_command_window.active=true
  1256.       @actor_command_window.active=false
  1257.       @actor_command_window.visible=false
  1258.       return
  1259.     end
  1260.     # B: cancel
  1261.     if Input.trigger?(Input::B)
  1262.       # cannot turn back
  1263.       $game_system.se_play($data_system.buzzer_se)
  1264.       return
  1265.     end
  1266.     # C: selection
  1267.     if Input.trigger?(Input::C)
  1268.       case @actor_command_window.commands[@actor_command_window.index]
  1269.       # attack
  1270.       when $data_system.words.attack
  1271.         $game_system.se_play($data_system.decision_se)
  1272.         @active_battler.current_action.kind = 0
  1273.         @active_battler.current_action.basic = 0
  1274.         start_enemy_select
  1275.       # item
  1276.       when $data_system.words.item
  1277.         $game_system.se_play($data_system.decision_se)
  1278.         @active_battler.current_action.kind = 2
  1279.         start_item_select
  1280.       when "Switch"
  1281.         if ($charlie_fleed_party_change==nil) or
  1282.         $game_party.backup_actors.empty?
  1283.           $game_system.se_play($data_system.buzzer_se)
  1284.           return
  1285.         else
  1286.           $game_system.se_play($data_system.decision_se)
  1287.           @active_battler.current_action.kind = 1
  1288.           start_switch_select
  1289.         end
  1290.       end
  1291.       # Retire
  1292.       if $charlie_fleed_summons != nil and
  1293.         @actor_command_window.commands[@actor_command_window.index]==RETIRE_NAME
  1294.         $game_system.se_play($data_system.decision_se)
  1295.         @active_battler.current_action.kind = 1
  1296.         @active_battler.current_action.skill_id = $retire_skill_id
  1297.         @retire_common_event=true
  1298.         phase3_next_actor
  1299.         return
  1300.       end  
  1301.       ### SUPPORT FOR INDIVIDUAL BATTLE COMMANDS ###
  1302.       if @active_battler.individual_commands.
  1303.         include?(@actor_command_window.commands[@actor_command_window.index])
  1304.         $game_system.se_play($data_system.decision_se)
  1305.         @active_battler.current_action.kind = 1
  1306.         @individual_battle_commands_skill_category = @actor_command_window.commands[@actor_command_window.index]
  1307.         start_skill_select
  1308.       end
  1309.       # The action has been decided
  1310.       @active_battler.action_decided($game_temp.battle_time, @active_battler.current_action)
  1311.       return
  1312.     end
  1313.     # An action has not been decided
  1314.     # update the battle_turn window if the selection has changed
  1315.     if (@actor_command_window.commands[@actor_command_window.index] != @prev_actor_command)
  1316.       case @actor_command_window.commands[@actor_command_window.index]
  1317.       # attack
  1318.       when $data_system.words.attack
  1319.         @active_battler.current_action.kind = 0
  1320.         @active_battler.current_action.basic = 0
  1321.       # item
  1322.       when $data_system.words.item
  1323.         @active_battler.current_action.kind = 2
  1324.       end
  1325.       ### SUPPORT FOR INDIVIDUAL BATTLE COMMANDS ###
  1326.       if @active_battler.individual_commands.
  1327.         include?(@actor_command_window.commands[@actor_command_window.index]) and
  1328.         ($charlie_fleed_summons != nil and RETIRE_NAME != @actor_command_window.commands[@actor_command_window.index])
  1329.         @active_battler.current_action.kind = 1
  1330.       end
  1331.       # A different action has been selected
  1332.       @active_battler.action_selected(@active_battler.current_action)
  1333.       @active_battler.last_command = @actor_command_window.index
  1334.       # Update the queue and the turn window
  1335.       update_battlers_queue
  1336.       @turn_window.set_new_battlers_and_animate(@battlers_queue)
  1337.       # Memorize the current selection
  1338.       @prev_actor_command = @actor_command_window.commands[@actor_command_window.index]
  1339.     end
  1340.   end
  1341.  
  1342.   #--------------------------------------------------------------------------
  1343.   # * Frame Update (actor command phase : left command)
  1344.   #--------------------------------------------------------------------------
  1345.  
  1346.   # seconda versione: individua il comando dalla stringa
  1347.   # kind -1 is used for skip
  1348.   # kind -2 is used for escape
  1349.   def update_phase3_left_command
  1350.     # RIGHT: cancel
  1351.     if Input.trigger?(Input::RIGHT)
  1352.       $game_system.se_play($data_system.decision_se)
  1353.       @left_actor_command_window.visible=false
  1354.       @left_actor_command_window.active=false
  1355.       @actor_command_window.active=true
  1356.       @actor_command_window.visible=true
  1357.       return
  1358.     end
  1359.     # B: cancel
  1360.     if Input.trigger?(Input::B)
  1361.       # cannot turn back
  1362.       $game_system.se_play($data_system.buzzer_se)
  1363.       return
  1364.     end
  1365.     # C: selection
  1366.     if Input.trigger?(Input::C)
  1367.       case @left_actor_command_window.commands[@left_actor_command_window.index]
  1368.       when $data_system.words.guard
  1369.         $game_system.se_play($data_system.decision_se)
  1370.         @active_battler.current_action.kind = 0
  1371.         @active_battler.current_action.basic = 1
  1372.         phase3_next_actor
  1373.       # skip
  1374.       when "Skip"
  1375.         $game_system.se_play($data_system.decision_se)
  1376.         @active_battler.current_action.kind = -1
  1377.         phase3_next_actor
  1378.       # escape
  1379.       when "Escape"
  1380.         if $game_temp.battle_can_escape == false
  1381.           # SE
  1382.           $game_system.se_play($data_system.buzzer_se)
  1383.           return
  1384.         else
  1385.           # SE
  1386.           $game_system.se_play($data_system.decision_se)
  1387.           escape_action = Game_BattleAction.new
  1388.           escape_action.kind =- 2
  1389.           @active_battler.action_decided($game_temp.battle_time,escape_action)
  1390.           update_phase2_escape
  1391.         end
  1392.         phase3_next_actor
  1393.       # status
  1394.       when "Status"
  1395.         $game_system.se_play($data_system.decision_se)
  1396.         @status_on_battle_window.actor = @active_battler
  1397.         @status_on_battle_window.refresh
  1398.         @status_on_battle_window.visible =! @status_on_battle_window.visible
  1399.         $game_system.status_on_battle = @status_on_battle_window.visible
  1400.         return
  1401.       end
  1402.       # The action has been decided
  1403.       @active_battler.action_decided($game_temp.battle_time, @active_battler.current_action)
  1404.       return
  1405.     end
  1406.     # An action has not been decided
  1407.     # update the battle_turn window if the selection has changed
  1408.     if (@left_actor_command_window.commands[@left_actor_command_window.index] != @prev_actor_command)
  1409.       case @left_actor_command_window.commands[@left_actor_command_window.index]
  1410.       # defend
  1411.       when $data_system.words.guard
  1412.         @active_battler.current_action.kind = 0
  1413.         @active_battler.current_action.basic = 1
  1414.       # skip
  1415.       when "Skip"
  1416.         @active_battler.current_action.kind = -1
  1417.       # escape
  1418.       when "Escape"
  1419.         @active_battler.current_action.kind = -2
  1420.       end
  1421.       # A different action has been selected
  1422.       @active_battler.action_selected(@active_battler.current_action)
  1423.       @active_battler.last_left_command = @left_actor_command_window.index
  1424.       # Update the queue and the turn window
  1425.       update_battlers_queue
  1426.       @turn_window.set_new_battlers_and_animate(@battlers_queue)
  1427.       # Memorize the current selection
  1428.       @prev_actor_command = @left_actor_command_window.commands[@left_actor_command_window.index]
  1429.     end
  1430.   end
  1431.  
  1432.   #--------------------------------------------------------------------------
  1433.   # * Frame Update (actor command phase : skill selection)
  1434.   #--------------------------------------------------------------------------
  1435.   def update_phase3_skill_select
  1436.     # Make skill window visible
  1437.     @skill_window.visible = true
  1438.     # Update skill window
  1439.     @skill_window.update
  1440.     # If B button was pressed
  1441.     if Input.trigger?(Input::B)
  1442.       # Play cancel SE
  1443.       $game_system.se_play($data_system.cancel_se)
  1444.  
  1445.       # Reset @active_battler.current_action.skill_id
  1446.       @active_battler.current_action.skill_id = 0
  1447.       # Update selected action
  1448.       @active_battler.action_selected(@active_battler.current_action)
  1449.       # Update the queue and the turn window
  1450.       update_battlers_queue
  1451.       @turn_window.set_new_battlers_and_animate(@battlers_queue)
  1452.  
  1453.       # End skill selection
  1454.       end_skill_select
  1455.       return
  1456.     end
  1457.  
  1458.     # Get currently selected data on the skill window
  1459.     @skill = @skill_window.skill
  1460.     # Update current action and call action_selected
  1461.     if @active_battler.current_action.skill_id != @skill.id
  1462.       # Set current_action.skill_id
  1463.       @active_battler.current_action.skill_id = @skill.id
  1464.       # Update selected action
  1465.       @active_battler.action_selected(@active_battler.current_action)
  1466.       # Update the queue and the turn window
  1467.       update_battlers_queue
  1468.       @turn_window.set_new_battlers_and_animate(@battlers_queue)
  1469.     end
  1470.    
  1471.     # If C button was pressed
  1472.     if Input.trigger?(Input::C)
  1473.       # Get currently selected data on the skill window
  1474.       @skill = @skill_window.skill
  1475.       # If it can't be used
  1476.       if @skill == nil or not @active_battler.skill_can_use?(@skill.id)
  1477.         # Play buzzer SE
  1478.         $game_system.se_play($data_system.buzzer_se)
  1479.         return
  1480.       end
  1481.       # Play decision SE
  1482.       $game_system.se_play($data_system.decision_se)
  1483.       # Set action
  1484.       @active_battler.current_action.skill_id = @skill.id
  1485.      
  1486.       @active_battler.action_decided($game_temp.battle_time,
  1487.           @active_battler.current_action)
  1488.  
  1489.       # Make skill window invisible
  1490.       @skill_window.visible = false
  1491.  
  1492.       # determine if the skill can have special targets
  1493.       @any_scope = false
  1494.       @single_all_scope = false
  1495.       @random_single_target = false
  1496.       # scope is single or all enemies
  1497.       if @skill.is_random_single_target()
  1498.         @random_single_target = true
  1499.         # End skill selection
  1500.         end_skill_select
  1501.         # Charlie: action!!!
  1502.         phase3_next_actor
  1503.       elsif @skill.is_single_all()
  1504.         @single_all_scope = true
  1505.         # If effect scope is single enemy
  1506.         if @skill.scope == 1
  1507.           start_enemy_select
  1508.         elsif @skill.scope == 3 or @skill.scope == 5
  1509.           start_actor_select
  1510.         end        
  1511.       # scope is single enemy or single ally
  1512.       elsif @skill.is_any_scope()
  1513.         @any_scope = true
  1514.         start_actor_select
  1515.  
  1516.       # If effect scope is single enemy
  1517.       elsif @skill.scope == 1
  1518.         # Start enemy selection
  1519.         start_enemy_select
  1520.       # If effect scope is single ally
  1521.       elsif @skill.scope == 3 or @skill.scope == 5
  1522.         # Start actor selection
  1523.         start_actor_select
  1524.       # If effect scope is not single
  1525.       else
  1526.         # End skill selection
  1527.         end_skill_select
  1528.        
  1529.         # Charlie: action!!!
  1530.         phase3_next_actor
  1531.       end
  1532.       return
  1533.     end
  1534.   end
  1535.  
  1536.   #--------------------------------------------------------------------------
  1537.   # * Frame Update (actor command phase : switch selection)
  1538.   #--------------------------------------------------------------------------
  1539.   def update_phase3_switch_select
  1540.     # Make switch window visible
  1541.     @switch_window.visible = true
  1542.     @switch_window_help.visible = true
  1543.     # Update switch window
  1544.     @switch_window.update
  1545.     @switch_window_help.set_switch(@switch_window.switch)
  1546.     # If B button was pressed
  1547.     if Input.trigger?(Input::B)
  1548.       # Play cancel SE
  1549.       $game_system.se_play($data_system.cancel_se)
  1550.       # End switch selection
  1551.       end_switch_select
  1552.       return
  1553.     end
  1554.     # If C button was pressed
  1555.     if Input.trigger?(Input::C)
  1556.       # Get currently selected data on the switch window
  1557.       switch = @switch_window.switch
  1558.       # If it can't be used
  1559.       if switch == nil or switch.hp==0
  1560.         # Play buzzer SE
  1561.         $game_system.se_play($data_system.buzzer_se)
  1562.         return
  1563.       end
  1564.       @switch_id=switch.id
  1565.       # Play decision SE
  1566.       $game_system.se_play($data_system.decision_se)
  1567.       # Set action
  1568.       @active_battler.current_action.skill_id = $switch_skill_id
  1569.       @switch_common_event=true
  1570.       # Make switch window invisible
  1571.       @switch_window.visible = false
  1572.       @switch_window_help.visible = false
  1573.  
  1574.       end_switch_select
  1575.        
  1576.       # Charlie: action!!!
  1577.       phase3_next_actor
  1578.       return
  1579.     end
  1580.   end
  1581.  
  1582.   #--------------------------------------------------------------------------
  1583.   # * Frame Update (actor command phase : item selection)
  1584.   #--------------------------------------------------------------------------
  1585.   def update_phase3_item_select
  1586.  
  1587.     # Make item window visible
  1588.     @item_window.visible = true
  1589.     # Update item window
  1590.     @item_window.update
  1591.     # If B button was pressed
  1592.     if Input.trigger?(Input::B)
  1593.       # Play cancel SE
  1594.       $game_system.se_play($data_system.cancel_se)
  1595.       # End item selection
  1596.       end_item_select
  1597.       return
  1598.     end
  1599.     # If C button was pressed
  1600.     if Input.trigger?(Input::C)
  1601.       # Get currently selected data on the item window
  1602.       @item = @item_window.item
  1603.       # If it can't be used
  1604.       unless $game_party.item_can_use?(@item.id)
  1605.         # Play buzzer SE
  1606.         $game_system.se_play($data_system.buzzer_se)
  1607.         return
  1608.       end
  1609.       # Play decision SE
  1610.       $game_system.se_play($data_system.decision_se)
  1611.       # Set action
  1612.       @active_battler.current_action.item_id = @item.id
  1613.       # Make item window invisible
  1614.       @item_window.visible = false
  1615.       # If effect scope is single enemy
  1616.       if @item.scope == 1
  1617.         # Start enemy selection
  1618.         start_enemy_select
  1619.       # If effect scope is single ally
  1620.       elsif @item.scope == 3 or @item.scope == 5
  1621.         # Start actor selection
  1622.         start_actor_select
  1623.       # If effect scope is not single
  1624.       else
  1625.         # End item selection
  1626.         end_item_select
  1627.         # Charlie: ACTION!!!
  1628.         phase3_next_actor
  1629.       end
  1630.       return
  1631.     end
  1632.   end
  1633.  
  1634.   #--------------------------------------------------------------------------
  1635.   # * Frame Update (actor command phase : enemy selection)
  1636.   #--------------------------------------------------------------------------
  1637.   def update_phase3_enemy_select
  1638.  
  1639.     if @any_scope == true
  1640.       if Input.trigger?(Input::RIGHT)
  1641.         end_enemy_select
  1642.         start_actor_select
  1643.         return
  1644.       end
  1645.     end
  1646.     if @single_all_scope == true
  1647.       if Input.trigger?(Input::SHIFT)
  1648.         end_enemy_select
  1649.         start_all_enemies_select
  1650.         return
  1651.       end
  1652.     end
  1653.     # Update targeted
  1654.     for i in 0 ... $game_troop.enemies.size
  1655.       $game_troop.enemies[i].targeted = (i == @enemy_arrow.index) ? true : false
  1656.     end
  1657.     @turn_window.update_indicators
  1658.     @grandia_bar_window.update(@battlers_array) if GRANDIA_MODE
  1659.  
  1660.     # Update enemy arrow
  1661.     @enemy_arrow.update
  1662.     # If B button was pressed
  1663.     if Input.trigger?(Input::B)
  1664.       # Play cancel SE
  1665.       $game_system.se_play($data_system.cancel_se)
  1666.       # End enemy selection
  1667.       end_enemy_select
  1668.       @any_scope = false
  1669.       @single_all_scope = false
  1670.       return
  1671.     end
  1672.    
  1673.     # If C button was pressed
  1674.     if Input.trigger?(Input::C)
  1675.      
  1676.       # Support for flying enemies
  1677.       if @active_battler.current_action.kind == 0 and
  1678.         @active_battler.current_action.basic == 0
  1679.         if FLYING_ENEMIES.include?($game_troop.enemies[@enemy_arrow.index].id)
  1680.           unless (MNK_STATIONARY_WEAPONS.include?(@active_battler.weapon_id) or
  1681.             FLYING_ACTORS.include?(@active_battler.id)) or
  1682.             @active_battler.states.include?($flight_state_id)
  1683.             # Play buzzer SE
  1684.             $game_system.se_play($data_system.buzzer_se)
  1685.             return
  1686.           end
  1687.         end
  1688.       end
  1689.       if @active_battler.current_action.kind == 1
  1690.         if FLYING_ENEMIES.include?($game_troop.enemies[@enemy_arrow.index].id) and
  1691.           MNK_MOVING_SKILL.include?(@active_battler.current_action.skill_id)
  1692.           unless  FLYING_ACTORS.include?(@active_battler.id)
  1693.             # Play buzzer SE
  1694.             $game_system.se_play($data_system.buzzer_se)
  1695.             return
  1696.           end
  1697.         end
  1698.       end      
  1699.      
  1700.       # Play decision SE
  1701.       $game_system.se_play($data_system.decision_se)
  1702.       # Set action
  1703.       @active_battler.current_action.target_index = @enemy_arrow.index
  1704.       # End enemy selection
  1705.       end_enemy_select
  1706.       # If skill window is showing
  1707.       if @skill_window != nil
  1708.         # End skill selection
  1709.         end_skill_select
  1710.       end
  1711.  
  1712.       # If item window is showing
  1713.       if @item_window != nil
  1714.         # End item selection
  1715.         end_item_select
  1716.       end
  1717.       # Charlie: ACTION!!!
  1718.       phase3_next_actor
  1719.     end
  1720.   end
  1721.  
  1722.   #--------------------------------------------------------------------------
  1723.   # * Frame Update (actor command phase : all enemy selection)
  1724.   #--------------------------------------------------------------------------
  1725.   def update_phase3_all_enemies_select
  1726.     # Update targeted
  1727.     for i in 0...$game_troop.enemies.size
  1728.       $game_troop.enemies[i].targeted=true
  1729.     end
  1730.     @turn_window.update_indicators
  1731.     @grandia_bar_window.update(@battlers_array) if GRANDIA_MODE
  1732.     if Input.trigger?(Input::SHIFT)
  1733.       end_all_enemies_select
  1734.       start_enemy_select
  1735.       return
  1736.     end
  1737.     # If B button was pressed
  1738.     if Input.trigger?(Input::B)
  1739.       # Play cancel SE
  1740.       $game_system.se_play($data_system.cancel_se)
  1741.       # End enemy selection
  1742.       end_all_enemies_select
  1743.       @single_all_scope = false
  1744.       return
  1745.     end
  1746.     if Input.trigger?(Input::C)
  1747.       $game_system.se_play($data_system.decision_se)
  1748.       end_all_enemies_select
  1749.       # override instruction inside end_all_enemies_select
  1750.       $game_temp.selecting_all_enemies=true
  1751.       if @skill_window != nil
  1752.         end_skill_select
  1753.       end
  1754.       if @item_window != nil
  1755.         end_item_select
  1756.       end
  1757.       phase3_next_actor
  1758.     end
  1759.   end
  1760.  
  1761.   #--------------------------------------------------------------------------
  1762.   # * Frame Update (actor command phase : actor selection)
  1763.   #--------------------------------------------------------------------------
  1764.   def update_phase3_actor_select
  1765.  
  1766.     if @any_scope == true
  1767.       if Input.trigger?(Input::LEFT)
  1768.         end_actor_select
  1769.         start_enemy_select
  1770.         return
  1771.       end
  1772.     end
  1773.     if @single_all_scope == true
  1774.       if Input.trigger?(Input::SHIFT)
  1775.         end_actor_select
  1776.         start_all_allies_select
  1777.         return
  1778.       end
  1779.     end
  1780.  
  1781.     # Update actor arrow
  1782.     @actor_arrow.update
  1783.  
  1784.     # Update targeted
  1785.     for i in 0 ... $game_party.actors.size
  1786.       $game_party.actors[i].targeted = (i == @actor_arrow.index) ? true : false
  1787.     end
  1788.     @turn_window.update_indicators
  1789.     @grandia_bar_window.update(@battlers_array) if GRANDIA_MODE
  1790.     @actor_select_window.index = @actor_arrow.get_index
  1791.  
  1792.     if @actor_arrow.get_index < 0
  1793.       @actor_select_window.set_index($game_party.actors.size - 1)
  1794.     end
  1795.  
  1796.     # If B button was pressed
  1797.     if Input.trigger?(Input::B)
  1798.       # Play cancel SE
  1799.       $game_system.se_play($data_system.cancel_se)
  1800.       # End actor selection
  1801.       end_actor_select
  1802.       @any_scope = false
  1803.       return
  1804.     end
  1805.     update_phase3_actor_select2
  1806.   end
  1807.  
  1808.   #--------------------------------------------------------------------------
  1809.   # *
  1810.   #--------------------------------------------------------------------------
  1811.   def update_phase3_actor_select2
  1812.     # If C button was pressed
  1813.     if Input.trigger?(Input::C)
  1814.       # Buzz if an item cannot be used
  1815.       if @active_battler.current_action.kind == 2
  1816.         item = $data_items[@active_battler.current_action.item_id]
  1817.         if ((item.scope == 3) and $game_party.actors[@actor_arrow.index].hp == 0) or
  1818.         ((item.scope == 5) and $game_party.actors[@actor_arrow.index].hp >= 1)
  1819.           # Play buzzer SE
  1820.           $game_system.se_play($data_system.buzzer_se)
  1821.           return
  1822.         end
  1823.       end
  1824.       # Buzz if a skill cannot be used
  1825.       if @active_battler.current_action.kind == 1
  1826.         skill = $data_skills[@active_battler.current_action.skill_id]
  1827.         if ((skill.scope == 3) and $game_party.actors[@actor_arrow.index].hp == 0) or
  1828.         ((skill.scope == 5) and $game_party.actors[@actor_arrow.index].hp >= 1)
  1829.           # Play buzzer SE
  1830.           $game_system.se_play($data_system.buzzer_se)
  1831.           return
  1832.         end
  1833.         # Support for Trincea and Altruismo
  1834.         if (skill.id == $altruismo_skill_id or
  1835.           skill.id == $trincea_skill_id) and
  1836.           @active_battler==$game_party.actors[@actor_arrow.index]
  1837.           # Play buzzer SE
  1838.           $game_system.se_play($data_system.buzzer_se)
  1839.           return
  1840.         end
  1841.       end
  1842.       # Play decision SE
  1843.       $game_system.se_play($data_system.decision_se)
  1844.       # Set action
  1845.       @active_battler.current_action.target_index = @actor_arrow.index
  1846.       # End actor selection
  1847.       end_actor_select
  1848.       # If skill window is showing
  1849.       if @skill_window != nil
  1850.         # End skill selection
  1851.         end_skill_select
  1852.       end
  1853.  
  1854.       # If item window is showing
  1855.       if @item_window != nil
  1856.         # End item selection
  1857.         end_item_select
  1858.       end
  1859.       # Charlie: ACTION!!!
  1860.       phase3_next_actor
  1861.     end
  1862.   end
  1863.  
  1864.   #--------------------------------------------------------------------------
  1865.   # * Frame Update (actor command phase : all allies selection)
  1866.   #--------------------------------------------------------------------------
  1867.   def update_phase3_all_allies_select
  1868.     # Update targeted
  1869.     for i in 0...$game_party.actors.size
  1870.       $game_party.actors[i].targeted=true
  1871.     end
  1872.     @turn_window.update_indicators
  1873.     @grandia_bar_window.update(@battlers_array) if GRANDIA_MODE
  1874.     if Input.trigger?(Input::SHIFT)
  1875.       end_all_allies_select
  1876.       start_actor_select
  1877.       return
  1878.     end
  1879.     # If B button was pressed
  1880.     if Input.trigger?(Input::B)
  1881.       # Play cancel SE
  1882.       $game_system.se_play($data_system.cancel_se)
  1883.       # End enemy selection
  1884.       end_all_allies_select
  1885.       @single_all_scope = false
  1886.       return
  1887.     end
  1888.     if Input.trigger?(Input::C)
  1889.       $game_system.se_play($data_system.decision_se)
  1890.       end_all_allies_select
  1891.       # override instruction inside end_all_allies_select
  1892.       $game_temp.selecting_all_allies = true
  1893.       if @skill_window != nil
  1894.         end_skill_select
  1895.       end
  1896.       if @item_window != nil
  1897.         end_item_select
  1898.       end
  1899.       phase3_next_actor
  1900.     end
  1901.   end
  1902.  
  1903.   #--------------------------------------------------------------------------
  1904.   # * Start Enemy Selection
  1905.   #--------------------------------------------------------------------------
  1906.   def start_enemy_select
  1907.  
  1908.     $game_temp.selecting_all_enemies=false
  1909.     @selecting_ally=false
  1910.  
  1911.     # Make enemy arrow
  1912.     @enemy_arrow = Arrow_Enemy.new(@spriteset.viewport1)
  1913.     # Associate help window
  1914.     @enemy_arrow.help_window = @help_window
  1915.     # Disable actor command window
  1916.     @actor_command_window.active = false
  1917.     # Charlie: don't want the commands to disappear
  1918.  
  1919.   end
  1920.  
  1921.  
  1922.   #--------------------------------------------------------------------------
  1923.   # * Start All Enemy Selection
  1924.   #--------------------------------------------------------------------------
  1925.   def start_all_enemies_select
  1926.     @help_window.set_text("Attacking all enemies", 1)
  1927.     @all_enemies_window.visible=true
  1928.     @selecting_ally=false
  1929.     $game_temp.selecting_all_enemies=true
  1930.     @actor_command_window.active = false
  1931.   end
  1932.  
  1933.   #--------------------------------------------------------------------------
  1934.   # * End All Enemy Selection
  1935.   #--------------------------------------------------------------------------
  1936.   def end_all_enemies_select
  1937.     # Update targeted
  1938.     for i in 0...$game_troop.enemies.size
  1939.       $game_troop.enemies[i].targeted=false
  1940.     end
  1941.     @turn_window.update_indicators
  1942.     @grandia_bar_window.update(@battlers_array) if GRANDIA_MODE
  1943.     $game_temp.selecting_all_enemies=false
  1944.     @all_enemies_window.visible=false
  1945.     @status_window.visible = true
  1946.     # If command is [fight]
  1947.     if @actor_command_window.index == 0
  1948.       @actor_command_window.active = true
  1949.       @actor_command_window.visible = true
  1950.       @battler_window.visible = true
  1951.       @help_window.visible = false
  1952.     end
  1953.   end
  1954.  
  1955.   #--------------------------------------------------------------------------
  1956.   # * End Enemy Selection
  1957.   #--------------------------------------------------------------------------
  1958.   def end_enemy_select
  1959.     @status_window.visible = true
  1960.     @enemy_arrow.dispose
  1961.     @enemy_arrow = nil
  1962.     # If command is [fight]
  1963.     if @actor_command_window.index == 0
  1964.       @actor_command_window.active = true
  1965.       @actor_command_window.visible = true
  1966.       @battler_window.visible = true
  1967.       @help_window.visible = false
  1968.     end
  1969.     # Update targeted
  1970.     for i in 0...$game_troop.enemies.size
  1971.       $game_troop.enemies[i].targeted=false
  1972.     end
  1973.     @turn_window.update_indicators
  1974.     @grandia_bar_window.update(@battlers_array) if GRANDIA_MODE
  1975.   end
  1976.  
  1977.   #--------------------------------------------------------------------------
  1978.   # * Start Actor Selection
  1979.   #--------------------------------------------------------------------------
  1980.   def start_actor_select
  1981.     # Make actor arrow
  1982.     @actor_arrow = Arrow_Actor.new(@spriteset.viewport2)
  1983.     @actor_arrow.index = @actor_index
  1984.     # Associate help window
  1985.     @actor_arrow.help_window = @help_window
  1986.     # Disable actor command window
  1987.     @actor_command_window.active = false
  1988.  
  1989.     @selecting_ally = true
  1990.     $game_temp.selecting_all_allies = false
  1991.     @actor_select_window.visible = true
  1992.     @actor_select_window.active = true
  1993.     @actor_select_window.set_index(@actor_index)
  1994.  
  1995.   end
  1996.  
  1997.   #--------------------------------------------------------------------------
  1998.   # * Start All Actors Selection
  1999.   #--------------------------------------------------------------------------
  2000.   def start_all_allies_select
  2001.     @help_window.set_text("All allies", 1)
  2002.     @all_allies_window.visible=true
  2003.     @selecting_ally=true
  2004.     $game_temp.selecting_all_allies = true
  2005.     @actor_command_window.active = false
  2006.     @actor_select_window.visible = false
  2007.     @actor_select_window.active = false
  2008.   end
  2009.  
  2010.   #--------------------------------------------------------------------------
  2011.   # * End All Actors Selection
  2012.   #--------------------------------------------------------------------------
  2013.   def end_all_allies_select
  2014.     # Update targeted
  2015.     for i in 0...$game_party.actors.size
  2016.       $game_party.actors[i].targeted=false
  2017.     end
  2018.     @turn_window.update_indicators
  2019.     @grandia_bar_window.update(@battlers_array) if GRANDIA_MODE
  2020.     $game_temp.selecting_all_allies = false
  2021.     @all_allies_window.visible = false
  2022.     @status_window.visible = true
  2023.     @actor_select_window.visible = false
  2024.   end
  2025.  
  2026.   #--------------------------------------------------------------------------
  2027.   # * End Actor Selection
  2028.   #--------------------------------------------------------------------------
  2029.   def end_actor_select
  2030.     # Dispose of actor arrow
  2031.     @actor_arrow.dispose
  2032.     @actor_arrow = nil
  2033.  
  2034.     @actor_select_window.visible = false
  2035.     # Update targeted
  2036.     for i in 0...$game_party.actors.size
  2037.       $game_party.actors[i].targeted=false
  2038.     end
  2039.     @turn_window.update_indicators
  2040.     @grandia_bar_window.update(@battlers_array) if GRANDIA_MODE
  2041.  
  2042.   end
  2043.  
  2044.   #--------------------------------------------------------------------------
  2045.   # * Start Skill Selection
  2046.   #--------------------------------------------------------------------------
  2047.   def start_skill_select
  2048.     # Make skill window
  2049.     @skill_window = Window_BattleSkill.new(@active_battler, @individual_battle_commands_skill_category)
  2050.     # Associate help window
  2051.     @skill_window.help_window = @help_window
  2052.     # Disable actor command window
  2053.     @actor_command_window.active = false
  2054.  
  2055.     # Charlie: don't want the commands to disappear
  2056.  
  2057.   end
  2058.  
  2059.   #--------------------------------------------------------------------------
  2060.   # * Start Switch Selection
  2061.   #--------------------------------------------------------------------------
  2062.   def start_switch_select
  2063.     # Make switch windows
  2064.     @switch_window = Window_Switch.new()
  2065.     @switch_window_help = Window_Switch_Help.new
  2066.     # Disable actor command window
  2067.     @actor_command_window.active = false
  2068.   end
  2069.  
  2070.   #--------------------------------------------------------------------------
  2071.   # * End Skill Selection
  2072.   #--------------------------------------------------------------------------
  2073.   def end_skill_select
  2074.     @battler_window.visible = true
  2075.  
  2076.     # Dispose of skill window
  2077.     @skill_window.dispose
  2078.     @skill_window = nil
  2079.     # Hide help window
  2080.     @help_window.visible = false
  2081.  
  2082.     # Enable actor command window
  2083.     @actor_command_window.active = true
  2084.     @actor_command_window.visible = true
  2085.   end
  2086.  
  2087.   #--------------------------------------------------------------------------
  2088.   # * End Switch Selection
  2089.   #--------------------------------------------------------------------------
  2090.   def end_switch_select
  2091.     @battler_window.visible = true
  2092.  
  2093.     # Dispose of switch window
  2094.     @switch_window.dispose
  2095.     @switch_window_help.dispose
  2096.     @switch_window = nil
  2097.     # Hide help window
  2098.     @help_window.visible = false
  2099.     # Enable actor command window
  2100.     @actor_command_window.active = true
  2101.     @actor_command_window.visible = true
  2102.   end
  2103.  
  2104.  
  2105.   #--------------------------------------------------------------------------
  2106.   # * Start Item Selection
  2107.   #--------------------------------------------------------------------------
  2108.   def start_item_select
  2109.     # Make item window
  2110.     @item_window = Window_BattleItem.new
  2111.     # Associate help window
  2112.     @item_window.help_window = @help_window
  2113.     # Disable actor command window
  2114.     @actor_command_window.active = false
  2115.     @actor_command_window.visible = true
  2116.   end
  2117.  
  2118.   #--------------------------------------------------------------------------
  2119.   # * End Item Selection
  2120.   #--------------------------------------------------------------------------
  2121.   def end_item_select
  2122.     # Dispose of item window
  2123.     @item_window.dispose
  2124.     @item_window = nil
  2125.     # Hide help window
  2126.     @help_window.visible = false
  2127.     # Enable actor command window
  2128.     @actor_command_window.active = true
  2129.     @actor_command_window.visible = true
  2130.  
  2131.     @battler_window.visible = true
  2132.  
  2133.   end
  2134.  
  2135.   #--------------------------------------------------------------------------
  2136.   # * Start Main Phase
  2137.   #--------------------------------------------------------------------------
  2138.   def start_phase4
  2139.     $outfile.write "*** start_phase4 ***\n" if $outfile
  2140.    
  2141.     # Shift to phase 4
  2142.     @phase = 4
  2143.  
  2144.     #######################
  2145.     # UNPLAYABLE REACTION #
  2146.     #######################
  2147.     if @reacting and !PLAYABLE_REACTION
  2148.       # print("start_phase4 UNPLAYABLE REACTION go to step 1")
  2149.       $game_temp.battle_main_phase = true
  2150.       @phase4_step = 1
  2151.       return
  2152.     elsif @using_auto_life
  2153.     #######################
  2154.     #     AUTO LIFE       #
  2155.     #######################
  2156.       # print("start_phase4 AUTO LIFE go to step 1")
  2157.       $game_temp.battle_main_phase = true
  2158.       @phase4_step = 1
  2159.       return
  2160.     elsif @using_phoenix
  2161.     #######################
  2162.     #    AUTO PHOENIX     #
  2163.     #######################
  2164.       # print("start_phase4 AUTO PHOENIX go to step 1")
  2165.       $game_temp.battle_main_phase = true
  2166.       @phase4_step = 1
  2167.       return
  2168.     end
  2169.        
  2170.     # Turn count- and Clear action completed flags-
  2171.     # controls put in end regular turn
  2172.    
  2173.     # Disable actor command window
  2174.     @actor_command_window.active = false
  2175.     @actor_command_window.visible = false
  2176.     @actor_command_bg.visible=false
  2177.  
  2178.     @left_actor_command_window.active = false
  2179.     @left_actor_command_window.visible = false
  2180.     @battler_window.visible = false
  2181.     # Make the turn window disappear
  2182.     @turn_window.visible=false unless @active_battler.is_a?(Game_Enemy)
  2183.     if @active_battler != nil
  2184.       @active_battler.blink = false
  2185.     end
  2186.  
  2187.     # Set main phase flag
  2188.     $game_temp.battle_main_phase = true
  2189.  
  2190.     # Shift to step 1
  2191.     @phase4_step = 1
  2192.   end
  2193.  
  2194.  
  2195.   #--------------------------------------------------------------------------
  2196.   # * Make Action Orders ELIMINATO
  2197.   #--------------------------------------------------------------------------
  2198.  
  2199.   #--------------------------------------------------------------------------
  2200.   # * Frame Update (main phase)
  2201.   #--------------------------------------------------------------------------
  2202.   def update_phase4
  2203.     $outfile.write "update_phase4\n" if $outfile
  2204.     case @phase4_step
  2205.     when 1
  2206.       # print("step1")
  2207.       update_phase4_step1
  2208.     when 2
  2209.       # print("step2")
  2210.       update_phase4_step2
  2211.     when 3
  2212.       # print("step3")
  2213.       update_phase4_step3
  2214.     when 3.1
  2215.       # print("step3.1")
  2216.       update_phase4_step3_1
  2217.     when 4
  2218.       # print("step4")
  2219.       update_phase4_step4
  2220.     when 5
  2221.       # print("step5")
  2222.       update_phase4_step5
  2223.     when 5.1
  2224.       # print("step5.1")
  2225.       update_phase4_step5_1
  2226.     when 6
  2227.       # print("step6")
  2228.       update_phase4_step6
  2229.     end
  2230.   end
  2231.  
  2232.   #--------------------------------------------------------------------------
  2233.   # * Frame Update (main phase step 1 : action preparation)
  2234.   #--------------------------------------------------------------------------
  2235.   def update_phase4_step1
  2236.     $outfile.write "update_phase4_step1\n" if $outfile
  2237.     # Hide help window
  2238.     @help_window.visible = false
  2239.     # Hide turn window
  2240.     @turn_window.visible = false
  2241.     # Hide enemy attacks window
  2242.     @enemy_attacks_window.visible = false
  2243.     # Determine win/loss
  2244.     if judge
  2245.       # If won, or if lost : end method
  2246.       $outfile.write "update_phase4_step1 judge\n" if $outfile
  2247.       return
  2248.     end
  2249.     # If an action forcing battler doesn't exist
  2250.     if $game_temp.forcing_battler == nil
  2251.       # Set up battle event
  2252.       # print "update_phase4_step1 setup_battle_event"
  2253.       setup_battle_event
  2254.       # If battle event is running
  2255.       if $game_system.battle_interpreter.running?
  2256.         return
  2257.       end
  2258.     end
  2259.     # Charlie: @action_battlers is no longer used
  2260.  
  2261.     if @end_turn == true
  2262.       start_phase2
  2263.       return
  2264.     end
  2265.  
  2266.     # Initialize animation ID and common event ID
  2267.     @animation1_id = 0
  2268.     @animation2_id = 0
  2269.     @common_event_id = 0
  2270.  
  2271.     #######################
  2272.     # UNPLAYABLE REACTION #
  2273.     #######################
  2274.     if @reacting and !PLAYABLE_REACTION
  2275.       # print("update_phase4_step1 UNPLAYABLE REACTION go to step 2")
  2276.       # skip slip damage and rigene effect
  2277.       @phase4_step = 2
  2278.       return
  2279.     elsif @using_auto_life
  2280.     #######################
  2281.     #     AUTO LIFE     #
  2282.     #######################
  2283.       # print("update_phase4_step1 AUTO LIFE go to step 2")
  2284.       # skip slip damage and rigene effect
  2285.       @phase4_step = 2
  2286.       return
  2287.     elsif @using_phoenix
  2288.     #######################
  2289.     #    AUTO PHOENIX     #
  2290.     #######################
  2291.       # print("update_phase4_step1 AUTO PHOENIX go to step 2")
  2292.       # skip slip damage and rigene effect
  2293.       @phase4_step = 2
  2294.       return
  2295.     end
  2296.  
  2297.     # If not switching
  2298.     unless (@active_battler.current_action.kind == 1 and
  2299.       @active_battler.current_action.skill_id == $switch_skill_id)
  2300.       # Slip damage moved at the end of the turn
  2301.        
  2302.       # Natural removal of states moved at the end of the turn
  2303.     end
  2304.  
  2305.     # Refresh status window
  2306.     @status_window.refresh
  2307.     # Shift to step 2
  2308.     @phase4_step = 2
  2309.   end
  2310.  
  2311.   #--------------------------------------------------------------------------
  2312.   # * Frame Update (main phase step 2 : start action)
  2313.   #--------------------------------------------------------------------------
  2314.   def update_phase4_step2
  2315.     # print ("update_phase4_step2")
  2316.     # AUTO LIFE
  2317.     if @using_auto_life
  2318.       @end_turn = true
  2319.       # Clear target battlers
  2320.       @target_battlers = []
  2321.       make_item_action_result
  2322.       # print("stop auto_life")
  2323.       @using_auto_life=false
  2324.       @phase4_step = 4 # skip user animation
  2325.       return
  2326.     end
  2327.      
  2328.     # If not a forcing action
  2329.     unless @active_battler.current_action.forcing
  2330.       # If restriction is [normal attack enemy] or [normal attack ally]
  2331.       if @active_battler.restriction == 2 or @active_battler.restriction == 3
  2332.         # Set attack as an action
  2333.         @active_battler.current_action.kind = 0
  2334.         @active_battler.current_action.basic = 0
  2335.       end
  2336.       # If restriction is [cannot perform action]
  2337.       if @active_battler.restriction == 4
  2338.         $outfile.write "update_phase4_step2: [cannot perform action] go to step 1\n" if $outfile
  2339.         # Clear battler being forced into action
  2340.         $game_temp.forcing_battler = nil unless $game_temp.forcing_battler != @active_battler
  2341.  
  2342.         # Shift to step 1
  2343.         @phase4_step = 1
  2344.  
  2345.         if !(@reacting or @using_phoenix)
  2346.           end_regular_turn
  2347.         else
  2348.           #############################
  2349.           # REACTION AND AUTO-PHOENIX #
  2350.           #############################
  2351.           if @return_guarding
  2352.             @active_battler.current_action.kind = 0
  2353.             @active_battler.current_action.basic = 1
  2354.           end  
  2355.           if @return_to_forced_action
  2356.             @active_battler.current_action =
  2357.               @active_battler_saved_forced_action.dup
  2358.           end  
  2359.           @end_turn = true
  2360.           $outfile.write "update_phase4_step2: restriction -> cancel reaction and auto-phoenix\n" if $outfile
  2361.           @reacting = false
  2362.           @using_phoenix = false
  2363.         end
  2364.  
  2365.         return
  2366.       end
  2367.     end
  2368.  
  2369.     # Clear target battlers
  2370.     @target_battlers = []
  2371.     # Branch according to each action
  2372.     case @active_battler.current_action.kind
  2373.     when 0  # basic
  2374.       make_basic_action_result
  2375.     when 1  # skill
  2376.       make_skill_action_result
  2377.     when 2  # item
  2378.       make_item_action_result
  2379.     end
  2380.     # Shift to step 3
  2381.     if @phase4_step == 2
  2382.       @phase4_step = 3
  2383.     end
  2384.   end
  2385.  
  2386.   #--------------------------------------------------------------------------
  2387.   # * Make Basic Action Results
  2388.   #--------------------------------------------------------------------------
  2389.   def make_basic_action_result
  2390.     $outfile.write "make_basic_action_result\n" if $outfile
  2391.     #######################
  2392.     # UNPLAYABLE REACTION #
  2393.     #######################
  2394.     if @reacting and !PLAYABLE_REACTION
  2395.       # print("make_basic_action_result UNPLAYABLE REACTION")
  2396.       @animation1_id = @active_battler.animation1_id
  2397.       @animation2_id = @active_battler.animation2_id
  2398.       # Apply normal attack results
  2399.       @target_battlers = [@target_of_reaction]
  2400.       for target in @target_battlers
  2401.         target.attack_effect(@active_battler)
  2402.         # No reactions to reactions
  2403.         if @reacting
  2404.           $game_temp.reaction = false
  2405.         end
  2406.       end
  2407.       return
  2408.     elsif @using_phoenix
  2409.     #######################
  2410.     #    AUTO PHOENIX     #
  2411.     #######################
  2412.       # print("make_basic_action_result AUTO PHOENIX")
  2413.       @animation1_id = @active_battler.animation1_id
  2414.       @animation2_id = @active_battler.animation2_id
  2415.       # Apply normal attack results
  2416.       @target_battlers = [@phoenix_targets.pop]
  2417.       for target in @target_battlers
  2418.         target.item_effect(@item)
  2419.       end
  2420.       return
  2421.     end
  2422.    
  2423.     # If attack
  2424.     if @active_battler.current_action.basic == 0
  2425.       # print("attack")
  2426.       # Set anaimation ID
  2427.       @animation1_id = @active_battler.animation1_id
  2428.       @animation2_id = @active_battler.animation2_id
  2429.       # If action battler is enemy
  2430.       if @active_battler.is_a?(Game_Enemy)
  2431.         if @active_battler.restriction == 3
  2432.           target = $game_troop.random_target_enemy
  2433.         elsif @active_battler.restriction == 2
  2434.           target = $game_party.random_target_actor
  2435.         else
  2436.           index = @active_battler.current_action.target_index
  2437.           target = $game_party.smooth_target_actor(index)
  2438.         end
  2439.       end      
  2440.       # If action battler is actor
  2441.       if @active_battler.is_a?(Game_Actor)
  2442.         if @active_battler.restriction == 3
  2443.           target = $game_party.random_target_actor
  2444.         elsif @active_battler.restriction == 2
  2445.           target = $game_troop.random_target_enemy
  2446.         else
  2447.           index = @active_battler.current_action.target_index
  2448.           target = $game_troop.smooth_target_enemy(index)
  2449.         end
  2450.       end
  2451.  
  2452.       #########################
  2453.       # SUPPORT FOR ALTRUISMO #
  2454.       #########################
  2455.       if target!=nil
  2456.         if target.defender_char!=nil and
  2457.         ($game_party.actors.include?(target.defender_char) or
  2458.         $game_troop.enemies.include?(target.defender_char)) and
  2459.         target.defender_char.exist? and target.defender_char.movable?
  2460.           # print(target.name+ " is defended by "+target.defender_char.name)
  2461.           target=target.defender_char
  2462.           target.show_defending_position=true
  2463.         end
  2464.       end
  2465.  
  2466.       # Set array of targeted battlers
  2467.       @target_battlers = [target]
  2468.       # Apply normal attack results
  2469.       for target in @target_battlers
  2470.         target.attack_effect(@active_battler)
  2471.  
  2472.         if PLAYABLE_REACTION
  2473.           # can react only if not dead
  2474.           if $game_temp.reaction and !target.dead?
  2475.             @reaction_window.actor = target
  2476.             @reaction_window.refresh
  2477.           else
  2478.             $game_temp.reaction=false
  2479.           end
  2480.         else # NOT PLAYABLE REACTION
  2481.           # can react only if not dead and the attacker is not dead
  2482.           if $game_temp.reaction and !target.dead? and !@active_battler.dead?
  2483.             @reaction_window.actor = target
  2484.             @reaction_window.refresh
  2485.             @target_of_reaction = @active_battler
  2486.             @reacting_battler = target
  2487.           else
  2488.             $game_temp.reaction = false
  2489.           end
  2490.         end
  2491.  
  2492.       end
  2493.       return
  2494.     end
  2495.     # If guard
  2496.     if @active_battler.current_action.basic == 1
  2497.       # print("guard")
  2498.       # Display "Guard" in help window
  2499.       @help_window.set_text($data_system.words.guard, 1)
  2500.       return
  2501.     end
  2502.     # If escape
  2503.     if @active_battler.is_a?(Game_Enemy) and
  2504.        @active_battler.current_action.basic == 2
  2505.       # print("escape enemy")
  2506.       # Display "Escape" in help window
  2507.       @help_window.set_text("Escape", 1)
  2508.       # Escape
  2509.       @active_battler.escape
  2510.       return
  2511.     end
  2512.     # If doing nothing
  2513.     if @active_battler.current_action.basic == 3
  2514.       # print("doing nothing")
  2515.       # Clear battler being forced into action
  2516.       $game_temp.forcing_battler = nil unless $game_temp.forcing_battler != @active_battler
  2517.       # Shift to step 1
  2518.       @phase4_step = 1
  2519.  
  2520.       end_regular_turn
  2521.  
  2522.       return
  2523.     end
  2524.   end
  2525.  
  2526.   #--------------------------------------------------------------------------
  2527.   # * Set Targeted Battler for Skill or Item
  2528.   #     scope : effect scope for skill or item
  2529.   #--------------------------------------------------------------------------
  2530.   def set_target_battlers(scope)
  2531.     # If battler performing action is enemy
  2532.     if @active_battler.is_a?(Game_Enemy)
  2533.       # Branch by effect scope
  2534.       case scope
  2535.       when 1  # single enemy
  2536.         index = @active_battler.current_action.target_index
  2537.         @target_battlers.push($game_party.smooth_target_actor(index))
  2538.       when 2  # all enemies
  2539.         for actor in $game_party.actors
  2540.           if actor.exist?
  2541.             @target_battlers.push(actor)
  2542.           end
  2543.         end
  2544.       when 3  # single ally
  2545.         index = @active_battler.current_action.target_index
  2546.         @target_battlers.push($game_troop.smooth_target_enemy(index))
  2547.       when 4  # all allies
  2548.         for enemy in $game_troop.enemies
  2549.           if enemy.exist?
  2550.             @target_battlers.push(enemy)
  2551.           end
  2552.         end
  2553.       when 5  # single ally (HP 0)
  2554.         index = @active_battler.current_action.target_index
  2555.         enemy = $game_troop.enemies[index]
  2556.         if enemy != nil and enemy.hp0?
  2557.           @target_battlers.push(enemy)
  2558.         end
  2559.       when 6  # all allies (HP 0)
  2560.         for enemy in $game_troop.enemies
  2561.           if enemy != nil and enemy.hp0?
  2562.             @target_battlers.push(enemy)
  2563.           end
  2564.         end
  2565.       when 7  # user
  2566.         @target_battlers.push(@active_battler)
  2567.       end
  2568.     end
  2569.     # If battler performing action is actor
  2570.     if @active_battler.is_a?(Game_Actor)
  2571.      
  2572.       #######################
  2573.       # UNPLAYABLE REACTION #
  2574.       #######################
  2575.       if @reacting
  2576.         # print ("not-playable reaction - setting target")
  2577.         @target_battlers = [@target_of_reaction]
  2578.         return
  2579.       end        
  2580.       # support for random single target
  2581.       if @random_single_target
  2582.         @target_battlers.push($game_troop.random_target_enemy)
  2583.         @random_single_target = false
  2584.         return
  2585.       end
  2586.       # support for any scope
  2587.       if @any_scope == true
  2588.         if (@selecting_ally)
  2589.           index = @active_battler.current_action.target_index
  2590.           @target_battlers.push($game_party.smooth_target_actor(index))
  2591.         else
  2592.           index = @active_battler.current_action.target_index
  2593.           @target_battlers.push($game_troop.smooth_target_enemy(index))
  2594.         end
  2595.         @any_scope = false
  2596.         return
  2597.       end
  2598.       if @single_all_scope == true
  2599.         if ($game_temp.selecting_all_enemies)
  2600.           for enemy in $game_troop.enemies
  2601.             if enemy.exist?
  2602.               @target_battlers.push(enemy)
  2603.             end
  2604.           end
  2605.           return
  2606.         end
  2607.         if ($game_temp.selecting_all_allies)
  2608.           for actor in $game_party.actors
  2609.             if actor.exist?
  2610.               @target_battlers.push(actor)
  2611.             end
  2612.           end
  2613.           return
  2614.         end
  2615.       end
  2616.  
  2617.       # Branch by effect scope
  2618.       case scope
  2619.       when 1  # single enemy
  2620.         index = @active_battler.current_action.target_index
  2621.         @target_battlers.push($game_troop.smooth_target_enemy(index))
  2622.       when 2  # all enemies
  2623.         for enemy in $game_troop.enemies
  2624.           if enemy.exist?
  2625.             @target_battlers.push(enemy)
  2626.           end
  2627.         end
  2628.       when 3  # single ally
  2629.         index = @active_battler.current_action.target_index
  2630.         @target_battlers.push($game_party.smooth_target_actor(index))
  2631.       when 4  # all allies
  2632.         for actor in $game_party.actors
  2633.           if actor.exist?
  2634.             @target_battlers.push(actor)
  2635.           end
  2636.         end
  2637.       when 5  # single ally (HP 0)
  2638.         index = @active_battler.current_action.target_index
  2639.         actor = $game_party.actors[index]
  2640.         if actor != nil and actor.hp0?
  2641.           @target_battlers.push(actor)
  2642.         end
  2643.       when 6  # all allies (HP 0)
  2644.         for actor in $game_party.actors
  2645.           if actor != nil and actor.hp0?
  2646.             @target_battlers.push(actor)
  2647.           end
  2648.         end
  2649.       when 7  # user
  2650.         @target_battlers.push(@active_battler)
  2651.       end
  2652.     end
  2653.   end
  2654.  
  2655.   #--------------------------------------------------------------------------
  2656.   # * Make Skill Action Results
  2657.   #--------------------------------------------------------------------------
  2658.   def make_skill_action_result
  2659.     $outfile.write "make_skill_action_result\n" if $outfile
  2660.     # Get skill
  2661.     @skill = $data_skills[@active_battler.current_action.skill_id]
  2662.     # If not a forcing action
  2663.     unless @active_battler.current_action.forcing
  2664.       # If unable to use due to SP running out
  2665.       unless @active_battler.skill_can_use?(@skill.id) or @skill.id == $switch_skill_id or @reacting or @hits_count > 0
  2666.         # Clear battler being forced into action
  2667.         $game_temp.forcing_battler = nil unless $game_temp.forcing_battler != @active_battler
  2668.         # Shift to step 1
  2669.         @phase4_step = 1
  2670.  
  2671.         end_regular_turn
  2672.  
  2673.         return
  2674.       end
  2675.     end
  2676.     #######################
  2677.     # UNPLAYABLE REACTION #
  2678.     #######################
  2679.     unless @reacting or (@hits_count > 0)
  2680.       # Use up SP
  2681.       if @active_battler.sp_override_cost
  2682.         sp_cost = @active_battler.sp_override_cost
  2683.         @active_battler.sp_override_cost = nil
  2684.       else
  2685.         sp_cost = @skill.sp_cost
  2686.       end
  2687.       if @active_battler.state?($mp1_state_id)
  2688.         @active_battler.sp -= 1
  2689.       elsif @active_battler.state?($half_mp_state_id)
  2690.         @active_battler.sp -= sp_cost / 2
  2691.       else
  2692.         @active_battler.sp -= sp_cost
  2693.       end
  2694.     end
  2695.     # Refresh status window
  2696.     @status_window.refresh
  2697.     # Show skill name on help window
  2698.     @help_window.set_text(@skill.name, 1)
  2699.     # Set animation ID
  2700.     @animation1_id = @skill.animation1_id
  2701.     @animation2_id = @skill.animation2_id
  2702.     # Set command event ID
  2703.     @common_event_id = @skill.common_event_id
  2704.     # Set target battlers
  2705.     set_target_battlers(@skill.scope)
  2706.     # Apply skill effect
  2707.     for target in @target_battlers
  2708.       $game_temp.skill_reflected = false
  2709.       # target.skill_effect will check if the target reflects
  2710.       # and set $game_temp.skill_reflected accordingly
  2711.      
  2712.       target.skill_effect(@active_battler, @skill)
  2713.  
  2714.       ###################
  2715.       # reflect support #
  2716.       ###################
  2717.       @reflected_battler = nil
  2718.       if $game_temp.skill_reflected
  2719.         if (target == @active_battler)
  2720.           @reflected_battler = $game_troop.random_target_enemy
  2721.         else
  2722.           @reflected_battler = @active_battler
  2723.         end
  2724.         @reflecters.push(target)
  2725.       end
  2726.       ###################
  2727.      
  2728.     end
  2729.  
  2730.     ###################
  2731.     # reflect support #
  2732.     ###################
  2733.     if @reflected_battler != nil
  2734.         @reflected_battler.skill_effect(@active_battler, @skill)
  2735.     end
  2736.     ###################
  2737.  
  2738.   end
  2739.  
  2740.   #--------------------------------------------------------------------------
  2741.   # * Make Item Action Results
  2742.   #--------------------------------------------------------------------------
  2743.   def make_item_action_result
  2744.     if @using_auto_life
  2745.     #######################
  2746.     #      AUTO LIFE      #
  2747.     #######################
  2748.       $outfile.write "make_item_action_result AUTO LIFE\n" if $outfile
  2749.       # Set animation ID
  2750.       @animation1_id = @item.animation1_id
  2751.       @animation2_id = @item.animation2_id
  2752.       # Apply item results
  2753.       @target_battlers = [@auto_life_targets.pop]
  2754.       for target in @target_battlers
  2755.         target.item_effect(@item)
  2756.       end
  2757.       return
  2758.     elsif @using_phoenix
  2759.     #######################
  2760.     #    AUTO PHOENIX     #
  2761.     #######################
  2762.       # print("make_item_action_result AUTO PHOENIX")
  2763.       # Set animation ID
  2764.       @animation1_id = @item.animation1_id
  2765.       @animation2_id = @item.animation2_id
  2766.       # Apply item results
  2767.       @target_battlers = [@phoenix_targets.pop]
  2768.       for target in @target_battlers
  2769.         target.item_effect(@item)
  2770.       end
  2771.       # If consumable
  2772.       if @item.consumable
  2773.         # Decrease used item by 1
  2774.         $game_party.lose_item(@item.id, 1)
  2775.       end
  2776.       # Display item name on help window
  2777.       @help_window.set_text(@item.name, 1)
  2778.       return
  2779.     end
  2780.  
  2781.     # Get item
  2782.     @item = $data_items[@active_battler.current_action.item_id]
  2783.     # If unable to use due to items running out
  2784.     unless $game_party.item_can_use?(@item.id)
  2785.       # Shift to step 1
  2786.       @phase4_step = 1
  2787.  
  2788.       end_regular_turn
  2789.  
  2790.       return
  2791.     end
  2792.     # If consumable
  2793.     if @item.consumable
  2794.       # Decrease used item by 1
  2795.       $game_party.lose_item(@item.id, 1)
  2796.     end
  2797.     # Display item name on help window
  2798.     @help_window.set_text(@item.name, 1)
  2799.     # Set animation ID
  2800.     @animation1_id = @item.animation1_id
  2801.     @animation2_id = @item.animation2_id
  2802.     # Set common event ID
  2803.     @common_event_id = @item.common_event_id
  2804.     # Decide on target
  2805.     index = @active_battler.current_action.target_index
  2806.     target = $game_party.smooth_target_actor(index)
  2807.     # Set targeted battlers
  2808.     set_target_battlers(@item.scope)
  2809.     # Apply item effect
  2810.     for target in @target_battlers
  2811.       target.item_effect(@item)
  2812.     end
  2813.   end
  2814.  
  2815.   #--------------------------------------------------------------------------
  2816.   # * Frame Update (main phase step 3 : animation for action performer)
  2817.   #--------------------------------------------------------------------------
  2818.   def update_phase4_step3
  2819.     # Animation for action performer (if ID is 0, then white flash)
  2820.     if @animation1_id == 0
  2821.       @active_battler.white_flash = true
  2822.     else
  2823.       @active_battler.animation_id = @animation1_id
  2824.       @active_battler.animation_hit = true
  2825.     end
  2826.     # Shift to step 3.1
  2827.     @phase4_step = 3.1
  2828.   end
  2829.  
  2830.   #--------------------------------------------------------------------------
  2831.   # * Frame Update (main phase step 3.1 : animation for reflect)
  2832.   #--------------------------------------------------------------------------
  2833.   def update_phase4_step3_1
  2834.     for actor in @reflecters
  2835.       @wait_count = 8
  2836.       actor.animation_id = REFLECT_ANIMATION_ID unless REFLECT_ANIMATION_ID == nil
  2837.     end
  2838.     # Shift to step 4
  2839.     @phase4_step = 4
  2840.   end
  2841.  
  2842.   #--------------------------------------------------------------------------
  2843.   # * Frame Update (main phase step 4: animation for target)
  2844.   #--------------------------------------------------------------------------
  2845.   def update_phase4_step4
  2846.     # Animation for target
  2847.     for target in @target_battlers
  2848.       target.animation_id = @animation2_id unless target.cancel_animation
  2849.       target.animation_hit = (target.damage != "Miss")
  2850.     end
  2851.    
  2852.     ###################
  2853.     # REFLECT SUPPORT #
  2854.     ###################
  2855.     # cancel animation if the targets reflect the skill
  2856.     for target in @reflecters
  2857.       target.animation_id = 0
  2858.     end
  2859.     # set animation for char on which the skill is reflected
  2860.     # unless it's in reflex state too
  2861.     if @reflected_battler != nil
  2862.       if @reflected_battler.state?($reflect_state_id)
  2863.         @reflected_battler.animation_id = REFLECT_ANIMATION_ID unless REFLECT_ANIMATION_ID == nil
  2864.       else
  2865.         @reflected_battler.animation_id = @animation2_id
  2866.         @reflected_battler.animation_hit = (target.damage != "Miss")      
  2867.       end
  2868.     end
  2869.     # Animation has at least 8 frames, regardless of its length
  2870.     @wait_count = 8
  2871.     # Shift to step 5
  2872.     @phase4_step = 5
  2873.    
  2874.   end
  2875.  
  2876.   #--------------------------------------------------------------------------
  2877.   # * Frame Update (main phase step 5 : damage display)
  2878.   #--------------------------------------------------------------------------
  2879.   def update_phase4_step5
  2880.     # Hide help window
  2881.     @help_window.visible = false
  2882.     # Refresh status window
  2883.     @status_window.refresh
  2884.     @status_window.animate_bars=true
  2885.     # Display damage
  2886.     for target in @target_battlers
  2887.       if target.damage != nil
  2888.         target.damage_pop = true
  2889.       end
  2890.     end
  2891.  
  2892.     # Support for Drain & Aspire & Drakoken
  2893.     if @active_battler.damage != nil
  2894.       @active_battler.damage_pop = true
  2895.     end
  2896.     # Support for Steal
  2897.     if $game_temp.stolen_item_id != nil
  2898.       @stolen_item_window = Window_StolenItem.new
  2899.       $game_temp.stolen_item_id = nil
  2900.     end
  2901.     # Support for changed state damage text
  2902.     for target in @target_battlers
  2903.       if target.changed_state_text != []
  2904.         target.changed_state_pop = true
  2905.         # Show changed state text
  2906.         @spriteset.battler(target).damage("", false, target.changed_state_text)
  2907.         target.changed_state_pop = false
  2908.         target.changed_state_text = []
  2909.       end
  2910.     end
  2911.     # Support for hp bars
  2912.     for enemy in $game_troop.enemies
  2913.       if $game_system.killed_enemies_ids.include?(enemy.id)
  2914.         enemy.show_hp_bar = true
  2915.       end
  2916.     end
  2917.    
  2918.     ###################
  2919.     # REFLECT SUPPORT #
  2920.     ###################
  2921.     if @reflected_battler != nil
  2922.       if @reflected_battler.damage != nil
  2923.         @reflected_battler.damage_pop = true
  2924.       end
  2925.       if @reflected_battler.changed_state_text != []
  2926.         @reflected_battler.changed_state_pop = true
  2927.         # Show changed state text
  2928.         @spriteset.battler(@reflected_battler).damage("", false, @reflected_battler.changed_state_text)
  2929.         @reflected_battler.changed_state_pop = false
  2930.         @reflected_battler.changed_state_text = []
  2931.       end
  2932.     end
  2933.     # Shift to step 5.1
  2934.     @phase4_step = 5.1
  2935.   end
  2936.  
  2937.  
  2938.   #--------------------------------------------------------------------------
  2939.   # * Frame Update (main phase step 5.1 : common events)
  2940.   #--------------------------------------------------------------------------
  2941.   def update_phase4_step5_1
  2942.     $outfile.write "update_phase4_step5_1" + "\n" if $outfile
  2943.     if @common_event_id > 0
  2944.       $outfile.write "setup common event" + "\n" if $outfile
  2945.       common_event = $data_common_events[@common_event_id]
  2946.       $game_system.battle_interpreter.setup(common_event.list, 0)
  2947.       @common_event_id = 0
  2948.     end
  2949.     if not $game_system.battle_interpreter.running?
  2950.       @phase4_step = 6
  2951.     end
  2952.   end
  2953.  
  2954.   #--------------------------------------------------------------------------
  2955.   # * Frame Update (main phase step 6 : refresh)
  2956.   #--------------------------------------------------------------------------
  2957.   def update_phase4_step6
  2958.     $game_temp.forcing_battler = nil unless $game_temp.forcing_battler != @active_battler
  2959.     #if @common_event_id > 0
  2960.     #  common_event = $data_common_events[@common_event_id]
  2961.     #  $game_system.battle_interpreter.setup(common_event.list, 0)
  2962.     #end
  2963.     @phase4_step = 1
  2964.    
  2965.     #######################
  2966.     # SWITCH              #
  2967.     #######################
  2968.     if @switch_common_event
  2969.       @switch_common_event = false
  2970.       $game_system.battle_interpreter.setup($switch_common_event.list, 0)
  2971.     end
  2972.     #######################
  2973.     # RETIRE              #
  2974.     #######################
  2975.     if @retire_common_event
  2976.       @retire_common_event = false
  2977.       $game_system.battle_interpreter.setup($retire_common_event.list, 0)
  2978.     end
  2979.     #######################
  2980.     # UNPLAYABLE REACTION #
  2981.     #######################
  2982.     if @reacting and !PLAYABLE_REACTION
  2983.       if @return_guarding
  2984.         @active_battler.current_action.kind = 0
  2985.         @active_battler.current_action.basic = 1
  2986.       end
  2987.       if @return_to_forced_action
  2988.         @active_battler.current_action =
  2989.           @active_battler_saved_forced_action.dup
  2990.       end  
  2991.       @end_turn = true
  2992.       @active_battler.active_in_this_battle = true if @active_battler.is_a?(Game_Actor)
  2993.       @reacting = false
  2994.       # print("stop reaction")
  2995.       return
  2996.     #######################
  2997.     #       AUTO LIFE     #
  2998.     #######################
  2999.     elsif @using_auto_life
  3000.       if @auto_life_targets.empty?
  3001.         @auto_life = false
  3002.         @auto_life_targets = []
  3003.       end
  3004.       return
  3005.     #######################
  3006.     #     AUTO PHOENIX    #
  3007.     #######################
  3008.     elsif @using_phoenix
  3009.       if @return_guarding
  3010.         @active_battler.current_action.kind = 0
  3011.         @active_battler.current_action.basic = 1
  3012.       end  
  3013.       if @return_to_forced_action
  3014.         @active_battler.current_action =
  3015.           @active_battler_saved_forced_action.dup
  3016.       end  
  3017.       @end_turn = true
  3018.       @using_phoenix = false
  3019.       # print("stop phoenix")
  3020.       if @phoenix_users.empty? or @phoenix_targets.empty? or $game_party.item_number(PHOENIX_ITEM_ID) == 0
  3021.         @auto_phoenix = false
  3022.         @phoenix_users = []
  3023.         @phoenix_targets = []
  3024.       end
  3025.       return
  3026.     end
  3027.     ########################
  3028.     # MULTIPLE HITS SKILLS #
  3029.     ########################
  3030.     if @active_battler.current_action.kind == 1 and
  3031.       MULTIPLE_HITS_SKILLS[@active_battler.current_action.skill_id] != nil
  3032.       @hits_count += 1
  3033.       target_alive = false
  3034.       for target in @target_battlers
  3035.         if not target.dead?
  3036.           target_alive = true
  3037.         end
  3038.       end
  3039.       $outfile.write "MULTIPLE_HITS_SKILLS - target alive: " + target_alive.to_s + "\n" if $outfile
  3040.       if @hits_count < MULTIPLE_HITS_SKILLS[@active_battler.current_action.skill_id] and
  3041.         target_alive
  3042.         return
  3043.       end
  3044.     end
  3045.    
  3046.     end_regular_turn # Not executed in case of not playable reaction, auto life
  3047.     # and auto phoenix
  3048.    
  3049.   end
  3050.  
  3051.  
  3052.   #============================================================================
  3053.   #================================= CTB ======================================  
  3054.   #============================================================================
  3055.   def end_regular_turn
  3056.     $outfile.write "end regular turn\n" if $outfile
  3057.     after_cast = @active_battler.after_cast
  3058.     if not @active_battler.regular_turn_ended
  3059.       # print("end regular turn\nactive battler: " + @active_battler.name)
  3060.       $game_temp.battle_time = @active_battler.next_action_time
  3061.       @active_battler.action_executed($game_temp.battle_time)
  3062.       @active_battler.regular_turn_ended = true
  3063.     end
  3064.     @active_battler.current_action.forcing = false
  3065.     @active_battler_copy = @active_battler
  3066.     # end_turn is used to determine the end of a turn in update_phase4_step1
  3067.     @end_turn = true
  3068.     # Turn count (do not update if switch)
  3069.     @new_battle_turn = true unless (@active_battler.current_action.kind == 1 and
  3070.       @active_battler.current_action.skill_id == $switch_skill_id)
  3071.    
  3072.     # Support for the stop time state
  3073.     if @active_battler.state?($stop_time_state_id)
  3074.       @active_battler.get_next_turn
  3075.     end
  3076.    
  3077.     # Slip damage, skip if switch, transformation or summon type 2 (party replaced)
  3078.     unless (@active_battler.current_action.kind == 1 and @active_battler.current_action.skill_id == $switch_skill_id)
  3079.       # skip if after cast
  3080.       unless after_cast
  3081.         unless ($charlie_fleed_summons != nil and
  3082.           @active_battler.current_action.kind == 1 and
  3083.           ($data_skills[@active_battler.current_action.skill_id].is_summon_type?(2) or
  3084.           $data_skills[@active_battler.current_action.skill_id].is_summon_type?(3)))
  3085.           if @active_battler.exist? and @active_battler.slip_damage?
  3086.             # slip_damage_effect subtracts the damage from the HPs
  3087.             @active_battler.slip_damage_effect
  3088.             # Show damage
  3089.             @spriteset.battler(@active_battler).damage(@active_battler.damage, @active_battler.critical)
  3090.             @active_battler.damage = nil
  3091.             @active_battler.critical = false
  3092.             # Animate bars
  3093.             @status_window.animate_bars = true
  3094.           end
  3095.         end
  3096.       end
  3097.     end
  3098.    
  3099.     # REGEN SUPPORT
  3100.     for battler in @battlers_array
  3101.       if (battler == @active_battler) or REGEN_EVERY_TURN
  3102.         # Rigene, skip if switch, transformation or summon type 2 (party replaced)
  3103.         unless (@active_battler.current_action.kind == 1 and @active_battler.current_action.skill_id == $switch_skill_id)
  3104.           # skip if after cast
  3105.           unless after_cast
  3106.             unless ($charlie_fleed_summons != nil and
  3107.               @active_battler.current_action.kind == 1 and
  3108.               ($data_skills[@active_battler.current_action.skill_id].is_summon_type?(2) or
  3109.               $data_skills[@active_battler.current_action.skill_id].is_summon_type?(3)))
  3110.               if battler.hp > 0 and battler.state?($rigene_state_id)
  3111.                 battler.rigene_effect
  3112.                 # Show damage
  3113.                 battler.damage_pop = true
  3114.                 @spriteset.battler(battler).damage(battler.damage, battler.critical)
  3115.                 battler.damage = nil
  3116.                 battler.critical = false
  3117.                 # Animate bars
  3118.                 @status_window.animate_bars = true
  3119.               end
  3120.             end
  3121.           end
  3122.         end
  3123.         # MP Rigene, skip if switch, transformation or summon type 2 (party replaced)
  3124.         unless (@active_battler.current_action.kind == 1 and @active_battler.current_action.skill_id == $switch_skill_id)
  3125.           # skip if after cast
  3126.           unless after_cast
  3127.             unless ($charlie_fleed_summons != nil and
  3128.               @active_battler.current_action.kind == 1 and
  3129.               ($data_skills[@active_battler.current_action.skill_id].is_summon_type?(2) or
  3130.               $data_skills[@active_battler.current_action.skill_id].is_summon_type?(3)))
  3131.               if battler.hp > 0 and battler.state?($rigene_mp_state_id)
  3132.                 battler.rigene_mp_effect
  3133.                 # Show damage
  3134.                 battler.sp_damage_pop = true
  3135.                 @spriteset.battler(battler).damage(battler.damage, battler.critical)
  3136.                 battler.damage = nil
  3137.                 battler.critical = false
  3138.                 # Animate bars
  3139.                 @status_window.animate_bars = true
  3140.               end
  3141.             end
  3142.           end
  3143.         end
  3144.       end
  3145.     end
  3146.  
  3147.     # Natural removal of states
  3148.     @active_battler.remove_states_auto
  3149.  
  3150.     # HP RECOVERY
  3151.     if ((@active_battler.is_a?(Game_Actor) and HP_RECOVERY_ON_DEFEND > 0) or
  3152.     (@active_battler.is_a?(Game_Enemy) and E_HP_RECOVERY_ON_DEFEND > 0)) and
  3153.     (@active_battler.exist?) and @active_battler.guarding?
  3154.       # Add HP
  3155.       @active_battler.hp += Integer(@active_battler.maxhp*
  3156.         ((@active_battler.is_a?(Game_Actor))?(HP_RECOVERY_ON_DEFEND):(E_HP_RECOVERY_ON_DEFEND)))
  3157.       # Set damage
  3158.       @active_battler.damage = -Integer(@active_battler.maxhp*
  3159.         ((@active_battler.is_a?(Game_Actor))?(HP_RECOVERY_ON_DEFEND):(E_HP_RECOVERY_ON_DEFEND)))
  3160.       # Show damage
  3161.       @spriteset.battler(@active_battler).damage(@active_battler.damage, @active_battler.critical)
  3162.       @active_battler.damage = nil
  3163.       @active_battler.critical = false
  3164.       # Animate bars
  3165.       @status_window.animate_bars=true
  3166.     end
  3167.     # SP RECOVERY
  3168.     if ((@active_battler.is_a?(Game_Actor) and SP_RECOVERY_ON_DEFEND > 0) or
  3169.     (@active_battler.is_a?(Game_Enemy) and E_SP_RECOVERY_ON_DEFEND > 0)) and
  3170.     (@active_battler.exist?) and @active_battler.guarding?
  3171.       # Add SP
  3172.       @active_battler.sp += Integer(@active_battler.maxsp*
  3173.         ((@active_battler.is_a?(Game_Actor))?(SP_RECOVERY_ON_DEFEND):(E_SP_RECOVERY_ON_DEFEND)))
  3174.       # Set damage  
  3175.       @active_battler.damage = -Integer(@active_battler.maxsp*
  3176.         ((@active_battler.is_a?(Game_Actor))?(SP_RECOVERY_ON_DEFEND):(E_SP_RECOVERY_ON_DEFEND)))
  3177.       # Show damage
  3178.       @active_battler.sp_damage_pop = true
  3179.       @spriteset.battler(@active_battler).damage(@active_battler.damage, @active_battler.critical)
  3180.       @active_battler.damage = nil
  3181.       @active_battler.critical = false
  3182.       # Animate bars
  3183.       @status_window.animate_bars=true
  3184.     end
  3185.     if ((@active_battler.is_a?(Game_Actor) and SP_RECOVERY_ON_ATTACK > 0) or
  3186.     (@active_battler.is_a?(Game_Enemy) and E_SP_RECOVERY_ON_ATTACK > 0)) and
  3187.     (@active_battler.exist?) and @active_battler.attacking?
  3188.       # Add SP
  3189.       @active_battler.sp += Integer(@active_battler.maxsp*
  3190.         ((@active_battler.is_a?(Game_Actor))?(SP_RECOVERY_ON_ATTACK):(E_SP_RECOVERY_ON_ATTACK)))
  3191.       # Set damage
  3192.       @active_battler.damage = -Integer(@active_battler.maxsp*
  3193.         ((@active_battler.is_a?(Game_Actor))?(SP_RECOVERY_ON_ATTACK):(E_SP_RECOVERY_ON_ATTACK)))
  3194.       # Show damage
  3195.       @active_battler.sp_damage_pop = true
  3196.       @spriteset.battler(@active_battler).damage(@active_battler.damage, @active_battler.critical)
  3197.       @active_battler.damage = nil
  3198.       @active_battler.critical = false
  3199.       # Animate bars
  3200.       @status_window.animate_bars=true
  3201.     end
  3202.    
  3203.     # Support for Doom
  3204.     if @active_battler.state?($doom_state_id)
  3205.       $outfile.write "@active_battler.doom_damage_effect\n" if $outfile
  3206.       @active_battler.doom_damage_effect
  3207.     end
  3208.    
  3209.     make_phoenix_users_and_targets
  3210.    
  3211.     $game_temp.reaction = false if (@active_battler.dead? and not PLAYABLE_REACTION)
  3212.    
  3213.     # set active_in_this_battle flag
  3214.     if @active_battler.is_a?(Game_Actor) and
  3215.       @active_battler.current_action.kind != -1 and
  3216.       not (@active_battler.current_action.kind == 1 and
  3217.       @active_battler.current_action.skill_id == $switch_skill_id)
  3218.       @active_battler.active_in_this_battle = true
  3219.     end
  3220.   end
  3221.  
  3222.   #--------------------------------------------------------------------------
  3223.   # *
  3224.   #--------------------------------------------------------------------------
  3225.   def update_battlers_array
  3226.     @battlers_array = []
  3227.     for enemy in $game_troop.enemies
  3228.       if not (enemy.dead? or enemy.hidden)
  3229.         @battlers_array.push(enemy)
  3230.       end
  3231.     end
  3232.     for actor in $game_party.actors
  3233.       if (not actor.dead?)
  3234.         @battlers_array.push(actor)
  3235.       end
  3236.     end
  3237.   end
  3238.  
  3239.   #--------------------------------------------------------------------------
  3240.   # *
  3241.   #--------------------------------------------------------------------------
  3242.   UPDATE_DELAYS = true
  3243.   # update delays is true only at the beginning of the turn, when the agilities
  3244.   # may have changed from the previous turn
  3245.   def update_battlers_queue(update_delays = false)
  3246.     # print("update_battlers_queue("+update_delays.to_s+")")
  3247.     @action_times = []
  3248.     @battlers_queue = []
  3249.     @battlers_array = []
  3250.     # reset all data for order computing and build the battlers_array
  3251.     for enemy in $game_troop.enemies
  3252.       if not (enemy.dead? or enemy.hidden)
  3253.         enemy.reset_order_data
  3254.         enemy.update_delays unless not update_delays
  3255.         @battlers_array.push(enemy)
  3256.       else
  3257.         # for dead or hidden enemies
  3258.         enemy.randomize_next_action_time
  3259.       end
  3260.     # reset all data for order computing and build the battlers_array
  3261.     # also set the row position in the battle status window
  3262.     end
  3263.     i = 0    
  3264.     for actor in $game_party.actors
  3265.       actor.battle_status_row_pos = i
  3266.       i += 1
  3267.       if (not actor.dead?)
  3268.         actor.reset_order_data
  3269.         actor.update_delays unless not update_delays
  3270.         @battlers_array.push(actor)
  3271.       else
  3272.         # for dead actors
  3273.         actor.randomize_next_action_time
  3274.       end
  3275.     end
  3276.     # insert the next battler in the queue till the queue is not full
  3277.     while(@battlers_queue.size < BATTLERS_QUEUE_SIZE)
  3278.       # update the order data at the beginning and
  3279.       # after every insertion
  3280.       for battler in @battlers_array
  3281.         battler.update_order_data(battler == @active_battler) # updates @currently_evaluated_action_time only
  3282.       end
  3283.       @battlers_array.sort! {|a,b|
  3284.       a.currently_evaluated_action_time - b.currently_evaluated_action_time }
  3285.       @battlers_queue.push(@battlers_array.first)
  3286.       # an action for this battler has been enqueed, update his last queued action time
  3287.       @action_times.push(@battlers_array.first.currently_evaluated_action_time)
  3288.       @battlers_array.first.enqueued_action() # updates @last_queued_action_time and @no_of_queued_actions
  3289.     end
  3290.     @turn_window.set_action_times(@action_times)
  3291.   end
  3292.  
  3293.   #--------------------------------------------------------------------------
  3294.   # *
  3295.   #--------------------------------------------------------------------------
  3296.   def battle_data_hard_reset
  3297.     for enemy in $game_troop.enemies
  3298.       enemy.battle_data_reset
  3299.     end
  3300.     for actor in $game_party.actors
  3301.       actor.battle_data_reset
  3302.       actor.active_in_this_battle=false
  3303.     end
  3304.   end
  3305.  
  3306.   #--------------------------------------------------------------------------
  3307.   # *
  3308.   #--------------------------------------------------------------------------
  3309.   def make_phoenix_users_and_targets
  3310.     @old_phoenix_targets = @phoenix_targets
  3311.     @phoenix_targets = []
  3312.     @phoenix_users = []
  3313.     for actor in $game_party.actors
  3314.       if actor.dead? and not actor.state?($auto_life_state_id)
  3315.         @phoenix_targets.push(actor)
  3316.         # print ("phoenix target: "+actor.name)
  3317.       end
  3318.     end
  3319.     make_phoenix_users_and_targets2
  3320.   end
  3321.  
  3322.   #--------------------------------------------------------------------------
  3323.   # *
  3324.   #--------------------------------------------------------------------------
  3325.   def make_phoenix_users_and_targets2
  3326.     if PHOENIX_ON_NEWLY_KILLED
  3327.       @phoenix_targets = @phoenix_targets-@old_phoenix_targets
  3328.     end
  3329.     if !@phoenix_targets.empty? and $game_party.item_number(PHOENIX_ITEM_ID) > 0
  3330.       for actor in $game_party.actors
  3331.         if !actor.dead? and actor.movable? and
  3332.         actor.state?($auto_phoenix_state_id) and
  3333.         not CANNOT_USE_ITEMS.include?(actor.id)
  3334.           @phoenix_users.push(actor)
  3335.           # print ("phoenix user: "+actor.name)
  3336.         end
  3337.       end
  3338.       if !@phoenix_users.empty?
  3339.         @auto_phoenix = true
  3340.       end
  3341.     end
  3342.   end
  3343.  
  3344.   #--------------------------------------------------------------------------
  3345.   # *
  3346.   #--------------------------------------------------------------------------
  3347.   def make_auto_life_targets
  3348.     $outfile.write "make_auto_life_targets\n" if $outfile
  3349.     @auto_life_targets = []
  3350.     @auto_life = false
  3351.     for actor in $game_party.actors
  3352.       if actor.dead? and actor.state?($auto_life_state_id)
  3353.         @auto_life_targets.push(actor)
  3354.         @auto_life = true
  3355.       end
  3356.     end
  3357.   end
  3358.  
  3359.   #--------------------------------------------------------------------------
  3360.   # *
  3361.   #--------------------------------------------------------------------------
  3362.   def update_stolen_item_window
  3363.     @stolen_item_window.update
  3364.     if Input.trigger?(Input::C)
  3365.       @stolen_item_window.dispose
  3366.       @stolen_item_window = nil
  3367.     end
  3368.   end
  3369.  
  3370.   #--------------------------------------------------------------------------
  3371.   # * Set initial action
  3372.   #--------------------------------------------------------------------------
  3373.   # identify the command based on the string
  3374.   def set_initial_action
  3375.     case @actor_command_window.commands[@actor_command_window.index]
  3376.     # attack
  3377.     when $data_system.words.attack
  3378.       @active_battler.current_action.kind = 0
  3379.       @active_battler.current_action.basic = 0
  3380.     # item
  3381.     when $data_system.words.item
  3382.       @active_battler.current_action.kind = 2
  3383.     # switch
  3384.     when "Switch"
  3385.       @active_battler.current_action.kind = 1
  3386.     end
  3387.     ### SUPPORT FOR INDIVIDUAL BATTLE COMMANDS ###
  3388.     if @active_battler.individual_commands.
  3389.       include?(@actor_command_window.commands[@actor_command_window.index])
  3390.       @active_battler.current_action.kind = 1
  3391.     end
  3392.     @active_battler.action_selected(@active_battler.current_action)
  3393.     # print("set_initial action " + @active_battler.current_action.kind.to_s + " " + @active_battler.current_action.basic.to_s)
  3394.   end
  3395.    
  3396.   #--------------------------------------------------------------------------
  3397.   # *
  3398.   #--------------------------------------------------------------------------
  3399.   def deal_damage(battler, damage)
  3400.     battler.hp -= damage
  3401.     battler.damage_pop = true
  3402.     @spriteset.battler(battler).damage(damage, battler.critical)
  3403.     battler.damage = nil
  3404.     battler.critical = false
  3405.     @status_window.animate_bars = true
  3406.   end
  3407.  
  3408.   #--------------------------------------------------------------------------
  3409.   # *
  3410.   #--------------------------------------------------------------------------
  3411.   def states_plus(battler, states)
  3412.     battler.states_plus(states)
  3413.     battler.changed_state_pop = true
  3414.     @spriteset.battler(battler).damage("", false, battler.changed_state_text)
  3415.     battler.changed_state_pop = false
  3416.     battler.changed_state_text = []
  3417.   end
  3418.  
  3419.   #--------------------------------------------------------------------------
  3420.   # *
  3421.   #--------------------------------------------------------------------------
  3422.   def show_text(battler, text)
  3423.     battler.damage_pop = true
  3424.     @spriteset.battler(battler).damage(text, battler.critical)
  3425.     battler.damage = nil
  3426.     battler.critical = false
  3427.   end
  3428.  
  3429.   #--------------------------------------------------------------------------
  3430.   # *
  3431.   #--------------------------------------------------------------------------
  3432.   def set_position(battler, x, y)
  3433.     battler.screen_x_override = x
  3434.     battler.screen_y_override = y
  3435.     @spriteset.battler(battler).update_position
  3436.   end
  3437.  
  3438. end
  3439.  
  3440. #==============================================================================
  3441. # ** Arrow_Enemy
  3442. #------------------------------------------------------------------------------
  3443. #==============================================================================
  3444. class Arrow_Enemy < Arrow_Base
  3445.   #--------------------------------------------------------------------------
  3446.   # * Frame Update
  3447.   #--------------------------------------------------------------------------
  3448.   def update
  3449.     super
  3450.     # Skip if indicating a nonexistant enemy
  3451.     $game_troop.enemies.size.times do
  3452.       break if self.enemy.exist?
  3453.       @index += 1
  3454.       @index %= $game_troop.enemies.size
  3455.     end
  3456.     # Cursor right
  3457.     if Input.repeat?(Input::DOWN)
  3458.       $game_system.se_play($data_system.cursor_se)
  3459.       $game_troop.enemies.size.times do
  3460.         @index += 1
  3461.         @index %= $game_troop.enemies.size
  3462.         break if self.enemy.exist?
  3463.       end
  3464.     end
  3465.     # Cursor left
  3466.     if Input.repeat?(Input::UP)
  3467.       $game_system.se_play($data_system.cursor_se)
  3468.       $game_troop.enemies.size.times do
  3469.         @index += $game_troop.enemies.size - 1
  3470.         @index %= $game_troop.enemies.size
  3471.         break if self.enemy.exist?
  3472.       end
  3473.     end
  3474.     # Set sprite coordinates
  3475.     if self.enemy != nil
  3476.       self.x = self.enemy.screen_x
  3477.       self.y = self.enemy.screen_y
  3478.     end
  3479.   end
  3480. end
  3481.  
  3482. #==============================================================================
  3483. # ** Arrow_Actor
  3484. #------------------------------------------------------------------------------
  3485. #==============================================================================
  3486. class Arrow_Actor < Arrow_Base
  3487.   #--------------------------------------------------------------------------
  3488.   # * Frame Update
  3489.   #--------------------------------------------------------------------------
  3490.   def update
  3491.     super
  3492.     # Cursor right
  3493.     if Input.repeat?(Input::DOWN)
  3494.       $game_system.se_play($data_system.cursor_se)
  3495.       @index += 1
  3496.       @index %= $game_party.actors.size
  3497.     end
  3498.     # Cursor left
  3499.     if Input.repeat?(Input::UP)
  3500.       $game_system.se_play($data_system.cursor_se)
  3501.       @index += $game_party.actors.size - 1
  3502.       @index %= $game_party.actors.size
  3503.     end
  3504.     # Set sprite coordinates
  3505.     if self.actor != nil
  3506.       self.x = self.actor.screen_x
  3507.       self.y = self.actor.screen_y
  3508.     end
  3509.   end
  3510. end
  3511.  
  3512. #==============================================================================
  3513. # ** Game_BattleAction
  3514. #------------------------------------------------------------------------------
  3515. #  This class handles actions in battle. It's used within the Game_Battler
  3516. #  class.
  3517. #==============================================================================
  3518.  
  3519. class Game_BattleAction
  3520.   #--------------------------------------------------------------------------
  3521.   # * Public Instance Variables
  3522.   #--------------------------------------------------------------------------
  3523.   attr_accessor :selecting_all_allies
  3524.   attr_accessor :selecting_all_enemies
  3525.  
  3526.   #--------------------------------------------------------------------------
  3527.   # * Clear
  3528.   #--------------------------------------------------------------------------
  3529.   alias cf_clear clear
  3530.   def clear
  3531.     cf_clear
  3532.     @selecting_all_allies = false
  3533.     @selecting_all_enemies = false
  3534.   end
  3535. end
Add Comment
Please, Sign In to add comment