daily pastebin goal
28%
SHARE
TWEET

One Player Battle System (Tigerus Fay)

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