TheoAllen

Edited wounded state

May 4th, 2014
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.52 KB | None | 0 0
  1. # =============================================================================
  2. # ♫ ~ Wounded state by TheoAllen ~ ♫
  3. # Version  : 1.2
  4. # Requires : N/A
  5. # Contact  : www.rpgmakerid.com
  6. # =============================================================================
  7. # ♫ UPDATES :
  8. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  9. # 2014.05.04 - Added script calls
  10. # 2013.03.04 - Add notetags for actor and enemy
  11. # 2013.02.22 - Started and finished script
  12. #
  13. # =============================================================================
  14. # ♫ DESCRIPTION :
  15. # This script allow you to automatically add state if the characters or enemy
  16. # in wounded condition. To disable this automatic add state for some enemies or
  17. # characters, just simply put resist state in feature system
  18. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  19. # ♫ INSTRUCTION :
  20. # Put this script below material but above main in script editor. Don't forget
  21. # to save.
  22. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  23. # ♫ HOW TO USE :
  24. # -------------------------------
  25. # ACTOR AND ENEMY NOTETAGS
  26. # -------------------------------
  27. # <wounded cond: x%>
  28. # To specify wounded condition. Default value can be configured below.
  29. #
  30. # <wounded state: x>
  31. # To specify which state will be add if the battler met the wounded condition.
  32. # Default value can be configured below.
  33. #
  34. # ----------------------------------------------------------
  35. # Newly added script call (2014.05.04)
  36. # ----------------------------------------------------------
  37. # To change actor wounded state id, use this script call
  38. # $game_actors[id].wound_state = state_id
  39. #
  40. # To change actor wounded percentage, use this script call
  41. # $game_actors[id].wound_cond = 0.x
  42. #
  43. # To be noted that the percentage value should be around 0.0 - 1.0
  44. # By entering 0.5 it means 50%. In other means when your actor's HP under 50%
  45. # your actor is considered as wounded
  46. #
  47. # =============================================================================
  48. # ♫ TERMS OF USE :
  49. # - Credit me, TheoAllen. If you think it's necessary.
  50. # - You may use and edit this script both commercial and non-commercial or even
  51. #   adult game as long as u don't claim it's yours.
  52. # - I'll be glad if you give me a free copy of your game if you use this script
  53. #   in your commercial project.
  54. # =============================================================================
  55. $imported = {} if $imported.nil?
  56. $imported["Theo-WoundedState"] = true
  57. # =============================================================================
  58. # ♫ CONFIGURATIONS ~ ♫
  59. # =============================================================================
  60. module THEOLIZED
  61.   module WS
  62.    
  63.     WOUNDED_CONDITION = 0.25 # default percentage of wounded condition.
  64.     WOUNDED_STATE_ID = 0     # default wounded state ID
  65.  
  66.   end
  67. end
  68. # =============================================================================
  69. # ♫ Do not edit unless you know what to do ~ ♫
  70. # =============================================================================
  71. # SCRIPT INFOS :
  72. # -------------------------------------
  73. # Rewriten method :
  74. # N/A
  75. # -------------------------------------
  76. # Aliased method :
  77. # - DataManager
  78. #     def self.load_database
  79. # - Game_BattlerBase
  80. #     def refresh
  81. # =============================================================================
  82. # ♫ NOTETAGS ~ ♫
  83. # =============================================================================
  84. module THEOLIZED
  85.   module NOTETAGS_WS
  86.    
  87.     WOUNDED_COND  = /<(?:WOUNDED COND|wounded cond):[ ]*(\d+)([%%])>/i
  88.     WOUNDED_STATE = /<(?:WOUNDED STATE|wounded state):[ ]*(\d+)>/i
  89.    
  90.   end
  91. end
  92. # =============================================================================
  93. # ♫ Module DataManager ~ ♫
  94. # =============================================================================
  95. module DataManager
  96.   #--------------------------------------------------------------------------
  97.   # ♫ Aliased load database
  98.   #--------------------------------------------------------------------------
  99.   class <<self; alias theolized_load_ws_db load_database; end
  100.   def self.load_database
  101.     theolized_load_ws_db
  102.     theolized_load_ws_notetags
  103.   end
  104.   #--------------------------------------------------------------------------
  105.   # ♫ Load wounded state notetags
  106.   #--------------------------------------------------------------------------
  107.   def self.theolized_load_ws_notetags
  108.     groups = [$data_enemies, $data_actors]
  109.     for group in groups
  110.       for obj in group
  111.         next if obj.nil?
  112.         obj.theolized_load_ws_notetags
  113.       end
  114.     end
  115.   end
  116. end
  117. # =============================================================================
  118. # ♫ RPG::Actor ~ ♫
  119. # =============================================================================
  120. class RPG::Actor
  121.   attr_accessor :wound_state
  122.   attr_accessor :wound_cond
  123.   #--------------------------------------------------------------------------
  124.   # ♫ Load wounded state notetags
  125.   #--------------------------------------------------------------------------
  126.   def theolized_load_ws_notetags
  127.     @wound_state = THEOLIZED::WS::WOUNDED_STATE_ID
  128.     @wound_cond  = THEOLIZED::WS::WOUNDED_CONDITION
  129.     self.note.split(/[\r\n]+/).each { |line|
  130.       case line
  131.       when THEOLIZED::NOTETAGS_WS::WOUNDED_COND
  132.         @wound_cond = $1.to_f * 0.01
  133.       when THEOLIZED::NOTETAGS_WS::WOUNDED_STATE
  134.         @wound_state = $1.to_i
  135.       end
  136.     }
  137.   end
  138.    
  139. end
  140. # =============================================================================
  141. # ♫ RPG::Enemy~ ♫
  142. # =============================================================================
  143. class RPG::Enemy
  144.   attr_accessor :wound_state
  145.   attr_accessor :wound_cond
  146.   #--------------------------------------------------------------------------
  147.   # ♫ Load wounded state notetags
  148.   #--------------------------------------------------------------------------
  149.   def theolized_load_ws_notetags
  150.     @wound_state = THEOLIZED::WS::WOUNDED_STATE_ID
  151.     @wound_cond  = THEOLIZED::WS::WOUNDED_CONDITION
  152.     self.note.split(/[\r\n]+/).each { |line|
  153.       case line
  154.       when THEOLIZED::NOTETAGS_WS::WOUNDED_COND
  155.         @wound_cond = $1.to_f * 0.01
  156.       when THEOLIZED::NOTETAGS_WS::WOUNDED_STATE
  157.         @wound_state = $1.to_i
  158.       end
  159.     }
  160.   end
  161.    
  162. end
  163. # =============================================================================
  164. # ♫ Game_BattlerBase ♫
  165. # =============================================================================
  166. class Game_BattlerBase
  167.   #--------------------------------------------------------------------------
  168.   # ♫ Aliased refresh
  169.   #--------------------------------------------------------------------------
  170.   alias theo_wound_refresh refresh
  171.   def refresh
  172.     theo_wound_refresh
  173.     apply_wounded_state
  174.   end
  175.   #--------------------------------------------------------------------------
  176.   # ♫ Check wounded
  177.   #--------------------------------------------------------------------------
  178.   def wounded?
  179.     return false
  180.   end
  181.   #--------------------------------------------------------------------------
  182.   # ♫ Get wounded state id
  183.   #--------------------------------------------------------------------------  
  184.   def wounded_state_id
  185.     return 0
  186.   end
  187.   #--------------------------------------------------------------------------
  188.   # ♫ Apply wounded state
  189.   #--------------------------------------------------------------------------
  190.   def apply_wounded_state
  191.     return if wounded_state_id <= 0
  192.     wounded? ? add_state(wounded_state_id) : remove_state(wounded_state_id)
  193.   end
  194. end
  195. # =============================================================================
  196. # ♫ Game_Actor ♫
  197. # =============================================================================
  198. class Game_Actor < Game_Battler
  199.   attr_accessor :wound_state
  200.   attr_accessor :wound_cond
  201.  
  202.   alias theo_wound_state_init initialize
  203.   def initialize(actor_id)
  204.     @wound_state = $data_actors[actor_id].wound_state
  205.     @wound_cond = $data_actors[actor_id].wound_cond
  206.     theo_wound_state_init(actor_id)
  207.   end
  208.  
  209.   #--------------------------------------------------------------------------
  210.   # ♫ Check wounded
  211.   #--------------------------------------------------------------------------
  212.   def wounded?
  213.     return hp_rate <= wound_cond
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # ♫ Get wounded state id
  217.   #--------------------------------------------------------------------------
  218.   def wounded_state_id
  219.     return wound_state
  220.   end
  221.  
  222. end
  223. # =============================================================================
  224. # ♫ Game_Enemy ♫
  225. # =============================================================================
  226. class Game_Enemy < Game_Battler
  227.   #--------------------------------------------------------------------------
  228.   # ♫ Check wounded
  229.   #--------------------------------------------------------------------------
  230.   def wounded?
  231.     return hp_rate <= $data_enemies[@enemy_id].wound_cond
  232.   end
  233.   #--------------------------------------------------------------------------
  234.   # ♫ Get wounded state id
  235.   #--------------------------------------------------------------------------
  236.   def wounded_state_id
  237.     return $data_enemies[@enemy_id].wound_state
  238.   end
  239.  
  240. end
  241. # =============================================================================
  242. # ♫ End of Script ♫
  243. # =============================================================================
Advertisement
Add Comment
Please, Sign In to add comment