SSTrihan

HorrorVale - State icon update

Sep 27th, 2024
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 18.77 KB | Source Code | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Don't remove this header!
  3. #-------------------------------------------------------------------------------
  4. # Enemy Custom Damage Popup + Enemy HP Bar
  5. # by Black Mage (https://burningwizard.wordpress.com/)
  6. # fix by Trihan
  7. #
  8. # Version : 1.7
  9. #
  10. # This script is commisioned by Batworks Software.
  11. #-------------------------------------------------------------------------------
  12.  
  13. #-------------------------------------------------------------------------------
  14. # Version History
  15. #-------------------------------------------------------------------------------
  16. # 1.7 - Added state icons on enemies. (Trihan)
  17. #
  18. # 1.6 - Fixed memory leak with HP icons. (Trihan)
  19. #
  20. # 1.5 - Fix a bug where dead enemies still do regen check.
  21. #     - Add option for buff debuff popup.
  22. #
  23. # 1.4 - Remove buff/debuff popup.
  24. #
  25. # 1.3 - Bugfix for Heal Over Time doesn't show the correct animation.
  26. #     - Add setting for resisted and super effective popup.
  27. #
  28. # 1.2 - Add compatibility fix for Mog's Enemy Animation script where the sprite
  29. #       position is changed in the background by the script.
  30. #
  31. # 1.1 - Add limit for the lowest Y coordinate position for enemy's HP icon to
  32. #       ensure that the icon is always visible.
  33. #
  34. # 1.0 - Initial design.
  35. #-------------------------------------------------------------------------------
  36.  
  37. #==============================================================================
  38. # This script requires Yanfly Damage Popup - Helladen Version. The script can
  39. # be found at the following link:
  40. #
  41. # https://forums.rpgmakerweb.com/index.php?threads/yanfly-damage-popup-1-0-4.12151/page-2#post-882832
  42. #==============================================================================
  43.  
  44. #-------------------------------------------------------------------------------
  45. # Settings for damage popup.
  46. #-------------------------------------------------------------------------------
  47. module BLACK_DMG_POPUP
  48.   DMG = { #           animation id    font size   RGB
  49.           'normal' => [207,           24,         [186,109,109]],
  50.          
  51.           'critical' => [208, 40, [175,109,186]],
  52.           #damage over time
  53.           'dot' => [209, 24, [186,185,109]],
  54.           #damage recovered over time
  55.           'drecovot' => [212, 24, [118,187,228]],
  56.           #damage recovered
  57.           'drecov' => [212, 24, [80,80,80]],
  58.           #damage rate in range (0,1)
  59.           'resisted' => [210, 20, [186,109,109]],
  60.           #damage rate > 1
  61.           'super_effective' => [211, 30, [186,109,109]],
  62.           #buff
  63.           'buff' => [206, 24, [255,127,39]],
  64.           #debuff
  65.           'debuff' => [206, 24, [128,0,128]]      
  66.         }
  67. end
  68. #-------------------------------------------------------------------------------
  69.  
  70. #-------------------------------------------------------------------------------
  71. # Settings for enemy HP icon.
  72. #-------------------------------------------------------------------------------
  73. module BLACK
  74.  
  75.   # This is the list of picture that will be used as enemy HP icon. The files
  76.   # are located on Graphics\System. You can use any ammount of picture and the
  77.   # script will adjust accordingly. The pictures must be ordered from the least
  78.   # HP to the most HP.
  79.   HP_IMAGES = ["skullb4", "skullb3", "skullb2", "skullb1"]
  80.  
  81.   # This is the number of icon that will show up on the screen when the enemy\
  82.   # HP is full.
  83.   HP_SECTIONS = 5
  84.  
  85.   # This is the width for each HP icon.
  86.   HP_IMG_WIDTH = 16
  87.  
  88.   # This is the offset setting for the enemy HP icon.
  89.   #            x, y
  90.   HP_OFFSET = [0, 0]
  91.  
  92.   # The y coordinate of the HP bar will never go below this value. Note that 0
  93.   # is located at the top of the window. For this purposes, this value
  94.   # overrides the offset setting in case there's conflict.
  95.   Y_POS_LIMIT = 100
  96.  
  97.   STATE_SECTIONS = 5
  98. end
  99. #-------------------------------------------------------------------------------
  100.  
  101.  
  102. #-------------------------------------------------------------------------------
  103. # * Beyond this is the sacred land of code. You need programming qualification
  104. #   to dwelve deeper, or it'll cause many unnecessary problems. Proceed on your
  105. #   own risk.
  106. #-------------------------------------------------------------------------------
  107.  
  108. #==============================================================================
  109. # Rewrite Damage_Popup constant to make the damage popup static.
  110. #==============================================================================
  111. class Sprite_Popup < Sprite_Base
  112.   def update
  113.     super
  114.     #---
  115.     if @flags.include?("critical") && YEA::BATTLE::FLASH_CRITICAL
  116.       @hue_duration = 2 if @hue_duration == nil || @hue_duration == 0
  117.       @hue_duration -= 1
  118.       self.bitmap.hue_change(15) if @hue_duration <= 0
  119.     end
  120.     #---
  121.     if @zoom_direction == "up"
  122.       self.zoom_x = [self.zoom_x + 0.075, @target_zoom].min
  123.       self.zoom_y = [self.zoom_y + 0.075, @target_zoom].min
  124.     else
  125.       self.zoom_x = [self.zoom_x - 0.075, @target_zoom].max
  126.       self.zoom_y = [self.zoom_y - 0.075, @target_zoom].max
  127.     end
  128.     #---
  129.     @full -= 1
  130.     return if @full > 0
  131.     self.opacity -= @fade
  132.   end
  133. end
  134. #==============================================================================
  135.  
  136.  
  137. #==============================================================================
  138. # Compatibility fix for Enemy Animations Script.
  139. #==============================================================================
  140. class Game_Actor < Game_Battler
  141.   # Redefine screen_x, screen_y to avoid endless loop inside Enemy Animations
  142.   # script upon attacking enemy.
  143.   undef screen_x; undef screen_y
  144.   def b_screen_x; -50; end; def b_screen_y; -50; end
  145. end
  146. class Sprite_Popup < Sprite_Base
  147.   # Redefine create_popup_bitmap to use the new method b_screen_x and
  148.   # b_screen_y instead.
  149.   def create_popup_bitmap
  150.     b_settings = $game_temp.b_popup_settings
  151.     rules_array = YEA::BATTLE::POPUP_RULES[@rules]
  152.     bw = Graphics.width
  153.     bw += 48 if @flags.include?("state")
  154.     bh = Font.default_size * 3
  155.     bitmap = Bitmap.new(bw, bh)
  156.     bitmap.font.name = rules_array[8]
  157.     size = @flags.include?("critical") ? rules_array[2] * 1.2 : rules_array[2]
  158.    
  159.     f_sz = b_settings[1]
  160.     f_sz = 6 if f_sz < 6
  161.     bitmap.font.size = f_sz
  162.     bitmap.font.bold = rules_array[3]
  163.     bitmap.font.italic = rules_array[4]
  164.     if flags.include?("critical")
  165.       crit = YEA::BATTLE::POPUP_RULES["CRITICAL"]
  166.       bitmap.font.out_color.set(crit[5], crit[6], crit[7], 255)
  167.     else
  168.       bitmap.font.out_color.set(0, 0, 0, 255)
  169.     end
  170.     dx = 0; dy = 0; dw = 0
  171.     dx += 24 if @flags.include?("state")
  172.     dw += 24 if @flags.include?("state")
  173.     if @flags.include?("state") || @flags.include?("buff")
  174.       c_width = bitmap.text_size(@value).width
  175.       icon_bitmap = $game_temp.iconset
  176.       icon_index = flag_state_icon
  177.       rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  178.       bitmap.blt(dx+(bw-c_width)/2-36, (bh - 24)/2, icon_bitmap, rect, 255)
  179.     end
  180.    
  181.     b_color = b_settings[2]
  182.     bitmap.font.color.set(b_color[0],b_color[1],b_color[2])
  183.  
  184.     bitmap.draw_text(dx, dy, bw-dw, bh, @value, 1)
  185.     self.bitmap = bitmap
  186.     if @battler.class.name == 'Game_Enemy'
  187.       self.x = @battler.screen_x
  188.     else
  189.       self.x = @battler.b_screen_x
  190.     end
  191.     self.x += rand(4) - rand(4) if @battler.sprite.popups.size >= 1
  192.     self.x -= SceneManager.scene.spriteset.viewport1.ox
  193.     if @battler.class.name == 'Game_Enemy'
  194.       self.y = @battler.screen_y - @battler.sprite.oy/2
  195.     else
  196.       self.y = @battler.b_screen_y - @battler.sprite.oy/2
  197.     end
  198.     self.y -= @battler.sprite.oy/2 if @battler.actor?
  199.     self.y -= SceneManager.scene.spriteset.viewport1.oy
  200.     self.ox = bw/2; self.oy = bh/2
  201.     self.zoom_x = self.zoom_y = rules_array[0]
  202.     if @flags.include?("no zoom")
  203.       self.zoom_x = self.zoom_y = rules_array[1]
  204.     end
  205.     @target_zoom = rules_array[1]
  206.     @zoom_direction = (self.zoom_x > @target_zoom) ? "down" : "up"
  207.     self.z = 500
  208.   end
  209. end
  210. #==============================================================================
  211.  
  212.  
  213. #==============================================================================
  214. # Play animation when damage is shown.
  215. #==============================================================================
  216. class Game_Temp
  217.   attr_accessor :b_popup_settings
  218.   attr_accessor :on_regen
  219.   alias b_ppp_init initialize
  220.   def initialize
  221.     b_ppp_init
  222.     #                    trigger  animation   font size   RGB       DoT/HoT
  223.     @b_popup_settings = [1,          24,         [186,109,109],  false]
  224.     @on_regen = false
  225.   end
  226. end
  227. class Game_BattlerBase
  228.   include BLACK_DMG_POPUP
  229.   def make_damage_popups(user)
  230.     if @result.hp_drain != 0
  231.       text = YEA::BATTLE::POPUP_SETTINGS[:drained]
  232.       rules = "DRAIN"
  233.       user.create_popup(text, rules)
  234.       setting = :hp_dmg  if @result.hp_drain < 0
  235.       setting = :hp_heal if @result.hp_drain > 0
  236.       rules = "HP_DMG"   if @result.hp_drain < 0
  237.       rules = "HP_HEAL"  if @result.hp_drain > 0
  238.       value = @result.hp_drain.abs
  239.       text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
  240.       user.create_popup(text, rules)
  241.     end
  242.     if @result.mp_drain != 0
  243.       text = YEA::BATTLE::POPUP_SETTINGS[:drained]
  244.       rules = "DRAIN"
  245.       user.create_popup(text, rules)
  246.       setting = :mp_dmg  if @result.mp_drain < 0
  247.       setting = :mp_heal if @result.mp_drain > 0
  248.       rules = "HP_DMG"   if @result.mp_drain < 0
  249.       rules = "HP_HEAL"  if @result.mp_drain > 0
  250.       value = @result.mp_drain.abs
  251.       text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
  252.       user.create_popup(text, rules)
  253.     end
  254.     #---
  255.     flags = []
  256.     flags.push("critical") if @result.critical
  257.     if @result.hp_damage != 0
  258.       setting = :hp_dmg  if @result.hp_damage > 0
  259.       setting = :hp_heal if @result.hp_damage < 0
  260.       rules = "HP_DMG"   if @result.hp_damage > 0
  261.       rules = "HP_HEAL"  if @result.hp_damage < 0
  262.       value = @result.hp_damage.abs
  263.       text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
  264.       create_popup(text, rules, flags)
  265.       if self.class.name == 'Game_Enemy'
  266.         type = 'normal'
  267.         if setting == :hp_dmg
  268.           type = 'critical' if @result.critical
  269.           type = 'dot' if $game_temp.on_regen
  270.         else
  271.           type = 'drecov'
  272.           type = 'drecovot' if $game_temp.on_regen
  273.         end
  274.         if type == 'normal'
  275.           type = 'super_effective' if @result.get_popups[0].include?('WEAK_ELE')
  276.           type = 'resisted' if @result.get_popups[0].include?('REST_ELE')
  277.         end
  278.         $game_temp.b_popup_settings = DMG[type]
  279.         $game_temp.popup_anim_start = [true, self.screen_x, self.screen_y]
  280.         SceneManager.scene.black_show_animation([self],DMG[type][0])
  281.       end
  282.     end
  283.     if @result.mp_damage != 0
  284.       setting = :mp_dmg  if @result.mp_damage > 0
  285.       setting = :mp_heal if @result.mp_damage < 0
  286.       rules = "MP_DMG"   if @result.mp_damage > 0
  287.       rules = "MP_HEAL"  if @result.mp_damage < 0
  288.       value = @result.mp_damage.abs
  289.       text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
  290.       create_popup(text, rules, flags)
  291.     end
  292.     if @result.tp_damage != 0
  293.       setting = :tp_dmg  if @result.tp_damage > 0
  294.       setting = :tp_heal if @result.tp_damage < 0
  295.       rules = "TP_DMG"   if @result.tp_damage > 0
  296.       rules = "TP_HEAL"  if @result.tp_damage < 0
  297.       value = @result.tp_damage.abs
  298.       text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
  299.       create_popup(text, rules)
  300.     end
  301.     $game_temp.on_regen = false
  302.     @result.store_damage
  303.     @result.clear_damage_values
  304.   end
  305. end
  306. class Game_ActionResult; def get_popups; @battler.popups; end; end
  307. class Game_Battler < Game_BattlerBase
  308.   alias b_regen_all regenerate_all
  309.   def regenerate_all; $game_temp.on_regen = true if alive?; b_regen_all; end
  310. end # Game_Battler
  311.  
  312. class Scene_Battle < Scene_Base
  313.   # Define an alternative of show_animation method to show enemy HP icon upon
  314.   # popup triggered.
  315.   def black_show_animation(targets, animation_id)
  316.     targets[0].show_hp_icon
  317.     if animation_id < 0; show_attack_animation(targets)
  318.     else; show_normal_animation(targets, animation_id)
  319.     end
  320.     @log_window.wait; wait_for_animation; targets[0].hide_hp_icon
  321.   end
  322. end
  323.  
  324. # Define flag for when the popup animation is played.
  325. class Game_Temp
  326.   attr_accessor :popup_anim_start
  327.   alias init_b_ppp_anim initialize
  328.   def initialize; init_b_ppp_anim; @popup_anim_start = [false, 0, 0]; end
  329. end
  330.  
  331. # Reset animation origin when the animation is flagged as popup animation.
  332. class Sprite_Base < Sprite
  333.   alias b_ppp_s_a_o set_animation_origin
  334.   def set_animation_origin
  335.     if @animation.position != 3 && $game_temp.popup_anim_start[0]
  336.       b_set_animation_origin
  337.     else
  338.       b_ppp_s_a_o
  339.     end
  340.   end
  341.   def b_set_animation_origin
  342.     old_x = x; old_y = y
  343.     x = $game_temp.popup_anim_start[1]
  344.     y = $game_temp.popup_anim_start[2]
  345.     @ani_ox = x - ox + width / 2
  346.     @ani_oy = y - oy + height / 2
  347.     if @animation.position == 0
  348.       @ani_oy -= height / 2
  349.     elsif @animation.position == 2
  350.       @ani_oy += height / 2
  351.     end
  352.     x = old_x; y = old_y; $game_temp.popup_anim_start = [false, 0, 0]
  353.   end
  354. end
  355. #==============================================================================
  356.  
  357.  
  358. #==============================================================================
  359. # Make state popup doesn't show.
  360. # Make miss, evade, and weakpoint popup doesn't show.
  361. #==============================================================================
  362.  
  363.  
  364. class Game_Battler < Game_BattlerBase
  365.   def make_miss_popups(user, item); end
  366. end
  367. class Sprite_Battler < Sprite_Base
  368.   alias b_c_n_ppp create_new_popup
  369.   def create_new_popup(value, rules, flags)
  370.     return if rules == "WEAK_ELE"
  371.     return if rules == "IMMU_ELE"
  372.     return if rules == "ABSB_ELE"
  373.     return if rules == "REST_ELE"
  374.     b_c_n_ppp(value, rules, flags)
  375.   end
  376. end
  377. #==============================================================================
  378.  
  379.  
  380. #==============================================================================
  381. # Create and show Enemy HP Icon.
  382. #==============================================================================
  383. class Sprite_Battler < Sprite_Base
  384.   include BLACK
  385.   attr_accessor :enemy_hp_icon
  386.   alias b_init_hp_icon initialize
  387.   def initialize(viewport, battler = nil)
  388.     b_init_hp_icon(viewport, battler)
  389.     if @battler.class.name == 'Game_Enemy'
  390.       @enemy_hp_icon = []
  391.       HP_SECTIONS.times do |i|
  392.         @enemy_hp_icon.push(Sprite.new)
  393.       end
  394.       enemy_hp_icon_update
  395.       @enemy_state_icon = []
  396.       STATE_SECTIONS.times do |i|
  397.         @enemy_state_icon.push(Sprite.new)
  398.       end
  399.       enemy_state_icon_update
  400.     end
  401.   end
  402.   def enemy_hp_icon_update
  403.     percentage = @battler.hp.to_f*100.to_f/@battler.mhp.to_f
  404.     treshold = (100.to_f/HP_SECTIONS.to_f)
  405.     b_height = Cache.battler(@battler.battler_name, @battler.battler_hue).height
  406.     ic_width = @enemy_hp_icon.size * HP_IMG_WIDTH
  407.     @enemy_hp_icon.size.times do |i|
  408.       opa = @battler.hp_icon ? 255 : 0; @enemy_hp_icon[i].opacity = opa
  409.       if [i*treshold, 100.to_f].min <= percentage && (percentage - i*treshold)/treshold >= 1
  410.         pic = HP_IMAGES.size - 1
  411.       elsif (percentage - i*treshold)/treshold > 0
  412.         pic = (((percentage - i*treshold)/treshold) * HP_IMAGES.size).ceil - 1
  413.       else
  414.         pic = -1
  415.       end
  416.       bmp = (pic == -1) ? nil : Cache.system(HP_IMAGES[pic])
  417.       @enemy_hp_icon[i].bitmap = bmp
  418.       @enemy_hp_icon[i].x = @battler.screen_x + (i*HP_IMG_WIDTH) - (ic_width/2) + HP_OFFSET[0]
  419.       @enemy_hp_icon[i].y = [@battler.screen_y - b_height + HP_OFFSET[1],Y_POS_LIMIT].max
  420.     end
  421.   end
  422.   def enemy_state_icon_update
  423.     b_height = Cache.battler(@battler.battler_name, @battler.battler_hue).height
  424.     ic_width = [@enemy_state_icon.size, @battler.state_icons.size].min * 24
  425.     @enemy_state_icon.size.times do |i|
  426.       opa = @battler.hp_icon ? 255 : 0; @enemy_state_icon[i].opacity = opa
  427.       if @battler.state_icons[i] != nil
  428.         @enemy_state_icon[i].bitmap = Bitmap.new(24, 24)
  429.         icon_index = @battler.state_icons[i]
  430.         bitmap = Cache.system("Iconset")
  431.         rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  432.         @enemy_state_icon[i].bitmap.blt(0, 0, bitmap, rect, 255)
  433.         @enemy_state_icon[i].x = @battler.screen_x + (i*24) - (ic_width/2) + HP_OFFSET[0]
  434.         @enemy_state_icon[i].y = @enemy_hp_icon[0].y + 40
  435.       else
  436.         @enemy_state_icon[i].bitmap = nil
  437.       end
  438.     end
  439.   end
  440.   alias b_hp_icon_updt update
  441.   def update
  442.     b_hp_icon_updt
  443.     if @battler.class.name == 'Game_Enemy'
  444.       enemy_hp_icon_update
  445.       enemy_state_icon_update
  446.     end
  447.   end
  448.   alias b_hp_icon_dispose dispose
  449.   def dispose
  450.     @enemy_hp_icon.each {|icon| icon.dispose} if @enemy_hp_icon
  451.     @enemy_state_icon.each {|icon| icon.dispose} if @enemy_state_icon
  452.     b_hp_icon_dispose
  453.   end
  454. end
  455. class Game_Enemy < Game_Battler
  456.   def show_hp_icon; @show_hp = true; end
  457.   def hide_hp_icon; @show_hp = false; end
  458.   def hp_icon; @show_hp; end
  459. end
  460. class Sprite_Battler  
  461.     alias b_hp_icon_upd_fx update_effect
  462.     def update_effect(*args)
  463.     if @battler.class.name == 'Game_Enemy'
  464.       @battler.show_hp_icon if @effect_type == :select_white
  465.     end
  466.     b_hp_icon_upd_fx(*args)
  467.     end
  468.   alias b_hp_icon_revert revert_to_normal
  469.   def revert_to_normal
  470.     b_hp_icon_revert
  471.     @battler.hide_hp_icon if @battler.class.name == 'Game_Enemy'
  472.   end
  473. end
  474. #==============================================================================
  475.  
  476. #==============================================================================
  477. # Version 1.5 Fix
  478. #==============================================================================
  479. # Removing popup that happened when a buff or debuff applied.
  480. class Game_BattlerBase
  481.   #def make_buff_popup(param_id, positive = true); return; end
  482.   def make_buff_popup(param_id, positive = true)
  483.     return unless SceneManager.scene_is?(Scene_Battle)
  484.     return unless alive?
  485.     name = Vocab::param(param_id)
  486.     if positive
  487.       text = sprintf(YEA::BATTLE::POPUP_SETTINGS[:add_buff], name)
  488.       rules = "BUFF"
  489.       type = "buff"
  490.       buff_level = 1
  491.     else
  492.       text = sprintf(YEA::BATTLE::POPUP_SETTINGS[:add_debuff], name)
  493.       rules = "DEBUFF"
  494.       type = "debuff"
  495.       buff_level = -1
  496.     end
  497.     icon = buff_icon_index(buff_level, param_id)
  498.     flags = ["buff", icon]
  499.     return if @popups.include?([text, rules, flags])
  500.     $game_temp.b_popup_settings = DMG[type]
  501.     create_popup(text, rules, flags)
  502.   end
  503. end
  504. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment