Advertisement
Trihan

HorrorVale - ScanSkill

Jul 11th, 2023
1,371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.15 KB | Source Code | 0 0
  1. #======================================================================
  2. # Scan Skill v2 by mjshi (edits by Trihan)
  3. #----------------------------------------------------------------------
  4. # Place images into Graphics/System.
  5. #----------------------------------------------------------------------
  6. # Usage: Set a skill ID to be the scan skill, then, in that skill's
  7. #        effects, call a common event.
  8. #        The common event should look like this:
  9. #          Script command: SceneManager.scene.run_scan_skill
  10. #----------------------------------------------------------------------
  11.  
  12. module ScanSkill
  13.  
  14.   #--------------------------------------------------------------------
  15.   #  Config
  16.  
  17.   # ID of the scan skill
  18.   SkillID = [ 45, 163, 384, 468 ]
  19.  
  20.   # Order to draw elements in (by type id)
  21.   ElementOrder = [ 2, 3, 4, 5, 6, 7, 8 ]
  22.  
  23.   # Mini element images, grabbed off the icon sheet
  24.   ElementIcons = {
  25.     #---------------------------
  26.     # Format:
  27.     # ElementId => IconIndex
  28.     #
  29.     1 => 313,
  30.     2 => 306,
  31.     3 => 307,
  32.     4 => 308,
  33.     5 => 309,
  34.     6 => 310,
  35.     7 => 311,
  36.     8 => 312,
  37.     #---------------------------
  38.   }
  39.  
  40.   # Images associated with each id
  41.   ElementImages = {
  42.     #---------------------------
  43.     # Format:
  44.     # ElementId => "icon image",
  45.     #
  46.     2 => "Bone",
  47.     3 => "Flesh",
  48.     4 => "Blood",
  49.     5 => "Nature",
  50.     6 => "Lightning",
  51.     7 => "Ectoplasm",
  52.     8 => "Sugar",
  53.     #---------------------------
  54.   }
  55.  
  56.   WeakText = "Wk"
  57.   StrongText = "Res"
  58.   NormalText = "--"
  59.   NullText = "Null"
  60.  
  61.   # Text that precedes the state icons. Leave blank for none.
  62.   StatusText = {
  63.     # Set this to "" for no text
  64.     :text => "Status",
  65.     :x => 325,
  66.     :y => 0,
  67.   }
  68.  
  69.   # If damage taken is 150% normal or higher, consider weak
  70.   WeakPercent = 1.5
  71.   # If damage taken is 50% normal or lower, consider strong
  72.   StrongPercent = 0.5
  73.   # If damage taken is 0%, consider null
  74.   NullPercent = 0
  75.  
  76.   NameWindow = {
  77.     :x => 0,
  78.     :y => 22,
  79.     :width => 544,
  80.     :height => 48,
  81.     :name_x => 0,
  82.     :name_y => 0,
  83.     :icon_x => 5,
  84.     :icon_y => 0,
  85.     :state_x => 415,
  86.     :state_y => 0,
  87.   }
  88.  
  89.   ElementWindow = {
  90.     :x => 0,
  91.     :y => 70,
  92.     :width => 544,
  93.     :height => 120,
  94.    
  95.     :image_x => 4,
  96.     :image_y => 8,
  97.     :text_x => 0,
  98.     :text_y => 70,
  99.   }
  100.  
  101.   DescriptionWindow = {
  102.     :x => 0,
  103.     :y => 190,
  104.     :width => 544,
  105.     :height => 120
  106.   }
  107.  
  108.   DescriptionOn = /<description>/i
  109.  
  110.   DescriptionOff = /<\/description>/i
  111.  
  112.   #  End Config
  113.   #--------------------------------------------------------------------
  114. end
  115.  
  116. #----------------------------------------------------------------------
  117. # Scene_Battle
  118. #
  119. class Scene_Battle
  120.  
  121.   def wait_for_scan
  122.     @scan_status_window.update
  123.     update_for_wait while @scan_status_window.visible
  124.   end
  125.  
  126.     alias mjshi_scan_create_all_windows create_all_windows
  127.     def create_all_windows
  128.       mjshi_scan_create_all_windows
  129.       create_scan_window
  130.   end
  131.  
  132.   def create_scan_window
  133.     @scan_status_window = Window_ScanStatus.new
  134.     @scan_resist_window = Window_Resistances.new
  135.     @scan_description_window = Window_ScanDescription.new
  136.   end
  137.  
  138.   alias mjshi_scan_on_enemy_ok on_enemy_ok
  139.   def on_enemy_ok
  140.     if (@should_scan)
  141.       @should_scan = false
  142.       @enemy_to_scan = $game_troop.members[@enemy_window.enemy.index]
  143.     end
  144.     mjshi_scan_on_enemy_ok
  145.   end
  146.  
  147.   alias mjshi_scan_on_skill_ok on_skill_ok
  148.   def on_skill_ok
  149.     @should_scan = true if (ScanSkill::SkillID.include?(@skill_window.item.id))
  150.     mjshi_scan_on_skill_ok
  151.   end
  152.  
  153.   def run_scan_skill
  154.     return if ($game_troop.all_dead?)
  155.     if (!$game_troop.alive_members.include?(@enemy_to_scan))
  156.       @enemy_to_scan = $game_troop.alive_members[0]
  157.     end
  158.     RPG::SE.new("ScanWindow Open", 100, 100).play
  159.  
  160.     @log_window.hide
  161.     @scan_status_window.set_enemy(@enemy_to_scan)
  162.     @scan_resist_window.set_enemy(@enemy_to_scan)
  163.     @scan_description_window.set_enemy(@enemy_to_scan)
  164.    
  165.     @scan_status_window.show
  166.     @scan_resist_window.show
  167.     @scan_description_window.show
  168.    
  169.     wait_for_scan
  170.   end
  171.  
  172.   def stop_scan_skill
  173.     RPG::SE.new("ScanWindow Close", 100, 100).play
  174.     @scan_status_window.hide
  175.     @scan_resist_window.hide
  176.     @scan_description_window.hide
  177.     @log_window.show
  178.   end
  179. end
  180.  
  181. #----------------------------------------------------------------------
  182. # Window_Resistances
  183. #
  184. class Window_ScanStatus < Window_Selectable
  185.   # icons = (actor.state_icons + actor.buff_icons)[0, width / 24]
  186.   # icons.each_with_index {|n, i| draw_icon(n, x + 24 * i, y) }
  187.  
  188.   def initialize
  189.     super(ScanSkill::NameWindow[:x], ScanSkill::NameWindow[:y], window_width, window_height)
  190.     self.visible = false
  191.   end
  192.  
  193.   def visible_line_number
  194.     return 1
  195.   end
  196.  
  197.   def col_max
  198.     return 1
  199.   end
  200.  
  201.   def window_width
  202.     ScanSkill::NameWindow[:width]
  203.   end
  204.  
  205.   def window_height
  206.     ScanSkill::NameWindow[:height]
  207.   end
  208.   def set_enemy(enemy)
  209.     @enemy = enemy
  210.     refresh
  211.     puts "test" if @enemy.note =~ /<description:(.?)>/m
  212.   end
  213.  
  214.   def draw_all_items
  215.     rect = item_rect_for_text(0)
  216.  
  217.     change_color(normal_color)
  218.     draw_text_ex(rect.x + ScanSkill::NameWindow[:name_x], rect.y + ScanSkill::NameWindow[:name_y], @enemy.original_name)
  219.     name_stripped = @enemy.original_name.sub(/^\\C\[\d+\]/i, '').sub(/\\C\[\d+\]$/i, '')
  220.     icon_x = text_size(name_stripped).width # cache end x
  221.    
  222.     draw_text(rect.x + ScanSkill::StatusText[:x], rect.y + ScanSkill::StatusText[:y], rect.width, rect.height, ScanSkill::StatusText[:text])
  223.  
  224.     # attack element
  225.     if !@enemy.atk_elements.empty? && ScanSkill::ElementIcons.include?(@enemy.atk_elements[0])
  226.       draw_icon(ScanSkill::ElementIcons[@enemy.atk_elements[0]], icon_x + ScanSkill::NameWindow[:icon_x], ScanSkill::NameWindow[:icon_y])
  227.     end
  228.    
  229.     # states
  230.     draw_actor_icons(@enemy, ScanSkill::NameWindow[:state_x], ScanSkill::NameWindow[:state_y])
  231.  
  232.     reset_font_settings
  233.   end
  234.  
  235.   def update
  236.     super
  237.     return if (!self.visible)
  238.     if Input.trigger?(:B) || Input.trigger?(:C)
  239.       SceneManager.scene.stop_scan_skill
  240.     end
  241.   end
  242.  
  243. end
  244.  
  245. #----------------------------------------------------------------------
  246. # Window_Resistances
  247. #
  248. class Window_Resistances < Window_Selectable
  249.  
  250.   def initialize
  251.     super(ScanSkill::ElementWindow[:x], ScanSkill::ElementWindow[:y], window_width, window_height)
  252.     self.visible = false
  253.   end
  254.  
  255.   def visible_line_number
  256.     return 1
  257.   end
  258.  
  259.   def col_max
  260.     return ScanSkill::ElementOrder.size
  261.   end
  262.  
  263.   def window_width
  264.     ScanSkill::ElementWindow[:width]
  265.   end
  266.  
  267.   def window_height
  268.     ScanSkill::ElementWindow[:height]
  269.   end
  270.  
  271.   def item_max
  272.     return col_max
  273.   end
  274.  
  275.   def set_enemy(enemy)
  276.     @enemy = enemy
  277.     refresh
  278.   end
  279.  
  280.   def draw_image(file, index, x, y, enabled = true)
  281.     bitmap = Cache.system(file)
  282.     rect = Rect.new(0, 0, bitmap.width, bitmap.height)
  283.     contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  284.   end
  285.  
  286.   def spacing
  287.     return 5
  288.   end
  289.  
  290.   def draw_item(index)
  291.     elementID = ScanSkill::ElementOrder[index]
  292.     rect = item_rect_for_text(index)
  293.     text = ScanSkill::NormalText
  294.     text = ScanSkill::WeakText if @enemy.element_rate(elementID) >= ScanSkill::WeakPercent
  295.     text = ScanSkill::StrongText if @enemy.element_rate(elementID) <= ScanSkill::StrongPercent
  296.     text = ScanSkill::NullText if @enemy.element_rate(elementID) == ScanSkill::NullPercent
  297.  
  298.     draw_image(ScanSkill::ElementImages[elementID], index, rect.x + ScanSkill::ElementWindow[:image_x], rect.y + ScanSkill::ElementWindow[:image_y])
  299.    
  300.     rect.x += ScanSkill::ElementWindow[:text_x]
  301.     rect.y += ScanSkill::ElementWindow[:text_y]
  302.    
  303.     change_color(normal_color)
  304.     draw_text(rect, text, 1)
  305.     reset_font_settings
  306.   end
  307. end
  308.  
  309. #----------------------------------------------------------------------
  310. # Window_ScanDescription
  311. #
  312. class Window_ScanDescription < Window_Base
  313.  
  314.   def initialize
  315.     super(ScanSkill::DescriptionWindow[:x], ScanSkill::DescriptionWindow[:y], window_width, window_height)
  316.     self.visible = false
  317.     @description_on = false
  318.     @description = ""
  319.   end
  320.  
  321.   def visible_line_number
  322.     return 3
  323.   end
  324.  
  325.   def window_width
  326.     ScanSkill::DescriptionWindow[:width]
  327.   end
  328.  
  329.   def window_height
  330.     ScanSkill::DescriptionWindow[:height]
  331.   end
  332.  
  333.   def set_enemy(enemy)
  334.     @enemy = enemy
  335.     refresh
  336.   end
  337.  
  338.   def refresh
  339.     if @enemy
  340.       @enemy.note.split(/[\r\n]+/).each { |line|
  341.         case line
  342.           when ScanSkill::DescriptionOn
  343.             @description_on = true
  344.           when ScanSkill::DescriptionOff
  345.             @description_on = false
  346.           else
  347.             @description += line.to_s + "\n" if @description_on
  348.           end
  349.       }
  350.       draw_text_ex(0, 0, @description)
  351.     end
  352.   end
  353. end
  354.  
  355. class Window_BattleLog < Window_Selectable
  356.  
  357.   alias mjshi_scan_display_failure display_failure
  358.   def display_failure(target, item)
  359.     return if item.is_a?(RPG::Skill) && ScanSkill::SkillID.include?(item.id)
  360.     mjshi_scan_display_failure(target, item)
  361.   end
  362.  
  363. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement