Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 55.61 KB | None | 0 0
  1. #===============================================================================
  2. # ~** Regashi::Scene_Battle_Base **~
  3. #-------------------------------------------------------------------------------
  4. #  Author:      Regashi
  5. #  Version:     0.1
  6. #  Build Date:  2010-03-24
  7. #  Last Update: 2010-03-24
  8. #-------------------------------------------------------------------------------
  9. # ~** Documentation **~
  10. #-------------------------------------------------------------------------------
  11. # * List Of Method Names & Usage of Methods
  12. #
  13. #   -  Initialize
  14. #   -  Main
  15. #   -  Initialize_windows
  16. #   -  Update_windows
  17. #   -  Dispose_windows
  18. #   -  Evaluate_battle
  19. #   -  Battle_End
  20. #   -  Setup_battle_event
  21. #   -  Update
  22. #   -  Pre_Battle
  23. #   -  Pre_battle_update
  24. #   -  Party_command
  25. #   -  Party_command_update
  26. #   -  Party_command_update_escape
  27. #   -  Actor_command
  28. #   -  Next_actor_command
  29. #   -  Previous_actor_command
  30. #   -  Actor_command_window_setup
  31. #   -  Actor_command_update
  32. #   -  Actor_command_basic_update
  33. #   -  Actor_command_skill_update
  34. #   -  Actor_command_item_update
  35. #   -  Actor_command_enemy_select_update
  36. #   -  Actor_command_actor_select_update
  37. #   -  Make_enemy_select_arrow
  38. #   -  Dispose_enemy_select_arrow
  39. #   -  Make_actor_select_arrow
  40. #   -  Dispose_actor_select_arrow
  41. #   -  Skill_select_start
  42. #   -  Skill_select_end
  43. #   -  Item_select_start
  44. #   -  Item_select_end
  45. #   -  Battle_start
  46. #   -  Start_command_orders
  47. #   -  Battle_start_update
  48. #   -  Battle_start_update_step1
  49. #   -  Battle_start_update_step2
  50. #   -  Command_orders_result
  51. #   -  Set_target_battlers
  52. #   -  Skill_action_result
  53. #   -  Item_action_result
  54. #   -  Battle_start_update_step3
  55. #   -  Battle_start_update_step4
  56. #   -  Battle_start_update_step5
  57. #   -  Battle_start_update_step6
  58. #   -  After_battle
  59. #   -  After_battle_update
  60. #
  61. #===============================================================================
  62. class Scene_Battle_Base
  63.   #-----------------------------------------------------------------------------
  64.   # * Name      : Initialize
  65.   #   Info      : Begin Object Initialization
  66.   #   Author    : Regashi
  67.   #   Call Info : No Arguments
  68.   #   Comments  : Includes temporary data in the initialization method to allow
  69.   #               further customazation to the main method.
  70.   #-----------------------------------------------------------------------------
  71.   def initialize
  72.    # Initialize each kind of temporary battle data
  73.     $game_temp.in_battle = true
  74.     $game_temp.battle_turn = 0
  75.     $game_temp.battle_event_flags.clear
  76.     $game_temp.battle_abort = false
  77.     $game_temp.battle_main_phase = false
  78.     $game_temp.battleback_name = $game_map.battleback_name
  79.     $game_temp.forcing_battler = nil
  80.     # Initialize battle event interpreter
  81.     $game_system.battle_interpreter.setup(nil, 0)
  82.     # Prepare troop
  83.     @troop_id = $game_temp.battle_troop_id
  84.     $game_troop.setup(@troop_id)
  85.   end
  86.   #-----------------------------------------------------------------------------
  87.   # * Name      : Main
  88.   #   Info      : Begin Main Processing
  89.   #   Author    : Regashi
  90.   #   Call Info : No Arguments
  91.   #-----------------------------------------------------------------------------
  92.   def main
  93.     #Creates windows
  94.     initialize_windows
  95.     # Make sprite set
  96.     @spriteset = Spriteset_Battle.new
  97.     # Initialize wait count
  98.     @wait_count = 0
  99.     # Execute transition
  100.     if $data_system.battle_transition == ''
  101.       Graphics.transition(20)
  102.     else
  103.       Graphics.transition(35, "Graphics/Transitions/" +
  104.         $data_system.battle_transition)
  105.       end
  106.     # Start pre-battle phase
  107.     pre_battle
  108.     # Main loop
  109.     loop do
  110.       # Update game screen
  111.       Graphics.update
  112.       # Update input information
  113.       Input.update
  114.       # Frame update
  115.       update
  116.       # Abort loop if screen is changed
  117.       if $scene != self
  118.         break
  119.       end
  120.     end
  121.     # Refresh map
  122.     $game_map.refresh
  123.     # Prepare for transition
  124.     Graphics.freeze
  125.     # Disposes windows
  126.     dispose_windows
  127.     # Dispose of sprite set
  128.     @spriteset.dispose
  129.     # If switching to title screen
  130.     if $scene.is_a?(Scene_Title)
  131.       # Fade out screen
  132.       Graphics.transition
  133.       Graphics.freeze
  134.     end
  135.     # If switching from battle test to any screen other than game over screen
  136.     if $BTEST and not $scene.is_a?(Scene_Gameover)
  137.       $scene = nil
  138.     end
  139.   end
  140.   #-----------------------------------------------------------------------------
  141.   # * Name      : Initialize_windows
  142.   #   Info      : Initializes windows & objects
  143.   #   Author    : Regashi
  144.   #   Call Info : No Arguments
  145.   #-----------------------------------------------------------------------------
  146.   def initialize_windows
  147.     # Make actor command window
  148.     s1 = $data_system.words.attack
  149.     s2 = $data_system.words.skill
  150.     s3 = $data_system.words.guard
  151.     s4 = $data_system.words.item
  152.     @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])
  153.     @actor_command_window.y = 160
  154.     @actor_command_window.back_opacity = 160
  155.     @actor_command_window.active = false
  156.     @actor_command_window.visible = false
  157.     # Make other windows
  158.     @party_command_window = Window_PartyCommand.new
  159.     @help_window = Window_Help.new
  160.     @help_window.back_opacity = 160
  161.     @help_window.visible = false
  162.     @status_window = Window_BattleStatus.new
  163.     @message_window = Window_Message.new
  164.   end
  165.   #-----------------------------------------------------------------------------
  166.   # * Name      : Update_windows
  167.   #   Info      : Update windows & Objects
  168.   #   Author    : Regashi
  169.   #   Call Info : No Arguments
  170.   #-----------------------------------------------------------------------------
  171.   def update_windows
  172.     # Update windows
  173.     @help_window.update
  174.     @party_command_window.update
  175.     @actor_command_window.update
  176.     @status_window.update
  177.     @message_window.update
  178.     # Update sprite set
  179.     @spriteset.update
  180.   end
  181.   #-----------------------------------------------------------------------------
  182.   # * Name      : Dispose_windows
  183.   #   Info      : Disposes windows & objects
  184.   #   Author    : Regashi
  185.   #   Call Info : No Arguments
  186.   #-----------------------------------------------------------------------------
  187.   def dispose_windows
  188.     # Dispose of windows
  189.     @actor_command_window.dispose
  190.     @party_command_window.dispose
  191.     @help_window.dispose
  192.     @status_window.dispose
  193.     @message_window.dispose
  194.     if @skill_window != nil
  195.       @skill_window.dispose
  196.     end
  197.     if @item_window != nil
  198.       @item_window.dispose
  199.     end
  200.     if @result_window != nil
  201.       @result_window.dispose
  202.     end
  203.   end
  204.   #-----------------------------------------------------------------------------
  205.   # * Name      : Evaluate_battle
  206.   #   Old Name  : Judge
  207.   #   Info      : Determines the Battle's Win/Loss Results
  208.   #   Author    : Regashi
  209.   #   Call Info : No Arguments
  210.   #-----------------------------------------------------------------------------
  211.   def evaluate_battle
  212.     # If all members of the party are wiped out or equal to 0
  213.     if $game_party.all_dead? or $game_party.actors.size == 0
  214.       # If it is possible to lose the battle
  215.       if $game_temp.battle_can_lose
  216.         # Return to BGM before battle starts
  217.         $game_system.bgm_play($game_temp.map_bgm)
  218.         # Battle ends
  219.         battle_end(2)
  220.         # Return true
  221.         return true
  222.       end
  223.       # Otherwise Set game over flag
  224.       $game_temp.gameover = true
  225.       # Return true
  226.       return true
  227.     end
  228.     # Return false if even 1 enemy exists
  229.     for enemy in $game_troop.enemies
  230.       if enemy.exist?
  231.         return false
  232.       end
  233.     end
  234.     # Start after battle phase (win)
  235.     after_battle
  236.     # Return true
  237.     return true
  238.   end
  239.   #-----------------------------------------------------------------------------
  240.   # * Name      : Battle_End
  241.   #   Info      : Displays the results of battle
  242.   #   Author    : Regashi
  243.   #   Call Info : result = 0:win 1:lose 2:escaped
  244.   #-----------------------------------------------------------------------------
  245.   def battle_end(result)
  246.     # Clear in battle flag
  247.     $game_temp.in_battle = false
  248.     # Clear entire party actions flag
  249.     $game_party.clear_actions
  250.     # Remove battle states
  251.     for actor in $game_party.actors
  252.       actor.remove_states_battle
  253.     end
  254.     # Clear enemies
  255.     $game_troop.enemies.clear
  256.     # Call battle callback
  257.     if $game_temp.battle_proc != nil
  258.       $game_temp.battle_proc.call(result)
  259.       $game_temp.battle_proc = nil
  260.     end
  261.     # Switch to map screen
  262.     $scene = Scene_Map.new
  263.   end
  264.   #-----------------------------------------------------------------------------
  265.   # * Name      : Setup_battle_event
  266.   #   Info      : Setup the battle events
  267.   #   Author    : Regashi
  268.   #   Call Info : No Arguments
  269.   #-----------------------------------------------------------------------------
  270.   def setup_battle_event
  271.     # If battle event is running
  272.     if $game_system.battle_interpreter.running?
  273.       return
  274.     end
  275.     # Search for all battle event pages
  276.     for index in 0...$data_troops[@troop_id].pages.size
  277.       # Get event pages
  278.       page = $data_troops[@troop_id].pages[index]
  279.       # Make event conditions possible for reference with c
  280.       c = page.condition
  281.       # Go to next page if no conditions are appointed
  282.       unless c.turn_valid or c.enemy_valid or
  283.              c.actor_valid or c.switch_valid
  284.         next
  285.       end
  286.       # Go to next page if action has been completed
  287.       if $game_temp.battle_event_flags[index]
  288.         next
  289.       end
  290.       # Confirm turn conditions
  291.       if c.turn_valid
  292.         n = $game_temp.battle_turn
  293.         a = c.turn_a
  294.         b = c.turn_b
  295.         if (b == 0 and n != a) or
  296.            (b > 0 and (n < 1 or n < a or n % b != a % b))
  297.           next
  298.         end
  299.       end
  300.       # Confirm enemy conditions
  301.       if c.enemy_valid
  302.         enemy = $game_troop.enemies[c.enemy_index]
  303.         if enemy == nil or enemy.hp * 100.0 / enemy.maxhp > c.enemy_hp
  304.           next
  305.         end
  306.       end
  307.       # Confirm actor conditions
  308.       if c.actor_valid
  309.         actor = $game_actors[c.actor_id]
  310.         if actor == nil or actor.hp * 100.0 / actor.maxhp > c.actor_hp
  311.           next
  312.         end
  313.       end
  314.       # Confirm switch conditions
  315.       if c.switch_valid
  316.         if $game_switches[c.switch_id] == false
  317.           next
  318.         end
  319.       end
  320.       # Set up event
  321.       $game_system.battle_interpreter.setup(page.list, 0)
  322.       # If this page span is [battle] or [turn]
  323.       if page.span <= 1
  324.         # Set action completed flag
  325.         $game_temp.battle_event_flags[index] = true
  326.       end
  327.       return
  328.     end
  329.   end
  330.   #-----------------------------------------------------------------------------
  331.   # * Name      : Update
  332.   #   Info      : Update the scene
  333.   #   Author    : Regashi
  334.   #   Call Info : No Arguments
  335.   #-----------------------------------------------------------------------------
  336.   def update
  337.      # If battle event is running
  338.     if $game_system.battle_interpreter.running?
  339.       # Update interpreter
  340.       $game_system.battle_interpreter.update
  341.       # If a battler which is forcing actions doesn't exist
  342.       if $game_temp.forcing_battler == nil
  343.         # If battle event has finished running
  344.         unless $game_system.battle_interpreter.running?
  345.           # Rerun battle event set up if battle continues
  346.           unless evaluate_battle
  347.             setup_battle_event
  348.           end
  349.         end
  350.         # If not after battle phase
  351.         if @phase != 5
  352.           # Refresh status window
  353.           @status_window.refresh
  354.         end
  355.       end
  356.     end
  357.     # Update system (timer) and screen
  358.     $game_system.update
  359.     $game_screen.update
  360.     # If timer has reached 0
  361.     if $game_system.timer_working and $game_system.timer == 0
  362.       # Abort battle
  363.       $game_temp.battle_abort = true
  364.     end
  365.     #updates windows
  366.     update_windows
  367.     # If transition is processing
  368.     if $game_temp.transition_processing
  369.       # Clear transition processing flag
  370.       $game_temp.transition_processing = false
  371.       # Execute transition
  372.       if $game_temp.transition_name == ""
  373.         Graphics.transition(20)
  374.       else
  375.         Graphics.transition(40, "Graphics/Transitions/" +
  376.           $game_temp.transition_name)
  377.       end
  378.     end
  379.     # If message window is showing
  380.     if $game_temp.message_window_showing
  381.       return
  382.     end
  383.     # If effect is showing
  384.     if @spriteset.effect?
  385.       return
  386.     end
  387.     # If game over
  388.     if $game_temp.gameover
  389.       # Switch to game over screen
  390.       $scene = Scene_Gameover.new
  391.       return
  392.     end
  393.     # If returning to title screen
  394.     if $game_temp.to_title
  395.       # Switch to title screen
  396.       $scene = Scene_Title.new
  397.       return
  398.     end
  399.     # If battle is aborted
  400.     if $game_temp.battle_abort
  401.       # Return to BGM used before battle started
  402.       $game_system.bgm_play($game_temp.map_bgm)
  403.       # Battle ends
  404.       battle_end(1)
  405.       return
  406.     end
  407.     # If waiting
  408.     if @wait_count > 0
  409.       # Decrease wait count
  410.       @wait_count -= 1
  411.       return
  412.     end
  413.     # If battler forcing an action doesn't exist,
  414.     # and battle event is running
  415.     if $game_temp.forcing_battler == nil and
  416.        $game_system.battle_interpreter.running?
  417.       return
  418.     end
  419.     # Branch according to phase
  420.     case @phase
  421.     when 1  # pre-battle phase
  422.      pre_battle_update
  423.     when 2  # party command phase
  424.      party_command_update
  425.     when 3  # actor command phase
  426.       actor_command_update
  427.     when 4  # main phase
  428.       battle_start_update
  429.     when 5  # after battle phase
  430.       after_battle_update
  431.     end
  432.   end
  433.   #-----------------------------------------------------------------------------
  434.   # * Name      : Pre_Battle
  435.   #   Old Name  : start_phase1
  436.   #   Info      : Clears actions and sets the battle phase
  437.   #   Author    : Regashi
  438.   #   Call Info : No Arguments
  439.   #-----------------------------------------------------------------------------
  440.   def pre_battle
  441.     # Shift to phase 1
  442.     @phase = 1
  443.     # Clear all party member actions
  444.     $game_party.clear_actions
  445.     # Set up battle event
  446.     setup_battle_event
  447.   end
  448.   #-----------------------------------------------------------------------------
  449.   # * Name      : Pre_battle_update
  450.   #   Old Name  : update_phase1
  451.   #   Info      : Begin actions before the battle starts.
  452.   #   Author    : Regashi
  453.   #   Call Info : No Arguments
  454.   #   Comments  : Select Fight or Escape
  455.   #-----------------------------------------------------------------------------
  456.   def pre_battle_update
  457.     if evaluate_battle
  458.       # If won or lost: end method
  459.       return
  460.     end
  461.     # Start party command phase
  462.     party_command
  463.   end
  464.   #-----------------------------------------------------------------------------
  465.   # * Name      : Party_command
  466.   #   Old Name  : start_phase2
  467.   #   Info      : Begin the party command window and options phase
  468.   #   Author    : Regashi
  469.   #   Call Info : No Arguments
  470.   #-----------------------------------------------------------------------------
  471.   def party_command
  472.     # Shift to phase 2
  473.     @phase = 2
  474.     # Set actor to non-selecting
  475.     @actor_index = -1
  476.     @active_battler = nil
  477.     # Enable party command window
  478.     @party_command_window.active = true
  479.     @party_command_window.visible = true
  480.     # Disable actor command window
  481.     @actor_command_window.active = false
  482.     @actor_command_window.visible = false
  483.     # Clear main phase flag
  484.     $game_temp.battle_main_phase = false
  485.     # Clear all party member actions
  486.     $game_party.clear_actions
  487.     # If impossible to input command
  488.     unless $game_party.inputable?
  489.       # Start main phase
  490.       battle_start
  491.     end
  492.   end
  493.   #-----------------------------------------------------------------------------
  494.   # * Name      : Party_command_update
  495.   #   Old Name  : update_phase2
  496.   #   Info      : Update the party command phase
  497.   #   Author    : Regashi
  498.   #   Call Info : No Arguments
  499.   #-----------------------------------------------------------------------------
  500.   def party_command_update
  501.     # If C button was pressed
  502.     if Input.trigger?(Input::C)
  503.       # Branch by party command window cursor position
  504.       case @party_command_window.index
  505.       when 0  # fight
  506.         # Play decision SE
  507.         $game_system.se_play($data_system.decision_se)
  508.         # Start actor command phase
  509.         actor_command
  510.       when 1  # escape
  511.         # If it's not possible to escape
  512.         if $game_temp.battle_can_escape == false
  513.           # Play buzzer SE
  514.           $game_system.se_play($data_system.buzzer_se)
  515.           return
  516.         end
  517.         # Play decision SE
  518.         $game_system.se_play($data_system.decision_se)
  519.         # Escape processing
  520.         party_command_update_escape
  521.       end
  522.       return
  523.     end
  524.   end
  525.   #-----------------------------------------------------------------------------
  526.   # * Name      : Party_command_update_escape
  527.   #   Old name  : update_phase2_escape
  528.   #   Info      : Begin events when escape is chosen
  529.   #   Author    : Regashi
  530.   #   Call Info : No Arguments
  531.   #-----------------------------------------------------------------------------
  532.   def party_command_update_escape
  533.    # Calculate enemy agility average
  534.     enemies_agi = 0
  535.     enemies_number = 0
  536.     for enemy in $game_troop.enemies
  537.       if enemy.exist?
  538.         enemies_agi += enemy.agi
  539.         enemies_number += 1
  540.       end
  541.     end
  542.     if enemies_number > 0
  543.       enemies_agi /= enemies_number
  544.     end
  545.     # Calculate actor agility average
  546.     actors_agi = 0
  547.     actors_number = 0
  548.     for actor in $game_party.actors
  549.       if actor.exist?
  550.         actors_agi += actor.agi
  551.         actors_number += 1
  552.       end
  553.     end
  554.     if actors_number > 0
  555.       actors_agi /= actors_number
  556.     end
  557.     # Determine if escape is successful
  558.     success = rand(100) < 50 * actors_agi / enemies_agi
  559.     # If escape is successful
  560.     if success
  561.       # Play escape SE
  562.       $game_system.se_play($data_system.escape_se)
  563.       # Return to BGM before battle started
  564.       $game_system.bgm_play($game_temp.map_bgm)
  565.       # Battle ends
  566.       battle_end(1)
  567.     # If escape is failure
  568.     else
  569.       # Clear all party member actions
  570.       $game_party.clear_actions
  571.       # Start main phase
  572.       battle_start
  573.     end
  574.   end
  575.   #-----------------------------------------------------------------------------
  576.   # * Name      : Actor_command
  577.   #   Old Name  : start_phase3
  578.   #   Info      : Begin the actor command phase
  579.   #   Author    : Regashi
  580.   #   Call Info : No Arguments
  581.   #-----------------------------------------------------------------------------
  582.   def actor_command
  583.     # Shift to phase 3
  584.     @phase = 3
  585.     # Set actor as unselectable
  586.     @actor_index = -1
  587.     @active_battler = nil
  588.     # Go to command input for next actor
  589.     next_actor_command
  590.   end
  591.   #-----------------------------------------------------------------------------
  592.   # * Name      : Next_actor_command
  593.   #   Old Name  : phase3_next_actor
  594.   #   Info      : Go to the command input for the next actor.
  595.   #   Author    : Regashi
  596.   #   Call Info : No Arguments
  597.   #-----------------------------------------------------------------------------
  598.   def next_actor_command
  599.     # Loop
  600.     begin
  601.       # Actor blink effect OFF
  602.       if @active_battler != nil
  603.         @active_battler.blink = false
  604.       end
  605.       # If last actor
  606.       if @actor_index == $game_party.actors.size-1
  607.         # Start main phase
  608.         battle_start
  609.         return
  610.       end
  611.       # Advance actor index
  612.       @actor_index += 1
  613.       @active_battler = $game_party.actors[@actor_index]
  614.       @active_battler.blink = true
  615.     # Once more if actor refuses command input
  616.     end until @active_battler.inputable?
  617.     # Set up actor command window
  618.     actor_command_window_setup
  619.   end
  620.   #-----------------------------------------------------------------------------
  621.   # * Name      : Previous_actor_command
  622.   #   Old Name  : phase3_prior_actor
  623.   #   Info      : Go to the command input for the previous actor.
  624.   #   Author    : Regashi
  625.   #   Call Info : No Arguments
  626.   #-----------------------------------------------------------------------------
  627.   def previous_actor_command
  628.     # Loop
  629.     begin
  630.       # Actor blink effect OFF
  631.       if @active_battler != nil
  632.         @active_battler.blink = false
  633.       end
  634.       # If first actor
  635.       if @actor_index == 0
  636.         # Start party command phase
  637.         party_command
  638.         return
  639.       end
  640.       # Return to actor index
  641.       @actor_index -= 1
  642.       @active_battler = $game_party.actors[@actor_index]
  643.       @active_battler.blink = true
  644.     # Once more if actor refuses command input
  645.     end until @active_battler.inputable?
  646.     # Set up actor command window
  647.     actor_command_window_setup
  648.   end
  649.   #-----------------------------------------------------------------------------
  650.   # * Name      : Actor_command_window_setup
  651.   #   Old Name  : phase3_setup_command_window
  652.   #   Info      : Setup the actor command window.
  653.   #   Author    : Regashi
  654.   #   Call Info : No Arguments
  655.   #-----------------------------------------------------------------------------
  656.   def actor_command_window_setup
  657.     # Disable party command window
  658.     @party_command_window.active = false
  659.     @party_command_window.visible = false
  660.     # Enable actor command window
  661.     @actor_command_window.active = true
  662.     @actor_command_window.visible = true
  663.     # Set actor command window position
  664.     @actor_command_window.x = @actor_index * 160
  665.     # Set index to 0
  666.     @actor_command_window.index = 0
  667.   end
  668.   #-----------------------------------------------------------------------------
  669.   # * Name      : Actor_command_update
  670.   #   Old Name  : update_phase3
  671.   #   Info      : Update the actor command phase
  672.   #   Author    : Regashi
  673.   #   Call Info : No Arguments
  674.   #-----------------------------------------------------------------------------
  675.   def actor_command_update
  676.     # If enemy arrow is enabled
  677.     if @enemy_arrow != nil
  678.       actor_command_enemy_select_update
  679.     # If actor arrow is enabled
  680.     elsif @actor_arrow != nil
  681.       actor_command_actor_select_update
  682.     # If skill window is enabled
  683.     elsif @skill_window != nil
  684.       actor_command_skill_update
  685.     # If item window is enabled
  686.     elsif @item_window != nil
  687.       actor_command_item_update
  688.     # If actor command window is enabled
  689.     elsif @actor_command_window.active
  690.       actor_command_basic_update
  691.     end
  692.   end
  693.   #-----------------------------------------------------------------------------
  694.   # * Name      : Actor_command_basic_update
  695.   #   Old Name  : update_phase3_basic_command
  696.   #   Info      : Determines the actor command selection.
  697.   #   Author    : Regashi
  698.   #   Call Info : No Arguments
  699.   #-----------------------------------------------------------------------------
  700.   def actor_command_basic_update
  701.     # If B button was pressed
  702.     if Input.trigger?(Input::B)
  703.       # Play cancel SE
  704.       $game_system.se_play($data_system.cancel_se)
  705.       # Go to command input for previous actor
  706.       Previous_actor_command
  707.       return
  708.     end
  709.     # If C button was pressed
  710.     if Input.trigger?(Input::C)
  711.       # Branch by actor command window cursor position
  712.       case @actor_command_window.index
  713.       when 0  # attack
  714.         # Play decision SE
  715.         $game_system.se_play($data_system.decision_se)
  716.         # Set action
  717.         @active_battler.current_action.kind = 0
  718.         @active_battler.current_action.basic = 0
  719.         # Start enemy selection
  720.         make_enemy_select_arrow
  721.       when 1  # skill
  722.         # Play decision SE
  723.         $game_system.se_play($data_system.decision_se)
  724.         # Set action
  725.         @active_battler.current_action.kind = 1
  726.         # Start skill selection
  727.         skill_select_start
  728.       when 2  # guard
  729.         # Play decision SE
  730.         $game_system.se_play($data_system.decision_se)
  731.         # Set action
  732.         @active_battler.current_action.kind = 0
  733.         @active_battler.current_action.basic = 1
  734.         # Go to command input for next actor
  735.         next_actor_command
  736.       when 3  # item
  737.         # Play decision SE
  738.         $game_system.se_play($data_system.decision_se)
  739.         # Set action
  740.         @active_battler.current_action.kind = 2
  741.         # Start item selection
  742.         item_select_start
  743.       end
  744.       return
  745.     end
  746.   end
  747.   #-----------------------------------------------------------------------------
  748.   # * Name      : Actor_command_skill_update
  749.   #   Old Name  : update_phase3_skill_select
  750.   #   Info      : Do events when skill is selected from the command window.
  751.   #   Author    : Regashi
  752.   #   Call Info : No Arguments
  753.   #-----------------------------------------------------------------------------
  754.   def actor_command_skill_update
  755.     # Make skill window visible
  756.     @skill_window.visible = true
  757.     # Update skill window
  758.     @skill_window.update
  759.     # If B button was pressed
  760.     if Input.trigger?(Input::B)
  761.       # Play cancel SE
  762.       $game_system.se_play($data_system.cancel_se)
  763.       # End skill selection
  764.       skill_select_end
  765.       return
  766.     end
  767.     # If C button was pressed
  768.     if Input.trigger?(Input::C)
  769.       # Get currently selected data on the skill window
  770.       @skill = @skill_window.skill
  771.       # If it can't be used
  772.       if @skill == nil or not @active_battler.skill_can_use?(@skill.id)
  773.         # Play buzzer SE
  774.         $game_system.se_play($data_system.buzzer_se)
  775.         return
  776.       end
  777.       # Play decision SE
  778.       $game_system.se_play($data_system.decision_se)
  779.       # Set action
  780.       @active_battler.current_action.skill_id = @skill.id
  781.       # Make skill window invisible
  782.       @skill_window.visible = false
  783.       # If effect scope is single enemy
  784.       if @skill.scope == 1
  785.         # Start enemy selection
  786.         make_enemy_select_arrow
  787.       # If effect scope is single ally
  788.       elsif @skill.scope == 3 or @skill.scope == 5
  789.         # Start actor selection
  790.         make_actor_select_arrow
  791.       # If effect scope is not single
  792.       else
  793.         # End skill selection
  794.         skill_select_end
  795.         # Go to command input for next actor
  796.         next_actor_command
  797.       end
  798.       return
  799.     end
  800.   end
  801.   #-----------------------------------------------------------------------------
  802.   # * Name      : Actor_command_item_update
  803.   #   Old Name  : update_phase3_item_select
  804.   #   Info      : Do events when item is selected from the command window
  805.   #   Author    : Regashi
  806.   #   Call Info : No Arguments
  807.   #-----------------------------------------------------------------------------
  808.   def actor_command_item_update
  809.     # Make item window visible
  810.     @item_window.visible = true
  811.     # Update item window
  812.     @item_window.update
  813.     # If B button was pressed
  814.     if Input.trigger?(Input::B)
  815.       # Play cancel SE
  816.       $game_system.se_play($data_system.cancel_se)
  817.       # End item selection
  818.       item_select_end
  819.       return
  820.     end
  821.     # If C button was pressed
  822.     if Input.trigger?(Input::C)
  823.       # Get currently selected data on the item window
  824.       @item = @item_window.item
  825.       # If it can't be used
  826.       unless $game_party.item_can_use?(@item.id)
  827.         # Play buzzer SE
  828.         $game_system.se_play($data_system.buzzer_se)
  829.         return
  830.       end
  831.       # Play decision SE
  832.       $game_system.se_play($data_system.decision_se)
  833.       # Set action
  834.       @active_battler.current_action.item_id = @item.id
  835.       # Make item window invisible
  836.       @item_window.visible = false
  837.       # If effect scope is single enemy
  838.       if @item.scope == 1
  839.         # Start enemy selection
  840.         make_enemy_select_arrow
  841.       # If effect scope is single ally
  842.       elsif @item.scope == 3 or @item.scope == 5
  843.         # Start actor selection
  844.         make_actor_select_arrow
  845.       # If effect scope is not single
  846.       else
  847.         # End item selection
  848.         item_select_end
  849.         # Go to command input for next actor
  850.         next_actor_command
  851.       end
  852.       return
  853.     end
  854.   end
  855.   #-----------------------------------------------------------------------------
  856.   # * Name      : Actor_command_enemy_select_update
  857.   #   Old Name  : update_phase3_enemy_select
  858.   #   Info      : Begin enemy selection.
  859.   #   Author    : Regashi
  860.   #   Call Info : No Arguments
  861.   #-----------------------------------------------------------------------------
  862.   def actor_command_enemy_select_update
  863.     # Update enemy arrow
  864.     @enemy_arrow.update
  865.     # If B button was pressed
  866.     if Input.trigger?(Input::B)
  867.       # Play cancel SE
  868.       $game_system.se_play($data_system.cancel_se)
  869.       # End enemy selection
  870.       dispose_enemy_select_arrow
  871.       return
  872.     end
  873.     # If C button was pressed
  874.     if Input.trigger?(Input::C)
  875.       # Play decision SE
  876.       $game_system.se_play($data_system.decision_se)
  877.       # Set action
  878.       @active_battler.current_action.target_index = @enemy_arrow.index
  879.       # End enemy selection
  880.       dispose_enemy_select_arrow
  881.       # If skill window is showing
  882.       if @skill_window != nil
  883.         # End skill selection
  884.         skill_select_end
  885.       end
  886.       # If item window is showing
  887.       if @item_window != nil
  888.         # End item selection
  889.         item_select_end
  890.       end
  891.       # Go to command input for next actor
  892.       next_actor_command
  893.     end
  894.   end
  895.   #-----------------------------------------------------------------------------
  896.   # * Name      : Actor_command_actor_select_update
  897.   #   Old Name  : update_phase3_actor_select
  898.   #   Info      : Begin actor selection.
  899.   #   Author    : Regashi
  900.   #   Call Info : No Arguments
  901.   #-----------------------------------------------------------------------------
  902.   def actor_command_actor_select_update
  903.     # Update actor arrow
  904.     @actor_arrow.update
  905.     # If B button was pressed
  906.     if Input.trigger?(Input::B)
  907.       # Play cancel SE
  908.       $game_system.se_play($data_system.cancel_se)
  909.       # End actor selection
  910.       dispose_actor_select_arrow
  911.       return
  912.     end
  913.     # If C button was pressed
  914.     if Input.trigger?(Input::C)
  915.       # Play decision SE
  916.       $game_system.se_play($data_system.decision_se)
  917.       # Set action
  918.       @active_battler.current_action.target_index = @actor_arrow.index
  919.       # End actor selection
  920.       dispose_actor_select_arrow
  921.       # If skill window is showing
  922.       if @skill_window != nil
  923.         # End skill selection
  924.         skill_select_end
  925.       end
  926.       # If item window is showing
  927.       if @item_window != nil
  928.         # End item selection
  929.         item_select_end
  930.       end
  931.       # Go to command input for next actor
  932.       next_actor_command
  933.     end
  934.   end
  935.   #-----------------------------------------------------------------------------
  936.   # * Name      : Make_enemy_select_arrow
  937.   #   Old Name  : start_enemy_select
  938.   #   Info      : Make the enemy selection arrow
  939.   #   Author    : Regashi
  940.   #   Call Info : No Arguments
  941.   #-----------------------------------------------------------------------------
  942.   def make_enemy_select_arrow
  943.      # Make enemy arrow
  944.     @enemy_arrow = Arrow_Enemy.new(@spriteset.viewport1)
  945.     # Associate help window
  946.     @enemy_arrow.help_window = @help_window
  947.     # Disable actor command window
  948.     @actor_command_window.active = false
  949.     @actor_command_window.visible = false
  950.   end
  951.   #-----------------------------------------------------------------------------
  952.   # * Name      : Dispose_enemy_select_arrow
  953.   #   Old Name  : end_enemy_select
  954.   #   Info      : Dispose of the enemy select arrow.
  955.   #   Author    : Regashi
  956.   #   Call Info : No Arguments
  957.   #-----------------------------------------------------------------------------
  958.   def dispose_enemy_select_arrow
  959.     # Dispose of enemy arrow
  960.     @enemy_arrow.dispose
  961.     @enemy_arrow = nil
  962.     # If command is [fight]
  963.     if @actor_command_window.index == 0
  964.       # Enable actor command window
  965.       @actor_command_window.active = true
  966.       @actor_command_window.visible = true
  967.       # Hide help window
  968.       @help_window.visible = false
  969.     end
  970.   end
  971.   #-----------------------------------------------------------------------------
  972.   # * Name      : Make_actor_select_arrow
  973.   #   Old Name  : start_actor_select
  974.   #   Info      : Make the actor select arrow.
  975.   #   Author    : Regashi
  976.   #   Call Info : No Arguments
  977.   #-----------------------------------------------------------------------------
  978.   def make_actor_select_arrow
  979.     # Make actor arrow
  980.     @actor_arrow = Arrow_Actor.new(@spriteset.viewport2)
  981.     @actor_arrow.index = @actor_index
  982.     # Associate help window
  983.     @actor_arrow.help_window = @help_window
  984.     # Disable actor command window
  985.     @actor_command_window.active = false
  986.     @actor_command_window.visible = false
  987.   end
  988.   #-----------------------------------------------------------------------------
  989.   # * Name      : Dispose_actor_select_arrow
  990.   #   Old Name  : end_actor_select
  991.   #   Info      : Dispose of the actor select arrow.
  992.   #   Author    : Regashi
  993.   #   Call Info : No Arguments
  994.   #-----------------------------------------------------------------------------
  995.   def dispose_actor_select_arrow
  996.     # Dispose of actor arrow
  997.     @actor_arrow.dispose
  998.     @actor_arrow = nil
  999.   end
  1000.   #-----------------------------------------------------------------------------
  1001.   # * Name      : Skill_select_start
  1002.   #   Old Name  : start_skill_select
  1003.   #   Info      : Start the Skill selection
  1004.   #   Author    : Regashi
  1005.   #   Call Info : No Arguments
  1006.   #-----------------------------------------------------------------------------
  1007.   def skill_select_start
  1008.     # Make skill window
  1009.     @skill_window = Window_Skill.new(@active_battler)
  1010.     # Associate help window
  1011.     @skill_window.help_window = @help_window
  1012.     # Disable actor command window
  1013.     @actor_command_window.active = false
  1014.     @actor_command_window.visible = false
  1015.   end
  1016.   #-----------------------------------------------------------------------------
  1017.   # * Name      : Skill_select_end
  1018.   #   Old Name  : end_skill_select
  1019.   #   Info      : End skill selection
  1020.   #   Author    : Regashi
  1021.   #   Call Info : No Arguments
  1022.   #-----------------------------------------------------------------------------
  1023.   def skill_select_end
  1024.     # Dispose of skill window
  1025.     @skill_window.dispose
  1026.     @skill_window = nil
  1027.     # Hide help window
  1028.     @help_window.visible = false
  1029.     # Enable actor command window
  1030.     @actor_command_window.active = true
  1031.     @actor_command_window.visible = true
  1032.   end
  1033.   #-----------------------------------------------------------------------------
  1034.   # * Name      : Item_select_start
  1035.   #   Old Name  : start_item_select
  1036.   #   Info      : Start item selection
  1037.   #   Author    : Regashi
  1038.   #   Call Info : No Arguments
  1039.   #-----------------------------------------------------------------------------
  1040.   def item_select_start
  1041.      # Make item window
  1042.     @item_window = Window_Item.new
  1043.     # Associate help window
  1044.     @item_window.help_window = @help_window
  1045.     # Disable actor command window
  1046.     @actor_command_window.active = false
  1047.     @actor_command_window.visible = false
  1048.   end
  1049.   #-----------------------------------------------------------------------------
  1050.   # * Name      : Item_select_end
  1051.   #   Old Name  : end_item_select
  1052.   #   Info      : End item selection
  1053.   #   Author    : Regashi
  1054.   #   Call Info : No Arguments
  1055.   #-----------------------------------------------------------------------------
  1056.   def item_select_end
  1057.     # Dispose of item window
  1058.     @item_window.dispose
  1059.     @item_window = nil
  1060.     # Hide help window
  1061.     @help_window.visible = false
  1062.     # Enable actor command window
  1063.     @actor_command_window.active = true
  1064.     @actor_command_window.visible = true
  1065.   end
  1066.   #-----------------------------------------------------------------------------
  1067.   # * Name      : Battle_start
  1068.   #   Old Name  : start_phase4
  1069.   #   Info      : Start the battle phase
  1070.   #   Author    : Regashi
  1071.   #   Call Info : No Arguments
  1072.   #-----------------------------------------------------------------------------
  1073.   def battle_start
  1074.     # Shift to phase 4
  1075.     @phase = 4
  1076.     # Turn count
  1077.     $game_temp.battle_turn += 1
  1078.     # Search all battle event pages
  1079.     for index in 0...$data_troops[@troop_id].pages.size
  1080.       # Get event page
  1081.       page = $data_troops[@troop_id].pages[index]
  1082.       # If this page span is [turn]
  1083.       if page.span == 1
  1084.         # Clear action completed flags
  1085.         $game_temp.battle_event_flags[index] = false
  1086.       end
  1087.     end
  1088.     # Set actor as unselectable
  1089.     @actor_index = -1
  1090.     @active_battler = nil
  1091.     # Enable party command window
  1092.     @party_command_window.active = false
  1093.     @party_command_window.visible = false
  1094.     # Disable actor command window
  1095.     @actor_command_window.active = false
  1096.     @actor_command_window.visible = false
  1097.     # Set main phase flag
  1098.     $game_temp.battle_main_phase = true
  1099.     # Make enemy action
  1100.     for enemy in $game_troop.enemies
  1101.       enemy.make_action
  1102.     end
  1103.     # Make action orders
  1104.     start_command_orders
  1105.     # Shift to step 1
  1106.     @phase4_step = 1
  1107.   end
  1108.   #-----------------------------------------------------------------------------
  1109.   # * Name      : Start_command_orders
  1110.   #   Old Name  : make_action_orders
  1111.   #   Info      : Make Action Orders
  1112.   #   Author    : v
  1113.   #   Call Info : No Arguments
  1114.   #-----------------------------------------------------------------------------
  1115.   def start_command_orders
  1116.     # Initialize @action_battlers array
  1117.     @action_battlers = []
  1118.     # Add enemy to @action_battlers array
  1119.     for enemy in $game_troop.enemies
  1120.       @action_battlers.push(enemy)
  1121.     end
  1122.     # Add actor to @action_battlers array
  1123.     for actor in $game_party.actors
  1124.       @action_battlers.push(actor)
  1125.     end
  1126.     # Decide action speed for all
  1127.     for battler in @action_battlers
  1128.       battler.make_action_speed
  1129.     end
  1130.     # Line up action speed in order from greatest to least
  1131.     @action_battlers.sort! {|a,b|
  1132.       b.current_action.speed - a.current_action.speed }
  1133.   end
  1134.   #-----------------------------------------------------------------------------
  1135.   # * Name      : Battle_start_update
  1136.   #   Old Name  : update_phase4
  1137.   #   Info      : Update the main battle phase
  1138.   #   Author    : Regashi
  1139.   #   Call Info : No Arguments
  1140.   #-----------------------------------------------------------------------------
  1141.   def battle_start_update
  1142.     case @phase4_step
  1143.     when 1
  1144.       battle_start_update_step1
  1145.     when 2
  1146.       battle_start_update_step2
  1147.     when 3
  1148.       battle_start_update_step3
  1149.     when 4
  1150.       battle_start_update_step4
  1151.     when 5
  1152.       battle_start_update_step5
  1153.     when 6
  1154.       battle_start_update_step6
  1155.     end
  1156.   end
  1157.   #-----------------------------------------------------------------------------
  1158.   # * Name      : Battle_start_update_step1
  1159.   #   Old Name  : update_phase4_step1
  1160.   #   Info      : Frame Update ( action preparation )
  1161.   #   Author    : Regashi
  1162.   #   Call Info : No Arguments
  1163.   #-----------------------------------------------------------------------------
  1164.   def battle_start_update_step1
  1165.      # Hide help window
  1166.     @help_window.visible = false
  1167.     # Determine win/loss
  1168.     if evaluate_battle
  1169.       # If won, or if lost : end method
  1170.       return
  1171.     end
  1172.     # If an action forcing battler doesn't exist
  1173.     if $game_temp.forcing_battler == nil
  1174.       # Set up battle event
  1175.       setup_battle_event
  1176.       # If battle event is running
  1177.       if $game_system.battle_interpreter.running?
  1178.         return
  1179.       end
  1180.     end
  1181.     # If an action forcing battler exists
  1182.     if $game_temp.forcing_battler != nil
  1183.       # Add to head, or move
  1184.       @action_battlers.delete($game_temp.forcing_battler)
  1185.       @action_battlers.unshift($game_temp.forcing_battler)
  1186.     end
  1187.     # If no actionless battlers exist (all have performed an action)
  1188.     if @action_battlers.size == 0
  1189.       # Start party command phase
  1190.       party_command
  1191.       return
  1192.     end
  1193.     # Initialize animation ID and common event ID
  1194.     @animation1_id = 0
  1195.     @animation2_id = 0
  1196.     @common_event_id = 0
  1197.     # Shift from head of actionless battlers
  1198.     @active_battler = @action_battlers.shift
  1199.     # If already removed from battle
  1200.     if @active_battler.index == nil
  1201.       return
  1202.     end
  1203.     # Slip damage
  1204.     if @active_battler.hp > 0 and @active_battler.slip_damage?
  1205.       @active_battler.slip_damage_effect
  1206.       @active_battler.damage_pop = true
  1207.     end
  1208.     # Natural removal of states
  1209.     @active_battler.remove_states_auto
  1210.     # Refresh status window
  1211.     @status_window.refresh
  1212.     # Shift to step 2
  1213.     @phase4_step = 2
  1214.   end
  1215.   #-----------------------------------------------------------------------------
  1216.   # * Name      : Battle_start_update_step2
  1217.   #   Old Name  : update_phase4_step2
  1218.   #   Info      : Frame Update ( start action )
  1219.   #   Author    : Regashi
  1220.   #   Call Info : No Arguments
  1221.   #-----------------------------------------------------------------------------
  1222.   def battle_start_update_step2
  1223.      # If not a forcing action
  1224.     unless @active_battler.current_action.forcing
  1225.       # If restriction is [normal attack enemy] or [normal attack ally]
  1226.       if @active_battler.restriction == 2 or @active_battler.restriction == 3
  1227.         # Set attack as an action
  1228.         @active_battler.current_action.kind = 0
  1229.         @active_battler.current_action.basic = 0
  1230.       end
  1231.       # If restriction is [cannot perform action]
  1232.       if @active_battler.restriction == 4
  1233.         # Clear battler being forced into action
  1234.         $game_temp.forcing_battler = nil
  1235.         # Shift to step 1
  1236.         @phase4_step = 1
  1237.         return
  1238.       end
  1239.     end
  1240.     # Clear target battlers
  1241.     @target_battlers = []
  1242.     # Branch according to each action
  1243.     case @active_battler.current_action.kind
  1244.     when 0  # basic
  1245.       command_orders_result
  1246.     when 1  # skill
  1247.       skill_action_result
  1248.     when 2  # item
  1249.       item_action_result
  1250.     end
  1251.     # Shift to step 3
  1252.     if @phase4_step == 2
  1253.       @phase4_step = 3
  1254.     end
  1255.   end
  1256.   #-----------------------------------------------------------------------------
  1257.   # * Name      : Command_orders_result
  1258.   #   Old Name  : make_basic_action_result
  1259.   #   Info      : Make Basic Action Results
  1260.   #   Author    : Regashi
  1261.   #   Call Info : No Arguments
  1262.   #-----------------------------------------------------------------------------
  1263.   def command_orders_result
  1264.     # If attack
  1265.     if @active_battler.current_action.basic == 0
  1266.       # Set anaimation ID
  1267.       @animation1_id = @active_battler.animation1_id
  1268.       @animation2_id = @active_battler.animation2_id
  1269.       # If action battler is enemy
  1270.       if @active_battler.is_a?(Game_Enemy)
  1271.         if @active_battler.restriction == 3
  1272.           target = $game_troop.random_target_enemy
  1273.         elsif @active_battler.restriction == 2
  1274.           target = $game_party.random_target_actor
  1275.         else
  1276.           index = @active_battler.current_action.target_index
  1277.           target = $game_party.smooth_target_actor(index)
  1278.         end
  1279.       end
  1280.       # If action battler is actor
  1281.       if @active_battler.is_a?(Game_Actor)
  1282.         if @active_battler.restriction == 3
  1283.           target = $game_party.random_target_actor
  1284.         elsif @active_battler.restriction == 2
  1285.           target = $game_troop.random_target_enemy
  1286.         else
  1287.           index = @active_battler.current_action.target_index
  1288.           target = $game_troop.smooth_target_enemy(index)
  1289.         end
  1290.       end
  1291.       # Set array of targeted battlers
  1292.       @target_battlers = [target]
  1293.       # Apply normal attack results
  1294.       for target in @target_battlers
  1295.         target.attack_effect(@active_battler)
  1296.       end
  1297.       return
  1298.     end
  1299.     # If guard
  1300.     if @active_battler.current_action.basic == 1
  1301.       # Display "Guard" in help window
  1302.       @help_window.set_text($data_system.words.guard, 1)
  1303.       return
  1304.     end
  1305.     # If escape
  1306.     if @active_battler.is_a?(Game_Enemy) and
  1307.        @active_battler.current_action.basic == 2
  1308.       # Display "Escape" in help window
  1309.       @help_window.set_text("Escape", 1)
  1310.       # Escape
  1311.       @active_battler.escape
  1312.       return
  1313.     end
  1314.     # If doing nothing
  1315.     if @active_battler.current_action.basic == 3
  1316.       # Clear battler being forced into action
  1317.       $game_temp.forcing_battler = nil
  1318.       # Shift to step 1
  1319.       @phase4_step = 1
  1320.       return
  1321.     end
  1322.   end
  1323.   #-----------------------------------------------------------------------------
  1324.   # * Name      : Set_target_battlers
  1325.   #   Old Name  : set_target_battlers
  1326.   #   Info      : Set Targeted Battler for Skill or Item
  1327.   #   Author    : Regashi
  1328.   #   Call Info :
  1329.   #       scope : effect scope for skill or item
  1330.   #-----------------------------------------------------------------------------
  1331.   def set_target_battlers(scope)
  1332.        # If battler performing action is enemy
  1333.     if @active_battler.is_a?(Game_Enemy)
  1334.       # Branch by effect scope
  1335.       case scope
  1336.       when 1  # single enemy
  1337.         index = @active_battler.current_action.target_index
  1338.         @target_battlers.push($game_party.smooth_target_actor(index))
  1339.       when 2  # all enemies
  1340.         for actor in $game_party.actors
  1341.           if actor.exist?
  1342.             @target_battlers.push(actor)
  1343.           end
  1344.         end
  1345.       when 3  # single ally
  1346.         index = @active_battler.current_action.target_index
  1347.         @target_battlers.push($game_troop.smooth_target_enemy(index))
  1348.       when 4  # all allies
  1349.         for enemy in $game_troop.enemies
  1350.           if enemy.exist?
  1351.             @target_battlers.push(enemy)
  1352.           end
  1353.         end
  1354.       when 5  # single ally (HP 0)
  1355.         index = @active_battler.current_action.target_index
  1356.         enemy = $game_troop.enemies[index]
  1357.         if enemy != nil and enemy.hp0?
  1358.           @target_battlers.push(enemy)
  1359.         end
  1360.       when 6  # all allies (HP 0)
  1361.         for enemy in $game_troop.enemies
  1362.           if enemy != nil and enemy.hp0?
  1363.             @target_battlers.push(enemy)
  1364.           end
  1365.         end
  1366.       when 7  # user
  1367.         @target_battlers.push(@active_battler)
  1368.       end
  1369.     end
  1370.     # If battler performing action is actor
  1371.     if @active_battler.is_a?(Game_Actor)
  1372.       # Branch by effect scope
  1373.       case scope
  1374.       when 1  # single enemy
  1375.         index = @active_battler.current_action.target_index
  1376.         @target_battlers.push($game_troop.smooth_target_enemy(index))
  1377.       when 2  # all enemies
  1378.         for enemy in $game_troop.enemies
  1379.           if enemy.exist?
  1380.             @target_battlers.push(enemy)
  1381.           end
  1382.         end
  1383.       when 3  # single ally
  1384.         index = @active_battler.current_action.target_index
  1385.         @target_battlers.push($game_party.smooth_target_actor(index))
  1386.       when 4  # all allies
  1387.         for actor in $game_party.actors
  1388.           if actor.exist?
  1389.             @target_battlers.push(actor)
  1390.           end
  1391.         end
  1392.       when 5  # single ally (HP 0)
  1393.         index = @active_battler.current_action.target_index
  1394.         actor = $game_party.actors[index]
  1395.         if actor != nil and actor.hp0?
  1396.           @target_battlers.push(actor)
  1397.         end
  1398.       when 6  # all allies (HP 0)
  1399.         for actor in $game_party.actors
  1400.           if actor != nil and actor.hp0?
  1401.             @target_battlers.push(actor)
  1402.           end
  1403.         end
  1404.       when 7  # user
  1405.         @target_battlers.push(@active_battler)
  1406.       end
  1407.     end
  1408.   end
  1409.   #-----------------------------------------------------------------------------
  1410.   # * Name      : Skill_action_result
  1411.   #   Old Name  : make_skill_action_result
  1412.   #   Info      : Make Skill Action Results
  1413.   #   Author    : Regashi
  1414.   #   Call Info : No Arguments
  1415.   #-----------------------------------------------------------------------------
  1416.   def skill_action_result
  1417.      # Get skill
  1418.     @skill = $data_skills[@active_battler.current_action.skill_id]
  1419.     # If not a forcing action
  1420.     unless @active_battler.current_action.forcing
  1421.       # If unable to use due to SP running out
  1422.       unless @active_battler.skill_can_use?(@skill.id)
  1423.         # Clear battler being forced into action
  1424.         $game_temp.forcing_battler = nil
  1425.         # Shift to step 1
  1426.         @phase4_step = 1
  1427.         return
  1428.       end
  1429.     end
  1430.     # Use up SP
  1431.     @active_battler.sp -= @skill.sp_cost
  1432.     # Refresh status window
  1433.     @status_window.refresh
  1434.     # Show skill name on help window
  1435.     @help_window.set_text(@skill.name, 1)
  1436.     # Set animation ID
  1437.     @animation1_id = @skill.animation1_id
  1438.     @animation2_id = @skill.animation2_id
  1439.     # Set command event ID
  1440.     @common_event_id = @skill.common_event_id
  1441.     # Set target battlers
  1442.     set_target_battlers(@skill.scope)
  1443.     # Apply skill effect
  1444.     for target in @target_battlers
  1445.       target.skill_effect(@active_battler, @skill)
  1446.     end
  1447.   end
  1448.   #-----------------------------------------------------------------------------
  1449.   # * Name      : Item_action_result
  1450.   #   Old Name  : make_item_action_result
  1451.   #   Info      : Make Item Action Results
  1452.   #   Author    : Regashi
  1453.   #   Call Info : No Arguments
  1454.   #-----------------------------------------------------------------------------
  1455.   def item_action_result
  1456.     # Get item
  1457.     @item = $data_items[@active_battler.current_action.item_id]
  1458.     # If unable to use due to items running out
  1459.     unless $game_party.item_can_use?(@item.id)
  1460.       # Shift to step 1
  1461.       @phase4_step = 1
  1462.       return
  1463.     end
  1464.     # If consumable
  1465.     if @item.consumable
  1466.       # Decrease used item by 1
  1467.       $game_party.lose_item(@item.id, 1)
  1468.     end
  1469.     # Display item name on help window
  1470.     @help_window.set_text(@item.name, 1)
  1471.     # Set animation ID
  1472.     @animation1_id = @item.animation1_id
  1473.     @animation2_id = @item.animation2_id
  1474.     # Set common event ID
  1475.     @common_event_id = @item.common_event_id
  1476.     # Decide on target
  1477.     index = @active_battler.current_action.target_index
  1478.     target = $game_party.smooth_target_actor(index)
  1479.     # Set targeted battlers
  1480.     set_target_battlers(@item.scope)
  1481.     # Apply item effect
  1482.     for target in @target_battlers
  1483.       target.item_effect(@item)
  1484.     end
  1485.   end
  1486.   #-----------------------------------------------------------------------------
  1487.   # * Name      : Battle_start_update_step3
  1488.   #   Old Name  : update_phase4_step3
  1489.   #   Info      : Frame Update ( animation for action performer )
  1490.   #   Author    : Regashi
  1491.   #   Call Info : No Arguments
  1492.   #-----------------------------------------------------------------------------
  1493.   def battle_start_update_step3
  1494.     # Animation for action performer (if ID is 0, then white flash)
  1495.     if @animation1_id == 0
  1496.       @active_battler.white_flash = true
  1497.     else
  1498.       @active_battler.animation_id = @animation1_id
  1499.       @active_battler.animation_hit = true
  1500.     end
  1501.     # Shift to step 4
  1502.     @phase4_step = 4
  1503.   end
  1504.   #-----------------------------------------------------------------------------
  1505.   # * Name      : Battle_start_update_step4
  1506.   #   Old Name  : update_phase4_step4
  1507.   #   Info      : Frame Update ( animation for target )
  1508.   #   Author    : Regashi
  1509.   #   Call Info : No Arguments
  1510.   #-----------------------------------------------------------------------------
  1511.   def battle_start_update_step4
  1512.      # Animation for target
  1513.     for target in @target_battlers
  1514.       target.animation_id = @animation2_id
  1515.       target.animation_hit = (target.damage != "Miss")
  1516.     end
  1517.     # Animation has at least 8 frames, regardless of its length
  1518.     @wait_count = 8
  1519.     # Shift to step 5
  1520.     @phase4_step = 5
  1521.   end
  1522.   #-----------------------------------------------------------------------------
  1523.   # * Name      : Battle_start_update_step5
  1524.   #   Old Name  : update_phase4_step5
  1525.   #   Info      : Frame Update ( damage display )
  1526.   #   Author    : Regashi
  1527.   #   Call Info : No Arguments
  1528.   #-----------------------------------------------------------------------------
  1529.   def battle_start_update_step5
  1530.     # Hide help window
  1531.     @help_window.visible = false
  1532.     # Refresh status window
  1533.     @status_window.refresh
  1534.     # Display damage
  1535.     for target in @target_battlers
  1536.       if target.damage != nil
  1537.         target.damage_pop = true
  1538.       end
  1539.     end
  1540.     # Shift to step 6
  1541.     @phase4_step = 6
  1542.   end
  1543.   #-----------------------------------------------------------------------------
  1544.   # * Name      : Battle_start_update_step6
  1545.   #   Old Name  : update_phase4_step6
  1546.   #   Info      : Frame Update ( refresh )
  1547.   #   Author    : Regashi
  1548.   #   Call Info : No Arguments
  1549.   #-----------------------------------------------------------------------------
  1550.   def battle_start_update_step6
  1551.      # Clear battler being forced into action
  1552.     $game_temp.forcing_battler = nil
  1553.     # If common event ID is valid
  1554.     if @common_event_id > 0
  1555.       # Set up event
  1556.       common_event = $data_common_events[@common_event_id]
  1557.       $game_system.battle_interpreter.setup(common_event.list, 0)
  1558.     end
  1559.     # Shift to step 1
  1560.     @phase4_step = 1
  1561.   end
  1562.   #-----------------------------------------------------------------------------
  1563.   # * Name      : After_battle
  1564.   #   Old Name  : start_phase5
  1565.   #   Info      : Do events after battle has finished.
  1566.   #   Author    : Regashi
  1567.   #   Call Info : No Arguments
  1568.   #-----------------------------------------------------------------------------
  1569.   def after_battle
  1570.     # Shift to phase 5
  1571.     @phase = 5
  1572.     # Play battle end ME
  1573.     $game_system.me_play($game_system.battle_end_me)
  1574.     # Return to BGM before battle started
  1575.     $game_system.bgm_play($game_temp.map_bgm)
  1576.     # Initialize EXP, amount of gold, and treasure
  1577.     exp = 0
  1578.     gold = 0
  1579.     treasures = []
  1580.     # Loop
  1581.     for enemy in $game_troop.enemies
  1582.       # If enemy is not hidden
  1583.       unless enemy.hidden
  1584.         # Add EXP and amount of gold obtained
  1585.         exp += enemy.exp
  1586.         gold += enemy.gold
  1587.         # Determine if treasure appears
  1588.         if rand(100) < enemy.treasure_prob
  1589.           if enemy.item_id > 0
  1590.             treasures.push($data_items[enemy.item_id])
  1591.           end
  1592.           if enemy.weapon_id > 0
  1593.             treasures.push($data_weapons[enemy.weapon_id])
  1594.           end
  1595.           if enemy.armor_id > 0
  1596.             treasures.push($data_armors[enemy.armor_id])
  1597.           end
  1598.         end
  1599.       end
  1600.     end
  1601.     # Treasure is limited to a maximum of 6 items
  1602.     treasures = treasures[0..5]
  1603.     # Obtaining EXP
  1604.     for i in 0...$game_party.actors.size
  1605.       actor = $game_party.actors[i]
  1606.       if actor.cant_get_exp? == false
  1607.         last_level = actor.level
  1608.         actor.exp += exp
  1609.         if actor.level > last_level
  1610.           @status_window.level_up(i)
  1611.         end
  1612.       end
  1613.     end
  1614.     # Obtaining gold
  1615.     $game_party.gain_gold(gold)
  1616.     # Obtaining treasure
  1617.     for item in treasures
  1618.       case item
  1619.       when RPG::Item
  1620.         $game_party.gain_item(item.id, 1)
  1621.       when RPG::Weapon
  1622.         $game_party.gain_weapon(item.id, 1)
  1623.       when RPG::Armor
  1624.         $game_party.gain_armor(item.id, 1)
  1625.       end
  1626.     end
  1627.     # Make battle result window
  1628.     @result_window = Window_BattleResult.new(exp, gold, treasures)
  1629.     # Set wait count
  1630.     @phase5_wait_count = 100
  1631.   end
  1632.   #-----------------------------------------------------------------------------
  1633.   # * Name      : After_battle_update
  1634.   #   Old Name  : update_phase5
  1635.   #   Info      : update the after_battle phase
  1636.   #   Author    : Regashi
  1637.   #   Call Info : No Arguments
  1638.   #-----------------------------------------------------------------------------
  1639.   def after_battle_update
  1640.     # If wait count is larger than 0
  1641.     if @phase5_wait_count > 0
  1642.       # Decrease wait count
  1643.       @phase5_wait_count -= 1
  1644.       # If wait count reaches 0
  1645.       if @phase5_wait_count == 0
  1646.         # Show result window
  1647.         @result_window.visible = true
  1648.         # Clear main phase flag
  1649.         $game_temp.battle_main_phase = false
  1650.         # Refresh status window
  1651.         @status_window.refresh
  1652.       end
  1653.       return
  1654.     end
  1655.     # If C button was pressed
  1656.     if Input.trigger?(Input::C)
  1657.       # Battle ends
  1658.       battle_end(0)
  1659.     end
  1660.   end
  1661. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement