Advertisement
mrbubble

Real-time Cooldowns

Jul 30th, 2012
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.63 KB | None | 0 0
  1. #==============================================================================
  2. # ++ Real-time Cooldowns ++                                     v1.2 (7/31/12)
  3. #==============================================================================
  4. # Script by:
  5. #     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
  6. #--------------------------------------------------------------------------
  7. # This script allows you to define real-time cooldowns for skills,
  8. # limiting the frequency of skill usage based on the Playtime timer.
  9. #
  10. # Inspiration for creating this script comes from Breath of Fire 3's
  11. # "Bonebreak" (テラブレイク) and "Celerity" skills which were known for
  12. # their 3-hour long cooldown timers.
  13. #
  14. # This script only affects Actor's skills. This has no effect on Enemies.
  15. #--------------------------------------------------------------------------
  16. #   ++ Changelog ++
  17. #--------------------------------------------------------------------------
  18. # v1.1 : Added proper $imported variable. (7/31/2012)
  19. # v1.1 : Efficiency update. (7/30/2012)
  20. # v1.0 : Initial release. (7/30/2012)
  21. #--------------------------------------------------------------------------
  22. #   ++ Installation ++
  23. #--------------------------------------------------------------------------
  24. # Install this script in the Materials section in your project's
  25. # script editor.
  26. #==============================================================================
  27. #   ++ Real-time Cooldown Notetags ++
  28. #==============================================================================
  29. # Note: Some tags are given shorter tags for typing convenience. You only
  30. #       need to use one <tag> from a given group for a notebox.
  31. #       Use common sense.
  32. #
  33. # The following Notetag is for Skills only:
  34. #  
  35. # <realtime cooldown: hrs:min:sec>
  36. # <rtcooldown: hrs:min:sec>
  37. #   This tag defines the amount of real-life time the skill needs to
  38. #   cooldown after being used once. All hours, minutes, and seconds
  39. #   values must be defined even if any one of them is zero. The cooldown
  40. #   uses the Playtime clock to determine time elapsed.
  41. #
  42. # Here is an example of a <realtime cooldown> tag:
  43. #
  44. #     <realtime cooldown: 02:30:00>
  45. #
  46. # A skill with this tag will have a 2 hour and 30 minute cooldown after
  47. # being used once. Leading zeroes are not necessary, but can be used.
  48. #
  49. #==============================================================================
  50. #   ++ Real-time Cooldown Script Calls ++
  51. #==============================================================================
  52. # The following script calls are meant to be used in "Script..." event
  53. # commands found under Tab 3 when creating a new event.
  54. #
  55. # reset_realtime_cooldowns(actor_id)
  56. #   Removes all current real-time cooldowns from the given Actor where
  57. #   actor_id is an actor ID number from your database.
  58. #
  59. #--------------------------------------------------------------------------
  60. #   ++ Compatibility ++
  61. #--------------------------------------------------------------------------
  62. # This script aliases the following default VXA methods:
  63. #
  64. #     DataManager#load_database
  65. #     Game_BattlerBase#initialize
  66. #     Game_BattlerBase#skill_conditions_met?
  67. #     Game_Battler#use_item
  68. #
  69. # There are no default method overwrites.
  70. #
  71. # Requests for compatibility with other scripts are welcome.
  72. #--------------------------------------------------------------------------
  73. #   ++ Terms and Conditions ++
  74. #--------------------------------------------------------------------------
  75. # Please do not repost this script elsewhere without permission.
  76. # Free for non-commercial use. For commercial use, contact me first.
  77. #
  78. # Newest versions of this script can be found at
  79. #                                           http://mrbubblewand.wordpress.com/
  80. #==============================================================================
  81.  
  82. $imported ||= {}
  83. $imported["BubsRealtimeCooldown"] = true
  84.  
  85. #==========================================================================
  86. # ++ This script contains no customization module ++
  87. #==========================================================================
  88.  
  89.  
  90.  
  91. #==========================================================================
  92. # ++ DataManager
  93. #==========================================================================
  94. module DataManager
  95.   #--------------------------------------------------------------------------
  96.   # alias : load_database
  97.   #--------------------------------------------------------------------------
  98.   class << self; alias load_database_bubs_rtcooldown load_database; end
  99.   def self.load_database
  100.     load_database_bubs_rtcooldown # alias
  101.     load_notetags_bubs_rtcooldown
  102.   end
  103.  
  104.   #--------------------------------------------------------------------------
  105.   # new method : load_notetags_bubs_rtcooldown
  106.   #--------------------------------------------------------------------------
  107.   def self.load_notetags_bubs_rtcooldown
  108.     for obj in $data_skills
  109.       next if obj.nil?
  110.       obj.load_notetags_bubs_rtcooldown
  111.     end # for obj
  112.   end # def
  113.  
  114. end # module DataManager
  115.  
  116.  
  117. #==========================================================================
  118. # ++ Bubs::Regexp
  119. #==========================================================================
  120. module Bubs
  121.   module Regexp
  122.     REALTIME_COOLDOWN_TAG =
  123.       /<(?:REAL[_\s\-]?TIME|rt)[_\s]?COOLDOWN:\s*(\d+):(\d+):(\d+)\s*>/i
  124.   end # module Regexp
  125. end # module Bubs
  126.  
  127.  
  128. #==========================================================================
  129. # ++ RPG::BaseItem
  130. #==========================================================================
  131. class RPG::BaseItem
  132.   #--------------------------------------------------------------------------
  133.   # public instance variables
  134.   #--------------------------------------------------------------------------
  135.   attr_accessor :realtime_cooldown
  136.   #--------------------------------------------------------------------------
  137.   # common cache : load_notetags_bubs_rtcooldown
  138.   #--------------------------------------------------------------------------
  139.   def load_notetags_bubs_rtcooldown
  140.     @realtime_cooldown = 0
  141.     return unless note =~ Bubs::Regexp::REALTIME_COOLDOWN_TAG ? true : false
  142.     hour = $1.to_i * 60 * 60
  143.     min = $2.to_i * 60
  144.     sec = $3.to_i
  145.     @realtime_cooldown = hour + min + sec
  146.   end
  147.  
  148. end # class RPG::BaseItem
  149.  
  150.  
  151. #==============================================================================
  152. # ++ Game_Interpreter
  153. #==============================================================================
  154. class Game_Interpreter
  155.   #--------------------------------------------------------------------------
  156.   # new method : reset_realtime_cooldowns
  157.   #--------------------------------------------------------------------------
  158.   def reset_realtime_cooldowns(actor_id)
  159.     return unless $game_actors[actor_id]
  160.     $game_actors[actor_id].realtime_cooldowns.clear
  161.   end
  162. end # class Game_Interpreter
  163.  
  164.  
  165. #==============================================================================
  166. # ++ Game_BattlerBase
  167. #==============================================================================
  168. class Game_BattlerBase
  169.   #--------------------------------------------------------------------------
  170.   # public instance variables
  171.   #--------------------------------------------------------------------------
  172.   attr_accessor :realtime_cooldowns
  173.   #--------------------------------------------------------------------------
  174.   # alias : initialize
  175.   #--------------------------------------------------------------------------
  176.   alias initialize_bubs_rtcooldown initialize
  177.   def initialize
  178.     initialize_bubs_rtcooldown # alias
  179.    
  180.     @realtime_cooldowns = {}
  181.   end
  182.  
  183.   #--------------------------------------------------------------------------
  184.   # alias : skill_conditions_met?
  185.   #--------------------------------------------------------------------------
  186.   alias skill_conditions_met_bubs_rtcooldown skill_conditions_met?
  187.   def skill_conditions_met?(skill)
  188.     return false if realtime_cooldown?(skill)
  189.     return skill_conditions_met_bubs_rtcooldown(skill) # alias
  190.   end
  191.  
  192.   #--------------------------------------------------------------------------
  193.   # new method : realtime_cooldown?
  194.   #--------------------------------------------------------------------------
  195.   def realtime_cooldown?(skill)
  196.     return false unless skill.realtime_cooldown > 0
  197.     return false unless actor?
  198.     return false if @realtime_cooldowns[skill.id].nil?
  199.    
  200.     elapsed = $game_system.playtime - @realtime_cooldowns[skill.id]
  201.     if elapsed > skill.realtime_cooldown
  202.       @realtime_cooldowns.delete(skill.id)
  203.       return false
  204.     else
  205.       return true
  206.     end
  207.   end
  208.  
  209. end # class Game_BattlerBase
  210.  
  211.  
  212. #==============================================================================
  213. # ++ Game_Battler
  214. #==============================================================================
  215. class Game_Battler < Game_BattlerBase
  216.   #--------------------------------------------------------------------------
  217.   # alias : use_item
  218.   #--------------------------------------------------------------------------
  219.   alias use_item_bubs_rtcooldown use_item
  220.   def use_item(item)
  221.     set_realtime_cooldown(item)
  222.    
  223.     use_item_bubs_rtcooldown(item) # alias
  224.   end
  225.  
  226.   #--------------------------------------------------------------------------
  227.   # new method : set_realtime_cooldown
  228.   #--------------------------------------------------------------------------
  229.   def set_realtime_cooldown(item)
  230.     return unless item.is_a?(RPG::Skill)
  231.     return unless item.realtime_cooldown > 0
  232.     return unless actor?
  233.    
  234.     @realtime_cooldowns[item.id] = $game_system.playtime
  235.   end
  236.  
  237. end # class Game_Battler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement