Advertisement
Szyu

Timed States

Aug 26th, 2014
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.04 KB | None | 0 0
  1. #==============================================================================
  2. # Timed States
  3. # Version 1.1
  4. # By Szyu
  5. #
  6. # About:
  7. # Create states, which trigger specific skills after they expire.
  8. # For example a time bomb skill, which applies the "bomb"-state which automatically
  9. # expires after 3 rounds. Then it will trigger a "detonation"-skill, which deals
  10. # damage and applies a "burn"-state.
  11. #
  12. # Instructions:
  13. # - Place below "Materials" but above "Main Process".
  14. #
  15. # How to Use:
  16. # - <timed: skill_id>
  17. # - <timed: skill_id1, skill_id2, ..., skill_idn>
  18. # This note in a state will let it trigger all skills defined after "timed:",
  19. # when the state expires. Mean if a state lasts 5 rounds, the skills are
  20. # triggered after round 5.
  21. #
  22. # When there are multiple skills set, the battle scene will trigger them sorted
  23. # from left to right.
  24. #
  25. # The expiration time is specified with the removal condition in the database.
  26. #
  27. #
  28. # Example:
  29. # <timed: 10, 50> will first trigger skill[10] and then skill[50]
  30. #
  31. #
  32. # Requires:
  33. # - RPG Maker VX Ace
  34. #
  35. # Terms of Use:
  36. # - Free for commercal and non-commercial use. Please list me
  37. #   in the credits to support my work.
  38. #
  39. # Pastebin:
  40. # http://pastebin.com/ye790Zsy
  41. #
  42. #
  43. #==============================================================
  44. #   * Game_Battler
  45. #==============================================================
  46. class Game_Battler < Game_BattlerBase
  47.  
  48.   alias sz_update_timed_states update_state_turns
  49.   def update_state_turns
  50.     sz_update_timed_states
  51.     update_timed_states
  52.   end
  53.  
  54.   def update_timed_states
  55.     states.each do |state|
  56.       if state.timed && @state_turns[state.id] == 0
  57.         state.triggered_skills.each do |s|
  58.           BattleManager.triggering_timed_states.push(RPG::EventCommand.new(339, 0, get_ts_params(s)))
  59.         end
  60.       end
  61.     end
  62.   end
  63.  
  64.   def get_ts_params(skill)
  65.     if self.is_a?(Game_Enemy)
  66.       return [0, self.index, skill, self.index]
  67.     elsif self.is_a?(Game_Actor)
  68.       return [1, self.character_index + 1, skill, self.index]
  69.     else
  70.       return [0, 0, 0, 0]
  71.     end
  72.   end
  73. end
  74.  
  75. #==============================================================
  76. #   * BattleManager
  77. #==============================================================
  78. module BattleManager
  79.   class << self
  80.     attr_accessor :triggering_timed_states
  81.     alias sz_ts_setup setup
  82.     alias sz_ts_turn_end turn_end
  83.   end
  84.  
  85.   def self.setup(troop_id, can_escape = true, can_lose = false)
  86.     sz_ts_setup(troop_id, can_escape, can_lose)
  87.     @triggering_timed_states = []
  88.   end
  89.  
  90.   def self.turn_end
  91.     sz_ts_turn_end
  92.     if @triggering_timed_states.size > 0
  93.       $game_troop.interpreter.setup(@triggering_timed_states.clone)
  94.       @triggering_timed_states.clear
  95.     end
  96.   end
  97. end
  98.  
  99. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  100.  
  101. #==============================================================
  102. #   * Initialize BaseItems
  103. #==============================================================
  104. module DataManager
  105.   class << self
  106.     alias load_db_timer_notes load_database
  107.   end
  108.  
  109.   def self.load_database
  110.     load_db_timer_notes
  111.     load_sz_timer_items
  112.   end
  113.  
  114.   def self.load_sz_timer_items
  115.     groups = [$data_states]
  116.     for group in groups
  117.       for obj in group
  118.         next if obj.nil?
  119.         obj.load_sz_state_timer
  120.       end
  121.     end
  122.   end
  123. end
  124.  
  125. #==============================================================
  126. #   * Notes
  127. #==============================================================
  128. class RPG::State < RPG::BaseItem
  129.   attr_accessor :timed
  130.   attr_accessor :triggered_skills
  131.  
  132.   def load_sz_state_timer
  133.     @timed = false
  134.     @triggered_skills = []
  135.    
  136.     self.note.split(/[\r\n]+/).each do |line|
  137.       scan_sz_timer_data(line)
  138.     end
  139.   end
  140.  
  141.   def scan_sz_timer_data(line)
  142.     return unless line =~ /<timed:\s*([\d+\s*,?\s*]+)>/i ? true : false
  143.     @timed = true
  144.     skills = $1.scan(/\s*,?\d+,?\s*/i)
  145.     skills.each do |skill|
  146.       @triggered_skills.push(skill.to_i)
  147.     end
  148.   end
  149.  
  150. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement