Double_X

DoubleX RMVXA State Triggers v1.03b

May 11th, 2015
376
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================|
  2. #  ** Script Info                                                              |
  3. #------------------------------------------------------------------------------|
  4. #  * Script Name                                                               |
  5. #    DoubleX RMVXA State Triggers                                              |
  6. #------------------------------------------------------------------------------|
  7. #  * Functions                                                                 |
  8. #    Sets some states to trigger additional effects when conditions are met    |
  9. #------------------------------------------------------------------------------|
  10. #  * Terms Of Use                                                              |
  11. #    You shall keep this script's Script Info part's contents intact           |
  12. #    You shalln't claim that this script is written by anyone other than       |
  13. #    DoubleX or his aliases                                                    |
  14. #    None of the above applies to DoubleX or his aliases                       |
  15. #------------------------------------------------------------------------------|
  16. #  * Prerequisites                                                             |
  17. #    Abilities:                                                                |
  18. #    1. Decent RGSS3 scripting proficiency to fully utilize this script        |
  19. #------------------------------------------------------------------------------|
  20. #  * Instructions                                                              |
  21. #    1. Open the script editor and put this script into an open slot between   |
  22. #       Materials and Main, save to take effect.                               |
  23. #------------------------------------------------------------------------------|
  24. #  * Links                                                                     |
  25. #    Script Usage 101:                                                         |
  26. #    1. forums.rpgmakerweb.com/index.php?/topic/32752-rmvxa-script-usage-101/  |
  27. #    2. rpgmakervxace.net/topic/27475-rmvxa-script-usage-101/                  |
  28. #    This script:                                                              |
  29. #    1. http://www.rpgmakervxace.net/topic/31374-doublex-rmvxa-state-triggers/ |
  30. #------------------------------------------------------------------------------|
  31. #  * Authors                                                                   |
  32. #    DoubleX                                                                   |
  33. #------------------------------------------------------------------------------|
  34. #  * Changelog                                                                 |
  35. #    v1.03b(GMT 1400 10-5-2016):                                               |
  36. #    1. timing while won't replace but will combine the state's existing       |
  37. #       features with all stax meeting the corresponding stcx                  |
  38. #    v1.03a(GMT 1500 9-5-2016):                                                |
  39. #    1. adding the timing while to <timing state trigger: stcx, stax>          |
  40. #    v1.02a(GMT 1300 26-2-2016):                                               |
  41. #    1. stcx and stax take the state calling them as an argument as well       |
  42. #    v1.01b(GMT 0300 7-11-2015):                                               |
  43. #    1. Notetag values are now symbols of methods in the configuration regions |
  44. #    2. This script doesn't need DoubleX RMVXA State Triggers Compatibility to |
  45. #       be compatible with all its addressed scripts                           |
  46. #    3. Further improved this script's compatibility, efficiency and simplicity|
  47. #    v1.01a(GMT 1100 8-5-2015):                                                |
  48. #    1. Lets users use state triggers with timings set by them                 |
  49. #    v1.00g(GMT 1600 4-5-2015):                                                |
  50. #    1. Improved this script's efficiency                                      |
  51. #    v1.00f(GMT 0300 25-4-2015):                                               |
  52. #    1. Improved this script's effectiveness                                   |
  53. #    v1.00e(GMT 1400 21-4-2015):                                               |
  54. #    1. Further improved this script's robustness                              |
  55. #    v1.00d(GMT 1500 14-4-2015):                                               |
  56. #    1. Improved this script's robustness                                      |
  57. #    v1.00c(GMT 0200 12-4-2015):                                               |
  58. #    1. Fixed triggering remove actions upon adding state resists bug          |
  59. #    2. Fixed not triggering remove actions upon death, escape and recovery bug|
  60. #    v1.00b(GMT 1400 11-4-2015):                                               |
  61. #    1. Fixed not supporting multiple notetags on the same state bug           |
  62. #    v1.00a(GMT 1100 11-4-2015):                                               |
  63. #    1. 1st version of this script finished                                    |
  64. #==============================================================================|
  65.  
  66. #==============================================================================|
  67. #  ** Notetag Info                                                             |
  68. #------------------------------------------------------------------------------|
  69. #  * State Notetags:                                                           |
  70. #    1. <timing state trigger: stcx, stax>                                     |
  71. #       - Sets a state to trigger stax when timing and stcx are met            |
  72. #       - timing can be add, turn, remove or custom timings set by you         |
  73. #       - add means the state's just added                                     |
  74. #       - turn means the state's remaining turn's just reduced by 1            |
  75. #       - remove means the state's just removed                                |
  76. #       - while means the stax effects are active as long as the state's active|
  77. #       - timing must only consist of alphanumeric characters                  |
  78. #       - stcx can be set in State Trigger Condition Notetag Values            |
  79. #       - stax can be set in State Trigger Action Notetag Values               |
  80. #==============================================================================|
  81.  
  82. #==============================================================================|
  83. #  ** Script Call Info                                                         |
  84. #------------------------------------------------------------------------------|
  85. #  * Battler manipulations                                                     |
  86. #    1. exec_state_triggers(state_id, timing)                                  |
  87. #       - Executes all state triggers with timing timing of state with id      |
  88. #         state_id                                                             |
  89. #    2. state_trigger_features(state, timing)                                  |
  90. #       - Returns an array of features returned by all stax meeting stcx with  |
  91. #         timing timing of state                                               |
  92. #       - This script call's not supposed to work with timing add, turn nor    |
  93. #         remove but supposed to work with timing while                        |
  94. #==============================================================================|
  95.  
  96. ($doublex_rmvxa ||= {})[:State_Triggers] = "v1.03b"
  97.  
  98. #==============================================================================|
  99. #  ** Script Configurations                                                    |
  100. #     You only need to edit this part as it's about what this script does      |
  101. #------------------------------------------------------------------------------|
  102.  
  103. module DoubleX_RMVXA
  104.  
  105.   module State_Triggers
  106.  
  107.     #--------------------------------------------------------------------------|
  108.     #  State Trigger Condition Notetag Values                                  |
  109.     #  - Setups stcx used by this script's notetags                            |
  110.     #--------------------------------------------------------------------------|
  111.     # stcx are read at:
  112.     # 1. RPG::State
  113.     #    - (@state_triggers[$1.downcase.to_sym] ||= []).push(
  114.     #      [$2.downcase, $3.downcase]) in load_state_triggers_notes
  115.     # stcx are used at:
  116.     # 1. Game_BattlerBase
  117.     #    - st.send(trigger[0], self, state) in state_trigger_features
  118.     # 2. Game_Battler
  119.     #    - st.send(trigger[1], self) if st.send(trigger[0], self) in
  120.     #      exec_state_triggers
  121.     # stcx are strings names of methods under DoubleX_RMVXA::State_Triggers
  122.     # stcx names can only use alphanumeric characters and can't use uppercase
  123.     # letters
  124.     # battler is the battler calling the stcx
  125.     # state is the state using the stcx
  126.     # The below stcx are examples added to help you set your stcx
  127.     # You can freely use, rewrite and/or delete these examples
  128.  
  129.     # Sets the state trigger condition as always true
  130.     def self.stc1(battler, state)
  131.       true
  132.     end
  133.  
  134.     # Sets the state trigger condition as always false
  135.     def self.stc2(battler, state)
  136.       false
  137.     end
  138.  
  139.     # Sets the state trigger condition as needing switch with id x to be on
  140.     def self.stc3(battler, state)
  141.       $game_switches[x]
  142.     end
  143.  
  144.     # Sets the state trigger condition as needing the state using this stcx to
  145.     # have its number of remaining turns greater than x
  146.     def self.stc4(battler, state)
  147.       battler.instance_exec { @state_turns[state_id] > x }
  148.     end
  149.  
  150.     # Adds new stcx here
  151.    
  152.  
  153.     #--------------------------------------------------------------------------|
  154.     #  State Trigger Action Notetag Values                                     |
  155.     #  - Setups stax used by this script's notetags                            |
  156.     #--------------------------------------------------------------------------|
  157.     # stax are read at:
  158.     # 1. RPG::State
  159.     #    - (@state_triggers[$1.downcase.to_sym] ||= []).push(
  160.     #      [$2.downcase, $3.downcase]) in load_state_triggers_notes
  161.     # stax are used at:
  162.     # 1. Game_BattlerBase
  163.     #    - }.collect! { |trigger| st.send(trigger[1], self, state) }.flatten! in
  164.     #      state_trigger_features
  165.     # 2. Game_Battler
  166.     #    - st.send(trigger[1], self) if st.send(trigger[0], self) in
  167.     #      exec_state_triggers
  168.     # stax are strings of names of methods under DoubleX_RMVXA::State_Triggers
  169.     # stax names can only use alphanumeric characters and can't use uppercase
  170.     # letters
  171.     # battler is the battler calling the stax
  172.     # state is the state using the stax
  173.     # If the timing using the stax is while, the stax must return an array of
  174.     # RPG::BaseItem::Feature
  175.     # You can refer to Game_BattlerBase and RPG::BaseItem::Feature for more info
  176.     # The below stax are examples added to help you set your stax
  177.     # You can freely use, rewrite and/or delete these examples
  178.  
  179.     # Sets the state trigger action as what Special Effect Escape does
  180.     # This stax's not supposed to work with the timing while as it doesn't
  181.     # return an array of RPG::BaseItem::Feature
  182.     def self.sta1(battler, state)
  183.       battler.hide
  184.     end
  185.  
  186.     # Sets the state trigger action as calling common event with id
  187.     # common_event_id
  188.     # This stax's not supposed to work with the timing while as it doesn't
  189.     # return an array of RPG::BaseItem::Feature
  190.     def self.sta2(battler, state)
  191.       $game_temp.reserve_common_event(common_event_id)
  192.     end
  193.  
  194.     # Sets the state trigger action as executing damage equal to the value of
  195.     # game variable with id x to self with type equal to that of skill with id
  196.     # equal to y
  197.     # This stax's not supposed to work with the timing while as it doesn't
  198.     # return an array of RPG::BaseItem::Feature
  199.     def self.sta3(battler, state)
  200.       battler.result.clear
  201.       battler.result.make_damage($game_variables[x], $data_skills[y])
  202.       battler.execute_damage(battler)
  203.     end
  204.  
  205.     # Sets the state trigger action as multiplying the battler's atk by x * 100%
  206.     # This stax's supposed to work with the timing while as it returns an array
  207.     # of RPG::BaseItem::Feature
  208.     def self.sta4(battler, state)
  209.       [RPG::BaseItem::Feature.new(21, 2, x)]
  210.     end
  211.  
  212.     # Adds new stax here
  213.    
  214.  
  215.   end # State_Triggers
  216.  
  217. end # DoubleX_RMVXA
  218.  
  219. #==============================================================================|
  220. #  ** Script Implementations                                                   |
  221. #     You need not edit this part as it's about how this script works          |
  222. #------------------------------------------------------------------------------|
  223. #  * Script Support Info:                                                      |
  224. #    1. Prerequisites                                                          |
  225. #       - Some RGSS3 scripting proficiency to fully comprehend this script     |
  226. #    2. Method documentation                                                   |
  227. #       - The 1st part describes why this method's rewritten/aliased for       |
  228. #         rewritten/aliased methods or what the method does for new methods    |
  229. #       - The 2nd part describes what the arguments of the method are          |
  230. #       - The 3rd part informs which version rewritten, aliased or created this|
  231. #         method                                                               |
  232. #       - The 4th part informs whether the method's rewritten or new           |
  233. #       - The 5th part informs whether the method's a real or potential hotspot|
  234. #       - The 6th part describes how this method works for new methods only,   |
  235. #         and describes the parts added, removed or rewritten for rewritten or |
  236. #         aliased methods only                                                 |
  237. #       Example:                                                               |
  238. # #--------------------------------------------------------------------------| |
  239. # #  Why rewrite/alias/What this method does                                 | |
  240. # #--------------------------------------------------------------------------| |
  241. # # *argv: What these variables are                                            |
  242. # # &argb: What this block is                                                  |
  243. # def def_name(*argv, &argb) # Version X+; Rewrite/New; Hotspot                |
  244. #   # Added/Removed/Rewritten to do something/How this method works            |
  245. #   def_name_code                                                              |
  246. #   #                                                                          |
  247. # end # def_name                                                               |
  248. #------------------------------------------------------------------------------|
  249.  
  250. class << DataManager # Edit
  251.  
  252.   alias load_database_state_triggers load_database
  253.   def load_database(*argv, &argb)
  254.     load_database_state_triggers(*argv, &argb)
  255.     $data_states.each { |obj| obj.load_state_triggers_notes if obj } # Added
  256.   end # load_database
  257.  
  258. end # DataManager
  259.  
  260. class RPG::State < RPG::BaseItem # Edit
  261.  
  262.   #----------------------------------------------------------------------------|
  263.   #  New public instance variable                                              |
  264.   #----------------------------------------------------------------------------|
  265.   attr_accessor :state_triggers # The storage of all state trigger notetags
  266.  
  267.   def load_state_triggers_notes
  268.     # Stores all timing, stcx and stax triples from matching lines sequentially
  269.     @state_triggers = {}
  270.     @note.split(/[\r\n]+/).each { |line|
  271.       next unless line =~ /< *(\w+) +state +trigger *: *(\w+) *, *(\w+) *>/i
  272.       (@state_triggers[$1.downcase.to_sym] ||= []).push(
  273.       [$2.downcase.to_sym, $3.downcase.to_sym])
  274.     }
  275.     #
  276.   end # load_state_triggers_notes
  277.  
  278. end # RPG::State
  279.  
  280. class Game_BattlerBase # Edit
  281.  
  282.   alias all_features_state_triggers all_features
  283.   def all_features(*argv, &argb) # v1.03a+
  284.     # Rewritten to use features returned by stax for states meeting any stcx
  285.     states.inject([]) {|r, obj|
  286.       r + state_trigger_features(obj, :while)
  287.     } + all_features_state_triggers(*argv, &argb)
  288.     #
  289.   end # all_features
  290.  
  291.   alias erase_state_triggers erase_state
  292.   def erase_state(state_id, &argb)
  293.     # Added to store the state existence flag right before it's erased
  294.     trigger = @states.include?(state_id)
  295.     #
  296.     erase_state_triggers(state_id, &argb)
  297.     # Added to trigger the remove actions when the remove conditions are met
  298.     exec_state_triggers(state_id, :remove) if trigger
  299.     #
  300.   end # erase_state
  301.  
  302.   # state: The state having its features returned by stax collected
  303.   # timing: The timing of the state collecting features returned by stax
  304.   def state_trigger_features(state, timing) # v1.03a+
  305.     return [] unless triggers = state.state_triggers[timing]
  306.     st = DoubleX_RMVXA::State_Triggers
  307.     # Collects all features returned by stax meeting stcx with timing timing
  308.     triggers.select { |trigger|
  309.       st.send(trigger[0], self, state)
  310.     }.collect! { |trigger| st.send(trigger[1], self, state) }.flatten!
  311.     #
  312.   end # state_trigger_features
  313.  
  314. end # Game_BattlerBase
  315.  
  316. class Game_Battler < Game_BattlerBase # Edit
  317.  
  318.   alias clear_states_triggers clear_states
  319.   def clear_states(*argv, &argb)
  320.     # Added to store the state array right before it's cleared
  321.     last_states = @states
  322.     #
  323.     clear_states_triggers(*argv, &argb)
  324.     # Added to trigger the remove actions when the remove conditions are met
  325.     return unless last_states
  326.     last_states.each { |state_id| exec_state_triggers(state_id, :remove) }
  327.     #
  328.   end # clear_states
  329.  
  330.   alias reset_state_counts_state_triggers reset_state_counts
  331.   def reset_state_counts(state_id, &argb)
  332.     reset_state_counts_state_triggers(state_id, &argb)
  333.     # Added to trigger the add actions when the add conditions are met
  334.     exec_state_triggers(state_id, :add) if @states.include?(state_id)
  335.     #
  336.   end # reset_state_counts
  337.  
  338.   alias update_state_turns_state_triggers update_state_turns
  339.   def update_state_turns(*argv, &argb)
  340.     update_state_turns_state_triggers(*argv, &argb)
  341.     # Added to trigger the turn actions when the turn conditions are met
  342.     @states.each { |state_id| exec_state_triggers(state_id, :turn) }
  343.     #
  344.   end # update_state_turns
  345.  
  346.   #----------------------------------------------------------------------------|
  347.   #  Triggers each state action when each respective condition's met           |
  348.   #----------------------------------------------------------------------------|
  349.   # state_id: The id of the state triggering its actions
  350.   # timing: The timing of the state triggering its actions
  351.   def exec_state_triggers(state_id, timing) # New
  352.     # Evaluates each stcx to see if its corresponding stax should be evaluated
  353.     state = $data_states[state_id]
  354.     return unless triggers = state.state_triggers[timing]
  355.     st = DoubleX_RMVXA::State_Triggers
  356.     triggers.each { |trigger|
  357.       st.send(trigger[1], self, state) if st.send(trigger[0], self, state)
  358.     }
  359.     #
  360.   end # exec_state_triggers
  361.  
  362. end # Game_Battler
  363.  
  364. #------------------------------------------------------------------------------|
  365.  
  366. #==============================================================================|
RAW Paste Data