blucalm

6 Nov. 2012 Cooldowns

Nov 6th, 2012
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.63 KB | None | 0 0
  1. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  2. # ** Cooldowns
  3. # Author: Eshra
  4. # Release Date: 6 Nov. 2012
  5. # Compatibility: RPG Maker VX Ace
  6. # Dependencies: (~^_^)~Hotkeys v0.1
  7. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  8. #
  9. # About:
  10. #
  11. # This script is an add-on for the hotkeys script I wrote. It allows items
  12. # and skills to be tagged with cooldowns to prevent them from being used
  13. # again immediately.
  14. #
  15. #------------------------------------------------------------------------------
  16. # * How to Use
  17. #------------------------------------------------------------------------------
  18. #
  19. # These notetags are supported:
  20. #
  21. # <cooldown VALUE>
  22. # gives an item or skill a cooldown period in frames
  23. #
  24. # <global cooldown VALUE>
  25. # gives an item a global cooldown, given in frames. (no skills or items can be
  26. # used while the global cooldown is active)
  27. #
  28. # <duration VALUE>
  29. # Can be used to specify how long a skill/item will be active (for scripted
  30. # skills/items only currently).
  31. #
  32. # - Replace VALUE in the above notetags with an integer -
  33. #
  34. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  35. # Original Release Date: 6 Nov. 2012
  36. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  37. #
  38. # Update Log
  39. # 6 Nov. 2012 - Decided to release without fixing the f12 problem.
  40. #
  41. # 23 Aug. 2012 - Finished first working version
  42. #
  43. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  44. # Author Notes:
  45. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  46. #
  47. # I still have not fixed the problem when using f12 to reset the game. I have
  48. # no idea how f12 actually works, it looks like it just calls SceneManager.run
  49. # but somehow all of the graphics are cleaned up.
  50. # Once I understand what f12 is doing I will fix this issue.
  51. #
  52. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  53. # Terms of Use
  54. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  55. # Free to use as you please. Please respect the header though so the dates can
  56. # be preserved.
  57. #------------------------------------------------------------------------------
  58.  
  59. ($imported||={})["(~^_^)~Cooldowns"] = 0.1
  60.  
  61. module COOLDOWNS
  62. module USE_FAILED
  63. SOUND = 3 # Default Buzzer
  64. end
  65. module REGEXP
  66. TAG = /<(?:!|)cooldown\s*(\d+)>/i
  67. GLOBAL = /<(?:!|)global cooldown\s*(\d+)>/i
  68. end
  69. end
  70.  
  71. module DURATION
  72. module REGEXP
  73. TAG = /<(?:!|)duration\s*(\d+)>/i
  74. end
  75. module NAME
  76. TAG = /<(?:!|)ts-name = (\w+)(?:\s|)\[T(\d+)\]>/i
  77. end
  78. end
  79. #==============================================================================
  80. # ** DataManager
  81. #==============================================================================
  82. module DataManager
  83.  
  84. #--------------------------------------------------------------------------
  85. # alias method: load_database
  86. #--------------------------------------------------------------------------
  87. class <<self; alias load_dtbase_mp_cd_ntags load_database; end
  88. def self.load_database
  89. load_dtbase_mp_cd_ntags
  90. load_map_cd_notetags
  91. end
  92.  
  93. #--------------------------------------------------------------------------
  94. # new method: load_notetags_abe
  95. #--------------------------------------------------------------------------
  96. def self.load_map_cd_notetags
  97. groups = [$data_armors, $data_weapons, $data_items, $data_skills]
  98. for group in groups
  99. for obj in group
  100. next if obj.nil?
  101. obj.load_sc_map_cd_notetags
  102. end
  103. end
  104. end
  105. end # DataManager
  106. #==============================================================================
  107. # ** RPG::UsableItem
  108. #==============================================================================
  109. class RPG::UsableItem < RPG::BaseItem
  110. attr_accessor :cooldown_timer
  111. attr_accessor :base_cooldown
  112. attr_accessor :duration_timer
  113. attr_accessor :base_duration
  114. attr_accessor :global_cooldown
  115.  
  116. def load_sc_map_cd_notetags
  117. @cooldown_timer = 0
  118. @base_cooldown = 0
  119. @duration_timer = 0
  120. @base_duration = 0
  121. @global_cooldown = 0
  122.  
  123. self.note.split(/[\r\n]+/).each { |line|
  124. next unless line != nil
  125. case line
  126. when COOLDOWNS::REGEXP::TAG
  127. @base_cooldown = $1.to_i
  128. when DURATION::REGEXP::TAG
  129. @base_duration = $1.to_i
  130. when COOLDOWNS::REGEXP::GLOBAL
  131. @global_cooldown = $1.to_i
  132. #print "loaded global cool = #{@global_cooldown}\n"
  133. end # End - case line
  134. } # End - self.note.split
  135. end # End - load_sc_map_cd_notetagss
  136.  
  137. end # End - RPG::UsableItem
  138.  
  139. #==============================================================================
  140. # ** RPG::BaseItem
  141. #==============================================================================
  142. class RPG::BaseItem
  143. attr_accessor :name
  144. end
  145. #==============================================================================
  146. # ** RPG::EquipItem
  147. #==============================================================================
  148. class RPG::EquipItem < RPG::BaseItem
  149. attr_accessor :cooldown_timer
  150. attr_accessor :base_cooldown
  151. attr_accessor :duration_timer
  152. attr_accessor :base_duration
  153. attr_accessor :global_cooldown
  154.  
  155. def load_sc_map_cd_notetags
  156. @cooldown_timer = 0
  157. @base_cooldown = 0
  158. @duration_timer = 0
  159. @base_duration = 0
  160. @global_cooldown = 0
  161.  
  162. self.note.split(/[\r\n]+/).each { |line|
  163. next unless line != nil
  164. case line
  165. when COOLDOWNS::REGEXP::TAG
  166. @base_cooldown = $1.to_i
  167. when DURATION::REGEXP::TAG
  168. @base_duration = $1.to_i
  169. when COOLDOWNS::REGEXP::GLOBAL
  170. @global_cooldown = $1.to_i
  171. end # End - case line
  172. } # End - self.note.split
  173. end # End - load_sc_map_cd_notetagss
  174. end # End - RPG::EquipItem
  175. #==============================================================================
  176. # ** Game_Map
  177. #==============================================================================
  178. class Game_Map
  179.  
  180. attr_accessor :cooldown_queue # Items on cd are placed here
  181. attr_accessor :duration_queue # Items that last over time are place here
  182. attr_accessor :global_cooldown
  183. attr_accessor :global_cooldown_base
  184.  
  185. #
  186. # ** Alias method initialize
  187. #
  188. alias gme_map_cool_down_ch_initialize initialize
  189. def initialize
  190. gme_map_cool_down_ch_initialize
  191. @cooldown_queue = []
  192. @duration_queue = []
  193. @global_cooldown = 0
  194. @global_cooldown_base = 0
  195.  
  196. end # End - initialize
  197.  
  198. #
  199. # ** Alias method update
  200. #
  201. alias gme_map_cool_down_ch_update_9817 update
  202. def update(*arg)
  203.  
  204. gme_map_cool_down_ch_update_9817(*arg)
  205.  
  206. @global_cooldown -= 1 if @global_cooldown > 0
  207. #print "global_cooldown remaining: #{global_cooldown}\n"
  208.  
  209.  
  210. #print "cooldown_queue = #{@cooldown_queue.inspect}\n"
  211. @cooldown_queue.each{ |item|
  212. item.cooldown_timer-=1
  213. #print "cooldown left on #{item}: #{item.cooldown_timer}\n"
  214. if(item.cooldown_timer <= 0)
  215. @cooldown_queue.delete(item)
  216. end
  217. } # End - @cooldown_queue.each
  218.  
  219. @duration_queue.each{ |item|
  220. item.duration_timer-=1
  221. #print "duration left on #{item}: #{item.duration_timer}\n"
  222. if(item.duration_timer <= 0)
  223. @duration_queue.delete(item)
  224. end
  225.  
  226. } # End - @duration_queue.each
  227. end # End - update
  228.  
  229. # Store all the cooldown data for the item.
  230.  
  231. def init_cooldown_timers(item)
  232. item.cooldown_timer = item.base_cooldown
  233. item.duration_timer = item.base_duration
  234.  
  235. #print "init cooldown_timer, item gcd = #{item.global_cooldown}\n"
  236.  
  237. if @global_cooldown < item.global_cooldown
  238. @global_cooldown = item.global_cooldown
  239. @global_cooldown_base = item.global_cooldown
  240. end
  241. @cooldown_queue.push(item) unless @cooldown_queue.include?(item)
  242. @duration_queue.push(item) unless @duration_queue.include?(item)
  243. end
  244.  
  245. def game_timer_skills
  246. @@game_timer_skills
  247. end
  248.  
  249. # Check if there is a global cooldown
  250. def all_cd?
  251. #print "on gcd = ", @global_cooldown > 0, "\n"
  252. return @global_cooldown > 0
  253. end
  254.  
  255. def gcd_val(mod = 0)
  256. @global_cooldown + mod
  257. end
  258.  
  259. def gcd_base(mod = 0)
  260. @global_cooldown_base + mod
  261. end
  262.  
  263. end # End - Scene_Map
  264.  
  265. #==============================================================================
  266. # ** Aliased use_item methods in various classes: **
  267. #==============================================================================
  268. class Scene_ItemBase < Scene_MenuBase
  269. alias item_usable_check_for_cd_4289_use_item use_item
  270. def use_item
  271. if item.cooldown_timer > 0 || $game_map.all_cd?
  272. Sound.play_system_sound(COOLDOWNS::USE_FAILED::SOUND)
  273. return
  274. end
  275. #print "on global cooldown? #{$game_map.all_cd?}\n"
  276. item_usable_check_for_cd_4289_use_item
  277. $game_map.init_cooldown_timers(item)
  278. end # End - use_item
  279. end # End - Scene_ItemBase
  280.  
  281. #==============================================================================
  282. # ** Game_Battler
  283. #==============================================================================
  284. class Game_Battler < Game_BattlerBase
  285. alias item_usable_check_for_cd_4285_use_item use_item
  286. def use_item(item)
  287. #print "cooldown_timer: #{item.cooldown_timer}"
  288. if item.cooldown_timer > 0 || $game_map.all_cd?
  289. Sound.play_system_sound(COOLDOWNS::USE_FAILED::SOUND)
  290. return
  291. end
  292. item_usable_check_for_cd_4285_use_item(item)
  293. $game_map.init_cooldown_timers(item)
  294. end # End - use_item
  295. end # End - Game_Battler
  296.  
  297. # End of File
Advertisement
Add Comment
Please, Sign In to add comment