Advertisement
Ocedic

OC Animated Gauges 1.3b

Mar 9th, 2013
1,163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.97 KB | None | 0 0
  1. # *****************************************************************************
  2. #
  3. # OC ANIMATED GAUGES
  4. # Author: Ocedic
  5. # Site: http://ocedic.wordpress.com/
  6. # Version: 1.3b
  7. # Last Updated: 3/16/13
  8. #
  9. # Updates:
  10. # 1.3b - Rate methods are now aliased
  11. # 1.3  - Now updates every two frames instead of every frame, update rate for
  12. #        specific bars can be set
  13. # 1.2  - Fixed a bug that prevented HP/MP comparison conditionals from
  14. #        functioning correctly
  15. # 1.1  - Rate change now works properly, added configuration option to disable
  16. #        animation for specific bars
  17. # 1.0  - First release
  18. #
  19. # *****************************************************************************
  20.  
  21. $imported = {} if $imported.nil?
  22. $imported["OC-AnimatedGauges"] = true
  23.  
  24. #==============================================================================
  25. # ▼ Introduction
  26. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  27. # This script changes HP, MP and TP gauges to have a gradual adjustment rather
  28. # than the default instantaneous feedback.
  29. #==============================================================================
  30. # ▼ Instructions
  31. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  32. # Plug and play script. Simply paste it above Main. Settings can be adjusted
  33. # in configuration section.
  34. #==============================================================================
  35. # ▼ Compatibility
  36. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  37. # This script is designed to work for the Default Battle System and Yanfly's
  38. # Battle Engine/Core Engine. Other custom gauge and battle systems may not be
  39. # compatible.
  40. #==============================================================================
  41. # ▼ Terms of Use
  42. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  43. # Can be freely used and modified in non-commercial projects. Proper attribution
  44. # must be given to Ocedic, and this header must be preserved.
  45. # For commercial terms, see here: https://ocedic.wordpress.com/terms-of-use/
  46. #==============================================================================
  47.  
  48. #==============================================================================
  49. # ■ Configuration
  50. #------------------------------------------------------------------------------
  51. #  Change customizable settings here
  52. #==============================================================================
  53. module OC
  54.   module GAUGE
  55.    
  56. #==============================================================================
  57. # * Enable Rates *
  58. #------------------------------------------------------------------------------
  59. #   This allows you to turn off animated gauges for any of the supported bars.
  60. #   To disable bar animation, simply set the corresponding switch to false.
  61. #==============================================================================
  62.  
  63.     ENABLE_HP_RATE = true
  64.     ENABLE_MP_RATE = true
  65.     ENABLE_TP_RATE = true
  66.  
  67. #==============================================================================
  68. # * Rate Change *
  69. #------------------------------------------------------------------------------
  70. #   Sets how much the gauge will change in each frame for each gauge type,
  71. #   denoted in %.
  72. #==============================================================================
  73. # * Max TP *
  74. #------------------------------------------------------------------------------
  75. #   Input the max TP here if you use a custom value for max TP.
  76. #==============================================================================
  77.     RATE_CHANGE_HP = 0.03    # Default 0.03
  78.     RATE_CHANGE_MP = 0.01    # Default 0.01
  79.     RATE_CHANGE_TP = 0.02    # Default 0.02
  80.     MAX_TP = 100             # Default 100
  81.  
  82.   end # BATTLE
  83. end #OC
  84.  
  85. #==============================================================================
  86. # ■ End of Configuration
  87. #==============================================================================
  88.  
  89. #==============================================================================
  90. # ■ Game_BattlerBase
  91. #==============================================================================
  92. class Game_BattlerBase
  93.  
  94. #==============================================================================
  95. # * Accessors *
  96. #==============================================================================
  97.   attr_accessor :current_hp_rate                
  98.   attr_accessor :current_mp_rate              
  99.   attr_accessor :current_tp_rate
  100.  
  101. #==============================================================================
  102. # * Alias: Initialize *
  103. #==============================================================================
  104.   alias oc_game_battlerbase_initialize_nl2d9s initialize
  105.   def initialize
  106.     oc_game_battlerbase_initialize_nl2d9s
  107.     @current_hp_rate = 1.0
  108.     @current_mp_rate = 1.0
  109.     @current_tp_rate = 1.0
  110.   end    
  111.  
  112. end #class game_battlerbase
  113.  
  114. #==============================================================================
  115. # ■ Game_Actor
  116. #==============================================================================
  117. class Game_Actor < Game_Battler
  118.  
  119. #==============================================================================
  120. # * Alias: HP Rate *
  121. #==============================================================================
  122.   alias oc_game_actor_hp_rate_n43ps hp_rate
  123.   def hp_rate
  124.     if OC::GAUGE::ENABLE_HP_RATE && SceneManager.scene_is?(Scene_Battle)
  125.       rate_diff = @hp.to_f / mhp - @current_hp_rate
  126.       if rate_diff > 0
  127.         @current_hp_rate += [OC::GAUGE::RATE_CHANGE_HP, rate_diff.abs / 5].min
  128.       elsif rate_diff < 0
  129.         @current_hp_rate -= [OC::GAUGE::RATE_CHANGE_HP, rate_diff.abs / 5].min
  130.       end
  131.       @current_hp_rate
  132.     else
  133.       oc_game_actor_hp_rate_n43ps
  134.     end
  135.   end
  136.  
  137. #==============================================================================
  138. # * Alias: MP Rate *
  139. #==============================================================================
  140.   alias oc_game_actor_mp_rate_a02sf mp_rate
  141.   def mp_rate
  142.     if OC::GAUGE::ENABLE_MP_RATE && SceneManager.scene_is?(Scene_Battle)
  143.       return 0 if mmp == 0
  144.       rate_diff = @mp.to_f / mmp - @current_mp_rate
  145.       if rate_diff > 0
  146.         @current_mp_rate += [OC::GAUGE::RATE_CHANGE_MP, rate_diff.abs / 5].min
  147.       elsif rate_diff < 0
  148.         @current_mp_rate -= [OC::GAUGE::RATE_CHANGE_MP, rate_diff.abs / 5].min
  149.       end
  150.       @current_mp_rate
  151.     else
  152.       oc_game_actor_mp_rate_a02sf
  153.     end
  154.   end  
  155.  
  156. #==============================================================================
  157. # * Alias: TP Rate *
  158. #==============================================================================
  159.   alias oc_game_actor_tp_rate_03ldn tp_rate
  160.   def tp_rate
  161.     if OC::GAUGE::ENABLE_TP_RATE && SceneManager.scene_is?(Scene_Battle)
  162.       rate_diff = @tp.to_f / OC::GAUGE::MAX_TP - @current_tp_rate
  163.       if rate_diff > 0
  164.         @current_tp_rate += [OC::GAUGE::RATE_CHANGE_TP, rate_diff.abs / 5].min
  165.       elsif rate_diff < 0
  166.         @current_tp_rate -= [OC::GAUGE::RATE_CHANGE_TP, rate_diff.abs / 5].min
  167.       end
  168.       @current_tp_rate
  169.     else
  170.       oc_game_actor_tp_rate_03ldn
  171.     end
  172.   end  
  173.  
  174. end #class game_actor
  175.  
  176. #==============================================================================
  177. # ■ Window_BattleStatus
  178. #==============================================================================
  179.  
  180. class Window_BattleStatus < Window_Selectable
  181.  
  182. #==============================================================================
  183. # * New Method: Refresh Gauges *
  184. #------------------------------------------------------------------------------
  185. #   Updates the HP, MP and TP bars of Yanfly's Battle Status. This part is
  186. #   isolated from the rest of Draw_Item in order to reduce lag by not having
  187. #   to draw actor graphics every update
  188. #==============================================================================  
  189.   def refresh_gauges
  190.     i = 0
  191.     $game_party.battle_members.each do |member|
  192.       rectwidth = contents.width / $game_party.max_battle_members
  193.       rectx = i * rectwidth
  194.       draw_actor_hp(member, rectx+2, line_height*2+11, rectwidth-4)
  195.       if draw_tp?(member) && draw_mp?(member)
  196.         dw = rectwidth/2-2
  197.         dw += 1 if $imported["YEA-CoreEngine"] && YEA::CORE::GAUGE_OUTLINE
  198.         draw_actor_tp(member, rectx+2, line_height*3, dw)
  199.         dw = rectwidth - rectwidth/2 - 2
  200.         draw_actor_mp(member, rectx+rectwidth/2, line_height*3, dw)
  201.       elsif draw_tp?(member) && !draw_mp?(member)
  202.         draw_actor_tp(member, rectx+2, line_height*3, rectwidth-4)
  203.       else
  204.         draw_actor_mp(member, rectx+2, line_height*3, rectwidth-4)
  205.       end
  206.       i += 1
  207.     end    
  208.   end
  209.  
  210. end #class window_battlestatus
  211.  
  212. #==============================================================================
  213. # ■ Scene_Battle
  214. #==============================================================================
  215. class Scene_Battle < Scene_Base
  216.  
  217. #==============================================================================
  218. # * Alias: Start *
  219. #==============================================================================
  220.   alias oc_scene_battle_start_3njs9 start
  221.   def start
  222.     oc_scene_battle_start_3njs9
  223.     $game_party.battle_members.each do |actor|
  224.       actor.current_hp_rate = actor.hp.to_f / actor.mhp
  225.       actor.current_mp_rate = actor.mp.to_f / actor.mmp
  226.       actor.current_tp_rate = actor.tp.to_f / OC::GAUGE::MAX_TP
  227.     end
  228.   end
  229.  
  230. #==============================================================================
  231. # * Alias: Update Basic *
  232. #==============================================================================
  233.   alias oc_scene_battle_update_vj902 update_basic
  234.   def update_basic
  235.     oc_scene_battle_update_vj902
  236.     @update_timer ||= 0
  237.     @update_timer += 1
  238.     return if @update_timer % 2 != 0
  239.     if $imported["YEA-BattleEngine"]
  240.       @status_window.refresh_gauges
  241.     else
  242.       @status_window.refresh
  243.     end
  244.   end
  245.  
  246. end #class scene_battle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement