Advertisement
roninator2

Kid Friendly Basic Quest - Battle System

Dec 14th, 2024
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 32.59 KB | None | 0 0
  1. # ╔═════════════════════════════════════╦════════════════════╗
  2. # ║ Title: KFBQ Battle System           ║  Version: 1.01     ║
  3. # ║ Author: Roninator2                  ║                    ║
  4. # ╠═════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                           ║   Date Created     ║
  6. # ║                                     ╠════════════════════╣
  7. # ║   Recreate FFMQ Battle Scene        ║    14 Mar 2023     ║
  8. # ╚═════════════════════════════════════╩════════════════════╝
  9. # ╔══════════════════════════════════════════════════════════╗
  10. # ║ Instructions:                                            ║
  11. # ║                                                          ║
  12. # ║  Recreate the Final Fantasy Mystic Quest Battle System   ║
  13. # ╚══════════════════════════════════════════════════════════╝
  14. # ╔══════════════════════════════════════════════════════════╗
  15. # ║ Terms of use:                                            ║
  16. # ║ Free for all uses in RPG Maker - Except nudity           ║
  17. # ╚══════════════════════════════════════════════════════════╝
  18.  
  19. # Requires Map Battle Data to get enemy remaining count
  20. module BattleManager
  21.   #--------------------------------------------------------------------------
  22.   # * Victory Processing
  23.   #--------------------------------------------------------------------------
  24.   def self.process_victory
  25.     play_battle_end_me
  26.     replay_bgm_and_bgs
  27.     $game_message.add(Vocab::Victory)
  28.     display_exp
  29.     gain_gold
  30.     gain_drop_items
  31.     gain_exp
  32.     number_remaining # <- battle data
  33.     SceneManager.return
  34.     battle_end(0)
  35.     return true
  36.   end
  37.   #--------------------------------------------------------------------------
  38.   # * Display EXP Earned
  39.   #--------------------------------------------------------------------------
  40.   def self.display_exp
  41.     if $game_troop.exp_total > 0
  42.       text = sprintf(Vocab::ObtainExp, $game_troop.exp_total)
  43.       $game_message.add('\.' + text)
  44.     end
  45.     wait_for_message
  46.   end
  47.   #--------------------------------------------------------------------------
  48.   # * Gold Acquisition and Display
  49.   #--------------------------------------------------------------------------
  50.   def self.gain_gold
  51.     if $game_troop.gold_total > 0
  52.       text = sprintf(Vocab::ObtainGold, $game_troop.gold_total)
  53.       $game_message.add('\.' + text)
  54.       $game_party.gain_gold($game_troop.gold_total)
  55.     end
  56.     wait_for_message
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # * Dropped Item Acquisition and Display
  60.   #--------------------------------------------------------------------------
  61.   def self.gain_drop_items
  62.     $game_troop.make_drop_items.each do |item|
  63.       $game_party.gain_item(item, 1)
  64.       $game_message.add(sprintf(Vocab::ObtainItem, item.name))
  65.    end
  66.     wait_for_message
  67.   end
  68.   #--------------------------------------------------------------------------
  69.   # * EXP Acquisition and Level Up Display
  70.   #--------------------------------------------------------------------------
  71.   def self.gain_exp
  72.     $game_party.all_members.each do |actor|
  73.       actor.gain_exp($game_troop.exp_total)
  74.     end
  75.     wait_for_message
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # * EXP Acquisition and Level Up Display
  79.   #--------------------------------------------------------------------------
  80.   def self.number_remaining
  81.     map = $game_variables[R2_Enemy_Count_Data::Data_Transfer][0]
  82.     return if R2_Enemy_Count_Data::Battle_Data[map].nil?
  83.     id = $game_variables[R2_Enemy_Count_Data::Data_Transfer][1]
  84.     $game_variables[R2_Enemy_Count_Data::Remaining] -= 1
  85.     $game_variables[R2_Enemy_Count_Data::Current_Data][map][id][1] =
  86.     $game_variables[R2_Enemy_Count_Data::Remaining]
  87.     if $game_variables[R2_Enemy_Count_Data::Remaining] > 0
  88.       text = sprintf("%s more to go!", $game_variables[R2_Enemy_Count_Data::Remaining])
  89.       $game_message.add('\.' + text)
  90.       wait_for_message
  91.     elsif $game_variables[R2_Enemy_Count_Data::Remaining] == 0
  92.       text = "All clear!"
  93.       $game_message.add('\.' + text)
  94.       wait_for_message
  95.     end
  96.   end
  97. end
  98.  
  99. #==============================================================================
  100. # * Scene_Battle
  101. #==============================================================================
  102. class Scene_Battle < Scene_Base
  103.   #--------------------------------------------------------------------------
  104.   # * Update Frame (Basic)
  105.   #--------------------------------------------------------------------------
  106.   def update_basic
  107.     super
  108.     $game_timer.update
  109.     $game_troop.update
  110.     @spriteset.update
  111.     update_message_open
  112.   end
  113.   #--------------------------------------------------------------------------
  114.   # * Update Information Display Viewport
  115.   #--------------------------------------------------------------------------
  116.   def update_info_viewport
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # * Update Processing for Opening Message Window
  120.   #    Set openness to 0 until the status window and so on are finished closing.
  121.   #--------------------------------------------------------------------------
  122.   def update_message_open
  123.     if $game_message.busy? && !@status_window.close?
  124.       @message_window.openness = 0
  125.       @status_window.close
  126.       @party_command_window.close
  127.       @actor_command_window.close
  128.       @spell_window.close
  129.       hide_actor_blank_windows
  130.     end
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # * Create All Windows
  134.   #--------------------------------------------------------------------------
  135.   def create_all_windows
  136.     create_log_window
  137.     create_log_window2
  138.     create_status_window
  139.     create_info_viewport
  140.     create_status_viewport
  141.     create_message_window
  142.     create_party_command_window
  143.     create_actor_command_window
  144.     create_help_window
  145.     create_item_window
  146.     create_actor_window
  147.     create_enemy_window
  148.     create_battlespell_command
  149.     create_spell_row_window
  150.     create_spell_arrow
  151.     create_spell_window
  152.     create_battleitem_command
  153.     create_party_blank_windows
  154.     create_actor_blank_windows
  155.     start_hud
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # * Create Log Window
  159.   #--------------------------------------------------------------------------
  160.   def create_log_window2
  161.     @log_window2 = KFBQ_BattleLog.new
  162.     @log_window2.method_wait = method(:wait)
  163.     @log_window2.method_wait_for_effect = method(:wait_for_effect)
  164.   end
  165.   #--------------------------------------------------------------------------
  166.   # * Create Party Commands Window
  167.   #--------------------------------------------------------------------------
  168.   def create_party_command_window
  169.     @party_command_window = Window_KFBQPartyCommand.new
  170.     @party_command_window.viewport = @info_viewport
  171.     @party_command_window.set_handler(:fight,  method(:command_fight))
  172.     @party_command_window.set_handler(:escape, method(:command_escape))
  173.     @party_command_window.set_handler(:control, method(:command_control))
  174.     @party_command_window.unselect
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # * Start Actor Commmand windows
  178.   #--------------------------------------------------------------------------
  179.   def create_party_blank_windows
  180.     @party_command1 = Window_BattleCommandBlank.new(35,290,120,1)
  181.     @party_command2 = Window_BattleCommandBlank.new(195,290,120,1)
  182.     @party_command3 = Window_BattleCommandBlank.new(360,290,120,1)
  183.     hide_party_blank_windows
  184.   end
  185.   #--------------------------------------------------------------------------
  186.   # * Create Actor Commands Window
  187.   #--------------------------------------------------------------------------
  188.   def create_actor_command_window
  189.     @actor_command_window = Window_KFBQActorCommand.new
  190.     @actor_command_window.viewport = @info_viewport
  191.     @actor_command_window.set_handler(:attack, method(:command_attack))
  192.     @actor_command_window.set_handler(:spell,  method(:command_spell))
  193.     @actor_command_window.set_handler(:guard,  method(:command_guard))
  194.     @actor_command_window.set_handler(:item,   method(:command_item))
  195.     @actor_command_window.set_handler(:cancel, method(:prior_command))
  196.     @actor_command_window.close
  197.   end
  198.   #--------------------------------------------------------------------------
  199.   # * Create Help Window
  200.   #--------------------------------------------------------------------------
  201.   def create_help_window
  202.     @help_window = KFBQ_BattleHelp.new
  203.     @help_window.visible = false
  204.   end
  205.   #--------------------------------------------------------------------------
  206.   # * Create Status Window
  207.   #--------------------------------------------------------------------------
  208.   def create_status_window
  209.     @status_window = Window_BattleStatus.new
  210.   end
  211.   #--------------------------------------------------------------------------
  212.   # * Create Skill Window
  213.   #--------------------------------------------------------------------------
  214.   def create_spell_window
  215.     @spell_window = KFBQ_BattleSpell.new(@help_window, @info_viewport)
  216.     @spell_window.help_window = @help_window
  217.     @spell_window.type_window = @spell_type
  218.     @spell_window.set_handler(:ok,     method(:on_spell_ok))
  219.     @spell_window.set_handler(:cancel, method(:on_spell_cancel))
  220.   end
  221.   #--------------------------------------------------------------------------
  222.   # * Create Item Command Text Window
  223.   #--------------------------------------------------------------------------
  224.   def create_battlespell_command
  225.     @spell_command_window = KFBQ_Spell_Command.new
  226.     @spell_command_window.viewport = @viewport
  227.     @spell_command_window.hide
  228.   end
  229.   #--------------------------------------------------------------------------
  230.   # * Create Spell Row Window
  231.   #--------------------------------------------------------------------------
  232.   def create_spell_row_window
  233.     @spell_type = KFBQ_Spell_Type.new(1)
  234.     @spell_type.hide
  235.   end
  236.   #--------------------------------------------------------------------------
  237.   # * Create Spell Arrow Window
  238.   #--------------------------------------------------------------------------
  239.   def create_spell_arrow
  240.     @spell_arrow = KFBQ_Spell_Arrow.new
  241.     @spell_arrow.hide
  242.   end
  243.   #--------------------------------------------------------------------------
  244.   # * Create Item Window
  245.   #--------------------------------------------------------------------------
  246.   def create_item_window
  247.     @item_window = KFBQ_BattleItem.new(@help_window, @info_viewport)
  248.     @item_window.help_window = @help_window
  249.     @item_window.set_handler(:ok,     method(:on_item_ok))
  250.     @item_window.set_handler(:cancel, method(:on_item_cancel))
  251.   end
  252.   #--------------------------------------------------------------------------
  253.   # * Create Item Command Text Window
  254.   #--------------------------------------------------------------------------
  255.   def create_battleitem_command
  256.     @item_command_window = KFBQ_Item_Command.new
  257.     @item_command_window.viewport = @viewport
  258.     @item_command_window.hide
  259.   end
  260.   #--------------------------------------------------------------------------
  261.   # * Start Actor Commmand windows
  262.   #--------------------------------------------------------------------------
  263.   def create_actor_blank_windows
  264.     @actor_command1 = Window_BattleCommandBlank.new(95,270,120,1)
  265.     @actor_command2 = Window_BattleCommandBlank.new(295,270,120,1)
  266.     @actor_command3 = Window_BattleCommandBlank.new(95,330,120,1)
  267.     @actor_command4 = Window_BattleCommandBlank.new(295,330,120,1)
  268.     hide_actor_blank_windows
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # * Create Message Window
  272.   #--------------------------------------------------------------------------
  273.   def create_message_window
  274.     @message_window = KFBQ_BattleMessage.new
  275.     @message_window.viewport = @viewport
  276.     @message_window.set_visible_line_number(1)
  277.   end
  278.   #--------------------------------------------------------------------------
  279.   # * Create Information Display Viewport
  280.   #--------------------------------------------------------------------------
  281.   def create_info_viewport
  282.     @info_viewport = Viewport.new
  283.     @info_viewport.rect.y = Graphics.height - @status_window.height - 120
  284.     @info_viewport.rect.x = 0
  285.     @info_viewport.rect.height = @status_window.height
  286.     @info_viewport.z = 200
  287.   end
  288.   #--------------------------------------------------------------------------
  289.   # * Create Information Display Viewport
  290.   #--------------------------------------------------------------------------
  291.   def create_status_viewport
  292.     @status_viewport = Viewport.new
  293.     @status_viewport.rect.y = Graphics.height - @status_window.height
  294.     @status_viewport.rect.height = @status_window.height
  295.     @status_viewport.z = 360
  296.     @status_window.viewport = @status_viewport
  297.   end
  298.   #--------------------------------------------------------------------------
  299.   # * Create Actor Window
  300.   #--------------------------------------------------------------------------
  301.   def create_actor_window
  302.     @actor_window = Window_BattleActor.new(@status_viewport)
  303.     @actor_window.set_handler(:ok,     method(:on_actor_ok))
  304.     @actor_window.set_handler(:cancel, method(:on_actor_cancel))
  305.     @actor_window.z = 300
  306.   end
  307.   #--------------------------------------------------------------------------
  308.   # * Start Actor Commmand windows
  309.   #--------------------------------------------------------------------------
  310.   def show_party_blank_windows
  311.     @party_command1.show
  312.     @party_command2.show
  313.     @party_command3.show
  314.   end
  315.   #--------------------------------------------------------------------------
  316.   # * Start Actor Commmand windows
  317.   #--------------------------------------------------------------------------
  318.   def hide_party_blank_windows
  319.     @party_command1.hide
  320.     @party_command2.hide
  321.     @party_command3.hide
  322.   end
  323.   #--------------------------------------------------------------------------
  324.   # * Start Actor Commmand windows
  325.   #--------------------------------------------------------------------------
  326.   def dispose_party_blank_windows
  327.     @party_command1.dispose if @party_command1
  328.     @party_command2.dispose if @party_command2
  329.     @party_command3.dispose if @party_command3
  330.   end
  331.   #--------------------------------------------------------------------------
  332.   # * Start Actor Commmand windows
  333.   #--------------------------------------------------------------------------
  334.   def hide_actor_blank_windows
  335.     @actor_command1.hide
  336.     @actor_command2.hide
  337.     @actor_command3.hide
  338.     @actor_command4.hide
  339.   end
  340.   #--------------------------------------------------------------------------
  341.   # * Start Actor Commmand windows
  342.   #--------------------------------------------------------------------------
  343.   def show_actor_blank_windows
  344.     @actor_command1.show
  345.     @actor_command2.show
  346.     @actor_command3.show
  347.     @actor_command4.show
  348.   end
  349.   #--------------------------------------------------------------------------
  350.   # * Start Actor Commmand windows
  351.   #--------------------------------------------------------------------------
  352.   def dispose_actor_blank_windows
  353.     @actor_command1.dispose if @actor_command1
  354.     @actor_command2.dispose if @actor_command2
  355.     @actor_command3.dispose if @actor_command3
  356.     @actor_command4.dispose if @actor_command4
  357.   end
  358.   #--------------------------------------------------------------------------
  359.   # * To Previous Command Input
  360.   #--------------------------------------------------------------------------
  361.   def prior_command
  362.     if BattleManager.prior_command
  363.       start_actor_command_selection
  364.     else
  365.       hide_actor_blank_windows
  366.       start_party_command_selection
  367.     end
  368.   end
  369.   #--------------------------------------------------------------------------
  370.   # * Start Party Command Selection
  371.   #--------------------------------------------------------------------------
  372.   def start_party_command_selection
  373.     unless scene_changing?
  374.       refresh_status
  375.       @status_window.unselect
  376.       @status_window.open
  377.       if BattleManager.input_start
  378.         @actor_command_window.close
  379.         @party_command_window.setup
  380.         @party_command_window.update_cursor
  381.         show_party_blank_windows
  382.       else
  383.         @party_command_window.deactivate
  384.         turn_start
  385.       end
  386.     end
  387.   end
  388.   #--------------------------------------------------------------------------
  389.   # * [Escape] Command
  390.   #--------------------------------------------------------------------------
  391.   def command_escape
  392.     hide_party_blank_windows
  393.     turn_start unless BattleManager.process_escape
  394.   end
  395.   #--------------------------------------------------------------------------
  396.   # * [Control] Command
  397.   #--------------------------------------------------------------------------
  398.   def command_control
  399.     $game_system.autobattle = !$game_system.autobattle?
  400.     @actor2_control.refresh if @actor2_control
  401.     @party_command_window.activate
  402.   end
  403.   #--------------------------------------------------------------------------
  404.   # * Start Actor Command Selection
  405.   #--------------------------------------------------------------------------
  406.   def start_actor_command_selection
  407.     @status_window.select(BattleManager.actor.index)
  408.     @party_command_window.close
  409.     hide_party_blank_windows
  410.     @actor_command_window.open
  411.     @actor_command_window.setup(BattleManager.actor)
  412.     show_actor_blank_windows
  413.   end
  414.   #--------------------------------------------------------------------------
  415.   # new method: command_use_skill
  416.   #--------------------------------------------------------------------------
  417.   def command_attack
  418.     @skill = $data_skills[BattleManager.actor.attack_skill_id]
  419.     if @skill.note.match(/<Bomb>/i)
  420.       if $game_party.bombs? == 0
  421.         Sound.play_buzzer
  422.         @actor_command_window.activate
  423.         return
  424.       end
  425.     end
  426.     if @skill.note.match(/<Ninja Star>/i)
  427.       if $game_party.ninja_stars? == 0
  428.         Sound.play_buzzer
  429.         @actor_command_window.activate
  430.         return
  431.       end
  432.     end
  433.     BattleManager.actor.input.set_skill(@skill.id)
  434.     hide_actor_blank_windows
  435.     @help_window.hide
  436.     if !@skill.need_selection?
  437.       next_command
  438.     elsif @skill.for_opponent?
  439.       select_enemy_selection
  440.     else
  441.       select_actor_selection
  442.     end
  443.   end
  444.   #--------------------------------------------------------------------------
  445.   # * [Spell] Command
  446.   #--------------------------------------------------------------------------
  447.   def command_spell
  448.     @help_window.show
  449.     @spell_command_window.show
  450.     @spell_window.actor = BattleManager.actor
  451.     @spell_window.show.activate
  452.     @spell_type.show
  453.     @spell_arrow.show
  454.     @spell_arrow.refresh
  455.     @actor_command_window.close
  456.     hide_actor_blank_windows
  457.   end
  458.   #--------------------------------------------------------------------------
  459.   # * [Item] Command
  460.   #--------------------------------------------------------------------------
  461.   def command_item
  462.     @help_window.show
  463.     @item_command_window.show
  464.     @item_window.refresh
  465.     @item_window.show.activate
  466.     @actor_command_window.close
  467.     hide_actor_blank_windows
  468.   end
  469.   #--------------------------------------------------------------------------
  470.   # * Actor [OK]
  471.   #--------------------------------------------------------------------------
  472.   def on_actor_ok
  473.     BattleManager.actor.input.target_index = @actor_window.index
  474.     @actor_window.deactivate
  475.     @status_window.show
  476.     @actor_window.hide
  477.     @spell_window.hide
  478.     @item_window.hide
  479.     @help_window.hide
  480.     @spell_command_window.hide
  481.     @spell_type.hide
  482.     @spell_arrow.hide
  483.     next_command
  484.   end
  485.   #--------------------------------------------------------------------------
  486.   # * Actor [Cancel]
  487.   #--------------------------------------------------------------------------
  488.   def on_actor_cancel
  489.     @actor_window.hide
  490.     @actor_window.deactivate
  491.     case @actor_command_window.current_symbol
  492.     when :attack
  493.       @help_window.hide
  494.       show_actor_blank_windows
  495.       @actor_command_window.open
  496.       @actor_command_window.activate
  497.     when :spell
  498.       @help_window.show
  499.       @spell_command_window.show
  500.       @spell_window.refresh
  501.       @spell_window.show.activate
  502.       @spell_type.show
  503.       @spell_arrow.show
  504.       @spell_arrow.refresh
  505.     when :item
  506.       @item_window.show.activate
  507.       @help_window.show
  508.       @item_command_window.show
  509.       @item_window.refresh
  510.     end
  511.     @status_window.hide
  512.   end
  513.   #--------------------------------------------------------------------------
  514.   # ? On enemy ok
  515.   #--------------------------------------------------------------------------    
  516.   def on_enemy_ok
  517.     BattleManager.actor.input.target_index = @target_index
  518.     @enemy_window.hide
  519.     @spell_window.hide
  520.     @item_window.hide  
  521.     @actor_command_window.show
  522.     next_command
  523.   end  
  524.   #--------------------------------------------------------------------------
  525.   # * Enemy [Cancel]
  526.   #--------------------------------------------------------------------------
  527.   def on_enemy_cancel
  528.     @enemy_window.hide
  529.     case @actor_command_window.current_symbol
  530.     when :attack
  531.       @help_window.hide
  532.       show_actor_blank_windows
  533.       @actor_command_window.show.activate
  534.     when :spell
  535.       @spell_command_window.show
  536.       @spell_window.show.activate
  537.       @help_window.show
  538.       @spell_window.refresh
  539.       @spell_type.show
  540.       @spell_arrow.show
  541.       @spell_arrow.refresh
  542.     when :item
  543.       @item_window.show.activate
  544.       @help_window.show
  545.       @item_command_window.show
  546.     end
  547.   end
  548.   #--------------------------------------------------------------------------
  549.   # * Skill [OK]
  550.   #--------------------------------------------------------------------------
  551.   def on_spell_ok
  552.     @spell = @spell_window.item
  553.     if @spell.nil?
  554.       @spell_window.activate
  555.       return
  556.     end
  557.     if !BattleManager.actor.skill_cost_payable?(@spell)
  558.       Sound.play_buzzer
  559.       @spell_window.activate
  560.       return
  561.     end
  562.     BattleManager.actor.input.set_skill(@spell.id)
  563.     BattleManager.actor.last_skill.object = @spell
  564.     @spell_window.hide
  565.     @help_window.hide
  566.     @spell_command_window.hide
  567.     @spell_type.hide
  568.     @spell_arrow.hide
  569.     if !@spell.need_selection?
  570.       @spell_window.hide
  571.       next_command
  572.     elsif @spell.for_opponent?
  573.       select_enemy_selection
  574.     else
  575.       select_actor_selection
  576.     end
  577.   end
  578.   #--------------------------------------------------------------------------
  579.   # * Skill [Cancel]
  580.   #--------------------------------------------------------------------------
  581.   def on_spell_cancel
  582.     @help_window.hide
  583.     @spell_window.hide
  584.     @spell_command_window.hide
  585.     @spell_type.hide
  586.     @spell_arrow.hide
  587.     show_actor_blank_windows
  588.     @actor_command_window.show.activate
  589.     @actor_command_window.setup(BattleManager.actor)
  590.   end
  591.   #--------------------------------------------------------------------------
  592.   # * Item [OK]
  593.   #--------------------------------------------------------------------------
  594.   def on_item_ok
  595.     @item = @item_window.item
  596.     if @item.nil?
  597.       @item_window.activate
  598.       return
  599.     end
  600.     BattleManager.actor.input.set_item(@item.id)
  601.     @item_window.hide
  602.     @help_window.hide
  603.     @item_command_window.hide
  604.     if !@item.need_selection?
  605.       @item_window.hide
  606.       next_command
  607.     elsif @item.for_opponent?
  608.       select_enemy_selection
  609.     else
  610.       select_actor_selection
  611.     end
  612.     $game_party.last_item.object = @item
  613.   end
  614.   #--------------------------------------------------------------------------
  615.   # * Item [Cancel]
  616.   #--------------------------------------------------------------------------
  617.   def on_item_cancel
  618.     @help_window.hide
  619.     @item_window.hide
  620.     @item_command_window.hide
  621.     show_actor_blank_windows
  622.     @actor_command_window.show.activate
  623.     @actor_command_window.setup(BattleManager.actor)
  624.   end
  625.   #--------------------------------------------------------------------------
  626.   # * Start Actor Selection
  627.   #--------------------------------------------------------------------------
  628.   def select_actor_selection
  629.     @status_window.show
  630.     @actor_window.refresh
  631.     @actor_window.show.activate
  632.   end
  633.   #--------------------------------------------------------------------------
  634.   # ? Selects an enemy
  635.   #--------------------------------------------------------------------------    
  636.   def select_enemy_selection
  637.     @actor_input = false
  638.     @help_window.show
  639.     @help_window.open
  640.     @spell_window.hide
  641.     @item_window.hide    
  642.     @target_index = 0
  643.     @target_sprites = get_sprites($game_troop.members).compact
  644.     @target_size = $game_troop.members.size
  645.     @cursor_sprite = Sprite_TargetCursor.new
  646.     while !@actor_input && $game_troop.members[@target_index].dead?
  647.       @target_index = (@target_index + 1) % @target_size
  648.     end    
  649.     @selection_active = true
  650.     while @selection_active
  651.       update_for_wait
  652.       if Input.trigger?(:C)
  653.         Sound.play_ok
  654.         @cursor_sprite.dispose
  655.         on_enemy_ok
  656.         return
  657.       elsif Input.trigger?(:B)
  658.         Sound.play_cancel
  659.         @cursor_sprite.dispose
  660.         on_enemy_cancel
  661.         return
  662.       end  
  663.       update_target_selection
  664.     end
  665.   end
  666.   #--------------------------------------------------------------------------
  667.   # * Start Turn
  668.   #--------------------------------------------------------------------------
  669.   def turn_start
  670.     @party_command_window.close
  671.     @actor_command_window.close
  672.     hide_party_blank_windows
  673.     hide_actor_blank_windows
  674.     @status_window.unselect
  675.     @subject =  nil
  676.     BattleManager.turn_start
  677.     @log_window.wait
  678.     @log_window.clear
  679.   end
  680.   #--------------------------------------------------------------------------
  681.   # * End Turn
  682.   #--------------------------------------------------------------------------
  683.   def turn_end
  684.     all_battle_members.each do |battler|
  685.       battler.on_turn_end
  686.       refresh_status
  687.     end
  688.     BattleManager.turn_end
  689.     process_event
  690.     start_party_command_selection
  691.   end
  692.   #--------------------------------------------------------------------------
  693.   # * Battle Action Processing
  694.   #--------------------------------------------------------------------------
  695.   def process_action
  696.     return if scene_changing?
  697.     if !@subject || !@subject.current_action
  698.       @subject = BattleManager.next_subject
  699.     end
  700.     return turn_end unless @subject
  701.     if @subject.current_action
  702.       @subject.current_action.prepare
  703.       if @subject.current_action.valid?
  704.         @status_window.open
  705.         execute_action
  706.       end
  707.       @subject.remove_current_action
  708.     end
  709.     process_action_end unless @subject.current_action
  710.   end
  711.   #--------------------------------------------------------------------------
  712.   # * Event Processing
  713.   #--------------------------------------------------------------------------
  714.   def process_event
  715.     while !scene_changing?
  716.       $game_troop.interpreter.update
  717.       $game_troop.setup_battle_event
  718.       wait_for_message
  719.       @log_window2.defeat_enemy if $game_troop.all_dead?
  720.       wait_for_effect if $game_troop.all_dead?
  721.       process_forced_action
  722.       BattleManager.judge_win_loss
  723.       break unless $game_troop.interpreter.running?
  724.       update_for_wait
  725.     end
  726.   end
  727.   #--------------------------------------------------------------------------
  728.   # * Execute Battle Actions
  729.   #--------------------------------------------------------------------------
  730.   def execute_action
  731.     @subject.sprite_effect_type = :whiten
  732.     use_item
  733.   end
  734.   #--------------------------------------------------------------------------
  735.   # * Processing at End of Action
  736.   #--------------------------------------------------------------------------
  737.   def process_action_end
  738.     @subject.on_action_end
  739.     refresh_status
  740.     BattleManager.judge_win_loss
  741.   end
  742.   #--------------------------------------------------------------------------
  743.   # * Pay Cost of Using Bombs/Ninja Stars * Use Skill/Item
  744.   #--------------------------------------------------------------------------
  745.     # R2_Element_Icons::Elements
  746.     # code 13 - state rate - states
  747.     # code 14 - state resist - states
  748.     # code 11 - element rate - elements - 3 = fire
  749.     # code 12 - debuff rate - params - 0 = mhp
  750.     # code 22 - xparam
  751.     # code 23 - sparams
  752.     # element defense
  753.     # weapons
  754.     # code 31 - attack element
  755.     # code 32 - attack state
  756.   def use_item
  757.     item = @subject.current_action.item
  758.     if @subject.is_a?(Game_Actor)
  759.       @log_window2.display_use_item(@subject, item)
  760.       @log_window2.wait_and_clear
  761.     end
  762.     @subject.use_item(item)
  763.     refresh_status
  764.     targets = @subject.current_action.make_targets.compact
  765.     if @subject.is_a?(Game_Actor) && targets[0].is_a?(Game_Enemy)
  766.       enmy = $data_enemies[targets[0].enemy_id]
  767.       enmy.features.each do |ft|
  768.         if ft.code == 13
  769.           case item
  770.           when RPG::Weapon
  771.             weapon = $data_weapons[@subject.equips[0].id]
  772.             weapon.features.each do |ft2|
  773.               if ft2.code == 32
  774.                 if ft2.data_id == ft.data_id
  775.                   @log_window2.display_enemy_weakness(enmy.name, ft.data_id, ft.value, ft2.value)
  776.                   @log_window2.wait_and_clear
  777.                 end
  778.               end
  779.             end
  780.           when RPG::Skill
  781.             spellft = $data_skills[item.id]
  782.             spellft.features.each do |ft2|
  783.               if ft2.code == 32
  784.                 if ft2.data_id == ft.data_id
  785.                   @log_window2.display_enemy_weakness(enmy.name, ft.data_id, ft.value, ft2.value)
  786.                   @log_window2.wait_and_clear
  787.                 end
  788.               end
  789.             end
  790.           when RPG::Item
  791.             itemft = $data_items[item.id]
  792.             itemft.features.each do |ft2|
  793.               if ft2.code == 32
  794.                 if ft2.data_id == ft.data_id
  795.                   @log_window2.display_enemy_weakness(enmy.name, ft.data_id, ft.value, ft2.value)
  796.                   @log_window2.wait_and_clear
  797.                 end
  798.               end
  799.             end
  800.           end
  801.             item.features.each do |ft2|
  802.               if ft2.code == 32
  803.                 if ft2.data_id == ft.data_id
  804.                   @log_window2.display_enemy_weakness(enmy.name, ft.data_id, ft.value, ft2.value)
  805.                   @log_window2.wait_and_clear
  806.                 end
  807.               end
  808.             end
  809.         end
  810.       end
  811.     end
  812.     show_animation(targets, item.animation_id)
  813.     targets.each {|target| item.repeats.times { invoke_item(target, item) } }
  814.     if item.note.match(/<Bomb>/i)
  815.       $game_party.use_bomb(true)
  816.     end
  817.     if item.note.match(/<Ninja Star>/i)
  818.       $game_party.use_star(true)
  819.     end
  820.   end
  821.   #--------------------------------------------------------------------------
  822.   # * Invoke Counterattack
  823.   #--------------------------------------------------------------------------
  824.   def invoke_counter_attack(target, item)
  825.     attack_skill = $data_skills[target.attack_skill_id]
  826.     @subject.item_apply(target, attack_skill)
  827.     refresh_status
  828.   end
  829.   #--------------------------------------------------------------------------
  830.   # * Apply Skill/Item Effect
  831.   #--------------------------------------------------------------------------
  832.   def apply_item_effects(target, item)
  833.     target.item_apply(@subject, item)
  834.     refresh_status
  835.     @log_window.display_action_results(target, item)
  836.   end
  837.   #--------------------------------------------------------------------------
  838.   # * Determine if Fast Forward
  839.   #--------------------------------------------------------------------------
  840.   def show_fast?
  841.     Input.press?(:A) || Input.press?(:C)
  842.   end
  843. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement