Advertisement
gerkrt

Battle log window

Sep 14th, 2011
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 18.05 KB | None | 0 0
  1.  
  2. #==============================================================================
  3. # Battle log window
  4. # By gerkrt/gerrtunk
  5. # Version: 1
  6. # License: MIT, credits
  7. # Date: 24/01/2011
  8. # IMPORTANT NOTE: to acces the more actualitzed or corrected version of this
  9. # script check here: http://usuarios.multimania.es/kisap/english_list.html
  10. #==============================================================================
  11.  
  12. =begin
  13.  
  14. ------INTRODUCTION------
  15.  
  16. This window shows a new window and in battle that displays a list of the last
  17. actions executed.
  18. You can configure witdh, lines heigh, x and y and all the vocabulary used.
  19.  
  20. -----INSTRUCTIONS-------
  21.  
  22. The vocabulary is pretty self explanatory. Thet are the variables called Voc and
  23. they dot whay you see. Note that a . is added always at the end of a phrase.
  24.  
  25. Lines height is the max lines of the log window.
  26.  
  27. Battle window X and Y control these positions. You can changue they at your will
  28. for aesthetichs or improve interface.
  29.  
  30. Finall You can modifiy the Battle witdht window if you think that it takes too
  31. space or you need more.
  32.  
  33. =end
  34.  
  35. module Wep
  36.  
  37.   Lines_height = 6
  38.  
  39.   BattleWindow_Width = 220
  40.   Wep::BattleWindow_X = 0
  41.   Wep::BattleWindow_Y = 96
  42.  
  43.   VocStart = 'Battle starts!'
  44.   VocMiss = ' missed'
  45.   VocAtk = ' attacked'
  46.   VocDies = ' fall'
  47.   VocWin = 'You win!'
  48.   VocLose = 'You lose!'
  49.   VocEscape = 'You escaped!'
  50.   VocEscapeFails = 'You failed to escape'
  51.   VocMag = ' cast '
  52.   VocItem = ' use '
  53.   VocDef = ' defended'
  54.   VocNothing = ' does nothing'
  55.  
  56. end
  57.  
  58.  
  59.  
  60.  
  61.  
  62. class Game_Battler
  63.     #--------------------------------------------------------------------------
  64.   # * Change HP
  65.   #     hp : new HP
  66.   # moded to add log line in battle if dead
  67.   #--------------------------------------------------------------------------
  68.   def hp=(hp)
  69.     @hp = [[hp, maxhp].min, 0].max
  70.     # Add log line if in battle and dead
  71.     if self.dead? and $game_temp.in_battle
  72.       $scene.log_add_line(Wep::VocDies, self)
  73.     end
  74.     # add or exclude incapacitation
  75.     for i in 1...$data_states.size
  76.       if $data_states[i].zero_hp
  77.         if self.dead?
  78.           add_state(i)
  79.         else
  80.           remove_state(i)
  81.         end
  82.       end
  83.     end
  84.   end
  85.  
  86. end
  87.  
  88. class Scene_Battle
  89.   #--------------------------------------------------------------------------
  90.   # * Battle Ends
  91.   #     result : results (0:win 1:escape 2:lose)
  92.   #--------------------------------------------------------------------------
  93.   def battle_end(result)
  94.    
  95.     case result
  96.       when 0; @log_window.add_special_line(Wep::VocWin)
  97.       when 1; @log_window.add_special_line(Wep::VocLose)
  98.     end
  99.  
  100.     # Clear in battle flag
  101.     $game_temp.in_battle = false
  102.     # Clear entire party actions flag
  103.     $game_party.clear_actions
  104.     # Remove battle states
  105.     for actor in $game_party.actors
  106.       actor.remove_states_battle
  107.     end
  108.     # Clear enemies
  109.     $game_troop.enemies.clear
  110.     # Call battle callback
  111.     if $game_temp.battle_proc != nil
  112.       $game_temp.battle_proc.call(result)
  113.       $game_temp.battle_proc = nil
  114.     end
  115.     # Switch to map screen
  116.     $scene = Scene_Map.new
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # * Make Skill Action Results
  120.   #--------------------------------------------------------------------------
  121.   def make_skill_action_result
  122.     # Get skill
  123.     @skill = $data_skills[@active_battler.current_action.skill_id]
  124.     # If not a forcing action
  125.     unless @active_battler.current_action.forcing
  126.       # If unable to use due to SP running out
  127.       unless @active_battler.skill_can_use?(@skill.id)
  128.         # Clear battler being forced into action
  129.         $game_temp.forcing_battler = nil
  130.         # Shift to step 1
  131.         @phase4_step = 1
  132.         return
  133.       end
  134.     end
  135.     # Use up SP
  136.     @active_battler.sp -= @skill.sp_cost
  137.     # Refresh status window
  138.     @status_window.refresh
  139.     # Show skill name on help window
  140.     @help_window.set_text(@skill.name, 1)
  141.     # Set animation ID
  142.     @animation1_id = @skill.animation1_id
  143.     @animation2_id = @skill.animation2_id
  144.     # Set command event ID
  145.     @common_event_id = @skill.common_event_id
  146.     # Set target battlers
  147.     set_target_battlers(@skill.scope)
  148.     # Add log line
  149.     $scene.log_add_line(Wep::VocMag, @active_battler, @skill.name)
  150.     # Apply skill effect
  151.     for target in @target_battlers
  152.       target.skill_effect(@active_battler, @skill)
  153.     end
  154.   end
  155.   #--------------------------------------------------------------------------
  156.   # * Make Item Action Results
  157.   #--------------------------------------------------------------------------
  158.   def make_item_action_result
  159.     # Get item
  160.     @item = $data_items[@active_battler.current_action.item_id]
  161.     # If unable to use due to items running out
  162.     unless $game_party.item_can_use?(@item.id)
  163.       # Shift to step 1
  164.       @phase4_step = 1
  165.       return
  166.     end
  167.     # If consumable
  168.     if @item.consumable
  169.       # Decrease used item by 1
  170.       $game_party.lose_item(@item.id, 1)
  171.     end
  172.     # Display item name on help window
  173.     @help_window.set_text(@item.name, 1)
  174.     # Set animation ID
  175.     @animation1_id = @item.animation1_id
  176.     @animation2_id = @item.animation2_id
  177.     # Set common event ID
  178.     @common_event_id = @item.common_event_id
  179.     # Decide on target
  180.     index = @active_battler.current_action.target_index
  181.     target = $game_party.smooth_target_actor(index)
  182.     # Set targeted battlers
  183.     set_target_battlers(@item.scope)
  184.     # Add log line
  185.     $scene.log_add_line(Wep::VocItem, @active_battler, @item.name)
  186.     # Apply item effect
  187.     for target in @target_battlers
  188.       target.item_effect(@item)
  189.     end
  190.   end
  191.   #--------------------------------------------------------------------------
  192.   # * Make Basic Action Results
  193.   #--------------------------------------------------------------------------
  194.   def make_basic_action_result
  195.     # If attack
  196.     if @active_battler.current_action.basic == 0
  197.       # Add log line
  198.       $scene.log_add_line(Wep::VocAtk, @active_battler)
  199.       # Set anaimation ID
  200.       @animation1_id = @active_battler.animation1_id
  201.       @animation2_id = @active_battler.animation2_id
  202.       # If action battler is enemy
  203.       if @active_battler.is_a?(Game_Enemy)
  204.         if @active_battler.restriction == 3
  205.           target = $game_troop.random_target_enemy
  206.         elsif @active_battler.restriction == 2
  207.           target = $game_party.random_target_actor
  208.         else
  209.           index = @active_battler.current_action.target_index
  210.           target = $game_party.smooth_target_actor(index)
  211.         end
  212.       end
  213.       # If action battler is actor
  214.       if @active_battler.is_a?(Game_Actor)
  215.         if @active_battler.restriction == 3
  216.           target = $game_party.random_target_actor
  217.         elsif @active_battler.restriction == 2
  218.           target = $game_troop.random_target_enemy
  219.         else
  220.           index = @active_battler.current_action.target_index
  221.           target = $game_troop.smooth_target_enemy(index)
  222.         end
  223.       end
  224.       # Set array of targeted battlers
  225.       @target_battlers = [target]
  226.       # Apply normal attack results
  227.       for target in @target_battlers
  228.         target.attack_effect(@active_battler)
  229.       end
  230.       return
  231.     end
  232.     # If guard
  233.     if @active_battler.current_action.basic == 1
  234.       # Display "Guard" in help window
  235.       # Add log line
  236.       $scene.log_add_line(Wep::VocDef, @active_battler)
  237.       @help_window.set_text($data_system.words.guard, 1)
  238.       return
  239.     end
  240.     # If escape
  241.     if @active_battler.is_a?(Game_Enemy) and
  242.        @active_battler.current_action.basic == 2
  243.       # Add log line
  244.       # @log_window.add_special_line(Wep::VocEscaping)
  245.  
  246.       # Display "Escape" in help window
  247.       @help_window.set_text("Escape", 1)
  248.       # Escape
  249.       @active_battler.escape
  250.       return
  251.     end
  252.     # If doing nothing
  253.     if @active_battler.current_action.basic == 3
  254.       # Add log line
  255.       $scene.log_add_line(Wep::VocNothing, @active_battler)
  256.       # Clear battler being forced into action
  257.       $game_temp.forcing_battler = nil
  258.       # Shift to step 1
  259.       @phase4_step = 1
  260.       return
  261.     end
  262.   end
  263.   #--------------------------------------------------------------------------
  264.   # * Frame Update (party command phase: escape)
  265.   #--------------------------------------------------------------------------
  266.   def update_phase2_escape
  267.     # Calculate enemy agility average
  268.     enemies_agi = 0
  269.     enemies_number = 0
  270.     for enemy in $game_troop.enemies
  271.       if enemy.exist?
  272.         enemies_agi += enemy.agi
  273.         enemies_number += 1
  274.       end
  275.     end
  276.     if enemies_number > 0
  277.       enemies_agi /= enemies_number
  278.     end
  279.     # Calculate actor agility average
  280.     actors_agi = 0
  281.     actors_number = 0
  282.     for actor in $game_party.actors
  283.       if actor.exist?
  284.         actors_agi += actor.agi
  285.         actors_number += 1
  286.       end
  287.     end
  288.     if actors_number > 0
  289.       actors_agi /= actors_number
  290.     end
  291.     # Determine if escape is successful
  292.     success = rand(100) < 50 * actors_agi / enemies_agi
  293.     # If escape is successful
  294.     if success
  295.       # Add log line
  296.       @log_window.add_special_line(Wep::VocEscape)
  297.       # Play escape SE
  298.       $game_system.se_play($data_system.escape_se)
  299.       # Return to BGM before battle started
  300.       $game_system.bgm_play($game_temp.map_bgm)
  301.       # Battle ends
  302.       battle_end(1)
  303.     # If escape is failure
  304.     else
  305.       # Add log line
  306.       @log_window.add_special_line(Wep::VocEscapeFails)
  307.       # Clear all party member actions
  308.       $game_party.clear_actions
  309.       # Start main phase
  310.       start_phase4
  311.     end
  312.   end
  313. end
  314.  
  315. #==============================================================================
  316. # ** Scene_Battle (part 1)
  317. #------------------------------------------------------------------------------
  318. #  This class performs battle screen processing.
  319. #==============================================================================
  320.  
  321. class Scene_Battle
  322.   #--------------------------------------------------------------------------
  323.   # * Main Processing
  324.   # moded to use
  325.   #--------------------------------------------------------------------------
  326.   def main
  327.     # Initialize each kind of temporary battle data
  328.     $game_temp.in_battle = true
  329.     $game_temp.battle_turn = 0
  330.     $game_temp.battle_event_flags.clear
  331.     $game_temp.battle_abort = false
  332.     $game_temp.battle_main_phase = false
  333.     $game_temp.battleback_name = $game_map.battleback_name
  334.     $game_temp.forcing_battler = nil
  335.     # Initialize battle event interpreter
  336.     $game_system.battle_interpreter.setup(nil, 0)
  337.     # Prepare troop
  338.     @troop_id = $game_temp.battle_troop_id
  339.     $game_troop.setup(@troop_id)
  340.     # Make actor command window
  341.     s1 = $data_system.words.attack
  342.     s2 = $data_system.words.skill
  343.     s3 = $data_system.words.guard
  344.     s4 = $data_system.words.item
  345.     @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])
  346.     @actor_command_window.y = 160
  347.     @actor_command_window.back_opacity = 160
  348.     @actor_command_window.active = false
  349.     @actor_command_window.visible = false
  350.     # Make other windows
  351.     @party_command_window = Window_PartyCommand.new
  352.     @help_window = Window_Help.new
  353.     @help_window.back_opacity = 160
  354.     @help_window.visible = false
  355.     @status_window = Window_BattleStatus.new
  356.     @message_window = Window_Message.new
  357.    
  358.     @log_window = Window_BattleLog.new(@troop_id)
  359.     @log_window.add_special_line(Wep::VocStart)
  360.    
  361.     # Make sprite set
  362.     @spriteset = Spriteset_Battle.new
  363.     # Initialize wait count
  364.     @wait_count = 0
  365.     # Execute transition
  366.     if $data_system.battle_transition == ""
  367.       Graphics.transition(20)
  368.     else
  369.       Graphics.transition(40, "Graphics/Transitions/" +
  370.       $data_system.battle_transition)
  371.     end
  372.     # Start pre-battle phase
  373.     start_phase1
  374.     # Main loop
  375.     loop do
  376.       # Update game screen
  377.       Graphics.update
  378.       # Update input information
  379.       Input.update
  380.       # Frame update
  381.       update
  382.       # Abort loop if screen is changed
  383.       if $scene != self
  384.         break
  385.       end
  386.     end
  387.     # Refresh map
  388.     $game_map.refresh
  389.     # Prepare for transition
  390.     Graphics.freeze
  391.     # Dispose of windows
  392.     @actor_command_window.dispose
  393.     @party_command_window.dispose
  394.     @help_window.dispose
  395.  
  396.     @log_window.dispose
  397.     @status_window.dispose
  398.     @message_window.dispose
  399.     if @skill_window != nil
  400.       @skill_window.dispose
  401.     end
  402.     if @item_window != nil
  403.       @item_window.dispose
  404.     end
  405.     if @result_window != nil
  406.       @result_window.dispose
  407.     end
  408.     # Dispose of sprite set
  409.     @spriteset.dispose
  410.     # If switching to title screen
  411.     if $scene.is_a?(Scene_Title)
  412.       # Fade out screen
  413.       Graphics.transition
  414.       Graphics.freeze
  415.     end
  416.     # If switching from battle test to any screen other than game over screen
  417.     if $BTEST and not $scene.is_a?(Scene_Gameover)
  418.       $scene = nil
  419.     end
  420.   end
  421.  
  422.   #--------------------------------------------------------------------------
  423.   # * Frame Update
  424.   # moded to use
  425.   #--------------------------------------------------------------------------
  426.   def update
  427.     # If battle event is running
  428.     if $game_system.battle_interpreter.running?
  429.       # Update interpreter
  430.       $game_system.battle_interpreter.update
  431.       # If a battler which is forcing actions doesn't exist
  432.       if $game_temp.forcing_battler == nil
  433.         # If battle event has finished running
  434.         unless $game_system.battle_interpreter.running?
  435.           # Rerun battle event set up if battle continues
  436.           unless judge
  437.             setup_battle_event
  438.           end
  439.         end
  440.         # If not after battle phase
  441.         if @phase != 5
  442.           # Refresh status window
  443.           @status_window.refresh
  444.         end
  445.       end
  446.     end
  447.     # Update system (timer) and screen
  448.     $game_system.update
  449.     $game_screen.update
  450.     # If timer has reached 0
  451.     if $game_system.timer_working and $game_system.timer == 0
  452.       # Abort battle
  453.       $game_temp.battle_abort = true
  454.     end
  455.     # Update windows
  456.     @help_window.update
  457.     @party_command_window.update
  458.     @actor_command_window.update
  459.     @log_window.update
  460.     @status_window.update
  461.     @message_window.update
  462.     # Update sprite set
  463.     @spriteset.update
  464.     # If transition is processing
  465.     if $game_temp.transition_processing
  466.       # Clear transition processing flag
  467.       $game_temp.transition_processing = false
  468.       # Execute transition
  469.       if $game_temp.transition_name == ""
  470.         Graphics.transition(20)
  471.       else
  472.         Graphics.transition(40, "Graphics/Transitions/" +
  473.         $game_temp.transition_name)
  474.       end
  475.     end
  476.     # If message window is showing
  477.     if $game_temp.message_window_showing
  478.       return
  479.     end
  480.     # If effect is showing
  481.     if @spriteset.effect?
  482.       return
  483.     end
  484.     # If game over
  485.     if $game_temp.gameover
  486.       # Switch to game over screen
  487.       $scene = Scene_Gameover.new
  488.       return
  489.     end
  490.     # If returning to title screen
  491.     if $game_temp.to_title
  492.       # Switch to title screen
  493.       $scene = Scene_Title.new
  494.       return
  495.     end
  496.     # If battle is aborted
  497.     if $game_temp.battle_abort
  498.       # Return to BGM used before battle started
  499.       $game_system.bgm_play($game_temp.map_bgm)
  500.       # Battle ends
  501.       battle_end(1)
  502.       return
  503.     end
  504.     # If waiting
  505.     if @wait_count > 0
  506.       # Decrease wait count
  507.       @wait_count -= 1
  508.       return
  509.     end
  510.     # If battler forcing an action doesn't exist,
  511.     # and battle event is running
  512.     if $game_temp.forcing_battler == nil and
  513.        $game_system.battle_interpreter.running?
  514.       return
  515.     end
  516.     # Branch according to phase
  517.     case @phase
  518.     when 1  # pre-battle phase
  519.       update_phase1
  520.     when 2  # party command phase
  521.       update_phase2
  522.     when 3  # actor command phase
  523.       update_phase3
  524.     when 4  # main phase
  525.       update_phase4
  526.     when 5  # after battle phase
  527.       update_phase5
  528.     end
  529.   end
  530.  
  531.  
  532.   # Chequea turno, linea, posa . final,etc
  533.   def log_add_line(line, origin, extra='')
  534.     complete = origin.name + line + extra + '.'
  535.  
  536.     @log_window.add_line(complete)
  537.     @log_window.refresh
  538.   end
  539.  
  540. end
  541.  
  542. #==============================================================================
  543. # ** Window_BattleLog
  544. #------------------------------------------------------------------------------
  545. #  This window displays amount of gold and EXP acquired at the end of a battle.
  546. #==============================================================================
  547.  
  548. class Window_BattleLog < Window_Base
  549.   #--------------------------------------------------------------------------
  550.   # * Object Initialization
  551.   #     exp       : EXP
  552.   #     gold      : amount of gold
  553.   #     treasures : treasures
  554.   #--------------------------------------------------------------------------
  555.   def initialize(troop_id)
  556.     @small_list = []
  557.     @troop_id = troop_id
  558.     #Wep::Lines_height.times {@list.push('')}
  559.     Wep::Lines_height.times {@small_list.push('')}
  560.     # until this, no contents
  561.     super(Wep::BattleWindow_X, Wep::BattleWindow_Y, Wep::BattleWindow_Width, Wep::Lines_height * 32 + 32)
  562.     self.z = 99
  563.     self.contents = Bitmap.new(width - 32, height - 32)
  564.     refresh
  565.   end
  566.  
  567.  
  568.   def end_log
  569.     if Wep::Battle_Ends[@troop_id] != nil
  570.       @list.push Wep::Battle_Ends[@troop_id]
  571.     else
  572.       @list.push Wep::Default_End
  573.     end
  574.  
  575.     @list.push Wep:Battle_Ends[troop_id]
  576.   end
  577.  
  578.   def refresh
  579.     self.contents = Bitmap.new(width - 32, height - 32)
  580.     for i in 0...@small_list.size
  581.       self.contents.draw_text(0, i * 32, Wep::BattleWindow_Width-32, 32, @small_list[i], 1)
  582.     end
  583.  
  584.   end
  585.  
  586.   def add_line(line)
  587.     # Add to the start and move
  588.     @small_list.unshift(line)
  589.     # Remove last element
  590.     @small_list.pop
  591.   end
  592.  
  593.   def add_special_line(line)
  594.     # Add to the start and move
  595.     @small_list.unshift(line)
  596.     # Remove last element
  597.     @small_list.pop
  598.     refresh
  599.   end
  600.  
  601. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement