Advertisement
neonblack

Scan Enemy V1.2a

Nov 11th, 2012
4,242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 35.74 KB | None | 0 0
  1. ###--------------------------------------------------------------------------###
  2. #  CP Enemy Scan 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.2a - 12.19.2013
  22. #   Quick fix for 2 issues
  23. #  V1.2 - 11.12.2012                                                           #
  24. #   Added libra effect                                                         #
  25. #   Recoded how discovered elements are stored/called                          #
  26. #   Added new options and visuals                                              #
  27. #  V1.1 - 11.11.2012                                                           #
  28. #   Fixed a bug related to adding weak states                                  #
  29. #   Added pop-ups when used with battleview 1                                  #
  30. #  V1.0 - 11.6.2012-11.9.2012                                                  #
  31. #   Wrote and debugged main script                                             #
  32. ###--------------------------------------------------------------------------###
  33.  
  34. ###--------------------------------------------------------------------------###
  35. #      Compatibility:                                                          #
  36. #  Alias       - Game_System: initialize                                       #
  37. #                Game_Battler: item_apply, item_effect_add_state_attack,       #
  38. #                              item_effect_add_state_normal                    #
  39. #                Scene_Battle: create_all_windows, create_enemy_window,        #
  40. #                              next_command, update, invoke_item               #
  41. #                Window_BattleEnemy: update                                    #
  42. #  New Methods - Game_System: scan_known_elements, scan_known_states,          #
  43. #                             add_known_element, add_known_state               #
  44. #                Game_Battler: scan_check_rate, cp_scan_enemy,                 #
  45. #                              scan_element_affinities, scan_state_affinities, #
  46. #                              scan_weak_elements, scan_weak_states,           #
  47. #                              scan_strong_elements, scan_strong_states        #
  48. #                Scene_Battle: create_scan_windows, open_enemy_scan,           #
  49. #                              close_enemy_scan, next_enemy, last_enemy        #
  50. #                              scan_windows, open_scan_window,                 #
  51. #                              close_scan_window, close_from_selection         #
  52. #                Window_ScanEnemy: initialize, refresh, enemy, draw_enemy_hp,  #
  53. #                                  draw_enemy_mp, draw_enemy_tp,               #
  54. #                                  process_pageup, process_pagedown,           #
  55. #                                  update_cursor
  56. #                Window_ScanElements: initialize, window_width, refresh,       #
  57. #                                     disc_element_type, draw_all_weak,        #
  58. #                                     draw_all_resist, xicon, col2,            #
  59. #                                     weaknesses, resistances,                 #
  60. #                                     all_element_type, draw_all_elements,     #
  61. #                                     draw_all_states, line_offset, text_pos,  #
  62. #                                     font_size, row_height, state_color,      #
  63. #                                     enemy, update_cursor                     #
  64. #                Window_ScanBio: initialize, refresh, bio, enemy,              #
  65. #                                contents_height, update_cursor                #
  66. #                RPG::Enemy: bio, hidden_stats, set_bio_info,                  #
  67. #                            set_hidden_stats                                  #
  68. #                RPG::UsableItem: scan_types, libra?, set_scan_type            #
  69. ###--------------------------------------------------------------------------###
  70.  
  71. ###--------------------------------------------------------------------------###
  72. #      Instructions:                                                           #
  73. #  Place this script in the "Materials" section of the scripts above main.     #
  74. #  This script adds a scan scene to battles that allows the player to view     #
  75. #  info on enemies by pressing a designated key.  There are multiple tags      #
  76. #  that may be used in enemies, skills, and items to allow different types of  #
  77. #  scan functions to be used.                                                  #
  78. ###-----                                                                -----###
  79. #      Enemy Tags:                                                             #
  80. #  <bio>  -and-  </bio>                                                        #
  81. #    Sets the text between these tags to the bio description for the enemy.    #
  82. #    This automatically formats allowing you to type the entire bio in a       #
  83. #    single line in the notebox and then showing it over the required lines    #
  84. #    on the scan screen.                                                       #
  85. #  USAGE:                                                                      #
  86. #    <bio>                                                                     #
  87. #    Enemy bio goes here.  You can type it all on one line.                    #
  88. #    Or you can use more than one line.                                        #
  89. #    </bio>                                                                    #
  90. #  hide hp  -and/or-  hide mp  -and/or-  hide tp                               #
  91. #    Hides the designated stat in the info box.  You can use one or each tag   #
  92. #    to hide several options at once.                                          #
  93. ###-----                                                                -----###
  94. #      Skill/Item Tags:                                                        #
  95. #  scan[libra]                                                                 #
  96. #    The skill gains a libra effect opening a scan window on the enemy the     #
  97. #    skill is used on.                                                         #
  98. #  scan[all]                                                                   #
  99. #    When the skill use used on a foe, it reveals all info about an enemy.     #
  100. #    This does not count hidden stats such as HP and MP.  Also, this tag will  #
  101. #    have no effect unless DISCOVER_TYPE is set to true.                       #
  102. #  scan[weak elements]  -or-  scan[strong states]  -or-  scan[weak]  -etc-     #
  103. #    Scans only specific parts of the attributes sections.  You can use the    #
  104. #    words "strong" or "weak" and/or "elements" or "states" to reveal          #
  105. #    whichever attributes you want revealed.  Note that if you use two words,  #
  106. #    strong/weak must come before elements/states.  Several similar tags can   #
  107. #    be present in a single skill or item.                                     #
  108. ###--------------------------------------------------------------------------###
  109.  
  110. ###--------------------------------------------------------------------------###
  111. #  These are the default values used by several of the functions in the        #
  112. #  script.  You may change these values as you find your game requires in      #
  113. #  order to give the player a better playing experience based on your game.    #
  114. #                                                                              #
  115. module CP   # Do not touch                                                     #
  116. module SCAN #  these two lines.                                                #
  117. ###-----                                                                -----###
  118. # These are the high and low values of STATES.  A state with an chance higher  #
  119. # than "TOP" is considered weak.  A state with a chance lower than "BOT" is    #
  120. # considered strong.  1.0 = 100% chance.                                       #
  121. STATE_NORM_TOP = 1.0 # Default = 1.0                                           #
  122. STATE_NORM_BOT = 1.0 # Default = 1.0                                           #
  123. #                                                                              #
  124. # Sets the button that can be used to open the scan menu.  This can be set to  #
  125. # nil to disable normal opening of the scan menu.                              #
  126. BUTTON_SCAN = :A # Default = :A                                                #
  127. #                                                                              #
  128. # Choose to use the percentage based scan screen (all elements and states      #
  129. # shown) or the icon based scan screen.                                        #
  130. PERCENTAGE_BASED = false # Default = false                                     #
  131. #                                                                              #
  132. # Choose if stats and states must be discovered or if they are all shown by    #
  133. # default.                                                                     #
  134. DISCOVER_TYPE = true # Default = true                                          #
  135. #                                                                              #
  136. # This is the text that displays on undiscovered affinities in the percentage  #
  137. # based screen.                                                                #
  138. HIDDEN_STAT = "--%" # Default = "--%"                                          #
  139. #                                                                              #
  140. # Determine if an info window is used to tell the player what button to press, #
  141. # the text of this window, and the X and Y position of the window.             #
  142. INFO_WINDOW = true # Default = true                                            #
  143. INFO_X = 264 # Default = 304                                                   #
  144. INFO_Y = 248 # Default = 248                                                   #
  145. INFO_TEXT = "Press shift for enemy info"                                       #
  146. #                                                                              #
  147. # This is the text that displays in the discovery type scan screen that above  #
  148. # the icons.                                                                   #
  149. WEAK_TEXT = "Weaknesses" # Default = "Weaknesses"                              #
  150. RESIST_TEXT = "Resistances" # Default = "Resistances"                          #
  151. #                                                                              #
  152. # This is the text that displays when HP, MP, or TP is hidden.                 #
  153. HIDDEN_TEXT = "? ? ?" # Default = "? ? ?"                                      #
  154. #                                                                              #
  155. # This hash contains all the elements that can be displayed in the scan screen #
  156. # and the icon to go with them.  You may have as many or as few as you want.   #
  157. # The ID relates to the element's ID in the "Terms" page of the database.      #
  158. ELEMENTS ={                                                                    #
  159. # ID => Icon,                                                                  #
  160.   1  => 116,
  161.   2  => 114,
  162.   3  => 96,
  163.   4  => 97,
  164.   5  => 98,
  165.   6  => 99,
  166.   7  => 100,
  167.   8  => 101,
  168.   9  => 102,
  169.   10 => 103,
  170. }                                                                              #
  171. #                                                                              #
  172. # This hash contains all the states that can be displayed in the scan screen   #
  173. # and the icon to go with them.  If you want to use the same icon from the     #
  174. # database, set the icon number to nil.                                        #
  175. STATES ={                                                                      #
  176. # ID => Icon,                                                                  #
  177.   1 => 1,
  178.   2 => 2,
  179.   3 => 3,
  180.   4 => 4,
  181.   5 => 5,
  182.   6 => 6,
  183.   7 => 7,
  184.   8 => 8,
  185. }                                                                              #
  186. #                                                                              #
  187. # These are the different things to be shown in each row of the namebox.  You  #
  188. # can set up as many or as few as you want in each one.  You may also remove   #
  189. # any lines of this hash as you want.  The valid tags for terms are :name,     #
  190. # :states, :hp, :mp, and :tp.  If you want a blank to be included, use an      #
  191. # empty array for that line.  Also note that the height of the name and        #
  192. # element windows are dependant on the number of rows you set here with a max  #
  193. # of 4 rows and a minimum of 2 rows.                                           #
  194. NAMEBOX ={                                                                     #
  195.   0 => [:name, :states],
  196.   1 => [:hp],
  197.   2 => [:mp, :tp],
  198.   #3 => [],
  199. }                                                                              #
  200. #                                                                              #
  201. ###-----                                                                -----###
  202. #  The following options can only be used if CP Pop-ups version 1.2 or higher  #
  203. #  is also present in the game.                                                #
  204. #                                                                              #
  205. # The text to display for skills that a battler is strong or weak to.          #
  206. WEAK_POP = "Weakness" # Default = "Weakness"                                   #
  207. STRONG_POP = "Resist" # Default = "Resist"                                     #
  208. #                                                                              #
  209. ###--------------------------------------------------------------------------###
  210.  
  211.  
  212. ###--------------------------------------------------------------------------###
  213. #  The following lines are the actual core code of the script.  While you are  #
  214. #  certainly invited to look, modifying it may result in undesirable results.  #
  215. #  Modify at your own risk!                                                    #
  216. ###--------------------------------------------------------------------------###
  217.  
  218.  
  219. end
  220. end
  221.  
  222. $imported = {} if $imported.nil?
  223. $imported["CP_SCAN_SCENE"] = 1.2
  224.  
  225. class Game_System
  226.   alias cp_scan_init initialize
  227.   def initialize  ## Adds the new hashes to store known affinities.
  228.     cp_scan_init
  229.     @known_elements = {}
  230.     @known_states = {}
  231.   end
  232.  
  233.   def scan_known_elements(mob)
  234.     mob = mob.enemy.id  ## Checks known elements/states based on arguments.
  235.     @known_elements = {} if @known_elements.nil?
  236.     @known_elements[mob] = [] unless @known_elements.include?(mob)
  237.     return @known_elements[mob]
  238.   end
  239.  
  240.   def scan_known_states(mob)
  241.     mob = mob.enemy.id
  242.     @known_states = {} if @known_states.nil?
  243.     @known_states[mob] = [] unless @known_states.include?(mob)
  244.     return @known_states[mob]
  245.   end
  246.  
  247.   def add_known_element(mob, element)
  248.     mob = mob.id  ## Adds a new id to the affinity array.
  249.     return unless CP::SCAN::ELEMENTS.include?(element)
  250.     @known_elements = {} if @known_elements.nil?
  251.     @known_elements[mob] = [] unless @known_elements.include?(mob)
  252.     return if @known_elements[mob].include?(element)
  253.     @known_elements[mob].push(element)
  254.   end
  255.  
  256.   def add_known_state(mob, state)
  257.     mob = mob.id
  258.     return unless CP::SCAN::STATES.include?(state)
  259.     @known_states = {} if @known_states.nil?
  260.     @known_states[mob] = [] unless @known_states.include?(mob)
  261.     return if @known_states[mob].include?(state)
  262.     @known_states[mob].push(state)
  263.   end
  264. end
  265.  
  266. class Game_Battler
  267.   alias cp_scan_item_apply item_apply
  268.   def item_apply(user, item)
  269.     cp_scan_item_apply(user, item)
  270.     cp_scan_enemy(item) unless item.scan_types.empty?
  271.     return if !@result.hit?  ## Adds an element to the affinity array.
  272.     if item.damage.element_id < 0
  273.       return if user.atk_elements.empty?
  274.       max_id_val = elements_max_rate(user.atk_elements)
  275.       do_weak_res_pop(max_id_val)
  276.       return if actor?
  277.       user.atk_elements.each do |id|
  278.         next unless element_rate(id) == max_id_val
  279.         $game_system.add_known_element(enemy, id)
  280.       end
  281.     else
  282.       rate = element_rate(item.damage.element_id)
  283.       do_weak_res_pop(rate)
  284.       return if actor?
  285.       $game_system.add_known_element(enemy, item.damage.element_id)
  286.     end
  287.   end
  288.  
  289.   def do_weak_res_pop(rate)
  290.     return unless $imported["CP_BATTLEVIEW"] && $imported["CP_BATTLEVIEW"] >= 1.2
  291.     do_weak_pop if rate > 1.0
  292.     do_strong_pop if rate < 1.0
  293.   end
  294.  
  295.   def do_weak_pop
  296.     pop = CP::BATTLEVIEW::POP_STYLE[:weak_pop]
  297.     create_pop(CP::SCAN::WEAK_POP, :weak_pop, pop)
  298.   end
  299.  
  300.   def do_strong_pop
  301.     pop = CP::BATTLEVIEW::POP_STYLE[:strong_pop]
  302.     create_pop(CP::SCAN::STRONG_POP, :strong_pop, pop)
  303.   end
  304.  
  305.   alias cp_scan_state_attack item_effect_add_state_attack
  306.   def item_effect_add_state_attack(user, item, effect)
  307.     cp_scan_state_attack(user, item, effect)
  308.     user.atk_states.each do |id|
  309.       scan_check_rate(id)
  310.     end
  311.   end  ## Check the states used by the skill and adds them to the array.
  312.  
  313.   alias cp_scan_state_normal item_effect_add_state_normal
  314.   def item_effect_add_state_normal(user, item, effect)
  315.     cp_scan_state_normal(user, item, effect)
  316.     scan_check_rate(effect.data_id)
  317.   end
  318.  
  319.   def scan_check_rate(id)  ## Common function that determines array args.
  320.     return if actor?
  321.     $game_system.add_known_state(enemy, id)
  322.   end
  323.  
  324.   def cp_scan_enemy(item)  ## Gets the basic types of scans on a skill.
  325.     return if actor?
  326.     item.scan_types.each do |type|
  327.       case type
  328.       when :we
  329.         scan_weak_elements
  330.       when :se
  331.         scan_strong_elements
  332.       when :ws
  333.         scan_weak_states
  334.       when :ss
  335.         scan_strong_states
  336.       when :e
  337.         scan_element_affinities
  338.       when :s
  339.         scan_state_affinities
  340.       end
  341.     end
  342.   end
  343.  
  344.   def scan_element_affinities
  345.     CP::SCAN::ELEMENTS.each do |id, icon|
  346.       $game_system.add_known_element(enemy, id)
  347.     end
  348.   end
  349.  
  350.   def scan_state_affinities
  351.     CP::SCAN::STATES.each do |id, icon|
  352.       $game_system.add_known_state(enemy, id)
  353.     end
  354.   end
  355.  
  356.   def scan_weak_elements  ## Performs the designated scan.
  357.     CP::SCAN::ELEMENTS.each do |id, icon|
  358.       rate = element_rate(id)
  359.       next if rate <= 1.0
  360.       $game_system.add_known_element(enemy, id)
  361.     end
  362.   end
  363.  
  364.   def scan_weak_states
  365.     CP::SCAN::STATES.each do |id, icon|
  366.       rate = state_rate(id)
  367.       next if rate <= CP::SCAN::STATE_NORM_TOP
  368.       $game_system.add_known_state(enemy, id)
  369.     end
  370.   end
  371.  
  372.   def scan_strong_elements
  373.     CP::SCAN::ELEMENTS.each do |id, icon|
  374.       rate = element_rate(id)
  375.       next if rate >= 1.0
  376.       $game_system.add_known_element(enemy, id)
  377.     end
  378.   end
  379.  
  380.   def scan_strong_states
  381.     CP::SCAN::STATES.each do |id, icon|
  382.       rate = state_rate(id)
  383.       next if rate >= CP::SCAN::STATE_NORM_BOT
  384.       $game_system.add_known_state(enemy, id)
  385.     end
  386.   end
  387. end
  388.  
  389. class Scene_Battle < Scene_Base
  390.   alias cp_scan_create_all_windows create_all_windows
  391.   def create_all_windows  ## Adds the new scan window stuff.
  392.     cp_scan_create_all_windows
  393.     create_scan_windows
  394.   end
  395.  
  396.   alias cp_create_enemy_window create_enemy_window
  397.   def create_enemy_window  ## Adds a new enemy window method.
  398.     cp_create_enemy_window
  399.     @enemy_window.set_handler(:scan, method(:open_enemy_scan))
  400.   end
  401.  
  402.   def create_scan_windows  ## Creates all required graphics for scanning.
  403.     @scan_viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
  404.     @scan_viewport.z = 400
  405.     @scan_viewport.visible = false
  406.     @scan_enemy = Window_ScanEnemy.new
  407.     @scan_bio = Window_ScanBio.new
  408.     @scan_elements = Window_ScanElements.new
  409.     @scan_info = Window_ScanInfo.new
  410.     @scan_info.z = 400
  411.     @scan_info.visible = false
  412.     scan_windows.each do |wind|
  413.       wind.viewport = @scan_viewport
  414.     end
  415.     @scan_enemy.set_handler(:ok,       method(:close_enemy_scan))
  416.     @scan_enemy.set_handler(:cancel,   method(:close_enemy_scan))
  417.     @scan_enemy.set_handler(:pagedown, method(:next_enemy))
  418.     @scan_enemy.set_handler(:pageup,   method(:last_enemy))
  419.   end
  420.  
  421.   def open_enemy_scan
  422.     @from_selection = true
  423.     open_scan_window
  424.     @scan_enemy.lock_foe = false
  425.     @enemy_window.deactivate
  426.     @scan_enemy.activate
  427.   end  ## Open and close the enemy scan.
  428.  
  429.   def close_enemy_scan
  430.     close_scan_window
  431.     close_from_selection if @from_selection
  432.     @from_selection = false
  433.   end
  434.  
  435.   def next_enemy
  436.     scan_windows.each do |wind|
  437.       wind.index += 1
  438.       next unless wind.index == $game_troop.alive_members.size
  439.       wind.index = 0
  440.     end
  441.     scan_windows.each {|wind| wind.refresh}
  442.     @scan_enemy.activate
  443.   end  ## Next and last enemies....
  444.  
  445.   def last_enemy
  446.     scan_windows.each do |wind|
  447.       wind.index -= 1
  448.       next unless wind.index == -1
  449.       wind.index = $game_troop.alive_members.size - 1
  450.     end
  451.     scan_windows.each {|wind| wind.refresh}
  452.     @scan_enemy.activate
  453.   end
  454.  
  455.   def scan_windows  ## Quickly returns each scan window.
  456.     return [@scan_enemy, @scan_bio, @scan_elements]
  457.   end
  458.  
  459.   alias cp_scan_next_command next_command
  460.   def next_command
  461.     @scan_info.visible = false
  462.     cp_scan_next_command
  463.   end
  464.  
  465.   alias cp_scan_update update
  466.   def update
  467.     cp_scan_update
  468.     return unless @scan_info && @enemy_window
  469.     @scan_info.visible = @enemy_window.active
  470.   end
  471.  
  472.   def open_scan_window(target = nil)
  473.     @window_tot_vis = {}
  474.     instance_variables.each do |varname|
  475.       ivar = instance_variable_get(varname)
  476.       next unless ivar.is_a?(Window)
  477.       next if ivar.viewport == @scan_viewport
  478.       @window_tot_vis[varname] = ivar.visible
  479.       ivar.visible = false
  480.     end
  481.     if target
  482.       target = $game_troop.alive_members.index(target)
  483.     end
  484.     enemy = target || @enemy_window.index
  485.     scan_windows.each {|wind| wind.index = enemy; wind.refresh}
  486.     @scan_viewport.visible = true
  487.     @scan_enemy.lock_foe = true
  488.     @scan_enemy.activate
  489.   end
  490.  
  491.   def close_scan_window
  492.     instance_variables.each do |varname|
  493.       ivar = instance_variable_get(varname)
  494.       next unless ivar.is_a?(Window)
  495.       next if ivar.viewport == @scan_viewport
  496.       ivar.visible = @window_tot_vis[varname]
  497.     end
  498.     scan_windows.each do |wind|
  499.       wind.index = @enemy_window.index
  500.     end
  501.     @scan_viewport.visible = false
  502.   end
  503.  
  504.   def close_from_selection
  505.     @enemy_window.activate
  506.     @scan_enemy.deactivate
  507.   end
  508.  
  509.   alias cp_scan_action invoke_item
  510.   def invoke_item(target, item)
  511.     scan_windows.each {|w| w.index = $game_troop.alive_members.index(target)}
  512.     target.cp_scan_enemy(item) if item.libra?
  513.     open_scan_window(target) if item.libra?
  514.     update_for_wait while @scan_viewport.visible
  515.     cp_scan_action(target, item)
  516.   end
  517. end
  518.  
  519. ##-----
  520. ## The new windows are located below.
  521. ##-----
  522. class Window_ScanEnemy < Window_Selectable
  523.   attr_accessor :lock_foe
  524.  
  525.   def initialize
  526.     w = !CP::SCAN::PERCENTAGE_BASED ? 208 : 200
  527.     h = fitting_height([[CP::SCAN::NAMEBOX.size, 2].max, 4].min)
  528.     super(0, 0, w, h)
  529.     @index = 0
  530.     @lock_foe
  531.     refresh
  532.   end
  533.  
  534.   def refresh
  535.     contents.clear
  536.     CP::SCAN::NAMEBOX.each do |id, array|
  537.       next unless [0, 1, 2, 3].include?(id)
  538.       next if (array.nil? || !array.is_a?(Array) || array.empty?)
  539.       wd = contents.width / array.size
  540.       array.each_with_index do |key, i|
  541.         case key
  542.         when :name
  543.           draw_text(wd * i + 2, id * line_height, wd, line_height, enemy.name)
  544.         when :states
  545.           draw_actor_icons(enemy, wd * i, id * line_height, wd)
  546.         when :hp
  547.           draw_enemy_hp(enemy, wd * i + 2, id * line_height, wd - 4)
  548.         when :mp
  549.           draw_enemy_mp(enemy, wd * i + 2, id * line_height, wd - 4)
  550.         when :tp
  551.           draw_enemy_tp(enemy, wd * i + 2, id * line_height, wd - 4)
  552.         end
  553.       end
  554.     end
  555.   end
  556.  
  557.   def enemy
  558.     $game_troop.alive_members[@index]
  559.   end
  560.  
  561.   def draw_enemy_hp(battler, x, y, width = 124)
  562.     unless battler.enemy.hidden_stats.include?(:hp)
  563.       draw_gauge(x, y, width, battler.hp_rate, hp_gauge_color1, hp_gauge_color2)
  564.       change_color(system_color)
  565.       draw_text(x, y, 30, line_height, Vocab::hp_a)
  566.       change_color(hp_color(battler))
  567.       draw_text(x + 32, y, width - 32, line_height, battler.hp.to_i, 2)
  568.     else
  569.       change_color(system_color)
  570.       draw_text(x, y, 30, line_height, Vocab::hp_a)
  571.       change_color(normal_color)
  572.       draw_text(x + 32, y, width - 32, line_height, CP::SCAN::HIDDEN_TEXT, 2)
  573.     end
  574.   end
  575.    
  576.   def draw_enemy_mp(battler, x, y, width = 124)
  577.     unless battler.enemy.hidden_stats.include?(:mp)
  578.       draw_gauge(x, y, width, battler.mp_rate, mp_gauge_color1, mp_gauge_color2)
  579.       change_color(system_color)
  580.       draw_text(x, y, 30, line_height, Vocab::mp_a)
  581.       change_color(mp_color(battler))
  582.       draw_text(x + 32, y, width - 32, line_height, battler.mp.to_i, 2)
  583.     else
  584.       change_color(system_color)
  585.       draw_text(x, y, 30, line_height, Vocab::mp_a)
  586.       change_color(normal_color)
  587.       draw_text(x + 32, y, width - 32, line_height, CP::SCAN::HIDDEN_TEXT, 2)
  588.     end
  589.   end
  590.    
  591.   def draw_enemy_tp(battler, x, y, width = 124)
  592.     unless battler.enemy.hidden_stats.include?(:tp)
  593.       draw_gauge(x, y, width, battler.tp_rate, tp_gauge_color1, tp_gauge_color2)
  594.       change_color(system_color)
  595.       draw_text(x, y, 30, line_height, Vocab::tp_a)
  596.       change_color(tp_color(battler))
  597.       draw_text(x + 32, y, width - 32, line_height, battler.tp.to_i, 2)
  598.     else
  599.       change_color(system_color)
  600.       draw_text(x, y, 30, line_height, Vocab::tp_a)
  601.       change_color(normal_color)
  602.       draw_text(x + 32, y, width - 32, line_height, CP::SCAN::HIDDEN_TEXT, 2)
  603.     end
  604.   end
  605.  
  606.   def process_pageup
  607.     return if @lock_foe
  608.     super
  609.   end
  610.  
  611.   def process_pagedown
  612.     return if @lock_foe
  613.     super
  614.   end
  615.  
  616.   def update_cursor
  617.   end
  618. end
  619.  
  620. class Window_ScanElements < Window_Selectable
  621.   def initialize
  622.     w = window_width
  623.     h = fitting_height([[CP::SCAN::NAMEBOX.size, 2].max, 4].min)
  624.     super(Graphics.width - w, 0, w, h)
  625.     @index = 0
  626.     refresh
  627.   end
  628.  
  629.   def window_width
  630.     if !CP::SCAN::PERCENTAGE_BASED
  631.       return Graphics.width - 208
  632.     else
  633.       icons = [CP::SCAN::ELEMENTS.size, CP::SCAN::STATES.size].max + 24
  634.       return [icons * 32, Graphics.width - 200].min
  635.     end
  636.   end
  637.  
  638.   def refresh
  639.     contents.clear
  640.     !CP::SCAN::PERCENTAGE_BASED ? disc_element_type : all_element_type
  641.   end
  642.  
  643.   def disc_element_type
  644.     draw_all_weak
  645.     draw_all_resist
  646.   end
  647.  
  648.   def draw_all_weak
  649.     draw_text(2, 0, 144, line_height, CP::SCAN::WEAK_TEXT, 1)
  650.     weaknesses.each_with_index do |id, i|
  651.       draw_icon(id, 24 * (i % xicon), line_height + 24 * (i / xicon))
  652.     end
  653.   end
  654.  
  655.   def draw_all_resist
  656.     draw_text(col2 + 2, 0, 144, line_height, CP::SCAN::RESIST_TEXT, 1)
  657.     resistances.each_with_index do |id, i|
  658.       draw_icon(id, col2 + 24 * (i % xicon), line_height + 24 * (i / xicon))
  659.     end
  660.   end
  661.  
  662.   def xicon
  663.     (contents.width / 2) / 24
  664.   end
  665.  
  666.   def col2
  667.     contents.width - xicon * 24
  668.   end
  669.  
  670.   def weaknesses
  671.     result = []
  672.     CP::SCAN::ELEMENTS.each do |id, icon|
  673.       next unless enemy.element_rate(id) > 1.0
  674.       if CP::SCAN::DISCOVER_TYPE
  675.         next unless $game_system.scan_known_elements(enemy).include?(id)
  676.       end
  677.       result.push(icon)
  678.     end
  679.     CP::SCAN::STATES.each do |id, icon|
  680.       next unless enemy.state_rate(id) > CP::SCAN::STATE_NORM_TOP
  681.       next if enemy.state_resist?(id)
  682.       if CP::SCAN::DISCOVER_TYPE
  683.         next unless $game_system.scan_known_states(enemy).include?(id)
  684.       end
  685.       result.push(icon ? icon : $data_states[id].icon_index)
  686.     end
  687.     return result
  688.   end
  689.  
  690.   def resistances
  691.     result = []
  692.     CP::SCAN::ELEMENTS.each do |id, icon|
  693.       next unless enemy.element_rate(id) < 1.0
  694.       if CP::SCAN::DISCOVER_TYPE
  695.         next unless $game_system.scan_known_elements(enemy).include?(id)
  696.       end
  697.       result.push(icon)
  698.     end
  699.     CP::SCAN::STATES.each do |id, icon|
  700.       next unless (enemy.state_rate(id) < CP::SCAN::STATE_NORM_BOT ||
  701.                    enemy.state_resist?(id))
  702.       if CP::SCAN::DISCOVER_TYPE
  703.         next unless $game_system.scan_known_states(enemy).include?(id)
  704.       end
  705.       result.push(icon ? icon : $data_states[id].icon_index)
  706.     end
  707.     return result
  708.   end
  709.  
  710.   def all_element_type
  711.     draw_all_elements
  712.     draw_all_states
  713.   end
  714.  
  715.   def draw_all_elements
  716.     i = 0
  717.     contents.font.size = font_size
  718.     CP::SCAN::ELEMENTS.each do |id, icon|
  719.       known = $game_system.scan_known_elements(enemy).include?(id)
  720.       if known
  721.         rate = sprintf("%d%", enemy.element_rate(id) * 100)
  722.         state_color(enemy.element_rate(id))
  723.       else
  724.         rate = CP::SCAN::HIDDEN_STAT
  725.         contents.font.color.set(normal_color)
  726.       end
  727.       draw_icon(icon, 32 * i + 4, line_offset)
  728.       draw_text(32 * i, text_pos, 32, font_size, rate, 1)
  729.       i += 1
  730.     end
  731.   end
  732.  
  733.   def draw_all_states
  734.     i = 0
  735.     contents.font.size = font_size
  736.     CP::SCAN::STATES.each do |id, icon|
  737.       known = $game_system.scan_known_states(enemy).include?(id)
  738.       if known
  739.         perc = enemy.state_resist?(id) ? 0 : enemy.state_rate(id)
  740.         rate = sprintf("%d%", perc * 100)
  741.         state_color(perc, true)
  742.       else
  743.         rate = CP::SCAN::HIDDEN_STAT
  744.         contents.font.color.set(normal_color)
  745.       end
  746.       iconid = icon ? icon : $data_states[id].icon_index
  747.       draw_icon(iconid, 32 * i + 4, row_height + line_offset)
  748.       draw_text(32 * i, row_height + text_pos, 32, font_size, rate, 1)
  749.       i += 1
  750.     end
  751.   end
  752.  
  753.   def line_offset
  754.     return 0 if CP::SCAN::NAMEBOX.size != 4
  755.     return (row_height - line_height) / 2
  756.   end
  757.  
  758.   def text_pos
  759.     row_height - font_size
  760.   end
  761.  
  762.   def font_size
  763.     (line_height * 0.75).to_i
  764.   end
  765.  
  766.   def row_height
  767.     contents.height / 2
  768.   end
  769.  
  770.   def state_color(rate, state = false)
  771.     hrate = state ? CP::SCAN::STATE_NORM_TOP : 1.0
  772.     lrate = state ? CP::SCAN::STATE_NORM_BOT : 1.0
  773.     if rate > hrate
  774.       contents.font.color.set(power_up_color)
  775.     elsif rate < lrate
  776.       contents.font.color.set(power_down_color)
  777.     else
  778.       contents.font.color.set(normal_color)
  779.     end
  780.   end
  781.  
  782.   def enemy
  783.     $game_troop.alive_members[@index]
  784.   end
  785.  
  786.   def update_cursor
  787.   end
  788. end
  789.  
  790. class Window_ScanBio < Window_Selectable
  791.   def initialize
  792.     w = Graphics.width
  793.     h = fitting_height(4)
  794.     super(0, Graphics.height - h, w, h)
  795.     refresh
  796.   end
  797.  
  798.   def refresh
  799.     contents.clear
  800.     draw_text_ex(0, 0, bio)
  801.   end
  802.  
  803.   def bio
  804.     temp = enemy.bio
  805.     result = ""; line = ""
  806.     temp.split(/ /).each do |word|
  807.       sz = contents.text_size(line).width + contents.text_size("#{word}").width
  808.       if sz > contents.width - 2
  809.         if line.empty?
  810.           word2 = ""
  811.           word.chars do |c|
  812.             s2 = contents.text_size(line).width + contents.text_size("#{c}").width
  813.             if s2 <= contents.width - 2
  814.               line += c
  815.             else
  816.               word2 += c
  817.             end
  818.           end
  819.           word = word2
  820.         end
  821.         result += "#{line}\n"
  822.         line = "#{word} "
  823.         next
  824.       else
  825.         line += "#{word} "
  826.       end
  827.       nl = (line =~ /\\n/i)
  828.       if line.length - 2 == nl
  829.         result += "#{line}\n"
  830.         line = word
  831.       end
  832.     end
  833.     result += "#{line}"
  834.     return result
  835.   end
  836.  
  837.   def enemy
  838.     $game_troop.alive_members[@index].enemy
  839.   end
  840.  
  841.   def contents_height
  842.     height - standard_padding * 2
  843.   end
  844.  
  845.   def update_cursor
  846.   end
  847. end
  848.  
  849. class Window_BattleEnemy < Window_Selectable
  850.   alias cp_scan_update update
  851.   def update
  852.     cp_scan_update
  853.     return unless active
  854.     call_handler(:scan) if Input.trigger?(CP::SCAN::BUTTON_SCAN)
  855.   end
  856. end
  857.  
  858. class RPG::Enemy < RPG::BaseItem
  859.   def bio
  860.     set_bio_info if @bio.nil?
  861.     return @bio
  862.   end
  863.  
  864.   def hidden_stats
  865.     set_hidden_stats if @hidden_stats.nil?
  866.     return @hidden_stats
  867.   end
  868.  
  869.   def set_bio_info
  870.     @bio = ""
  871.     get_bio = false
  872.     self.note.split(/[\r\n]+/).each do |line|
  873.       case line
  874.       when /<bio>/i
  875.         get_bio = true
  876.         next
  877.       when /<\/bio>/i
  878.         return
  879.       end
  880.       next unless get_bio
  881.       @bio += "#{line}\n"
  882.     end
  883.   end
  884.  
  885.   def set_hidden_stats
  886.     @hidden_stats = []
  887.     self.note.split(/[\r\n]+/).each do |line|
  888.       case line
  889.       when /hide hp/i
  890.         @hidden_stats.push(:hp)
  891.       when /hide mp/i
  892.         @hidden_stats.push(:mp)
  893.       when /hide tp/i
  894.         @hidden_stats.push(:tp)
  895.       end
  896.     end
  897.     @hidden_stats.uniq!
  898.   end
  899. end
  900.  
  901. class RPG::UsableItem < RPG::BaseItem
  902.   def scan_types
  903.     set_scan_type if @scan_types.nil?
  904.     return @scan_types
  905.   end
  906.  
  907.   def libra?
  908.     set_scan_type if @libra_skill.nil?
  909.     return @libra_skill
  910.   end
  911.  
  912.   def set_scan_type
  913.     @scan_types = []
  914.     @libra_skill = false
  915.     self.note.split(/[\r\n]+/).each do |line|
  916.       case line
  917.       when /scan\[libra\]/i
  918.         @libra_skill = true
  919.       when /scan\[all\]/i
  920.         @scan_types = [:e, :s]
  921.       when /scan\[(strong|weak)?\s*(elements|states)?\]/i
  922.         affinity = $1.to_s.downcase; type = $2.to_s.downcase
  923.         if affinity == ""
  924.           @scan_types += [:e] if type == "elements"
  925.           @scan_types += [:s] if type == "states"
  926.         elsif type == ""
  927.           @scan_types += [:se, :ss] if affinity == "strong"
  928.           @scan_types += [:we, :ws] if affinity == "weak"
  929.         elsif affinity == "strong"
  930.           if type == "elements"
  931.             @scan_types.push(:se)
  932.           elsif type == "states"
  933.             @scan_types.push(:ss)
  934.           end
  935.         elsif affinity == "weak"
  936.           if type == "elements"
  937.             @scan_types.push(:we)
  938.           elsif type == "states"
  939.             @scan_types.push(:ws)
  940.           end
  941.         end
  942.       end
  943.     end
  944.     @scan_types.uniq!
  945.   end
  946. end
  947.  
  948. class Window_ScanInfo < Window_Base
  949.   def initialize
  950.     super(CP::SCAN::INFO_X, CP::SCAN::INFO_Y, 280, fitting_height(1))
  951.     self.back_opacity = 255
  952.     refresh
  953.   end
  954.  
  955.   def refresh
  956.     contents.clear
  957.     draw_text(2, 0, contents.width - 4, line_height, CP::SCAN::INFO_TEXT, 1)
  958.     self.opacity = 0 if !CP::SCAN::INFO_WINDOW
  959.     self.contents_opacity = 0 if !CP::SCAN::INFO_WINDOW
  960.   end
  961. end
  962.  
  963.  
  964. ###--------------------------------------------------------------------------###
  965. #  End of script.                                                              #
  966. ###--------------------------------------------------------------------------###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement