Advertisement
gerkrt

RPGXP - ENG - Retro-Styled Battle Result Window

Sep 18th, 2011
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 15.34 KB | None | 0 0
  1. #==============================================================================
  2. # Retro-Styled Battle Result Window
  3. # By gerkrt/gerrtunk
  4. # Version: 1.1
  5. # License: GPL, credits
  6. # Date: 22/08/2011
  7. # IMPORTANT NOTE: to acces the more actualitzed or corrected version of this
  8. # script check here: http://usuarios.multimania.es/kisap/english_list.html
  9. #==============================================================================
  10.  
  11. =begin
  12.  
  13. --------Introduction-----------
  14.  
  15. This scripts lets you use a retro styled battle result window, like FFVI for
  16. example, where a small window on the top shows line per line the information.
  17.  
  18. But i expanded that. You can configure what you want to show or not and how it will
  19. be shown, grouped or not, and what number of lines will have the window.
  20.  
  21. Finally you can use a wait key mode or a wait time one.
  22.  
  23. ------Instructions-------------
  24.  
  25. First you have to select what you want to see. To do that use the option
  26. Things_to_show. This is a list of codes so if the code is here that option
  27. will be shown. The codes are:
  28.  
  29. :level_up, :gain_skill, :win_phrase, :gold, :exp, :treasures
  30.  
  31. Later you can configure the number of lines of the window in Lines_to_show.
  32. The retro games used 1, but you can add more lines to the window so the
  33. messages are shown faster.
  34.  
  35. Show_levels_in_one_line = true
  36.  
  37. These options define if for example it says , actor level up! actor level up!
  38. or actor level up!(2). true/false, active and inactive.
  39.  
  40. ------Vocabulary-----
  41.  
  42. The last options are the words the system show in the window. You can changue
  43. that.
  44.  
  45. Also you can configure battle wins phrases for each enemy troop.
  46.  
  47.   Battle_wins_phrases = {
  48.     2=>'Wep winned again2',
  49.     3=>'Wep winned again3',
  50.   }
  51. Where X=> is the troop id number and 'text' is th eprharse, respect the syntax.
  52. Note that exist a default option for the ones that dont have a entry here.
  53.  
  54. -----Compatibility----
  55.  
  56. You can desactivate the modification of the battle status windows, thats the one
  57. used for draw character info in battle.
  58.  
  59. Modify_window_battle_status = false
  60.  
  61. =end
  62.  
  63. module Wep
  64.   Show_levels_in_one_line = true
  65.   Lines_to_show = 1
  66.   Things_to_show = [:level_up, :gain_skill, :win_phrase, :gold, :exp, :treasures]
  67.   Modify_window_battle_status = true
  68.   Gain_level_phrase = ' level up'
  69.   Gain_skill_phrase = ' learned'
  70.   Gain_gold_phrase = ' gained.'
  71.   Treasure_gain_phrase = ' gained.'
  72.   Gain_exp_phrase = ' Exp gained.'
  73.   Battle_win_default_phrase = 'Wep! You win!.'
  74.   Battle_wins_phrases = {
  75.     2=>'Wep winned again2',
  76.     3=>'Wep winned again3',
  77.   }
  78.  
  79. end
  80.  
  81.  
  82. if Wep::Modify_window_battle_status
  83. #==============================================================================
  84. # ** Window_BattleStatus
  85. #------------------------------------------------------------------------------
  86. #  This window displays the status of all party members on the battle screen.
  87. #==============================================================================
  88.  
  89. class Window_BattleStatus < Window_Base
  90.    #--------------------------------------------------------------------------
  91.   # * Refresh
  92.   #--------------------------------------------------------------------------
  93.   def refresh
  94.     self.contents.clear
  95.     @item_max = $game_party.actors.size
  96.     for i in 0...$game_party.actors.size
  97.       actor = $game_party.actors[i]
  98.       actor_x = i * 160 + 4
  99.       draw_actor_name(actor, actor_x, 0)
  100.       draw_actor_hp(actor, actor_x, 32, 120)
  101.       draw_actor_sp(actor, actor_x, 64, 120)
  102.       if @level_up_flags[i]
  103.         #self.contents.font.color = normal_color
  104.         #self.contents.draw_text(actor_x, 96, 120, 32, "¡Sube Nivel!")
  105.       else
  106.         draw_actor_state(actor, actor_x, 96)
  107.       end
  108.     end
  109.   end
  110. end
  111.  
  112. end
  113.  
  114.  
  115. #==============================================================================
  116. # ** Window_BattleResult
  117. #------------------------------------------------------------------------------
  118. #  This window displays amount of gold and EXP acquired at the end of a battle.
  119. #==============================================================================
  120.  
  121.  
  122. class Window_BattleResult < Window_Base
  123.   attr_reader   :messages_max
  124.   attr_reader   :messages_index
  125.  
  126.   #--------------------------------------------------------------------------
  127.   # * Object Initialization
  128.   #     exp       : EXP
  129.   #     gold      : amount of gold
  130.   #     treasures : treasures
  131.   #--------------------------------------------------------------------------
  132.   def initialize(br)
  133.     @br = br # get battle result
  134.     @messages_index = 0 # shows the actual mesage of the window
  135.     @messages = [] # array of mesages: exp, gold,e tc
  136.     super(0, 0, 640,  (Wep::Lines_to_show * 32) + 32)
  137.     self.contents = Bitmap.new(width - 32, height - 32)
  138.     self.y = 0
  139.     self.back_opacity = 160
  140.     self.visible = false
  141.     generate_messages
  142.     refresh
  143.   end
  144.  
  145.   #--------------------------------------------------------------------------
  146.   # * Generate messages
  147.   # This extracts all the information of the battle result and push it in the
  148.   # messages list as phrases
  149.   #--------------------------------------------------------------------------
  150.   def generate_messages
  151.     i = 0
  152.    
  153.     # Win phrase
  154.     if Wep::Things_to_show.include? :win_phrase
  155.       if Wep::Battle_wins_phrases[$game_temp.battle_troop_id] != nil
  156.         @messages.push Wep::Battle_wins_phrases[$game_temp.battle_troop_id]
  157.       else
  158.         @messages.push Wep::Battle_win_default_phrase
  159.       end
  160.     end
  161.    
  162.     # Gold & exp
  163.     @messages.push @br.exp.to_s + Wep::Gain_exp_phrase if Wep::Things_to_show.include? :exp
  164.     @messages.push @br.gold.to_s + ' ' + $data_system.words.gold + Wep::Gain_gold_phrase  if Wep::Things_to_show.include? :gold
  165.    
  166.     # Actors iteration
  167.     for br_actor in @br.actors_data
  168.      
  169.         # Check diff so can gain levels or exp
  170.         if br_actor.gained_levels > 0
  171.          
  172.           # LEVEL UP. If actived to show levelup, use configurated method
  173.           if Wep::Things_to_show.include? :level_up
  174.             if Wep::Show_levels_in_one_line
  175.               @messages.push (br_actor.actor.name + ' ' + Wep::Gain_level_phrase +
  176.               "(#{br_actor.gained_levels}).")
  177.             else
  178.               for lv in 0...br_actor.gained_levels
  179.                 @messages.push (br_actor.actor.name + ' ' + Wep::Gain_level_phrase)
  180.               end
  181.             end
  182.           end
  183.          
  184.          
  185.           # SKILL GAIN UP. If actived to show skill learn, use configurated method
  186.           if Wep::Things_to_show.include? :gain_skill
  187.              for skill_id in br_actor.gained_skills
  188.                 @messages.push (br_actor.actor.name + ' ' + Wep::Gain_skill_phrase + ' ' +
  189.                    $data_skills[skill_id].name + '.')
  190.               end
  191.      
  192.           end
  193.        
  194.         end
  195.        
  196.       i += 1
  197.     end
  198.  
  199.     # Tesoros
  200.     if Wep::Things_to_show.include? :treasures
  201.       b = Hash.new(0) # use this hash to count duplicates
  202.      
  203.       # iterate over the array, counting duplicate entries
  204.       @br.treasures.each do |v|
  205.         b[v] += 1
  206.       end
  207.      
  208.       b.each do |k, v|
  209.         @messages.push k.name + '(' + v.to_s + ')' + Wep::Treasure_gain_phrase
  210.       end
  211.     end
  212.  
  213.   end
  214.  
  215.   #--------------------------------------------------------------------------
  216.   # * Refresh
  217.   # Refresh with new messages each time.
  218.   #--------------------------------------------------------------------------
  219.   def refresh
  220.     self.contents.clear
  221.     if @messages[@messages_index] != nil
  222.       # Use lines configuration
  223.       if Wep::Lines_to_show == 1
  224.          self.contents.draw_text(0, 0, 640, 32, @messages[@messages_index])
  225.       else
  226.          for i in 0...Wep::Lines_to_show
  227.            # It adds the line count to message index to show more lines
  228.            if @messages[@messages_index + i] != nil
  229.              self.contents.draw_text(0, i * 32, 640, 32, @messages[@messages_index + i])
  230.            end
  231.          end
  232.       end
  233.       @messages_index += Wep::Lines_to_show
  234.     end
  235.     # When false, it will end battle
  236.     if @messages_index >= @messages.size - 1
  237.       return false
  238.     else
  239.       return true
  240.     end
  241.   end
  242.  
  243. end
  244.  
  245.  
  246. module Wep
  247.   Scripts_list = [] unless defined? Scripts_list
  248.   Scripts_list.push ('Retro-Styled Battle Result Window')
  249. end
  250.  
  251.  
  252. #==============================================================================
  253. # Battle Result
  254. # By gerkrt/gerrtunk
  255. # Version: 1.0
  256. # License: GPL, credits
  257. # Date: 22/08/2011
  258. # IMPORTANT NOTE: to acces the more actualitzed or corrected version of this
  259. # script check here: http://usuarios.multimania.es/kisap/english_list.html
  260. #==============================================================================
  261.  
  262. =begin
  263.  
  264. --------Introduction-----------
  265.  
  266. I created this class so anyone can easily create a custom or more advanced
  267. battle result window. This object gives you all the information need in a simplier
  268. way and without a lot of trouble. It creates a array of party actors with:
  269.  
  270. -Array of learned skills ids of each actor
  271. -Gained levels
  272. -Actor referen ce
  273. -Origin and ending exp and levels
  274. -All the default info(gold,etc)
  275.  
  276. ------Instructions-------------
  277.  
  278. You just need to give to it the initial levels of the party. For that, i put
  279. here the sample code i use in scene battle start_phase5
  280.  
  281.     initial_levels = []
  282.     for ac in $game_party.actors
  283.       initial_levels.push (ac.level)
  284.     end
  285.    
  286.     You only have to pass that array.
  287.    
  288.    
  289. =end
  290.  
  291.  
  292.  
  293. ResultActor = Struct.new( :actor, :origin_level,  :gained_skills,
  294.   :gained_levels)
  295.  
  296. class Battle_Result
  297.  
  298.   attr_reader :actors_data
  299.   attr_reader :exp
  300.   attr_reader :gold
  301.   attr_reader :treasures
  302.  
  303.   #--------------------------------------------------------------------------
  304.   # * Initialize
  305.   #--------------------------------------------------------------------------
  306.   def initialize(initial_levels, exp, gold, treasures)
  307.     @actors_initals_levels = initial_levels
  308.     @exp = exp
  309.     @gold = gold
  310.     @treasures = treasures
  311.     @actors_data = []
  312.     generate_data(initial_levels)
  313.  
  314.     #p @messages
  315.   end
  316.  
  317.  
  318.   #--------------------------------------------------------------------------
  319.   # * Generate data
  320.   # This method generates the object data.
  321.   #--------------------------------------------------------------------------
  322.   def generate_data(initial_levels)
  323.     i = 0
  324.     # Actors gain level
  325.     for actor in $game_party.actors
  326.       @actors_data.push (ResultActor.new(actor, initial_levels[i],  
  327.       [], 0))
  328.       count = 0
  329.       # Valid actor?
  330.       if actor.cant_get_exp? == false
  331.         difference = actor.level - @actors_initals_levels[i]
  332.         # Check diff so can gain levels or exp
  333.         if difference > 0
  334.          
  335.           # LEVEL UP.
  336.           @actors_data.last.gained_levels = difference
  337.          
  338.           # SKILL GAIN UP.
  339.           for lv in 0...difference
  340.             # If it have skills learning
  341.             for lea in $data_classes[actor.class_id].learnings
  342.               if lea.level ==  @actors_initals_levels[i] + lv
  343.                 @actors_data.last.gained_skills.push (lea.skill_id)
  344.               end
  345.             end
  346.           end
  347.         end
  348.       end
  349.       i += 1
  350.     end
  351.   end
  352.  
  353. end
  354.  
  355.  
  356.  
  357. module Wep
  358.   Scripts_list = [] unless defined? Scripts_list
  359.   Scripts_list.push ('Battle Result')
  360. end
  361.  
  362.  
  363.  
  364. #==============================================================================
  365. # ** Scene_Battle (part 1)
  366. #------------------------------------------------------------------------------
  367. #  This class performs battle screen processing.
  368. #==============================================================================
  369.  
  370. class Scene_Battle
  371.   #--------------------------------------------------------------------------
  372.   # * Main Processing
  373.   #--------------------------------------------------------------------------
  374.   alias wep_rbr_sb_main main
  375.   def main
  376.     @br_mark_end = false
  377.     wep_rbr_sb_main
  378.   end
  379.  
  380.   #--------------------------------------------------------------------------
  381.   # * Start After Battle Phase
  382.   # moded to extract initial levels and call battle result
  383.   #--------------------------------------------------------------------------
  384.   def start_phase5
  385.     # Obtain extra info for battle result object
  386.     initial_levels = []
  387.     for ac in $game_party.actors
  388.       initial_levels.push (ac.level)
  389.     end
  390.     # Shift to phase 5
  391.     @phase = 5
  392.     # Play battle end ME
  393.     $game_system.me_play($game_system.battle_end_me)
  394.     # Return to BGM before battle started
  395.     $game_system.bgm_play($game_temp.map_bgm)
  396.     # Initialize EXP, amount of gold, and treasure
  397.     exp = 0
  398.     gold = 0
  399.     treasures = []
  400.     # Loop
  401.     for enemy in $game_troop.enemies
  402.       # If enemy is not hidden
  403.       unless enemy.hidden
  404.         # Add EXP and amount of gold obtained
  405.         exp += enemy.exp
  406.         gold += enemy.gold
  407.         # Determine if treasure appears
  408.         if rand(100) < enemy.treasure_prob
  409.           if enemy.item_id > 0
  410.             treasures.push($data_items[enemy.item_id])
  411.           end
  412.           if enemy.weapon_id > 0
  413.             treasures.push($data_weapons[enemy.weapon_id])
  414.           end
  415.           if enemy.armor_id > 0
  416.             treasures.push($data_armors[enemy.armor_id])
  417.           end
  418.         end
  419.       end
  420.     end
  421.     # Treasure is limited to a maximum of 6 items
  422.     treasures = treasures[0..5]
  423.     # Obtaining EXP
  424.     for i in 0...$game_party.actors.size
  425.       actor = $game_party.actors[i]
  426.       if actor.cant_get_exp? == false
  427.         last_level = actor.level
  428.         actor.exp += exp
  429.         if actor.level > last_level
  430.           @status_window.level_up(i)
  431.         end
  432.       end
  433.     end
  434.     # Obtaining gold
  435.     $game_party.gain_gold(gold)
  436.     # Obtaining treasure
  437.     for item in treasures
  438.       case item
  439.       when RPG::Item
  440.         $game_party.gain_item(item.id, 1)
  441.       when RPG::Weapon
  442.         $game_party.gain_weapon(item.id, 1)
  443.       when RPG::Armor
  444.         $game_party.gain_armor(item.id, 1)
  445.       end
  446.     end
  447.     # Make battle result
  448.     br = Battle_Result.new(initial_levels, exp, gold, treasures)
  449.     @result_window = Window_BattleResult.new(br)
  450.     # Set wait count
  451.     @phase5_wait_count = 100
  452.   end
  453.  
  454.   #--------------------------------------------------------------------------
  455.   # * Frame Update (after battle phase)
  456.   # moded so refresh battle result each time until it ends
  457.   #--------------------------------------------------------------------------
  458.   def update_phase5
  459.     # If wait count is larger than 0
  460.     if @phase5_wait_count > 0
  461.       # Decrease wait count
  462.       @phase5_wait_count -= 1
  463.       # If wait count reaches 0
  464.       if @phase5_wait_count == 0
  465.         # Show result window
  466.         @result_window.visible = true
  467.         # Clear main phase flag
  468.         $game_temp.battle_main_phase = false
  469.         # Refresh status window
  470.         @status_window.refresh
  471.       end
  472.       return
  473.     end
  474.    
  475.    
  476.  
  477.     # If C button was pressed advance battleresutl info
  478.     if Input.trigger?(Input::C)
  479.  
  480.      # Battle end only if +1 refresh of the window,so, the last have to
  481.      # be pressed
  482.      if @br_mark_end
  483.        battle_end(0)
  484.      end
  485.      
  486.      if not @result_window.refresh
  487.        @br_mark_end = true
  488.      end
  489.      
  490.     end
  491.    
  492.   end
  493. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement