Advertisement
Double_X

DoubleX RMVXA Linked Battlers v1.00b

Aug 7th, 2015 (edited)
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 17.74 KB | None | 0 0
  1. #==============================================================================|
  2. #  ** Script Info                                                              |
  3. #------------------------------------------------------------------------------|
  4. #  * Script Name                                                               |
  5. #    DoubleX RMVXA Linked Battlers                                             |
  6. #------------------------------------------------------------------------------|
  7. #  * Functions                                                                 |
  8. #    Lets users set some states to make their owners share some stats together |
  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. Some 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://pastebin.com/bfCuAkKT                                           |
  30. #    Mentioned Patreon Supporters:                                             |
  31. #    https://www.patreon.com/posts/71738797                                    |
  32. #------------------------------------------------------------------------------|
  33. #  * Authors                                                                   |
  34. #    DoubleX                                                                   |
  35. #------------------------------------------------------------------------------|
  36. #  * Changelog                                                                 |
  37. #    v1.00b(GMT 0400 8-11-2015):                                               |
  38. #    1. Notetag values are now symbols of methods in the configuration regions |
  39. #    2. This script doesn't need DoubleX RMVXA Linked Battlers Compatibility to|
  40. #       be compatible with all its addressed scripts                           |
  41. #    3. Further improved this script's compatibility, efficiency and simplicity|
  42. #    v1.00a(GMT 1500 7-8-2015):                                                |
  43. #    1. 1st version of this script finished                                    |
  44. #==============================================================================|
  45.  
  46. #==============================================================================|
  47. #  ** Notetag Info                                                             |
  48. #------------------------------------------------------------------------------|
  49. #  * State Notetags:                                                           |
  50. #    1. <linked battlers: lbcx, lbsx, lbwx>                                    |
  51. #       - Sets the owners of this state meeting lbcx to share stats included in|
  52. #         lbsx with weight lbwx applied to each of them when any included stat |
  53. #         of any included battler changes                                      |
  54. #       - Only the 1st applicable notetag of the state with the highest        |
  55. #         priority will be applied to the stat change of the linked battler    |
  56. #       - If a linked battler can't take all of that battler's share due to    |
  57. #         hitting the minimum or maximum stat value, thost not being taken by  |
  58. #         that battler will be shared by the rest of the linked battlers also  |
  59. #       - The battler having a stat to be changed is the last linked battler   |
  60. #         taking that battler's share                                          |
  61. #       - lbcx can be set in Linked Battler Condition Notetag Values           |
  62. #       - lbsx can be set in Linked Battler Stat Notetag Values                |
  63. #       - lbwx can be set in Linked Battler Weight Notetag Values              |
  64. #==============================================================================|
  65.  
  66. ($doublex_rmvxa ||= {})[:Linked_Battlers] = "v1.00b"
  67.  
  68. #==============================================================================|
  69. #  ** Script Configurations                                                    |
  70. #     You only need to edit this part as it's about what this script does      |
  71. #------------------------------------------------------------------------------|
  72.  
  73. module DoubleX_RMVXA
  74.  
  75.   module Linked_Battlers
  76.  
  77.     #--------------------------------------------------------------------------|
  78.     #  Linked Battler Condition Notetag Values                                 |
  79.     #  - Setups lbcx used by <linked battlers: lbcx, lbsx, lbwx>               |
  80.     #--------------------------------------------------------------------------|
  81.     # lbcx are read at:
  82.     # 1. RPG::State
  83.     #    - @linked_battlers << [$1.downcase.to_sym, $2.downcase.to_sym,
  84.     #      $3.downcase.to_sym] in load_linked_battlers_notes
  85.     # lbcx are used at:
  86.     # 1. Game_BattlerBase
  87.     #    - mem.state?(state_id) && lb.send(cond, mem, self) in
  88.     #      get_linked_battlers
  89.     # lbcx are strings of names of methods under DoubleX_RMVXA::Linked_Battlers
  90.     # lbcx names can only use alphanumeric characters and can't use uppercase
  91.     # letters
  92.     # The battler having a stat to be changed can be referenced by target
  93.     # Each of the rest of the linked battlers can be referenced by battler
  94.     # The below lbcx are examples added to help you set your lbcx
  95.     # You can freely use, rewrite and/or delete these examples
  96.  
  97.     # Sets the linked battler condition to include all linked battlers
  98.     def self.lbc1(battler, target)
  99.       true
  100.     end
  101.  
  102.     # Sets the linked battler condition to include all and no linked battlers if
  103.     # switch with id x is on and off respectively
  104.     def self.lbc2(battler, target)
  105.       $game_switches[x]
  106.     end
  107.  
  108.     # Sets the linked battler condition to include all linked battlers that are
  109.     # opponents of the battler having a stat to be changed
  110.     def self.lbc3(battler, target)
  111.       target.opposite?(battler)
  112.     end
  113.  
  114.     # Adds new lbcx here
  115.    
  116.  
  117.     #--------------------------------------------------------------------------|
  118.     #  Linked Battler Stat Notetag Values                                      |
  119.     #  - Setups lbsx used by <linked battlers: lbcx, lbsx, lbwx>               |
  120.     #--------------------------------------------------------------------------|
  121.     # lbsx are read at:
  122.     # 1. RPG::State
  123.     #    - @linked_battlers << [$1.downcase.to_sym, $2.downcase.to_sym,
  124.     #      $3.downcase.to_sym] in load_linked_battlers_notes
  125.     # lbsx are used at:
  126.     # 1. Game_BattlerBase
  127.     #    - return [l_b, state_id] if lb.send(l_b[1], self).include?(stat) in
  128.     #      linked_battler_state_id
  129.     # lbsx are strings of names of methods under DoubleX_RMVXA::Linked_Battlers
  130.     # lbsx names can only use alphanumeric characters and can't use uppercase
  131.     # letters
  132.     # The battler having a stat to be changed can be referenced by battler
  133.     # It must return an array, which should include strings of a getter method
  134.     # of each stat to be included
  135.     # The below lbsx are examples added to help you set your lbsx
  136.     # You can freely use, rewrite and/or delete these examples
  137.  
  138.     # Sets the linked battler stat to include hp, mp and tp
  139.     def self.lbs1(battler)
  140.       ["hp", "mp", "tp"]
  141.     end
  142.  
  143.     # Sets the linked battler stat to always include hp and mp, and include tp
  144.     # only if it's displayed in battle
  145.     def self.lbs2(battler)
  146.       ["hp", "mp", $data_system.opt_display_tp ? "tp" : nil]
  147.     end
  148.  
  149.     # Sets the linked battler stat to include nothing
  150.     def self.lbs3(battler)
  151.       []
  152.     end
  153.  
  154.     # Adds new lbsx here
  155.    
  156.  
  157.     #--------------------------------------------------------------------------|
  158.     #  Linked Battler Weight Notetag Values                                    |
  159.     #  - Setups lbwx used by <linked battlers: lbcx, lbsx, lbwx>               |
  160.     #--------------------------------------------------------------------------|
  161.     # lbwx are read at:
  162.     # 1. RPG::State
  163.     #    - @linked_battlers << [$1.downcase.to_sym, $2.downcase.to_sym,
  164.     #      $3.downcase.to_sym] in load_linked_battlers_notes
  165.     # lbwx are used in methods included in LINKED_STAT
  166.     # lbwx are strings of names of methods under DoubleX_RMVXA::Linked_Battlers
  167.     # lbwx names can only use alphanumeric characters and can't use uppercase
  168.     # letters
  169.     # It must return a real number
  170.     # The battler having a stat to be changed can be referenced by target
  171.     # Each of the rest of the linked battlers can be referenced by battler
  172.     # The below lbwx are examples added to help you set your lbwx
  173.     # You can freely use, rewrite and/or delete these examples
  174.  
  175.     # Sets the linked battler weight to be the same for all linked battlers
  176.     def self.lbw1(battler, target)
  177.       1
  178.     end
  179.  
  180.     # Sets the linked battler weight to be multiplied by x if the linked battler
  181.     # is the one having a stat to be changed
  182.     def self.lbw2(battler, target)
  183.       battler == target ? x : 1
  184.     end
  185.  
  186.     # Sets the linked battler weight to be 0 for all linked battlers
  187.     def self.lbw3(battler, target)
  188.       0
  189.     end
  190.  
  191.     # Adds new lbwx here
  192.    
  193.  
  194.     # Sets the battler methods to be used by linked battlers
  195.     # Its keys must be the battler stat getter method string
  196.     # Its values must be an array containing the battler stat setter method,
  197.     # its argument list, the one being modified, and the minimum and maximum
  198.     # value of that battler stat of each linked battler
  199.     # The methods returning those minimum and maximum values must be referenced
  200.     # by battler
  201.     # Methods with name method_name will be aliased to
  202.     # linked_battlers_method_name
  203.     LINKED_STATS = {
  204.  
  205.       # General form:
  206.       # [:def_class, :super_class] => {
  207.       #   "getter" => ["setter", "args", "mod arg", "stat_min", "stat_max"]
  208.       # }
  209.  
  210.       [:Game_BattlerBase] => {
  211.         # General form:
  212.         # "getter" => ["setter", "args", "mod arg", "stat_min", "stat_max"]
  213.         "hp" => ["hp=", "hp", "hp", "0", "battler.mhp"],
  214.         "mp" => ["mp=", "mp", "mp", "0", "battler.mmp"],
  215.         "tp" => ["tp=", "tp", "tp", "0", "battler.max_tp"]
  216.         # Adds new methods here
  217.        
  218.       }
  219.  
  220.       # Adds new classes here
  221.      
  222.  
  223.     }
  224.  
  225.   end # Linked_Battlers
  226.  
  227. end # DoubleX_RMVXA
  228.  
  229. #==============================================================================|
  230. #  ** Script Implementations                                                   |
  231. #     You need not edit this part as it's about how this script works          |
  232. #------------------------------------------------------------------------------|
  233. #  * Script Support Info:                                                      |
  234. #    1. Prerequisites                                                          |
  235. #       - Decent RGSS3 scripting proficiency to fully comprehend this script   |
  236. #    2. Method documentation                                                   |
  237. #       - The 1st part describes why this method's rewritten/aliased for       |
  238. #         rewritten/aliased methods or what the method does for new methods    |
  239. #       - The 2nd part describes what the arguments of the method are          |
  240. #       - The 3rd part informs which version rewritten, aliased or created this|
  241. #         method                                                               |
  242. #       - The 4th part informs whether the method's rewritten or new           |
  243. #       - The 5th part informs whether the method's a real or potential hotspot|
  244. #       - The 6th part describes how this method works for new methods only,   |
  245. #         and describes the parts added, removed or rewritten for rewritten or |
  246. #         aliased methods only                                                 |
  247. #       Example:                                                               |
  248. # #--------------------------------------------------------------------------| |
  249. # #  Why rewrite/alias/What this method does                                 | |
  250. # #--------------------------------------------------------------------------| |
  251. # # *argv: What these variables are                                            |
  252. # # &argb: What this block is                                                  |
  253. # def def_name(*argv, &argb) # Version X+; Rewrite/New; Hotspot                |
  254. #   # Added/Removed/Rewritten to do something/How this method works            |
  255. #   def_name_code                                                              |
  256. #   #                                                                          |
  257. # end # def_name                                                               |
  258. #------------------------------------------------------------------------------|
  259.  
  260. class << DataManager # Edit
  261.  
  262.   alias load_database_linked_battlers load_database
  263.   def load_database(*argv, &argb)
  264.     load_database_linked_battlers(*argv, &argb)
  265.     $data_states.each { |obj| obj.load_linked_battlers_notes if obj } # Added
  266.   end # load_database
  267.  
  268. end # DataManager
  269.  
  270. class RPG::State < RPG::BaseItem # Edit
  271.  
  272.   #----------------------------------------------------------------------------|
  273.   #  New public instance variable                                              |
  274.   #----------------------------------------------------------------------------|
  275.   attr_accessor :linked_battlers # An array of all linked battler notetag values
  276.  
  277.   def load_linked_battlers_notes # New
  278.     @linked_battlers = []
  279.     # Stores all lbcx, lbsx and lbwx triples from matching lines sequentially
  280.     @note.split(/[\r\n]+/).each { |l|
  281.       next unless l =~ /< *linked +battlers *: *(\w+) *, *(\w+) *, *(\w+) *>/i
  282.       @linked_battlers << [$1.downcase.to_sym, $2.downcase.to_sym,
  283.       $3.downcase.to_sym]
  284.     }
  285.     #
  286.   end # load_linked_battlers_notes
  287.  
  288. end # RPG::State
  289.  
  290. #------------------------------------------------------------------------------|
  291. #  *  Adds helper methods used by methods used by linked battlers              |
  292. #------------------------------------------------------------------------------|
  293. class Game_BattlerBase # Edit
  294.  
  295.   # state_id: The id of the state to be included by all linked battlers
  296.   # cond: The conditions for a linked battlers to be included
  297.   def get_linked_battlers(state_id, cond) # New
  298.     lb = DoubleX_RMVXA::Linked_Battlers
  299.     ($game_party.alive_members + $game_troop.alive_members).select! { |mem|
  300.       mem.state?(state_id) && lb.send(cond, mem, self)
  301.     }
  302.   end # get_linked_battlers
  303.  
  304.   # stat: The stat of a linked battler to be changed
  305.   def linked_battler_state_id(stat) # New
  306.     lb = DoubleX_RMVXA::Linked_Battlers
  307.     @states.each { |state_id|
  308.       $data_states[state_id].linked_battlers.each { |l_b|
  309.         return [l_b, state_id] if lb.send(l_b[1], self).include?(stat)
  310.       }
  311.     }
  312.     nil
  313.   end # linked_battler_state_id
  314.  
  315. end # Game_BattlerBase
  316.  
  317. # Aliases methods used by linked battlers
  318. DoubleX_RMVXA::Linked_Battlers::LINKED_STATS.each { |klass, defs|
  319.   klass_def = %Q(
  320. class #{klass[0].id2name}#{klass[1] ? " < #{klass[1].id2name}" : ""}
  321. )
  322.   defs.each { |get, stat|
  323.     klass_def += %Q(
  324.   alias linked_battlers_#{stat[0]} #{stat[0]}
  325.   def #{stat[0]}(#{stat[1]})
  326.     lb_si = linked_battler_state_id("#{get}")
  327.     return self.linked_battlers_#{stat[0]}(#{stat[1]}) unless lb_si
  328.     get_linked_battlers_#{get}(#{stat[1]}, lb_si[0], lb_si[1])
  329.   end
  330.  
  331.   def get_linked_battlers_#{get}(#{stat[1]}, linked_battler, state_id)
  332.     battlers = get_linked_battlers(state_id, linked_battler[0])
  333.     index = battlers.index(self)
  334.     battlers[index], battlers[-1] = battlers[-1], battlers[index]
  335.     lb = DoubleX_RMVXA::Linked_Battlers
  336.     weights = battlers.collect { |b| lb.send(linked_battler[2], b, self) }
  337.     return if (sum = weights.inject(:+)) == 0
  338.     diff = #{stat[2]} - self.#{get}
  339.     set_linked_battlers_#{get}(#{stat[1]}, battlers, diff, sum, weights)
  340.   end
  341.  
  342.   def set_linked_battlers_#{get}(#{stat[1]}, battlers, diff, sum, weights)
  343.     battlers.each_with_index { |battler, index|
  344.       change = diff * (weight = weights[index]) / sum
  345.       if (new_stat = battler.#{get} + change) < min = #{stat[3]}
  346.         change = battler.#{get} - min
  347.         #{stat[2]} = min
  348.       elsif new_stat > max = #{stat[4]}
  349.         change = max - battler.#{get}
  350.         #{stat[2]} = max
  351.       else
  352.         #{stat[2]} = new_stat
  353.       end
  354.       battler.linked_battlers_#{stat[0]}(#{stat[1]})
  355.       diff -= change
  356.       sum -= weight
  357.     }
  358.   end
  359. )
  360.   }
  361.   eval(klass_def + %Q(
  362. end
  363. ))
  364. }
  365.  
  366. #------------------------------------------------------------------------------|
  367.  
  368. #==============================================================================|
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement