Advertisement
neonblack

Battle Pop-ups V1.2

Nov 11th, 2012
1,458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 28.87 KB | None | 0 0
  1. ###--------------------------------------------------------------------------###
  2. #  CP Pop-ups script                                                           #
  3. #  Version 1.2a                                                                #
  4. #                                                                              #
  5. #      Credits:                                                                #
  6. #  Original code by: Neon Black                                                #
  7. #  Modified by:                                                                #
  8. #                                                                              #
  9. #  This work is licensed under the Creative Commons Attribution-NonCommercial  #
  10. #  3.0 Unported License. To view a copy of this license, visit                 #
  11. #  http://creativecommons.org/licenses/by-nc/3.0/.                             #
  12. #  Permissions beyond the scope of this license are available at               #
  13. #  http://cphouseset.wordpress.com/liscense-and-terms-of-use/.                 #
  14. #                                                                              #
  15. #      Contact:                                                                #
  16. #  NeonBlack - neonblack23@live.com (e-mail) or "neonblack23" on skype         #
  17. ###--------------------------------------------------------------------------###
  18.  
  19. ###--------------------------------------------------------------------------###
  20. #      Revision information:                                                   #
  21. #  V1.2 - 11.10.2012~11.11.2012                                                #
  22. #   Removed info view                                                          #
  23. #   Added state and buff pop-ups                                               #
  24. #   Lots of large changes                                                      #
  25. #  V1.1 - 8.23.2012                                                            #
  26. #   Slight tweaks for later use                                                #
  27. #  V1.0 - 7.15.2012                                                            #
  28. #   Wrote and debugged main script                                             #
  29. ###--------------------------------------------------------------------------###
  30.  
  31. ###--------------------------------------------------------------------------###
  32. #      Compatibility:                                                          #
  33. #  Alias       - Game_Battler: initialize, regenerate_hp, regenerate_mp,       #
  34. #                              regenerate_tp                                   #
  35. #                Sprite_Battler: update                                        #
  36. #                Window_BattleLog: display_counter, display_reflection,        #
  37. #                                  display_substitute,                         #
  38. #                                  display_action_results, display_failure,    #
  39. #                                  display_critical, display_miss,             #
  40. #                                  display_evasion, display_hp_damage,         #
  41. #                                  display_mp_damage, display_tp_damage        #
  42. #  Overwrites  - Window_BattleLog: display_added_states,                       #
  43. #                                  display_removed_states,                     #
  44. #                                  display_changed_buffs, display_buffs        #
  45. #  New Objects - Game_Battler: create_pop, do_pop, pop_hp, pop_mp, pop_tp,     #
  46. #                              get_popup, pop_reset                            #
  47. #                Sprite_Battler: setup_new_popup, from_viewport,               #
  48. #                                make_pop_hash, pop_types, create_popup,       #
  49. #                                pos_by_type, update_popup,                    #
  50. #                                check_pops_for_nil, find_pos_arc, find_arc,   #
  51. #                                find_pos_raise, find_pos_slow_raise,          #
  52. #                                find_pos_zoom, lowest_point                   #
  53. #                Window_BattleLog: create_state_pop                            #
  54. #                RPG::State: pop_values, set_pop_values                        #
  55. ###--------------------------------------------------------------------------###
  56.  
  57. ###--------------------------------------------------------------------------###
  58. #      Instructions:                                                           #
  59. #  Place this script in the "Materials" section of the scripts above main.     #
  60. #  This script adds an extra little window to the battle screen when           #
  61. #  selecting an enemy that displays a guage with the enemey's hp, mp, tp, and  #
  62. #  states.  This also adds pop-ups to the enemies when they take damage,       #
  63. #  reflect or counter an attack, or just any other general information that    #
  64. #  may be easier to read as a pop-up than in the battle log window.  You can   #
  65. #  adjust how many of these look with the info below.                          #
  66. ###-----                                                                -----###
  67. #      Tags:                                                                   #
  68. #  Several tags can be used in states to change the pop-up text that appears   #
  69. #  when the state is inflicted or removed.  Simply add the tag to a state's    #
  70. #  notebox.  The tags are as follows.                                          #
  71. #                                                                              #
  72. #    pop add[text] - Displays "text" when the state is added.                  #
  73. #    pop remove[text] - Displays "text" when the state is removed.  Leave      #
  74. #                       blank to disable the state.                            #
  75. #                                                                              #
  76. #    pop add color[x] - Changes the pop-up color when the state is added.      #
  77. #    pop remove color[x] - Changes the color of the pop-up when the state is   #
  78. #                          removed.  If "x" is a number, it chooses the color  #
  79. #                          from the windowskin.  If "x" is a word, it chooses  #
  80. #                          the color from the COLOUR hash in the config        #
  81. #                          section.                                            #
  82. #                                                                              #
  83. #    pop add style[type] - Changes the pop-up style when the state is added.   #
  84. #    pop remove style[type] - Changes the pop-up style when the state is       #
  85. #                             removed.  Can be set to any of the following:    #
  86. #                             bounce, zoom, raise, slow_raise                  #
  87. ###--------------------------------------------------------------------------###
  88.  
  89. ###--------------------------------------------------------------------------###
  90. #      Config:                                                                 #
  91. #  These are the default values used by several of the functions in the        #
  92. #  script.  You may change these values as you find your game requires in      #
  93. #  order to give the player a better playing experience based on your game.    #
  94. #                                                                              #
  95. module CP         # Do not                                                     #
  96. module BATTLEVIEW #  change these.                                             #
  97. #                                                                              #
  98. ###-----                                                                -----###
  99. # These are the settings for the pop-up display.  The height is how high from  #
  100. # the origin a pop-up will fly.  Width is how far across vertically it can go  #
  101. # from the origin in either direction.  These settings effect all pop-up       #
  102. # styles.                                                                      #
  103. HEIGHT = 64 # Default = 64                                                     #
  104. WIDTH = 16 # Default = 16                                                      #
  105. #                                                                              #
  106. # These are the font settings for pop-ups.  These affect many of the settings  #
  107. # of all pop-ups overall.                                                      #
  108. POP_SIZE = 32 # Default = 32                                                   #
  109. POP_BOLD = true # Default = true                                               #
  110. #                                                                              #
  111. # To prevent pop-ups from covering each other up, new pop-ups will be offset   #
  112. # based on the text size and appear above the last one.  This value is the max #
  113. # number of times the pop-ups will offset before returning to the bottom.      #
  114. OFFSETS = 4 # Default = 4                                                      #
  115. #                                                                              #
  116. # This hash contains the text that pops up for different situations.  You can  #
  117. # set each of them to different text to change what they say when they pop-up. #
  118. # This hash MUST include :hp, :mp, and :tp.  In each of the tags you can       #
  119. # include "%s" for the default information for the pop up (such as state names #
  120. # or damage numbers).                                                          #
  121. TEXT ={ # Don't edit this line.                                                #
  122.  
  123. :hp       => "%s",
  124. :mp       => "%s MP",
  125. :tp       => "%s FP",
  126. :counter  => "Counter",
  127. :reflect  => "Reflect",
  128. :sub      => "Stand-in",
  129. :fail     => "Fail",
  130. :critical => "Critical",
  131. :miss     => "Miss",
  132. :evade    => "Evade",
  133. :hpregen  => "+%s HP",
  134. :mpregen  => "+%s MP",
  135. :tpregen  => "+%s FP",
  136. :hpslip   => "-%s HP",
  137. :mpslip   => "-%s MP",
  138. :tpslip   => "-%s FP",
  139. :addstate => "+%s",
  140. :substate => "-%s",
  141. :buff     => "%s Up",
  142. :debuff   => "%s Down",
  143. :rebuff   => "%s Revert",
  144.  
  145. } # Don't edit this line.                                                      #
  146. #                                                                              #
  147. # This hash contains the colours used by the pop-ups.  Each must contain both  #
  148. # a main colour and an outline colour.  Also note that this hash MUST contain  #
  149. # :null, :hpdamage, :hpheal, :mpdamage, :mpheal, :tpdamage, and :tpheal.  It   #
  150. # can then use any of the other hash values in the hash above except for :hp,  #
  151. # :mp, or :tp.  If a hash value is not defined, null is used instead.          #
  152. COLOUR ={ # Don't edit this line.                                              #
  153.  
  154. :null     => [Color.new(255, 255, 255), Color.new(  0,   0,   0)],
  155. :hpdamage => [Color.new(255, 255, 255), Color.new(200,   0,   0)],
  156. :hpheal   => [Color.new(255, 255, 255), Color.new( 25, 155,  25)],
  157. :mpdamage => [Color.new(200, 255, 255), Color.new(200,   0,   0)],
  158. :mpheal   => [Color.new(200, 255, 255), Color.new( 25, 155,  25)],
  159. :tpdamage => [Color.new(120, 255, 120), Color.new(200,   0,   0)],
  160. :tpheal   => [Color.new(120, 255, 120), Color.new( 25, 155,  25)],
  161. :hpslip   => [Color.new(255, 255, 255), Color.new(200,   0,   0)],
  162. :hpregen  => [Color.new(255, 255, 255), Color.new( 25, 155,  25)],
  163. :mpslip   => [Color.new(200, 255, 255), Color.new(200,   0,   0)],
  164. :mpregen  => [Color.new(200, 255, 255), Color.new( 25, 155,  25)],
  165. :tpslip   => [Color.new(120, 255, 120), Color.new(200,   0,   0)],
  166. :tpregen  => [Color.new(120, 255, 120), Color.new( 25, 155,  25)],
  167. #                                                                              #
  168. # The following colors are used by different scripts.  Please check the name   #
  169. # of the script directly above the set of colors.                              #
  170. #   CP Enemy Scan v1.1+                                                        #
  171. :weak_pop   => [Color.new(255, 100,   0), Color.new( 50,   0,   0)],
  172. :strong_pop => [Color.new(100, 100, 225), Color.new(  0,   0,  45)],
  173.  
  174. } # Don't edit this line.                                                      #
  175. #                                                                              #
  176. # The following hash contains the style of each of the pop-ups.  Any tag from  #
  177. # either of the last two hashes may be used except for :null.  If a tag is not #
  178. # present, the pop-up style will be bounce.  The valid styles are:             #
  179. #  :bounce, :raise, :slow_raise, :zoom                                         #
  180. POP_STYLE ={ # Don't edit this line.                                           #
  181.  
  182. :counter  => :zoom,
  183. :reflect  => :zoom,
  184. :sub      => :zoom,
  185. :fail     => :slow_raise,
  186. :critical => :raise,
  187. :miss     => :slow_raise,
  188. :evade    => :slow_raise,
  189. :addstate => :raise,
  190. :substate => :slow_raise,
  191. :hpregen  => :slow_raise,
  192. :mpregen  => :slow_raise,
  193. :tpregen  => :slow_raise,
  194. :buff     => :raise,
  195. :debuff   => :raise,
  196. :rebuff   => :slow_raise,
  197. #                                                                              #
  198. # The following styles are used by different scripts.  Please check the name   #
  199. # of the script directly above the set of styles.                              #
  200. #   CP Enemy Scan v1.1+                                                        #
  201. :weak_pop   => :raise,
  202. :strong_pop => :slow_raise,
  203.  
  204. } # Don't edit this line.                                                      #
  205. ###--------------------------------------------------------------------------###
  206.  
  207.  
  208. ###--------------------------------------------------------------------------###
  209. #  The following lines are the actual core code of the script.  While you are  #
  210. #  certainly invited to look, modifying it may result in undesirable results.  #
  211. #  Modify at your own risk!                                                    #
  212. ###--------------------------------------------------------------------------###
  213.  
  214.  
  215. end
  216. end
  217.  
  218. $imported = {} if $imported.nil?
  219. $imported["CP_BATTLEVIEW"] = 1.2
  220.  
  221. class Game_Battler < Game_BattlerBase
  222.   attr_accessor :popup  ## Allows use of the popup array.
  223.  
  224.   alias cp_bv_initialize initialize
  225.   def initialize
  226.     cp_bv_initialize
  227.     @popup = []  ## Adds the popup array.
  228.   end
  229.  
  230.   def create_pop(text, colour, type = nil)  ## Create a new popup.
  231.     tmp = [text, colour, type]              ## Colour comes form the hash above.
  232.     @popup = [] if @popup.nil?
  233.     @popup.push(tmp)  ## Push the popup to the array.
  234.   end
  235.  
  236.   def do_pop(key, text = "")
  237.     return unless CP::BATTLEVIEW::TEXT.include?(key)  ## Checks text hash.
  238.     string = CP::BATTLEVIEW::TEXT[key] ## Gets the text from the text hash.
  239.     n1 = string.gsub(/%s/, text.to_s)
  240.     n2 = key  ## Sets the colour hash value.
  241.     pop = CP::BATTLEVIEW::POP_STYLE[key]
  242.     create_pop(n1, n2, pop)  ## Sends it to the popup maker.
  243.   end
  244.    
  245.   def pop_hp(dmg)  ## Similar to the above, but with added steps.
  246.     if dmg < 0  ## Check for healing or damage.
  247.       i = dmg * -1  ## Makes damage negative for healing.
  248.       n2 = :hpheal  ## Gets the heal colour hash value.
  249.       pop = CP::BATTLEVIEW::POP_STYLE[:hpheal]
  250.     else
  251.       i = dmg
  252.       n2 = :hpdamage  ## Gets the damage colour hash value.
  253.       pop = CP::BATTLEVIEW::POP_STYLE[:hpdamage]
  254.     end
  255.     pop = CP::BATTLEVIEW::POP_STYLE[:hp] if pop.nil?
  256.     string = CP::BATTLEVIEW::TEXT[:hp]
  257.     n1 = string.gsub(/%s/, i.to_s)  ## Sets the string for damage.
  258.     create_pop(n1, n2, pop)  ## Sends it to the popup maker.
  259.   end
  260.  
  261.   def pop_mp(dmg)
  262.     if dmg < 0
  263.       i = dmg * -1
  264.       n2 = :mpheal
  265.       pop = CP::BATTLEVIEW::POP_STYLE[:mpheal]
  266.     else
  267.       i = dmg
  268.       n2 = :mpdamage
  269.       pop = CP::BATTLEVIEW::POP_STYLE[:mpdamage]
  270.     end
  271.     pop = CP::BATTLEVIEW::POP_STYLE[:mp] if pop.nil?
  272.     string = CP::BATTLEVIEW::TEXT[:mp]
  273.     n1 = string.gsub(/%s/, i.to_s)
  274.     create_pop(n1, n2, pop)
  275.   end
  276.  
  277.   def pop_tp(dmg)
  278.     if dmg < 0
  279.       i = dmg * -1
  280.       n2 = :tpheal
  281.       pop = CP::BATTLEVIEW::POP_STYLE[:tpheal]
  282.     else
  283.       i = dmg
  284.       n2 = :tpdamage
  285.       pop = CP::BATTLEVIEW::POP_STYLE[:tpdamage]
  286.     end
  287.     pop = CP::BATTLEVIEW::POP_STYLE[:tp] if pop.nil?
  288.     string = CP::BATTLEVIEW::TEXT[:tp]
  289.     n1 = string.gsub(/%s/, i.to_s)
  290.     create_pop(n1, n2, :bounce)
  291.   end
  292.  
  293.   def get_popup  ## Gets a popup and removes the bottom one.
  294.     res = @popup[0]  ## Gets the next popup to display.
  295.     @popup = @popup.last(@popup.size - 1)  ## Removes it from the list.
  296.     return res  ## Returns the popup.
  297.   end
  298.  
  299.   def pop_reset
  300.     @popup = []  ## Removes all popups from the list.
  301.   end
  302.  
  303.   alias cp_pop_slip_hp regenerate_hp
  304.   def regenerate_hp
  305.     cp_pop_slip_hp
  306.     if @result.hp_damage < 0
  307.       do_pop(:hpregen, -@result.hp_damage)
  308.     elsif @result.hp_damage > 0
  309.       do_pop(:hpslip, @result.hp_damage)
  310.     end
  311.   end
  312.  
  313.   alias cp_pop_slip_mp regenerate_mp
  314.   def regenerate_mp
  315.     cp_pop_slip_mp
  316.     if @result.mp_damage < 0
  317.       do_pop(:mpregen, -@result.mp_damage)
  318.     elsif @result.mp_damage > 0
  319.       do_pop(:mpslip, @result.mp_damage)
  320.     end
  321.   end
  322.  
  323.   alias cp_pop_slip_tp regenerate_tp
  324.   def regenerate_tp
  325.     cp_pop_slip_tp
  326.     rate = (max_tp * trg).to_i
  327.     if rate > 0
  328.       do_pop(:tpregen, rate)
  329.     elsif rate < 0
  330.       do_pop(:tpslip, rate)
  331.     end
  332.   end
  333. end
  334.  
  335. class Sprite_Battler < Sprite_Base
  336.   alias cp_bv_update update
  337.   def update
  338.     cp_bv_update
  339.     if @battler && @battler.use_sprite?
  340.       setup_new_popup  ## Sets up popups if sprites are used.
  341.       update_popup
  342.     end
  343.   end
  344.  
  345.   def setup_new_popup
  346.     unless @battler.popup.empty?  ## Only makes popups for enemies.
  347.       create_popup(@battler.get_popup)  ## Sorry sideview battles.
  348.       update_popup
  349.     end
  350.   end
  351.  
  352.   def from_viewport
  353.     return @viewport4.nil? ? viewport : @viewport4
  354.   end
  355.  
  356.   def make_pop_hash
  357.     if @pop_sprite.nil?  ## Holds sprites in an array.
  358.       @pop_sprite = {}
  359.       pop_types.each {|type| @pop_sprite[type] = [] }
  360.     end
  361.   end
  362.  
  363.   def pop_types
  364.     [:bounce, :raise, :slow_raise, :zoom]
  365.   end
  366.  
  367.   def create_popup(pop)  ## Creates the popup sprite.
  368.     type = pop_types.include?(pop[2]) ? pop[2] : pop_types[0]
  369.     make_pop_hash
  370.     sprite = ::Sprite.new(from_viewport)  ## Makes a new sprite.
  371.     sprite.bitmap = Bitmap.new(240, 64)  ## Makes the sprite bitmap.
  372.     if pop[1].is_a?(Symbol)  ## Pop colour.
  373.       n = CP::BATTLEVIEW::COLOUR.include?(pop[1]) ? pop[1] : :null
  374.       c1 = CP::BATTLEVIEW::COLOUR[n][0]
  375.       c2 = CP::BATTLEVIEW::COLOUR[n][1]
  376.     elsif pop[1].is_a?(Integer)
  377.       n = pop[1]
  378.       c1 = Cache.system("Window").get_pixel(64 + (n % 8) * 8, 96 + (n / 8) * 8)
  379.       c2 = Font.default_out_color
  380.     else
  381.       c1 = Font.default_color
  382.       c2 = Font.default_out_color
  383.     end
  384.     sprite.bitmap.font.color.set(c1)  ## Text.
  385.     sprite.bitmap.font.out_color.set(c2)  ## Outline.
  386.     sprite.bitmap.font.bold = CP::BATTLEVIEW::POP_BOLD  ## Makes the text bold.
  387.     sprite.bitmap.font.size = CP::BATTLEVIEW::POP_SIZE  ## Sets the font size.
  388.     numb = sprite.bitmap.text_size(pop[0]).height
  389.     sprite.ox = sprite.bitmap.width / 2  ## Sets the sprite's center.
  390.     sprite.oy = (sprite.bitmap.height + numb) / 2
  391.     sprite.bitmap.draw_text(0, 0, 240, 64, pop[0], 1)  ## Draws the bitmap.
  392.     i = rand(2)  ## Chooses left or right movement for the sprite.
  393.     pl = i == 1 ? rand * 1 : rand * -1  ## Sets max offset.
  394.     frame = 1  ## Frame for the sprite.
  395.     pos =  pos_by_type(frame, pl, type) ## Finds the on screen position.
  396.     sprite.x = pos[0]  ## Moves the sprite.
  397.     sprite.y = pos[1] - (@pop_sprite[type].size % CP::BATTLEVIEW::OFFSETS) * CP::BATTLEVIEW::POP_SIZE
  398.     sprite.zoom_x = pos[2]  ## Zooms the sprite.
  399.     sprite.zoom_y = pos[3]
  400.     sprite.z = z + 350  ## Changes the sprite's Z position.
  401.     first = @pop_sprite[type].last(CP::BATTLEVIEW::OFFSETS).index(nil)
  402.     if first
  403.       if @pop_sprite[type].size < CP::BATTLEVIEW::OFFSETS
  404.         @pop_sprite[type][first] = [sprite, frame, pl, type]
  405.       else
  406.         @pop_sprite[type][CP::BATTLEVIEW::OFFSETS - first] = [sprite, frame, pl, type]
  407.       end
  408.     else
  409.       @pop_sprite[type].push([sprite, frame, pl, type])  ## Adds the sprite to an array.
  410.     end
  411.   end
  412.  
  413.   def pos_by_type(frame, pl, type)
  414.     case type
  415.     when :bounce
  416.       find_pos_arc(frame, pl)
  417.     when :raise
  418.       find_pos_raise(frame, pl)
  419.     when :slow_raise
  420.       find_pos_slow_raise(frame, pl)
  421.     when :zoom
  422.       find_pos_zoom(frame, pl)
  423.     else
  424.       find_pos_arc(frame, pl)
  425.     end
  426.   end
  427.  
  428.   def update_popup
  429.     deltree = {}  ## Sets sprites to delete this turn.
  430.     make_pop_hash
  431.     @pop_sprite.each do |type, array|
  432.       next if array.empty?  ## Return if no sprites.
  433.       array.each_with_index do |sprite, i|
  434.         next unless sprite
  435.         sprite[0].opacity = 255  ## Sets the sprite's opacity.
  436.         sprite[1] += 1  ## Update the sprite's frame.
  437.         if sprite[1] >= 70  ## Prepare to delete.
  438.           deltree[type] = [] if deltree[type].nil?
  439.           deltree[type].push(i)
  440.         end
  441.         if sprite[1] >= 60  ## Begins to fade at frame 60.
  442.           n = 70 - sprite[1]
  443.           n *= 25
  444.           sprite[0].opacity = n
  445.         end
  446.         pos = pos_by_type(sprite[1], sprite[2], sprite[3])  ## Gets the position.
  447.         sprite[0].x = pos[0]  ## Moves the sprite.
  448.         sprite[0].y = pos[1] - (i % CP::BATTLEVIEW::OFFSETS) * CP::BATTLEVIEW::POP_SIZE
  449.         sprite[0].zoom_x = pos[2]  ## Zooms the sprite.
  450.         sprite[0].zoom_y = pos[3]
  451.       end
  452.     end
  453.     deltree.each do |type, array|
  454.       array.each do |dm|
  455.         @pop_sprite[type][dm][0].dispose
  456.         @pop_sprite[type][dm] = nil
  457.       end
  458.       while @pop_sprite[type].size > CP::BATTLEVIEW::OFFSETS
  459.         if check_pops_for_nil(type)
  460.           @pop_sprite[type] = @pop_sprite[type].last(@pop_sprite[type].size - 4)
  461.         else
  462.           break
  463.         end
  464.       end
  465.     end
  466.     @pop_sprite.each do |type, array|
  467.       @pop_sprite[type] = [] if array.compact.empty?
  468.     end
  469.   end
  470.  
  471.   def check_pops_for_nil(type)
  472.     CP::BATTLEVIEW::OFFSETS.times do |i|
  473.       return false unless @pop_sprite[type][i].nil?
  474.     end
  475.     return true
  476.   end
  477.  
  478.   def find_pos_arc(frame, pl)  ## Finds the sprite position.
  479.     rw = CP::BATTLEVIEW::WIDTH * pl  ## Gets the grid to use.
  480.     rh = CP::BATTLEVIEW::HEIGHT
  481.     rx = x  ## Gets the origin X and Y.
  482.     im = lowest_point
  483.     ry = [y - height * 0.3, im].min
  484.     ra = [(frame * 9), 180].min  ## Finds the position on an arc.
  485.     ax, ay = find_arc(rw, rh, ra, frame)
  486.     ix = rx + ax  ## Places the arc on the grid.
  487.     iy = ry - ay
  488.     if frame > 20
  489.       rw2 = rw / 2
  490.       rh2 = rh / 2
  491.       ra2 = [((frame - 20) * 9), 180].min
  492.       ax2, ay2 = find_arc(rw2, rh2, ra2, frame - 20)
  493.       ix += (ax2 - rw2)
  494.       iy -= ay2
  495.     end
  496.     return [ix, iy, 1.0, 1.0]  ## Returns the positions.
  497.   end
  498.  
  499.   def find_arc(rw, rh, ra, frame)  ## Gets X and Y of the arc pos.
  500.     sx = (rw * Math.cos((45 + 0.5 * ra) * Math::PI / 180))
  501.     sy = rh * Math.sin(ra * Math::PI / 180)
  502.     sy = (sy * -1) / 3 if sy < 0
  503.     return [sx, sy]
  504.   end
  505.  
  506.   def find_pos_raise(frame, pl)
  507.     rx = x
  508.     b = [y - height / 2, lowest_point].min
  509.     ry = b - CP::BATTLEVIEW::HEIGHT * (1 - ((70 - frame) ** 12).to_f / (70 ** 12))
  510.     return [rx, ry, 1.0, 1.0]
  511.   end
  512.  
  513.   def find_pos_slow_raise(frame, pl)
  514.     rx = x
  515.     b = [y - height / 2, lowest_point].min
  516.     ry = b - CP::BATTLEVIEW::HEIGHT * (frame.to_f / 70)
  517.     return [rx, ry, 1.0, 1.0]
  518.   end
  519.  
  520.   def find_pos_zoom(frame, pl)
  521.     zoom = 3.0 - [frame.to_f, 10.0].min / 5
  522.     ry = [y - height / 2, lowest_point].min + CP::BATTLEVIEW::POP_SIZE *
  523.          (1 - [frame.to_f, 10.0].min / 10)
  524.     return [x, ry, zoom, zoom]
  525.   end
  526.  
  527.   def lowest_point
  528.     $imported["CP_BATTLEVIEW_2"] ? Graphics.height - 120 : Graphics.height
  529.   end
  530. end
  531.  
  532. class Window_BattleLog < Window_Selectable
  533.   alias cp_bv_display_counter display_counter
  534.   def display_counter(target, item)  ## Aliased to create a popup.
  535.     target.do_pop(:counter)  ## Sets the popup.
  536.     cp_bv_display_counter(target, item)  ## Displays normally.
  537.   end  ## Identical to the next few.
  538.  
  539.   alias cp_bv_display_reflection display_reflection
  540.   def display_reflection(target, item)
  541.     target.do_pop(:reflect)
  542.     cp_bv_display_reflection(target, item)
  543.   end
  544.  
  545.   alias cp_bv_display_substitute display_substitute
  546.   def display_substitute(substitute, target)
  547.     substitute.do_pop(:sub)
  548.     cp_bv_display_substitute(substitute, target)
  549.   end
  550.  
  551.   alias cp_bv_display_action_results display_action_results
  552.   def display_action_results(target, item)
  553.     cp_bv_display_action_results(target, item)
  554.     if target.result.used  ## Resets popups at the end of the log.
  555.       target.pop_reset
  556.     end
  557.   end
  558.  
  559.   alias cp_bv_display_failure display_failure
  560.   def display_failure(target, item)
  561.     if target.result.hit? && !target.result.success
  562.       target.do_pop(:fail)
  563.       cp_bv_display_failure(target, item)
  564.     end
  565.   end
  566.  
  567.   alias cp_bv_display_critical display_critical
  568.   def display_critical(target, item)
  569.     if target.result.critical
  570.       target.do_pop(:critical)
  571.       cp_bv_display_critical(target, item)
  572.     end
  573.   end
  574.  
  575.   alias cp_bv_display_miss display_miss
  576.   def display_miss(target, item)
  577.     target.do_pop(:miss)
  578.     cp_bv_display_miss(target, item)
  579.   end
  580.  
  581.   alias cp_bv_display_evasion display_evasion
  582.   def display_evasion(target, item)
  583.     target.do_pop(:evade)
  584.     cp_bv_display_evasion(target, item)
  585.   end
  586.  
  587.   alias cp_bv_display_hp_damage display_hp_damage
  588.   def display_hp_damage(target, item)
  589.     return if target.result.hp_damage == 0 && item && !item.damage.to_hp?
  590.     target.pop_hp(target.result.hp_damage)
  591.     cp_bv_display_hp_damage(target, item)
  592.   end
  593.  
  594.   alias cp_bv_display_mp_damage display_mp_damage
  595.   def display_mp_damage(target, item)
  596.     return if target.dead? || target.result.mp_damage == 0
  597.     target.pop_mp(target.result.mp_damage)
  598.     cp_bv_display_mp_damage(target, item)
  599.   end
  600.  
  601.   alias cp_bv_display_tp_damage display_tp_damage
  602.   def display_tp_damage(target, item)
  603.     return if target.dead? || target.result.tp_damage == 0
  604.     target.pop_tp(target.result.tp_damage)
  605.     cp_bv_display_tp_damage(target, item)
  606.   end
  607.  
  608.   def display_added_states(target)
  609.     target.result.added_state_objects.each do |state|
  610.       state_msg = target.actor? ? state.message1 : state.message2
  611.       target.perform_collapse_effect if state.id == target.death_state_id
  612.       if state.pop_values[4]
  613.         create_state_pop(target, state, :addstate)
  614.       else
  615.         target.do_pop(:addstate, state.name) unless state.name.empty?
  616.       end
  617.       next if state_msg.empty?
  618.       replace_text(target.name + state_msg)
  619.       wait
  620.       wait_for_effect
  621.     end
  622.   end
  623.  
  624.   def display_removed_states(target)
  625.     target.result.removed_state_objects.each do |state|
  626.       if state.pop_values[4]
  627.         create_state_pop(target, state, :substate)
  628.       else
  629.         target.do_pop(:substate, state.name) unless state.name.empty?
  630.       end
  631.       next if state.message4.empty?
  632.       replace_text(target.name + state.message4)
  633.       wait
  634.     end
  635.   end
  636.  
  637.   def create_state_pop(target, state, key)
  638.     n1 = key == :addstate ? state.pop_values[0] : state.pop_values[1]
  639.     n2 = state.pop_values[2]; pop = state.pop_values[3]
  640.     return if (n1.nil? && !CP::BATTLEVIEW::TEXT.include?(key)) || state.name.empty?
  641.     n1 = CP::BATTLEVIEW::TEXT[key].gsub(/%s/, state.name.to_s) if n1.nil?
  642.     n2 = key if n2.nil?
  643.     pop = CP::BATTLEVIEW::POP_STYLE[key] if pop.nil?
  644.     target.create_pop(n1, n2, pop)
  645.   end
  646.  
  647.   def display_changed_buffs(target)
  648.     display_buffs(target, target.result.added_buffs, Vocab::BuffAdd, :buff)
  649.     display_buffs(target, target.result.added_debuffs, Vocab::DebuffAdd, :debuff)
  650.     display_buffs(target, target.result.removed_buffs, Vocab::BuffRemove, :rebuff)
  651.   end
  652.  
  653.   def display_buffs(target, buffs, fmt, pop = nil)
  654.     buffs.each do |param_id|
  655.       target.do_pop(pop, Vocab::param(param_id))
  656.       replace_text(sprintf(fmt, target.name, Vocab::param(param_id)))
  657.       wait
  658.     end
  659.   end
  660. end
  661.  
  662. class RPG::State < RPG::BaseItem
  663.   def pop_values
  664.     set_pop_values if @pop_values.nil?
  665.     return @pop_values
  666.   end
  667.  
  668.   def set_pop_values
  669.     @pop_values = [nil, nil, nil, nil, false]
  670.     self.note.split(/[\r\n]+/).each do |line|
  671.       case line
  672.       when /pop add\[(.*)]/i
  673.         @pop_values[0] = $1.to_s
  674.         @pop_values[4] = true
  675.       when /pop remove\[(.*)]/i
  676.         @pop_values[1] = $1.to_s
  677.         @pop_values[4] = true
  678.       when /pop color\[(\d*)(\w*)\]/i
  679.         n = $1.to_s != "" ? $1.to_i : nil
  680.         s = $2.to_sym
  681.         @pop_values[2] = n.nil? ? s : n
  682.         @pop_values[4] = true
  683.       when /pop style\[(\w+)\]/i
  684.         @pop_values[3] = $1.to_sym
  685.         @pop_values[4] = true
  686.       end
  687.     end
  688.   end
  689. end
  690.  
  691.  
  692. ###--------------------------------------------------------------------------###
  693. #  End of script.                                                              #
  694. ###--------------------------------------------------------------------------###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement