Guest User

Untitled

a guest
Jan 4th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 45.11 KB | None | 0 0
  1. #==============================================================================
  2. # ** Scene_Battle
  3. #------------------------------------------------------------------------------
  4. #  This class performs battle screen processing.
  5. #==============================================================================
  6.  
  7. class Scene_Battle < Scene_Base
  8.   #--------------------------------------------------------------------------
  9.   # * Start processing
  10.   #--------------------------------------------------------------------------
  11.   def start
  12.     super
  13.     $game_temp.in_battle = true
  14.     @spriteset = Spriteset_Battle.new
  15.     @message_window = Window_BattleMessage.new
  16.     @action_battlers = []
  17.     @enemy_window = Window_EnemyHP.new
  18.     @enemy_window.z = 95    
  19.     create_info_viewport
  20.   end
  21.   #--------------------------------------------------------------------------
  22.   # * Post-Start Processing
  23.   #--------------------------------------------------------------------------
  24.   def post_start
  25.     super
  26.     process_battle_start
  27.   end
  28.   #--------------------------------------------------------------------------
  29.   # * Termination Processing
  30.   #--------------------------------------------------------------------------
  31.   def terminate
  32.     super
  33.     dispose_info_viewport
  34.     @message_window.dispose
  35.     @enemy_window.dispose
  36.     @spriteset.dispose
  37.     unless $scene.is_a?(Scene_Gameover)
  38.       $scene = nil if $BTEST
  39.     end
  40.   end
  41.   #--------------------------------------------------------------------------
  42.   # * Basic Update Processing
  43.   #     main : Call from main update method
  44.   #--------------------------------------------------------------------------
  45.   def update_basic(main = false)
  46.     Graphics.update unless main     # Update game screen
  47.     Input.update unless main        # Update input information
  48.     $game_system.update             # Update timer
  49.     $game_troop.update              # Update enemy group
  50.     @spriteset.update               # Update sprite set
  51.     @message_window.update          # Update message window
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # * Wait a set amount of time
  55.   #     duration : Wait time (number of frames)
  56.   #     no_fast  : Fast forward disabled
  57.   #    A method for inserting a wait during scene class update processing.
  58.   #    As a rule, update is called once for each frame, but during battle it
  59.   #    can be difficult to grasp the processing flow, so this method is used#
  60.   #    as an exception.
  61.   #--------------------------------------------------------------------------
  62.   def wait(duration, no_fast = false)
  63.     for i in 0...duration
  64.       update_basic
  65.       break if not no_fast and i >= duration / 2 and show_fast?
  66.     end
  67.   end
  68.   #--------------------------------------------------------------------------
  69.   # * Wait Until Message Display has Finished
  70.   #--------------------------------------------------------------------------
  71.   def wait_for_message
  72.     @message_window.update
  73.     while $game_message.visible
  74.       update_basic
  75.     end
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # * Wait Until Animation Display has Finished
  79.   #--------------------------------------------------------------------------
  80.   def wait_for_animation
  81.     while @spriteset.animation?
  82.       update_basic
  83.     end
  84.   end
  85.   #--------------------------------------------------------------------------
  86.   # * Determine Fast Forward
  87.   #--------------------------------------------------------------------------
  88.   def show_fast?
  89.     return (Input.press?(Input::A) or Input.press?(Input::C))
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # * Frame Update
  93.   #--------------------------------------------------------------------------
  94.   def update
  95.     super
  96.     update_basic(true)
  97.     update_info_viewport                  # Update information viewport
  98.     @enemy_window.refresh unless @enemy_window == nil
  99.     if $game_message.visible
  100.       @info_viewport.visible = false
  101.       @filth_viewport.visible = false
  102.       @message_window.visible = true
  103.     end
  104.     unless $game_message.visible          # Unless displaying a message
  105.       return if judge_win_loss            # Determine win/loss results
  106.       update_scene_change
  107.       if @target_enemy_window != nil
  108.         update_target_enemy_selection     # Select target enemy
  109.       elsif @target_actor_window != nil
  110.         update_target_actor_selection     # Select target actor
  111.       elsif @skill_window != nil
  112.         update_skill_selection            # Select skill
  113.       elsif @item_window != nil
  114.         update_item_selection             # Select item
  115.       elsif @equip_window != nil          # UPDATE EQUIP
  116.         update_item_windows
  117.         if @equip_window.active
  118.           update_equip_selection            
  119.         elsif @equipitem_window.active
  120.           update_equipitem_selection
  121.         end        
  122.       elsif @party_command_window.active
  123.         update_party_command_selection    # Select party command
  124.       elsif @actor_command_window.active
  125.         update_actor_command_selection    # Select actor command
  126.       else
  127.         process_battle_event              # Battle event processing
  128.         process_action                    # Battle action
  129.         process_battle_event              # Battle event processing
  130.       end
  131.     end
  132.   end
  133.   #--------------------------------------------------------------------------
  134.   # * Create Information Display Viewport
  135.   #--------------------------------------------------------------------------
  136.   def create_info_viewport
  137.     @filth_viewport = Viewport.new(0, 0, 544, 128)
  138.     @filth_viewport.z = 99
  139.     @filth_viewport.visible = false    
  140.    
  141.     @info_viewport = Viewport.new(0, 288, 544, 128)
  142.     @info_viewport.z = 100
  143.     @status_window = Window_BattleStatus.new
  144.     @party_command_window = Window_PartyCommand.new
  145.     @actor_command_window = Window_ActorCommand.new
  146.     @status_window.viewport = @info_viewport
  147.     @party_command_window.viewport = @info_viewport
  148.     @actor_command_window.viewport = @info_viewport
  149.     @status_window.x = 128
  150.     @actor_command_window.x = 544
  151.     @info_viewport.visible = false
  152.   end
  153.   #--------------------------------------------------------------------------
  154.   # * Dispose of Information Display Viewport
  155.   #--------------------------------------------------------------------------
  156.   def dispose_info_viewport
  157.     @status_window.dispose
  158.     @party_command_window.dispose
  159.     @actor_command_window.dispose
  160.     @info_viewport.dispose
  161.     @filth_viewport.dispose
  162.   end
  163.   #--------------------------------------------------------------------------
  164.   # * Update Information Display Viewport
  165.   #--------------------------------------------------------------------------
  166.   def update_info_viewport
  167.     @party_command_window.update
  168.     @actor_command_window.update
  169.     @status_window.update
  170.     if @party_command_window.active and @info_viewport.ox > 0
  171.       @info_viewport.ox -= 16
  172.     elsif @actor_command_window.active and @info_viewport.ox < 128
  173.       @info_viewport.ox += 16
  174.     end
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # * Battle Event Processing
  178.   #--------------------------------------------------------------------------
  179.   def process_battle_event
  180.     loop do
  181.       return if judge_win_loss
  182.       return if $game_temp.next_scene != nil
  183.       $game_troop.interpreter.update
  184.       $game_troop.setup_battle_event
  185.       wait_for_message
  186.       process_action if $game_troop.forcing_battler != nil
  187.       return unless $game_troop.interpreter.running?
  188.       update_basic
  189.     end
  190.   end
  191.   #--------------------------------------------------------------------------
  192.   # * Determine Win/Loss Results
  193.   #--------------------------------------------------------------------------
  194.   def judge_win_loss
  195.     if $game_temp.in_battle
  196.       if $game_party.all_dead?
  197.         process_defeat
  198.         return true
  199.       elsif $game_troop.all_dead?
  200.         @enemy_window.visible = false
  201.         process_victory
  202.         return true
  203.       else
  204.         return false
  205.       end
  206.     else
  207.       return true
  208.     end
  209.   end
  210.   #--------------------------------------------------------------------------
  211.   # * End Battle
  212.   #     result : Results (0: win, 1: escape, 2:lose)
  213.   #--------------------------------------------------------------------------
  214.   def battle_end(result)
  215.     if result == 2 and not $game_troop.can_lose
  216.       call_gameover
  217.     else
  218.       $game_party.clear_actions
  219.       $game_party.remove_states_battle
  220.       $game_troop.clear
  221.       if $game_temp.battle_proc != nil
  222.         $game_temp.battle_proc.call(result)
  223.         $game_temp.battle_proc = nil
  224.       end
  225.       unless $BTEST
  226.         $game_temp.map_bgm.play
  227.         $game_temp.map_bgs.play
  228.       end
  229.       $scene = Scene_Map.new
  230.       @message_window.clear
  231.       Graphics.fadeout(30)
  232.     end
  233.     $game_temp.in_battle = false
  234.   end
  235.   #--------------------------------------------------------------------------
  236.   # * Go to Command Input for Next Actor
  237.   #--------------------------------------------------------------------------
  238.   def next_actor
  239.     loop do
  240.       if @actor_index == $game_party.members.size-1
  241.         start_main
  242.         return
  243.       end
  244.       @status_window.index = @actor_index += 1
  245.       @active_battler = $game_party.members[@actor_index]
  246.       if @active_battler.auto_battle
  247.         @active_battler.make_action
  248.         next
  249.       end
  250.       break if @active_battler.inputable?
  251.     end
  252.     start_actor_command_selection
  253.   end
  254.   #--------------------------------------------------------------------------
  255.   # * Go to Command Input of Previous Actor
  256.   #--------------------------------------------------------------------------
  257.   def prior_actor
  258.     loop do
  259.       if @actor_index == 0
  260.         start_party_command_selection
  261.         return
  262.       end
  263.       @status_window.index = @actor_index -= 1
  264.       @active_battler = $game_party.members[@actor_index]
  265.       next if @active_battler.auto_battle
  266.       break if @active_battler.inputable?
  267.     end
  268.     start_actor_command_selection
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # * Start party command selection
  272.   #--------------------------------------------------------------------------
  273.   def start_party_command_selection
  274.     if $game_temp.in_battle
  275.       @status_window.refresh
  276.       @status_window.index = @actor_index = -1
  277.       @active_battler = nil
  278.       @info_viewport.visible = true
  279.       @filth_viewport.visible = true
  280.       @message_window.visible = false
  281.       @party_command_window.active = true
  282.       @party_command_window.index = 0
  283.       @actor_command_window.active = false
  284.       $game_party.clear_actions
  285.       if $game_troop.surprise or not $game_party.inputable?
  286.         start_main
  287.       end
  288.     end
  289.   end
  290.   #--------------------------------------------------------------------------
  291.   # * Update Party Command Selection
  292.   #--------------------------------------------------------------------------
  293.   def update_party_command_selection
  294.     if Input.trigger?(Input::C)
  295.       case @party_command_window.index
  296.       when 0  # Fight
  297.         Sound.play_decision
  298.         @status_window.index = @actor_index = -1
  299.         next_actor
  300.       when 1  # Escape
  301.         if $game_troop.can_escape == false
  302.           Sound.play_buzzer
  303.           return
  304.         end
  305.         Sound.play_decision
  306.         process_escape
  307.       end
  308.     end
  309.   end
  310.   #--------------------------------------------------------------------------
  311.   # * Start Actor Command Selection
  312.   #--------------------------------------------------------------------------
  313.   def start_actor_command_selection
  314.     @party_command_window.active = false
  315.     @actor_command_window.setup(@active_battler)
  316.     @actor_command_window.active = true
  317.     @actor_command_window.index = 0
  318.   end
  319.   #--------------------------------------------------------------------------
  320.   # * Update Actor Command Selection
  321.   #--------------------------------------------------------------------------
  322.   def update_actor_command_selection
  323.     if Input.trigger?(Input::B)
  324.       Sound.play_cancel
  325.       prior_actor
  326.     elsif Input.trigger?(Input::C)
  327.       case @actor_command_window.index
  328.       when 0  # Attack
  329.         Sound.play_decision
  330.         @active_battler.action.set_attack
  331.         start_target_enemy_selection
  332.       when 1  # Skill
  333.         Sound.play_decision
  334.         start_skill_selection
  335.       when 2  # Guard
  336.         Sound.play_decision
  337.         @active_battler.action.set_guard
  338.         next_actor
  339.       when 3  # Item
  340.         Sound.play_decision
  341.         start_item_selection
  342. #      when 4  # Equip Was this added? I'm not sure. RYE
  343. #        Sound.play_decision
  344. #        start_equip_selection
  345.       end
  346.     end
  347.   end
  348.   #--------------------------------------------------------------------------
  349.   # * Start Target Enemy Selection
  350.   #--------------------------------------------------------------------------
  351.   def start_target_enemy_selection
  352.     @target_enemy_window = Window_TargetEnemy.new
  353.     @target_enemy_window.y = 640 #@info_viewport.rect.y
  354.     #@target_enemy_window.y = @filth_viewport.rect.y
  355.     #@target_enemy_window.opacity = 0
  356.     #@target_enemy_window.back_opacity = 0    
  357.     @info_viewport.rect.x += @info_viewport.width
  358.     @info_viewport.ox += @target_enemy_window.width
  359.     #@filth_viewport.rect.x += @filth_viewport.width
  360.     #@filth_viewport.ox += @target_enemy_window.width
  361.     @actor_command_window.active = false
  362.   end
  363.  
  364.   #--------------------------------------------------------------------------
  365.   # * Start Target Enemy Selection
  366.   #--------------------------------------------------------------------------
  367.   def start_target_enemy_selection
  368.     @target_enemy_window = Window_TargetEnemy.new
  369.     @target_enemy_window.y = 640#@info_viewport.rect.y
  370.     @info_viewport.rect.x += @target_enemy_window.width
  371.     @info_viewport.ox += @target_enemy_window.width
  372.     @actor_command_window.active = false
  373.   end  
  374.  
  375.   #--------------------------------------------------------------------------
  376.   # * End Target Enemy Selection
  377.   #--------------------------------------------------------------------------
  378.   def end_target_enemy_selection    
  379.     @info_viewport.rect.x -= @target_enemy_window.width
  380.     @info_viewport.ox -= @target_enemy_window.width
  381.     @target_enemy_window.dispose
  382.     @target_enemy_window = nil
  383.     if @actor_command_window.index == 0
  384.       @actor_command_window.active = true
  385.     end
  386.   end
  387.   #--------------------------------------------------------------------------
  388.   # * Update Target Enemy Selection
  389.   #--------------------------------------------------------------------------
  390.   def update_target_enemy_selection
  391.     @target_enemy_window.update
  392.     if Input.trigger?(Input::B)
  393.       Sound.play_cancel
  394.       end_target_enemy_selection
  395.       @skill_window.visible = true if @skill_window != nil
  396.       @item_window.visible = true if @item_window != nil
  397.     elsif Input.trigger?(Input::C)
  398.       Sound.play_decision
  399.       @active_battler.action.target_index = @target_enemy_window.enemy.index
  400.       end_target_enemy_selection
  401.       end_skill_selection
  402.       end_item_selection
  403.       next_actor
  404.     end
  405.     if @target_enemy_window != nil
  406.       if @target_enemy_window.type == 1
  407.         for bob in $game_troop.group[@target_enemy_window.enemy_name]
  408.           bob.white_flash = true unless bob.dead?      
  409.         end
  410.       else
  411.         @target_enemy_window.enemy.white_flash = true
  412.       end
  413.     end    
  414.   end
  415.   #--------------------------------------------------------------------------
  416.   # * Start Target Actor Selection
  417.   #--------------------------------------------------------------------------
  418.   def start_target_actor_selection
  419.     @target_actor_window = Window_BattleStatus.new
  420.     @target_actor_window.index = 0
  421.     @target_actor_window.active = true
  422.     @target_actor_window.y = @info_viewport.rect.y
  423.     @info_viewport.rect.x += @target_actor_window.width
  424.     @info_viewport.ox += @target_actor_window.width
  425.     @actor_command_window.active = false
  426.   end
  427.   #--------------------------------------------------------------------------
  428.   # * End Target Actor Selection
  429.   #--------------------------------------------------------------------------
  430.   def end_target_actor_selection
  431.     @info_viewport.rect.x -= @target_actor_window.width
  432.     @info_viewport.ox -= @target_actor_window.width
  433.     @target_actor_window.dispose
  434.     @target_actor_window = nil
  435.   end
  436.   #--------------------------------------------------------------------------
  437.   # * Update Target Actor Selection
  438.   #--------------------------------------------------------------------------
  439.   def update_target_actor_selection
  440.     @target_actor_window.update
  441.     if Input.trigger?(Input::B)
  442.       Sound.play_cancel
  443.       end_target_actor_selection
  444.     elsif Input.trigger?(Input::C)
  445.       Sound.play_decision
  446.       @active_battler.action.target_index = @target_actor_window.index
  447.       end_target_actor_selection
  448.       end_skill_selection
  449.       end_item_selection
  450.       next_actor
  451.     end
  452.   end
  453.   #--------------------------------------------------------------------------
  454.   # * Start Skill Selection
  455.   #--------------------------------------------------------------------------
  456.   def start_skill_selection
  457.     @help_window = Window_Help.new
  458.     @skill_window = Window_Skill.new(0, 56, 544, 232, @active_battler)
  459.     @skill_window.help_window = @help_window
  460.     @actor_command_window.active = false
  461.   end
  462.   #--------------------------------------------------------------------------
  463.   # * End Skill Selection
  464.   #--------------------------------------------------------------------------
  465.   def end_skill_selection
  466.     if @skill_window != nil
  467.       @skill_window.dispose
  468.       @skill_window = nil
  469.       @help_window.dispose
  470.       @help_window = nil
  471.     end
  472.     @actor_command_window.active = true
  473.   end
  474.   #--------------------------------------------------------------------------
  475.   # * Update Skill Selection
  476.   #--------------------------------------------------------------------------
  477.   def update_skill_selection
  478.     @skill_window.active = true
  479.     @skill_window.update
  480.     @help_window.update
  481.     if Input.trigger?(Input::B)
  482.       Sound.play_cancel
  483.       end_skill_selection
  484.     elsif Input.trigger?(Input::C)
  485.       @skill = @skill_window.skill
  486.       if @skill != nil
  487.         @active_battler.last_skill_id = @skill.id
  488.       end
  489.       if @active_battler.skill_can_use?(@skill)
  490.         Sound.play_decision
  491.         determine_skill
  492.       else
  493.         Sound.play_buzzer
  494.       end
  495.     end
  496.   end
  497.   #--------------------------------------------------------------------------
  498.   # * Confirm Skill
  499.   #--------------------------------------------------------------------------
  500.   def determine_skill
  501.     @active_battler.action.set_skill(@skill.id)
  502.     @skill_window.active = false
  503.     if @skill.need_selection?
  504.       if @skill.for_opponent?
  505.         @skill_window.visible = false
  506.         start_target_enemy_selection
  507.       else
  508.         start_target_actor_selection
  509.       end
  510.     else
  511.       end_skill_selection
  512.       next_actor
  513.     end
  514.   end
  515.   #--------------------------------------------------------------------------
  516.   # * Start Item Selection
  517.   #--------------------------------------------------------------------------
  518.   def start_item_selection
  519.     @help_window = Window_Help.new
  520.     @item_window = Window_Item.new(0, 56, 544, 232)
  521.     @item_window.help_window = @help_window
  522.     @actor_command_window.active = false
  523.   end
  524.   #--------------------------------------------------------------------------
  525.   # * End Item Selection
  526.   #--------------------------------------------------------------------------
  527.   def end_item_selection
  528.     if @item_window != nil
  529.       @item_window.dispose
  530.       @item_window = nil
  531.       @help_window.dispose
  532.       @help_window = nil
  533.     end
  534.     @actor_command_window.active = true
  535.   end
  536.   #--------------------------------------------------------------------------
  537.   # * Update Item Selection
  538.   #--------------------------------------------------------------------------
  539.   def update_item_selection
  540.     @item_window.active = true
  541.     @item_window.update
  542.     @help_window.update
  543.     if Input.trigger?(Input::B)
  544.       Sound.play_cancel
  545.       end_item_selection
  546.     elsif Input.trigger?(Input::C)
  547.       @item = @item_window.item
  548.       if @item != nil
  549.         $game_party.last_item_id = @item.id
  550.       end
  551.       if $game_party.item_can_use?(@item)
  552.         Sound.play_decision
  553.         determine_item
  554.       else
  555.         Sound.play_buzzer
  556.       end
  557.     end
  558.   end
  559.   #--------------------------------------------------------------------------
  560.   # * Confirm Item
  561.   #--------------------------------------------------------------------------
  562.   def determine_item
  563.     @active_battler.action.set_item(@item.id)
  564.     @item_window.visible = false
  565.     @item_window.active = false
  566.     if @item.need_selection?
  567.       if @item.for_opponent?
  568.         start_target_enemy_selection
  569.       else
  570.         start_target_actor_selection
  571.       end
  572.     else
  573.       end_item_selection
  574.       next_actor
  575.     end
  576.   end
  577.   #--------------------------------------------------------------------------
  578.   # * Battle Start Processing
  579.   #--------------------------------------------------------------------------
  580.   def process_battle_start
  581.     @message_window.clear
  582.     wait(10)
  583.     for name in $game_troop.enemy_names
  584.       text = sprintf(Vocab::Emerge, name)
  585.       $game_message.texts.push(text)
  586.     end
  587.     if $game_troop.preemptive
  588.       text = sprintf(Vocab::Preemptive, $game_party.name)
  589.       $game_message.texts.push(text)
  590.     elsif $game_troop.surprise
  591.       text = sprintf(Vocab::Surprise, $game_party.name)
  592.       $game_message.texts.push(text)
  593.     end
  594.     wait_for_message
  595.     @message_window.clear
  596.     make_escape_ratio
  597.     process_battle_event
  598.     start_party_command_selection
  599.   end
  600.   #--------------------------------------------------------------------------
  601.   # * Create Escape Ratio
  602.   #--------------------------------------------------------------------------
  603.   def make_escape_ratio
  604.     actors_agi = $game_party.average_agi
  605.     enemies_agi = $game_troop.average_agi
  606.     @escape_ratio = 150 - 100 * enemies_agi / actors_agi
  607.   end
  608.   #--------------------------------------------------------------------------
  609.   # * Escape Processing
  610.   #--------------------------------------------------------------------------
  611.   def process_escape
  612.     @info_viewport.visible = false
  613.     @filth_viewport.visible = false
  614.     @message_window.visible = true
  615.     text = sprintf(Vocab::EscapeStart, $game_party.name)
  616.     $game_message.texts.push(text)
  617.     if $game_troop.preemptive
  618.       success = true
  619.     else
  620.       success = (rand(100) < @escape_ratio)
  621.     end
  622.     Sound.play_escape
  623.     if success
  624.       wait_for_message
  625.       battle_end(1)
  626.     else
  627.       @escape_ratio += 10
  628.       $game_message.texts.push('\.' + Vocab::EscapeFailure)
  629.       wait_for_message
  630.       $game_party.clear_actions
  631.       start_main
  632.     end
  633.   end
  634.   #--------------------------------------------------------------------------
  635.   # * Victory Processing
  636.   #--------------------------------------------------------------------------
  637.   def process_victory
  638.     @info_viewport.visible = false
  639.     @filth_viewport.visible = false
  640.     @message_window.visible = true
  641.     RPG::BGM.stop
  642.     $game_system.battle_end_me.play
  643.     unless $BTEST
  644.       $game_temp.map_bgm.play
  645.       $game_temp.map_bgs.play
  646.     end
  647.     display_exp_and_gold
  648.     display_drop_items
  649.     display_level_up
  650.     battle_end(0)
  651.   end
  652.   #--------------------------------------------------------------------------
  653.   # * Display Gained Experience and Gold
  654.   #--------------------------------------------------------------------------
  655.   def display_exp_and_gold
  656.     exp = $game_troop.exp_total
  657.     gold = $game_troop.gold_total
  658.     $game_party.gain_gold(gold)
  659.     text = sprintf(Vocab::Victory, $game_party.name)
  660.     $game_message.texts.push('\|' + text)
  661.     if exp > 0
  662.       text = sprintf(Vocab::ObtainExp, exp)
  663.       $game_message.texts.push('\.' + text)
  664.     end
  665.     if gold > 0
  666.       text = sprintf(Vocab::ObtainGold, gold, Vocab::gold)
  667.       $game_message.texts.push('\.' + text)
  668.     end
  669.     wait_for_message
  670.   end
  671.   #--------------------------------------------------------------------------
  672.   # * Display Gained Drop Items
  673.   #--------------------------------------------------------------------------
  674.   def display_drop_items
  675.     drop_items = $game_troop.make_drop_items
  676.     for item in drop_items
  677.       $game_party.gain_item(item, 1)
  678.       text = sprintf(Vocab::ObtainItem, item.name)
  679.       $game_message.texts.push(text)
  680.     end
  681.     wait_for_message
  682.   end
  683.   #--------------------------------------------------------------------------
  684.   # * Display Level Up
  685.   #--------------------------------------------------------------------------
  686.   def display_level_up
  687.     exp = $game_troop.exp_total
  688.     for actor in $game_party.existing_members
  689.       last_level = actor.level
  690.       last_skills = actor.skills
  691.       actor.gain_exp(exp, true)
  692.     end
  693.     wait_for_message
  694.   end
  695.   #--------------------------------------------------------------------------
  696.   # * Defeat Processing
  697.   #--------------------------------------------------------------------------
  698.   def process_defeat
  699.     @info_viewport.visible = false
  700.     @filth_viewport.visible = false
  701.     @message_window.visible = true
  702.     text = sprintf(Vocab::Defeat, $game_party.name)
  703.     $game_message.texts.push(text)
  704.     wait_for_message
  705.     battle_end(2)
  706.   end
  707.   #--------------------------------------------------------------------------
  708.   # * Execute Screen Switch
  709.   #--------------------------------------------------------------------------
  710.   def update_scene_change
  711.     case $game_temp.next_scene
  712.     when "map"
  713.       call_map
  714.     when "gameover"
  715.       call_gameover
  716.     when "title"
  717.       call_title
  718.     else
  719.       $game_temp.next_scene = nil
  720.     end
  721.   end
  722.   #--------------------------------------------------------------------------
  723.   # * Switch to Map Screen
  724.   #--------------------------------------------------------------------------
  725.   def call_map
  726.     $game_temp.next_scene = nil
  727.     battle_end(1)
  728.   end
  729.   #--------------------------------------------------------------------------
  730.   # * Switch to Game Over Screen
  731.   #--------------------------------------------------------------------------
  732.   def call_gameover
  733.     $game_temp.next_scene = nil
  734.     $scene = Scene_Gameover.new
  735.     @message_window.clear
  736.   end
  737.   #--------------------------------------------------------------------------
  738.   # * Switch to Title Screen
  739.   #--------------------------------------------------------------------------
  740.   def call_title
  741.     $game_temp.next_scene = nil
  742.     $scene = Scene_Title.new
  743.     @message_window.clear
  744.     Graphics.fadeout(60)
  745.   end
  746.   #--------------------------------------------------------------------------
  747.   # * Start Execution of Battle Processing
  748.   #--------------------------------------------------------------------------
  749.   def start_main
  750.     $game_troop.increase_turn
  751.     @info_viewport.visible = false
  752.     @info_viewport.ox = 0
  753.     @filth_viewport.visible = false
  754.     @filth_viewport.ox = 0
  755.     @message_window.visible = true
  756.     @party_command_window.active = false
  757.     @actor_command_window.active = false
  758.     @status_window.index = @actor_index = -1
  759.     @active_battler = nil
  760.     @message_window.clear
  761.     $game_troop.make_actions
  762.     make_action_orders
  763.     wait(20)
  764.   end
  765.   #--------------------------------------------------------------------------
  766.   # * Create Action Orders
  767.   #--------------------------------------------------------------------------
  768.   def make_action_orders
  769.     @action_battlers = []
  770.     unless $game_troop.surprise
  771.       @action_battlers += $game_party.members
  772.     end
  773.     unless $game_troop.preemptive
  774.       @action_battlers += $game_troop.members
  775.     end
  776.     for battler in @action_battlers
  777.       battler.action.make_speed
  778.     end
  779.     @action_battlers.sort! do |a,b|
  780.       b.action.speed - a.action.speed
  781.     end
  782.   end
  783.   #--------------------------------------------------------------------------
  784.   # * Battle Action Processing
  785.   #--------------------------------------------------------------------------
  786.   def process_action
  787.     return if judge_win_loss
  788.     return if $game_temp.next_scene != nil
  789.     set_next_active_battler
  790.     if @active_battler == nil
  791.       turn_end
  792.       return
  793.     end
  794.     @message_window.clear
  795.     wait(5)
  796.     @active_battler.white_flash = true
  797.     unless @active_battler.action.forcing
  798.       @active_battler.action.prepare
  799.     end
  800.     if @active_battler.action.valid?
  801.       execute_action
  802.     end
  803.     unless @active_battler.action.forcing
  804.       @message_window.clear
  805.       remove_states_auto
  806.       display_current_state
  807.     end
  808.     @active_battler.white_flash = false
  809.     @message_window.clear
  810.   end
  811.   #--------------------------------------------------------------------------
  812.   # * Execute Battle Actions
  813.   #--------------------------------------------------------------------------
  814.   def execute_action
  815.     case @active_battler.action.kind
  816.     when 0  # Basic
  817.       case @active_battler.action.basic
  818.       when 0  # Attack
  819.         execute_action_attack
  820.       when 1  # Guard
  821.         execute_action_guard
  822.       when 2  # Escape
  823.         execute_action_escape
  824.       when 3  # Wait
  825.         execute_action_wait
  826.       end
  827.     when 1  # Skill
  828.       execute_action_skill
  829.     when 2  # Item
  830.       execute_action_item
  831.     end
  832.   end
  833.   #--------------------------------------------------------------------------
  834.   # * End Turn
  835.   #--------------------------------------------------------------------------
  836.   def turn_end
  837.     $game_troop.turn_ending = true
  838.     $game_party.slip_damage_effect
  839.     $game_troop.slip_damage_effect
  840.     $game_party.do_auto_recovery
  841.     $game_troop.preemptive = false
  842.     $game_troop.surprise = false
  843.     process_battle_event
  844.     $game_troop.turn_ending = false
  845.     start_party_command_selection
  846.   end
  847.   #--------------------------------------------------------------------------
  848.   # * Set Next Battler to Act
  849.   #    When the [Force Battle Action] event command is being performed, set
  850.   #    that battler and remove him from the list. Otherwise, get from top of
  851.   #    list. If an actor that is not currently in the party is obtained (may
  852.   #    occur if the index is nil, just after leaving via a battle event, etc.)
  853.   #    it is skipped.
  854.   #--------------------------------------------------------------------------
  855.   def set_next_active_battler
  856.     loop do
  857.       if $game_troop.forcing_battler != nil
  858.         @active_battler = $game_troop.forcing_battler
  859.         @action_battlers.delete(@active_battler)
  860.         $game_troop.forcing_battler = nil
  861.       else
  862.         @active_battler = @action_battlers.shift
  863.       end
  864.       return if @active_battler == nil
  865.       return if @active_battler.index != nil
  866.     end
  867.   end
  868.   #--------------------------------------------------------------------------
  869.   # * Natural Removal of States
  870.   #--------------------------------------------------------------------------
  871.   def remove_states_auto
  872.     last_st = @active_battler.states
  873.     @active_battler.remove_states_auto
  874.     if @active_battler.states != last_st
  875.       wait(5)
  876.       display_state_changes(@active_battler)
  877.       wait(30)
  878.       @message_window.clear
  879.     end
  880.   end
  881.   #--------------------------------------------------------------------------
  882.   # * Show Current State
  883.   #--------------------------------------------------------------------------
  884.   def display_current_state
  885.     state_text = @active_battler.most_important_state_text
  886.     unless state_text.empty?
  887.       wait(5)
  888.       text = @active_battler.name + state_text
  889.       @message_window.add_instant_text(text)
  890.       wait(45)
  891.       @message_window.clear
  892.     end
  893.   end
  894.   #--------------------------------------------------------------------------
  895.   # * Execute Battle Action: Attack
  896.   #--------------------------------------------------------------------------
  897.   def execute_action_attack
  898.     text = sprintf(Vocab::DoAttack, @active_battler.name)
  899.     @message_window.add_instant_text(text)
  900.     targets = @active_battler.action.make_targets
  901.     display_attack_animation(targets)
  902.     wait(20)
  903.     for target in targets
  904.       target.attack_effect(@active_battler)
  905.       display_action_effects(target)
  906.     end
  907.   end
  908.   #--------------------------------------------------------------------------
  909.   # * Execute Battle Action: Guard
  910.   #--------------------------------------------------------------------------
  911.   def execute_action_guard
  912.     text = sprintf(Vocab::DoGuard, @active_battler.name)
  913.     @message_window.add_instant_text(text)
  914.     wait(45)
  915.   end
  916.   #--------------------------------------------------------------------------
  917.   # * Execute Battle Action: Escape
  918.   #--------------------------------------------------------------------------
  919.   def execute_action_escape
  920.     text = sprintf(Vocab::DoEscape, @active_battler.name)
  921.     @message_window.add_instant_text(text)
  922.     @active_battler.escape
  923.     Sound.play_escape
  924.     wait(45)
  925.   end
  926.   #--------------------------------------------------------------------------
  927.   # * Execute Battle Action: Wait
  928.   #--------------------------------------------------------------------------
  929.   def execute_action_wait
  930.     text = sprintf(Vocab::DoWait, @active_battler.name)
  931.     @message_window.add_instant_text(text)
  932.     wait(45)
  933.   end
  934.   #--------------------------------------------------------------------------
  935.   # * Execute Battle Action: Skill
  936.   #--------------------------------------------------------------------------
  937.   def execute_action_skill
  938.     skill = @active_battler.action.skill
  939.     text = @active_battler.name + skill.message1
  940.     @message_window.add_instant_text(text)
  941.     unless skill.message2.empty?
  942.       wait(10)
  943.       @message_window.add_instant_text(skill.message2)
  944.     end
  945.     targets = @active_battler.action.make_targets
  946.     display_animation(targets, skill.animation_id)
  947.     @active_battler.mp -= @active_battler.calc_mp_cost(skill)
  948.     $game_temp.common_event_id = skill.common_event_id
  949.     for target in targets
  950.       target.skill_effect(@active_battler, skill)
  951.       display_action_effects(target, skill)
  952.     end
  953.   end
  954.   #--------------------------------------------------------------------------
  955.   # * Execute Battle Action: Item
  956.   #--------------------------------------------------------------------------
  957.   def execute_action_item
  958.     item = @active_battler.action.item
  959.     text = sprintf(Vocab::UseItem, @active_battler.name, item.name)
  960.     @message_window.add_instant_text(text)
  961.     targets = @active_battler.action.make_targets
  962.     display_animation(targets, item.animation_id)
  963.     $game_party.consume_item(item)
  964.     $game_temp.common_event_id = item.common_event_id
  965.     for target in targets
  966.       target.item_effect(@active_battler, item)
  967.       display_action_effects(target, item)
  968.     end
  969.   end
  970.   #--------------------------------------------------------------------------
  971.   # * Show Animation
  972.   #     targets      : Target array
  973.   #     animation_id : Animation ID (-1: same as normal attack)
  974.   #--------------------------------------------------------------------------
  975.   def display_animation(targets, animation_id)
  976.     if animation_id < 0
  977.       display_attack_animation(targets)
  978.     else
  979.       display_normal_animation(targets, animation_id)
  980.     end
  981.     wait(20)
  982.     wait_for_animation
  983.   end
  984.   #--------------------------------------------------------------------------
  985.   # * Show Attack Animation
  986.   #     targets : Target array
  987.   #    If enemy, play the [Enemy normal attack] sound effect and wait
  988.   #    a moment. If actor, take dual wielding into account (display left hand
  989.   #    weapon reversed)
  990.   #--------------------------------------------------------------------------
  991.   def display_attack_animation(targets)
  992.     if @active_battler.is_a?(Game_Enemy)
  993.       Sound.play_enemy_attack
  994.       wait(15, true)
  995.     else
  996.       aid1 = @active_battler.atk_animation_id
  997.       aid2 = @active_battler.atk_animation_id2
  998.       display_normal_animation(targets, aid1, false)
  999.       display_normal_animation(targets, aid2, true)
  1000.     end
  1001.     wait_for_animation
  1002.   end
  1003.   #--------------------------------------------------------------------------
  1004.   # * Show Normal Animation
  1005.   #     targets      : Target array
  1006.   #     animation_id : Animation ID
  1007.   #     mirror       : Flip horizontal
  1008.   #--------------------------------------------------------------------------
  1009.   def display_normal_animation(targets, animation_id, mirror = false)
  1010.     animation = $data_animations[animation_id]
  1011.     if animation != nil
  1012.       to_screen = (animation.position == 3)       # Is the positon "screen"?
  1013.       for target in targets.uniq
  1014.         target.animation_id = animation_id
  1015.         target.animation_mirror = mirror
  1016.         wait(20, true) unless to_screen           # If for one, wait
  1017.       end
  1018.       wait(20, true) if to_screen                 # If for all, wait
  1019.     end
  1020.   end
  1021.   #--------------------------------------------------------------------------
  1022.   # * Show Action Results
  1023.   #     target : Target
  1024.   #     obj    : Skill or item
  1025.   #--------------------------------------------------------------------------
  1026.   def display_action_effects(target, obj = nil)
  1027.     unless target.skipped
  1028.       line_number = @message_window.line_number
  1029.       wait(5)
  1030.       display_critical(target, obj)
  1031.       display_damage(target, obj)
  1032.       display_state_changes(target, obj)
  1033.       if line_number == @message_window.line_number
  1034.         display_failure(target, obj) unless target.states_active?
  1035.       end
  1036.       if line_number != @message_window.line_number
  1037.         wait(30)
  1038.       end
  1039.       @message_window.back_to(line_number)
  1040.     end
  1041.   end
  1042.   #--------------------------------------------------------------------------
  1043.   # * Show Critical Hit
  1044.   #     target : Target
  1045.   #     obj    : Skill or item
  1046.   #--------------------------------------------------------------------------
  1047.   def display_critical(target, obj = nil)
  1048.     if target.critical
  1049.       if target.actor?
  1050.         text = Vocab::CriticalToActor
  1051.       else
  1052.         text = Vocab::CriticalToEnemy
  1053.       end
  1054.       @message_window.add_instant_text(text)
  1055.       wait(20)
  1056.     end
  1057.   end
  1058.   #--------------------------------------------------------------------------
  1059.   # * Show Damage
  1060.   #     target : Target
  1061.   #     obj    : Skill or item
  1062.   #--------------------------------------------------------------------------
  1063.   def display_damage(target, obj = nil)
  1064.     if target.missed
  1065.       display_miss(target, obj)
  1066.     elsif target.evaded
  1067.       display_evasion(target, obj)
  1068.     else
  1069.       display_hp_damage(target, obj)
  1070.       display_mp_damage(target, obj)
  1071.     end
  1072.   end
  1073.   #--------------------------------------------------------------------------
  1074.   # * Show Miss
  1075.   #     target : Target
  1076.   #     obj    : Skill or item
  1077.   #--------------------------------------------------------------------------
  1078.   def display_miss(target, obj = nil)
  1079.     if obj == nil or obj.physical_attack
  1080.       if target.actor?
  1081.         text = sprintf(Vocab::ActorNoHit, target.name)
  1082.       else
  1083.         text = sprintf(Vocab::EnemyNoHit, target.name)
  1084.       end
  1085.       Sound.play_miss
  1086.     else
  1087.       text = sprintf(Vocab::ActionFailure, target.name)
  1088.     end
  1089.     @message_window.add_instant_text(text)
  1090.     wait(30)
  1091.   end
  1092.   #--------------------------------------------------------------------------
  1093.   # * Show Escape
  1094.   #     target : Target
  1095.   #     obj    : Skill or item
  1096.   #--------------------------------------------------------------------------
  1097.   def display_evasion(target, obj = nil)
  1098.     if target.actor?
  1099.       text = sprintf(Vocab::ActorEvasion, target.name)
  1100.     else
  1101.       text = sprintf(Vocab::EnemyEvasion, target.name)
  1102.     end
  1103.     Sound.play_evasion
  1104.     @message_window.add_instant_text(text)
  1105.     wait(30)
  1106.   end
  1107.   #--------------------------------------------------------------------------
  1108.   # * Show HP Damage
  1109.   #     target : Target
  1110.   #     obj    : Skill or item
  1111.   #--------------------------------------------------------------------------
  1112.   def display_hp_damage(target, obj = nil)
  1113.     if target.hp_damage == 0                # No damage
  1114.       return if obj != nil and obj.damage_to_mp
  1115.       return if obj != nil and obj.base_damage == 0
  1116.       fmt = target.actor? ? Vocab::ActorNoDamage : Vocab::EnemyNoDamage
  1117.       text = sprintf(fmt, target.name)
  1118.     elsif target.absorbed                   # Absorb
  1119.       fmt = target.actor? ? Vocab::ActorDrain : Vocab::EnemyDrain
  1120.       text = sprintf(fmt, target.name, Vocab::hp, target.hp_damage)
  1121.     elsif target.hp_damage > 0              # Damage
  1122.       if target.actor?
  1123.         text = sprintf(Vocab::ActorDamage, target.name, target.hp_damage)
  1124.         Sound.play_actor_damage
  1125.         $game_troop.screen.start_shake(5, 5, 10)
  1126.       else
  1127.         text = sprintf(Vocab::EnemyDamage, target.name, target.hp_damage)
  1128.         Sound.play_enemy_damage
  1129.         target.blink = true
  1130.       end
  1131.     else                                    # Recovery
  1132.       fmt = target.actor? ? Vocab::ActorRecovery : Vocab::EnemyRecovery
  1133.       text = sprintf(fmt, target.name, Vocab::hp, -target.hp_damage)
  1134.       Sound.play_recovery
  1135.     end
  1136.     @message_window.add_instant_text(text)
  1137.     wait(30)
  1138.   end
  1139.   #--------------------------------------------------------------------------
  1140.   # * Show MP Damage
  1141.   #     target : Target
  1142.   #     obj    : Skill or item
  1143.   #--------------------------------------------------------------------------
  1144.   def display_mp_damage(target, obj = nil)
  1145.     return if target.dead?
  1146.     return if target.mp_damage == 0
  1147.     if target.absorbed                      # Absorb
  1148.       fmt = target.actor? ? Vocab::ActorDrain : Vocab::EnemyDrain
  1149.       text = sprintf(fmt, target.name, Vocab::mp, target.mp_damage)
  1150.     elsif target.mp_damage > 0              # Damage
  1151.       fmt = target.actor? ? Vocab::ActorLoss : Vocab::EnemyLoss
  1152.       text = sprintf(fmt, target.name, Vocab::mp, target.mp_damage)
  1153.     else                                    # Recovery
  1154.       fmt = target.actor? ? Vocab::ActorRecovery : Vocab::EnemyRecovery
  1155.       text = sprintf(fmt, target.name, Vocab::mp, -target.mp_damage)
  1156.       Sound.play_recovery
  1157.     end
  1158.     @message_window.add_instant_text(text)
  1159.     wait(30)
  1160.   end
  1161.   #--------------------------------------------------------------------------
  1162.   # * Show State Change
  1163.   #     target : Target
  1164.   #     obj    : Skill or item
  1165.   #--------------------------------------------------------------------------
  1166.   def display_state_changes(target, obj = nil)
  1167.     return if target.missed or target.evaded
  1168.     return unless target.states_active?
  1169.     if @message_window.line_number < 4
  1170.       @message_window.add_instant_text("")
  1171.     end
  1172.     display_added_states(target, obj)
  1173.     display_removed_states(target, obj)
  1174.     display_remained_states(target, obj)
  1175.     if @message_window.last_instant_text.empty?
  1176.       @message_window.back_one
  1177.     else
  1178.       wait(10)
  1179.     end
  1180.   end
  1181.   #--------------------------------------------------------------------------
  1182.   # * Show Added State
  1183.   #     target : Target
  1184.   #     obj    : Skill or item
  1185.   #--------------------------------------------------------------------------
  1186.   def display_added_states(target, obj = nil)
  1187.     for state in target.added_states
  1188.       if target.actor?
  1189.         next if state.message1.empty?
  1190.         text = target.name + state.message1
  1191.       else
  1192.         next if state.message2.empty?
  1193.         text = target.name + state.message2
  1194.       end
  1195.       if state.id == 1                      # Incapacitated
  1196.         target.perform_collapse
  1197.       end
  1198.       @message_window.replace_instant_text(text)
  1199.       wait(20)
  1200.     end
  1201.   end
  1202.   #--------------------------------------------------------------------------
  1203.   # * Show Removed State
  1204.   #     target : Target
  1205.   #     obj    : Skill or item
  1206.   #--------------------------------------------------------------------------
  1207.   def display_removed_states(target, obj = nil)
  1208.     for state in target.removed_states
  1209.       next if state.message4.empty?
  1210.       text = target.name + state.message4
  1211.       @message_window.replace_instant_text(text)
  1212.       wait(20)
  1213.     end
  1214.   end
  1215.   #--------------------------------------------------------------------------
  1216.   # * Show Unchanged State
  1217.   #     target : Target
  1218.   #     obj    : Skill or item
  1219.   #    Used when trying to put someone to sleep who is already asleep, etc.
  1220.   #--------------------------------------------------------------------------
  1221.   def display_remained_states(target, obj = nil)
  1222.     for state in target.remained_states
  1223.       next if state.message3.empty?
  1224.       text = target.name + state.message3
  1225.       @message_window.replace_instant_text(text)
  1226.       wait(20)
  1227.     end
  1228.   end
  1229.   #--------------------------------------------------------------------------
  1230.   # * Show Failure
  1231.   #     target : Target (actor)
  1232.   #     obj    : Skill or item
  1233.   #--------------------------------------------------------------------------
  1234.   def display_failure(target, obj)
  1235.     text = sprintf(Vocab::ActionFailure, target.name)
  1236.     @message_window.add_instant_text(text)
  1237.     wait(20)
  1238.   end
  1239. end
Add Comment
Please, Sign In to add comment