Advertisement
mrbubble

Advanced Disable/Silence States

Oct 29th, 2011
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.06 KB | None | 0 0
  1. #========================================================================
  2. # ++ Advanced Disable/Silence States v1.0 (10/29/11)
  3. #========================================================================
  4. #   RMVX script by:
  5. #       Mr. Bubble (http://mrbubblewand.wordpress.com/)
  6. #  
  7. #   Special thanks to:
  8. #       Mithran (for Regexp examples and code design inspiration)
  9. #       KGC (for Regexp examples)
  10. #
  11. #   Please do not repost elsewhere without direct permission.
  12. #========================================================================
  13. #     This is a rather simple script which expands upon silencing/disabling
  14. #   skills from being used when inflicted by a state. In default RMVX, when
  15. #   a state's "Restriction" setting is set to "Cannot Use Magic", it will
  16. #   only silence/disable skills that have a spi_f (spirit factor) greater
  17. #   than 0. That just isn't enough.
  18. #     This script provides some more options for disable/silence states
  19. #   and can hopefully help with providing more interesting battle mechanics.
  20. #------------------------------------------------------------------------
  21. #   ++ Changelog ++
  22. #     v1.0 - Initital release
  23. #------------------------------------------------------------------------
  24. #   ++ How To Use ++
  25. #
  26. #     This script uses state notetags exclusively. There is (currently) no
  27. #   customization module in this script. Notetags are placed in the
  28. #   "Note" box at the lower-right corner of the State tab in your
  29. #   project's database.
  30. #------------------------------------------------------------------------
  31. #   ++ State Notetag Info ++
  32. #  
  33. #     All references to the keyword "disable" is interchangable with the
  34. #   keyword "silence". For example:
  35. #  
  36. #       <disable all skills>
  37. #           or
  38. #       <silence all skills>
  39. #  
  40. #     Using either of these tags will accomplish the same thing. For
  41. #   simplicity's sake, I will simply use the keyword "disable" in the rest
  42. #   this document.
  43. #  
  44. #     Rememeber that all notetags in this script are for State noteboxes only!
  45. #========================================================================
  46. #   ++ State Notetags ++
  47. #========================================================================
  48. #
  49. #       <disable all skills>
  50. #      
  51. #   -Disables all skills when inflicted by the state.
  52. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  53. #
  54. #       <disable physical skills>
  55. #      
  56. #   -Disables all skills that have the "Physical Attack" option checkmarked.
  57. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  58. #
  59. #       <disable non-physical skills>
  60. #      
  61. #   -Disables all skills that *DO NOT* have the "Physical Attack" option
  62. #   checkmarked.
  63. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  64. #      
  65. #       <disable elements: elem_ids>
  66. #      
  67. #   -Disables skills that have a specific element. elem_ids can be a list
  68. #   of element ID numbers separated by commas. Element ID numbers can be
  69. #   found under the "System" tab in your database.
  70. #  
  71. #     Example Notetag:
  72. #       <disable elements: 9,10,11>
  73. #      
  74. #     This example tag will disable all skills with the element ID number
  75. #     of 9, 10, or 11.
  76. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  77. #    
  78. #       <disable skills: skill_ids>
  79. #      
  80. #   -Disables specific skill IDs from being used. skill_ids can be a list
  81. #   of skill ID numbers separated by commas. Skill ID numbers can be
  82. #   found under the "Skills" tab in your database.
  83. #  
  84. #     Example Notetag:
  85. #       <disable skills: 33,34>
  86. #      
  87. #     This example tag will disable skill IDs 33 and 34 from being used
  88. #     if the actor has them learned.
  89. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  90. #
  91. #       <disable "factor" skills>
  92. #
  93. #   -Disables skills that have a "factor" of more than zero in a
  94. #   certain stat. "factor" is the abbreviated name of the stat (do not
  95. #   include quotes, see examples).
  96. #
  97. #   Available factors are:
  98. #                         atk
  99. #                         spi
  100. #
  101. #   More can be added by request.
  102. #
  103. #      Example:
  104. #        <disable atk skills>
  105. #
  106. #      This example tag will disable skills that have an atk_f of
  107. #      more than 0 (zero).
  108. #
  109. #      Example:
  110. #        <disable spi skills>
  111. #
  112. #      This example tag will disable skills that have an spi_f of
  113. #      more than 0 (zero). This replicates VX's default silence option.
  114. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  115. #   Requires KGC_Overdrive installed in your project.
  116. #
  117. #       <disable overdrive skills>
  118. #         or
  119. #       <disable od skills>
  120. #      
  121. #   -Disables skills tagged as Overdrive skills, preventing their use.
  122. #========================================================================
  123. #   ++ Scripter Info ++
  124. #========================================================================
  125. #   This script aliases the following default methods:
  126. #
  127. #   Game_Battler#skill_can_use?(skill)
  128. #------------------------------------------------------------------------
  129.  
  130. $imported = {} if $imported == nil
  131. $imported["BubsAdvancedDisableStates"] = true
  132.  
  133. class Game_Battler
  134.   #--------------------------------------------------------------------------
  135.   # ++ Determine Usable Skills : alias
  136.   #     skill : skill
  137.   #--------------------------------------------------------------------------
  138.   alias skill_can_use_bubs_advanced_skill_disable skill_can_use? unless $@
  139.   def skill_can_use?(skill)
  140.     return false unless skill_can_use_bubs_advanced_skill_disable(skill) # alias
  141.    
  142.     return false if disabled?(skill) # advanced disable states check
  143.     return true
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # ++ Determine Disabled State Flags
  147.   #--------------------------------------------------------------------------
  148.   # returns true if the skill is unusable due to a state
  149.   def disabled?(skill)
  150.     disabled = false
  151.     for state in states
  152.      
  153.       # all skills disabled check
  154.       if state.all_skills_disabled?
  155.         disabled = true
  156.      
  157.       # physical skills check
  158.       elsif skill.physical_attack && state.physical_skills_disabled?
  159.         disabled = true
  160.      
  161.       # non-physical skills check
  162.       elsif !skill.physical_attack && state.non_physical_skills_disabled?
  163.         disabled = true
  164.      
  165.       # element_set check
  166.       elsif state.skill_element_disabled?(skill)
  167.         disabled = true
  168.      
  169.       # skill id check
  170.       elsif state.skill_id_disabled?(skill)
  171.         disabled = true
  172.        
  173.       elsif state.skill_factor_disabled?(skill)
  174.         disabled = true
  175.        
  176.       # overdrive check
  177.       elsif $imported["OverDrive"]
  178.         if skill.overdrive? && state.overdrive_skills_disabled?
  179.           disabled = true
  180.         end
  181.       end
  182.       break if disabled
  183.     end # end for state in states
  184.     return disabled
  185.   end # end disabled?(skill)
  186. end
  187.  
  188.  
  189. #--------------------------------------------------------------------------
  190. # ++ Regexp
  191. #--------------------------------------------------------------------------
  192. module Bubs
  193. module AdvancedDisableStatesRegexp
  194.   # <disable physical skills>
  195.   DISABLE_PHYSICAL =
  196.     /<(?:SILENCE|disable)[_\s]?(?:phys|physical)[_\s]?(?:skill[s]?)?\s?>/i
  197.  
  198.   # <disable non-physical skills>
  199.   DISABLE_NON_PHYSICAL =
  200.     /<(?:SILENCE|disable)[_\s]?non[-_\s]?(?:phys|physical)?[_\s]?(?:skill[s]?)?\s?>/i
  201.  
  202.   # <disable all skills>
  203.   DISABLE_ALL =
  204.     /<(?:SILENCE|disable)[_\s]?all[_\s]?(?:skill[s]?)?\s?>/i
  205.  
  206.   # <disable skill elem: ids>
  207.   DISABLE_ELEMENTS =
  208.     /<(?:SILENCE|disable)[_\s]?(?:skill[s]?)?[_\s]?(?:ele[m]?|element[s]?)\s?[:]?\s?(\d+(?:\s*,\s*\d+)*)\s?>/
  209.  
  210.   # <disable skill ids: ids>
  211.   DISABLE_SKILLS =
  212.     /<(?:SILENCE|disable)[_\s]?skill[s]?[_\s]?(?:id[s])?\s?[:]?\s?(\d+(?:\s*,\s*\d+)*)\s?>/
  213.  
  214.   # <disable overdrive skills>
  215.   DISABLE_OVERDRIVE =
  216.     /<(?:SILENCE|disable)[_\s]?(?:OD|over[_\s]?drive)[_\s]?(?:skill[s]?)?\s?>/
  217.    
  218.   # <disable factor skills>
  219.   STAT_FACTORS =
  220.     /(atk|spi|def|agi|dex|res)/
  221.   DISABLE_STAT_FACTORS =
  222.     /<(?:SILENCE|disable)[_\s]?#{STAT_FACTORS}[_\s]?skill[s]?\s?>/
  223.    
  224. end # module Bubs
  225. end # module AdvancedDisableRegexp
  226.  
  227. #--------------------------------------------------------------------------
  228. # ++ RPG::State
  229. #--------------------------------------------------------------------------
  230. class RPG::State
  231.   include Bubs::AdvancedDisableStatesRegexp
  232.   #--------------------------------------------------------------------------
  233.   # ++ Create Advanced Disable Cache
  234.   #--------------------------------------------------------------------------
  235.   def create_advanced_disable_cache
  236.     # Skill tag cache
  237.     @disable_all_skills = false
  238.     @disable_physical_skills = false
  239.     @disable_non_physical_skills = false
  240.     @disable_skill_elements = []
  241.     @disable_skill_ids = []
  242.     @disable_stat_factors = []
  243.     @disable_overdrive_skills = false
  244.        
  245.     self.note.split(/[\r\n]+/).each { |line|
  246.       case line
  247.      
  248.       when DISABLE_PHYSICAL
  249.         @disable_physical_skills = true
  250.        
  251.       when DISABLE_NON_PHYSICAL
  252.         @disable_non_physical_skills = true
  253.        
  254.       when DISABLE_ALL
  255.         @disable_all_skills = true
  256.        
  257.       when DISABLE_ELEMENTS
  258.         element_ids = $1.scan(/\d+/)
  259.         element_ids.each { |id|
  260.           @disable_skill_elements.push(id.to_i)
  261.         }
  262.        
  263.       when DISABLE_SKILLS
  264.         skill_ids = $1.scan(/\d+/)
  265.         skill_ids.each { |id|
  266.           @disable_skill_ids.push(id.to_i)
  267.         }
  268.        
  269.       when DISABLE_STAT_FACTORS
  270.         @disable_stat_factors.push($1)
  271.        
  272.       when DISABLE_OVERDRIVE
  273.         @disable_overdrive_skills = true
  274.        
  275.       end
  276.  
  277.     } # <-
  278.     @advanced_disable_cache = true
  279.   end
  280.  
  281.   #--------------------------------------------------------------------------
  282.   # ++ Determine Physical Skills Disable
  283.   #--------------------------------------------------------------------------
  284.   def physical_skills_disabled?
  285.     create_advanced_disable_cache if @advanced_disable_cache.nil?
  286.     return @disable_physical_skills
  287.   end
  288.   alias physical_skills_disable? physical_skills_disabled? unless $@
  289.  
  290.   #--------------------------------------------------------------------------
  291.   # ++ Determine Non-Physical Skills Disable
  292.   #--------------------------------------------------------------------------
  293.   def non_physical_skills_disabled?
  294.     create_advanced_disable_cache if @advanced_disable_cache.nil?
  295.     return @disable_non_physical_skills
  296.   end
  297.   alias non_physical_skills_disable? non_physical_skills_disabled? unless $@
  298.  
  299.   #--------------------------------------------------------------------------
  300.   # ++ Determine All Skills Disable
  301.   #--------------------------------------------------------------------------
  302.   def all_skills_disabled?
  303.     create_advanced_disable_cache if @advanced_disable_cache.nil?
  304.     return @disable_all_skills
  305.   end
  306.   alias all_skills_disable? all_skills_disabled? unless $@
  307.  
  308.   #--------------------------------------------------------------------------
  309.   # ++ Determine Skill Elements Disable
  310.   #--------------------------------------------------------------------------
  311.   def skill_element_disabled?(skill)
  312.     create_advanced_disable_cache if @advanced_disable_cache.nil?
  313.     skill.element_set.each { |elem_id|
  314.       return true if @disable_skill_elements.include?(elem_id)
  315.     }
  316.     return false
  317.   end
  318.   alias skill_element_disable? skill_element_disabled? unless $@
  319.  
  320.   #--------------------------------------------------------------------------
  321.   # ++ Determine Skill IDs Disable
  322.   #--------------------------------------------------------------------------
  323.   def skill_id_disabled?(skill)
  324.     create_advanced_disable_cache if @advanced_disable_cache.nil?
  325.     return true if @disable_skill_ids.include?(skill.id)
  326.     return false
  327.   end
  328.   alias skill_id_disable? skill_id_disabled? unless $@
  329.  
  330.   #--------------------------------------------------------------------------
  331.   # ++ Determine Skill Factor Disable
  332.   #--------------------------------------------------------------------------
  333.   def skill_factor_disabled?(skill)
  334.     create_advanced_disable_cache if @advanced_disable_cache.nil?
  335.     return false if @disable_stat_factors.empty?
  336.     for factor in @disable_stat_factors
  337.       if factor == "atk"
  338.         return true if skill.atk_f > 0
  339.       elsif factor == "spi"
  340.         return true if skill.spi_f > 0
  341.       end
  342.     end
  343.     return false
  344.   end
  345.   alias skill_factor_disable? skill_factor_disabled? unless $@
  346.  
  347.   #--------------------------------------------------------------------------
  348.   # ++ Determine Overdrive Disable : Requires KGC_Overdrive
  349.   #--------------------------------------------------------------------------
  350.   def overdrive_skills_disabled?(skill)
  351.     create_advanced_disable_cache if @advanced_disable_cache.nil?
  352.     return @disable_overdrive_skills
  353.   end
  354.   alias overdrive_skills_disable? overdrive_skills_disabled? unless $@
  355.  
  356. end # RPG::State
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement