Advertisement
TroyZ

TroyZ - States Damage Count Removal

Jul 9th, 2013
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.64 KB | None | 0 0
  1. # ==============================================================================
  2. # ▼▼▼▼▼▼              TroyZ - States Damage Count Removal               ▼▼▼▼▼▼
  3. # ==============================================================================
  4. # Script by : Agung Prasetyo(TroyZ)
  5. # Contact me by : - Email agung.endisnear.xyz@gmail.com
  6. #                 - Forum RPGMakerID, username TroyZ
  7. #                 - Handphone 085756289121
  8. # Engine : VXAce
  9. # Level : Easy
  10. # Version : 1.0
  11. # ------------------------------------------------------------------------------
  12. # Change Logs :
  13. # 18 June 2013 : Version 1.0 released
  14. # ------------------------------------------------------------------------------
  15. # How this work :
  16. # This script will give you an ability to create states that removed when the
  17. # battler has suffered certain amount of damage at certain probability.
  18. # ------------------------------------------------------------------------------
  19. # How to use :
  20. # Place it between material and main. Use this notetags inside states :
  21. #
  22. # <remove by damage: x>
  23. # <remove by damage chance: y>
  24. #
  25. # The states that have this notetags will be removed when the affected battler
  26. # suffers the x total damage at y% probability. You don't have to write the percent
  27. # sign at y, just put the number actually. For example, a state have this notetags :
  28. #
  29. # <remove by damage: 800>
  30. # <remove by damage chance: 50>
  31. #
  32. # The state will be removed when the affected battler suffers 800 damage from enemy.
  33. # When the battler get 800 damage from enemy, the state will be removed at 50%
  34. # chance.
  35. # ------------------------------------------------------------------------------
  36. # Compatibility issues :
  37. # None yet. If you found some, let me know, and bug fixes will come out soon.
  38. # ------------------------------------------------------------------------------
  39. # Who to credit :
  40. # - Allah swt. : For the chance of living that he has given to me.
  41. # - Nabi Muhammad saw. : As a leader and messenger and prophet of Muslim.
  42. #                        I'm proud to be your follower. :)
  43. # - Agung Prasetyo(TroyZ) : Thats me, of course, the ones that made this script. :P
  44. # ------------------------------------------------------------------------------
  45. # License :
  46. # - Free Game : Just credit those names above.
  47. # - Commercial Game : Same as free game's license.
  48. # ------------------------------------------------------------------------------
  49. $imported = {} if $imported.nil?
  50. $imported[:TroyZ_StatesDamageCountRemoval] = true
  51. # ------------------------------------------------------------------------------
  52. # There is nothing to config beyond this line
  53. # ------------------------------------------------------------------------------
  54. module AGUNG
  55.   module DAMAGE_COUNT
  56.     DAMAGE_COUNT_DEFAULT = 0
  57.     DAMAGE_COUNT_REMOVE_CHANCE_DEFAULT = 0
  58.   end
  59.  
  60.   module NOTETAGS_DAMAGE_COUNT
  61.     DAMAGE_COUNT = /<(?:REMOVE BY DAMAGE|remove by damage):[ ]*(\d+)>/i
  62.     DAMAGE_COUNT_REMOVE_CHANCE = /<(?:REMOVE BY DAMAGE CHANCE|remove by damage chance):[ ]*(\d+)>/i
  63.   end
  64. end
  65.  
  66. module DataManager
  67.   class << self
  68.     alias agung_load_states_damage_count_removal_dbase_x    load_database
  69.   end
  70.  
  71.   def self.load_database
  72.     agung_load_states_damage_count_removal_dbase_x
  73.     agung_load_notetags_damage_count_removal_x
  74.   end
  75.  
  76.   def self.agung_load_notetags_damage_count_removal_x
  77.     [$data_states].each do |states|
  78.       states.each do |obj|
  79.         next unless obj
  80.         obj.agung_load_notetags_damage_count_removal_x
  81.       end
  82.     end
  83.   end
  84. end
  85.  
  86. class RPG::State < RPG::BaseItem
  87.  
  88.   include AGUNG::DAMAGE_COUNT
  89.   include AGUNG::NOTETAGS_DAMAGE_COUNT
  90.  
  91.   attr_accessor :damage_count
  92.   attr_accessor :chance_by_damage_count
  93.  
  94.   def agung_load_notetags_damage_count_removal_x
  95.     @damage_count = DAMAGE_COUNT_DEFAULT
  96.     @chance_by_damage_count = DAMAGE_COUNT_REMOVE_CHANCE_DEFAULT
  97.     self.note.split(/[\r\n]+/).each { |baris|
  98.       case baris
  99.       when DAMAGE_COUNT
  100.         @damage_count = $1.to_i
  101.       when DAMAGE_COUNT_REMOVE_CHANCE
  102.         @chance_by_damage_count = $1.to_i
  103.       end
  104.     }
  105.   end  
  106. end
  107.  
  108. class Game_BattlerBase
  109.   alias agung_clear_states_damage_count_x    clear_states
  110.   def clear_states
  111.     agung_clear_states_damage_count_x
  112.     @state_damage_count = {}
  113.   end
  114.  
  115.   alias agung_erase_state_damage_count_x   erase_state
  116.   def erase_state(state_id)
  117.     agung_erase_state_damage_count_x(state_id)
  118.     @state_damage_count.delete(state_id)
  119.   end
  120. end
  121.  
  122. class Game_Battler < Game_BattlerBase
  123.   def reset_state_damage_counts(state_id)
  124.     state = $data_states[state_id]
  125.     @state_damage_count[state_id] = state.damage_count
  126.   end
  127.  
  128.   def add_state(state_id)
  129.     if state_addable?(state_id)
  130.       add_new_state(state_id) unless state?(state_id)
  131.       reset_state_counts(state_id)
  132.       reset_state_damage_counts(state_id)
  133.       @result.added_states.push(state_id).uniq!
  134.     end
  135.   end
  136.  
  137.   def update_states_damage_count
  138.     states.each do |state|
  139.       @state_damage_count[state.id] -= @result.hp_damage if @state_damage_count[state.id] > 0
  140.     end
  141.   end
  142.  
  143.   def remove_states_by_damage_count
  144.     states.each do |state|
  145.       if @state_damage_count[state.id] <= 0 && rand(100) < state.chance_by_damage_count
  146.         remove_state(state.id)
  147.       end
  148.     end
  149.   end
  150.  
  151.   alias agung_on_damage_count_x   on_damage
  152.   def on_damage(value)    
  153.     agung_on_damage_count_x(value)
  154.     update_states_damage_count
  155.     remove_states_by_damage_count
  156.   end
  157. end
  158. # ------------------------------------------------------------------------------
  159. # END OF SCRIPT
  160. # ------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement