Double_X

DoubleX RMVXA Unison Addon to Yanfly Engine Ace - Ace Battle

Jul 22nd, 2015 (edited)
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 34.70 KB | None | 0 0
  1. #==============================================================================|
  2. #  ** Script Info                                                              |
  3. #------------------------------------------------------------------------------|
  4. #  * Script Name                                                               |
  5. #    DoubleX RMVXA Unison Addon to Yanfly Engine Ace - Ace Battle Engine       |
  6. #------------------------------------------------------------------------------|
  7. #  * Functions                                                                 |
  8. #    Lets users make actor unison skills/items needing multiple actors to use  |
  9. #------------------------------------------------------------------------------|
  10. #  * Terms Of Use                                                              |
  11. #    You shall:                                                                |
  12. #    1. Follow the terms of use of Yanfly Engine Ace - Ace Battle Engine       |
  13. #    2. Keep this script's Script Info part's contents intact                  |
  14. #    You shalln't claim that this script's written by anyone other than        |
  15. #    DoubleX, his aliases, Yanfly, or his/her aliases                          |
  16. #    None of the above applies to Yanfly or his/her aliases                    |
  17. #------------------------------------------------------------------------------|
  18. #  * Prerequisites                                                             |
  19. #    Scripts:                                                                  |
  20. #    1. Yanfly Engine Ace - Ace Battle Engine                                  |
  21. #    2. DoubleX RMVXA Clear Addon to Yanfly Engine Ace - Ace Battle Engine     |
  22. #    Abilities:                                                                |
  23. #    1. Some RGSS3 scripting proficiency to fully utilize this script          |
  24. #------------------------------------------------------------------------------|
  25. #  * Instructions                                                              |
  26. #    1. Open the script editor and put this script into an open slot between   |
  27. #       DoubleX RMVXA Clear Addon to Yanfly Engine Ace - Ace Battle Engine and |
  28. #       Main, save to take effect.                                             |
  29. #    2. This script can't be used with DoubleX RMVXA Unison Item.              |
  30. #------------------------------------------------------------------------------|
  31. #  * Links                                                                     |
  32. #    Script Usage 101:                                                         |
  33. #    1. forums.rpgmakerweb.com/index.php?/topic/32752-rmvxa-script-usage-101/  |
  34. #    2. rpgmakervxace.net/topic/27475-rmvxa-script-usage-101/                  |
  35. #    This script:                                                              |
  36. #    1. http://pastebin.com/uPjXtgXn                                           |
  37. #    Video:                                                                    |
  38. #    1. https://www.youtube.com/watch?v=S-d6geAoYsM&feature=youtu.be           |
  39. #    Mentioned Patreon Supporters:                                             |
  40. #    https://www.patreon.com/posts/71738797                                    |
  41. #------------------------------------------------------------------------------|
  42. #  * Authors                                                                   |
  43. #    DoubleX:                                                                  |
  44. #    1. This script                                                            |
  45. #    Yanfly:                                                                   |
  46. #    1. Yanfly Engine Ace - Ace Battle Engine                                  |
  47. #------------------------------------------------------------------------------|
  48. #  * Changelog                                                                 |
  49. #    v1.00b(GMT 1100 26-7-2015):                                               |
  50. #    1. Fixed reserving nonempty action slots and selecting reserved ones bug  |
  51. #    v1.00a(GMT 1200 22-7-2015):                                               |
  52. #    1. 1st version of this script finished                                    |
  53. #==============================================================================|
  54.  
  55. #==============================================================================|
  56. #  ** Notetag Info                                                             |
  57. #     Notetag settings override their corresponding configuration settings     |
  58. #------------------------------------------------------------------------------|
  59. #  * Skill/Item Notetags:                                                      |
  60. #    1. <unison actors: ids>                                                   |
  61. #       - Sets the list of id of actors needed for the skill/item as ids.      |
  62. #         For example:                                                         |
  63. #         <unison actors: 1> means actor with id 1 is required to use it       |
  64. #         <unison actors: 4, 2> means actors with id 4 and 2 are needed        |
  65. #       - All actors in list ids needs to be in the battle, inputable, able to |
  66. #         use it and pay its cost. They'll all pay the cost after using it.    |
  67. #         Only actors in list x can select it.                                 |
  68. #    2. <unison def rule: rule                                                 |
  69. #       - Sets the rule of setting user's def in the skill/item's damage       |
  70. #         formula as rule, whose symbol is one of those in UNISON_RULES.       |
  71. #       - The symbol of def must be included in UNISON_DEFS                    |
  72. #       - This notetag needs to be written below <unison item: ids> to work.   |
  73. #    3. <unison def actors: ids>                                               |
  74. #       - Sets user's method def in the skill/item's damage formula to use its |
  75. #         unison rule to combine those of actors with id includedin the list   |
  76. #         ids. def needs to be able to take no arguments and return a Numeric  |
  77. #         to work.                                                             |
  78. #         For example:                                                         |
  79. #         <unison atk actors: 1> means the user's atk in its damage formula    |
  80. #         uses thatof actor with id 1                                          |
  81. #         <unison mat actors: 4, 2> means the user's mat in its damage formula |
  82. #         uses mat of actors with id 4 and 2 under the skill/item's unison rule|
  83. #       - The symbol of def must be included in UNISON_DEFS                    |
  84. #       - This notetag needs to be written below <unison item: ids> to work.   |
  85. #------------------------------------------------------------------------------|
  86.  
  87. ($doublex_rmvxa ||= {})[:YEA_BattleEngine_Unison] = "v1.00b"
  88.  
  89. #==============================================================================|
  90. #  ** Script Configurations                                                    |
  91. #     You only need to edit this part as it's about what this script does      |
  92. #------------------------------------------------------------------------------|
  93.  
  94. module DoubleX_RMVXA
  95.  
  96.   module YEA_BattleEngine_Unison
  97.  
  98.     # Sets if the battlelog will show all actors involved in the unison skills
  99.     # or items instead of only the one invoking them
  100.     # If SHOW_UNISON_ACTOR_SWITCH_ID is a natural number, the state of switch
  101.     # with id SHOW_UNISON_ACTOR_SWITCH_ID will be used instead
  102.     SHOW_UNISON_ACTOR = true
  103.     SHOW_UNISON_ACTOR_SWITCH_ID = 0
  104.  
  105.     # Sets the symbol of the rule used for setting the user's methods in the
  106.     # damage formula by using those of the included unison actors
  107.     # or items instead of only the one invoking them
  108.     # It must return a symbol included in UNISON_RULES
  109.     # If UNISON_DEF_RULE_VAR_ID is a natural number, the value of variable
  110.     # with id UNISON_DEF_RULE_VAR_ID will be used instead
  111.     UNISON_DEF_RULE = :avg
  112.     UNISON_DEF_RULE_VAR_ID = 0
  113.  
  114.     # Implements the unison method rules
  115.     # The unison method value of all unison battlers can be referneced by vals
  116.     # The unison method rule symbol can be referenced by rule
  117.     # It's a method under Game_BattlerBase
  118.     # It must return a real number
  119.     UNISON_RULES = %Q(
  120.   def unison_rules(vals, rule) # This line shalln't be changed
  121.     if rule == :min
  122.       vals.min
  123.     elsif rule == :avg
  124.       avg = 0
  125.       vals.each { |val| avg += val }
  126.       avg / vals.size
  127.     elsif rule == :max
  128.       vals.max
  129.     else
  130.       0
  131.     end
  132.   end
  133.     )
  134.  
  135.     # Sets the battler methods to use the unison method rules
  136.     # Its keys must be the battler method name symbols
  137.     # Methods with name method_name will be aliased to method_name_unison
  138.     UNISON_DEFS = {
  139.  
  140.       # General Form:
  141.       # [:method_class, :super_class] => [
  142.       #   :method_name
  143.       # ]
  144.  
  145.       [:Game_BattlerBase] => [
  146.         :hp,
  147.         :mp,
  148.         :tp,
  149.         :mhp,
  150.         :mmp,
  151.         :atk,
  152.         :def,
  153.         :mat,
  154.         :mdf,
  155.         :agi
  156.         # Adds new methods here
  157.        
  158.       ],
  159.  
  160.       [:Game_Actor, :Game_Battler] => [
  161.         :level
  162.         # Adds new methods here
  163.        
  164.       ]
  165.  
  166.       # Adds new classes here
  167.      
  168.  
  169.     }
  170.  
  171. #==============================================================================|
  172.  
  173. #==============================================================================|
  174. #  ** Script Implementations                                                   |
  175. #     You need not edit this part as it's about how this script works          |
  176. #------------------------------------------------------------------------------|
  177. #  * Script Support Info:                                                      |
  178. #    1. Prerequisites                                                          |
  179. #       - Thorough comprehension of the relations between unison skills/items  |
  180. #         and the Yanfly Engine Ace - Ace Battle Engine action input mechanisms|
  181. #       - Advanced RGSS3 scripting proficiency to fully comprehend this script |
  182. #    2. Method documentation                                                   |
  183. #       - The 1st part informs which version rewritten, aliased or created this|
  184. #         method                                                               |
  185. #       - The 2nd part informs whether the method's rewritten, aliased or new  |
  186. #       - The 3rd part describes why this method's rewritten/aliased for       |
  187. #         rewritten/aliased methods or what the method does for new methods    |
  188. #       - The 4th part describes what the arguments of the method are          |
  189. #       - The 5th part describes how this method works for new methods only,   |
  190. #         and describes the parts added, removed or rewritten for rewritten or |
  191. #         aliased methods only                                                 |
  192. #       Example:                                                               |
  193. # #--------------------------------------------------------------------------| |
  194. # #  (Version X+; Rewrite/Alias/New)Why rewrite/alias/What this method does  | |
  195. # #--------------------------------------------------------------------------| |
  196. # # *argv: What these variables are                                            |
  197. # # &argb: What this block is                                                  |
  198. # def def_name(*argv, &argb)                                                   |
  199. #   # Added/Removed/Rewritten to does something/How this method works          |
  200. #   def_name_code                                                              |
  201. #   #                                                                          |
  202. # end # def_name                                                               |
  203. #------------------------------------------------------------------------------|
  204.  
  205.     #--------------------------------------------------------------------------|
  206.     #  Returns if all unison actors should be displayed                        |
  207.     #--------------------------------------------------------------------------|
  208.     def self.show_unison_actor?
  209.       # Checks if the value of a selected switch's used instead of a fixed value
  210.       (i = SHOW_UNISON_ACTOR_SWITCH_ID) > 0 ? $game_switches[i] :
  211.       SHOW_UNISON_ACTOR
  212.       #
  213.     end # show_unison_actor?
  214.  
  215.     #--------------------------------------------------------------------------|
  216.     #  Returns the current unison user method rule                             |
  217.     #--------------------------------------------------------------------------|
  218.     def self.unison_def_rule
  219.       # Checks if the value of a selected var's used instead of a fixed value
  220.       (id = UNISON_DEF_RULE_VAR_ID) > 0 ? $game_variables[id] : UNISON_DEF_RULE
  221.       #
  222.     end # unison_def_rule
  223.  
  224.   end # YEA_BattleEngine_Unison
  225.  
  226. end # DoubleX_RMVXA
  227.  
  228. if $imported["YEA-BattleEngine"]
  229.  
  230. if $doublex_rmvxa[:YEA_BattleEngine_Clear]
  231.  
  232. if $imported["DoubleX RMVXA Unison Item"]
  233.  
  234.   # Informs users that they used DoubleX RMVXA Unison Item with this script
  235.   msgbox("DoubleX RMVXA Unison Addon to Yanfly Engine Ace - Ace Battle " +  
  236.          "Engine can't be used with:\nDoubleX RMVXA Unison Item")
  237.  
  238. else
  239.  
  240. #------------------------------------------------------------------------------|
  241. #  * (Edit)Loads this script's notetags                                        |
  242. #------------------------------------------------------------------------------|
  243. class << DataManager
  244.  
  245.   #----------------------------------------------------------------------------|
  246.   #  (Alias)Loads all of this script's notetags from all skills/items as well  |
  247.   #----------------------------------------------------------------------------|
  248.   alias load_database_unison load_database
  249.   def load_database
  250.     load_database_unison
  251.     # Added to load all of this script's notetags from all skills/items
  252.     load_notetags_unison
  253.     #
  254.   end # load_database
  255.  
  256.   #----------------------------------------------------------------------------|
  257.   #  (New)Loads all of this script's notetags from all skills/items            |
  258.   #----------------------------------------------------------------------------|
  259.   def load_notetags_unison
  260.     # Loads each notetag from each skill/item sequentially
  261.     [$data_skills, $data_items].each { |data|
  262.       data.each { |obj| obj.load_notetags_unison if obj }
  263.     }
  264.     #
  265.   end # load_notetags_unison
  266.  
  267. end # DataManager
  268.  
  269. #------------------------------------------------------------------------------|
  270. #  * (Edit)Reads this script's notetags from this item                         |
  271. #------------------------------------------------------------------------------|
  272. class RPG::UsableItem < RPG::BaseItem
  273.  
  274.   #----------------------------------------------------------------------------|
  275.   #  New public instance variables                                             |
  276.   #----------------------------------------------------------------------------|
  277.   attr_accessor :unison_actor_ids # The list of id of all unison actors
  278.   attr_accessor :unison_rules # The mapping of which user's def uses which rule
  279.   attr_accessor :unison_def_actor_ids # The unison actors' def used by the user
  280.  
  281.   #----------------------------------------------------------------------------|
  282.   #  (New)Reads all of this script's notetags from the notebox                 |
  283.   #----------------------------------------------------------------------------|
  284.   def load_notetags_unison
  285.     @unison_actor_ids = []
  286.     @unison_rules = {}
  287.     @unison_def_actor_ids = {}
  288.     # Reads each line to check against each of this script's notetag
  289.     @note.split(/[\r\n]+/).each { |line|
  290.       case line
  291.       when /<unison actors:\s*(\d+(?:\s*,\s*\d+)*)>/i
  292.         $1.scan(/\d+/).each { |n| @unison_actor_ids << n.to_i if n.to_i > 0 }
  293.       when /<unison (\w+) rule:\s*(\w+)>/i
  294.         @unison_rules[$1.to_sym] = $2.to_sym unless @unison_actor_ids.empty?
  295.       when /<unison (\w+) actors:\s*(\d+(?:\s*,\s*\d+)*)>/i
  296.         @unison_def_actor_ids[sym = $1.to_sym] ||= []
  297.         $2.scan(/\d+/).each { |num|
  298.           @unison_def_actor_ids[sym] << num.to_i if num.to_i > 0
  299.         }
  300.       end
  301.     }
  302.     #
  303.   end # load_notetags_unison_addon
  304.  
  305. end # RPG::UsableItem
  306.  
  307. #------------------------------------------------------------------------------|
  308. #  * (Edit)Changes actor inputability and unison skill/item usability checks   |
  309. #------------------------------------------------------------------------------|
  310. class Game_BattlerBase
  311.  
  312.   #----------------------------------------------------------------------------|
  313.   #  (Alias)Checks if at least 1 action slot isn't reserved as well            |
  314.   #----------------------------------------------------------------------------|
  315.   alias inputable_unison? inputable?
  316.   def inputable?
  317.     # Rewritten to only check the new condition against actors in battles
  318.     return false unless inputable_unison?
  319.     return true unless SceneManager.scene_is?(Scene_Battle) && @unison_inputs
  320.     @unison_inputs.size < @actions.size
  321.     #
  322.   end # inputable?
  323.  
  324.   #----------------------------------------------------------------------------|
  325.   #  (Alias)Checks if unison skills/items are usable as well                   |
  326.   #----------------------------------------------------------------------------|
  327.   alias usable_unison? usable?
  328.   def usable?(item)
  329.     # Rewritten to check if all unison actors can use the unison skill/item
  330.     return usable_unison?(item) unless actor? && item &&
  331.     item.is_a?(RPG::UsableItem) && !item.unison_actor_ids.empty?
  332.     return false unless item.unison_actor_ids.include?(id)
  333.     return false unless usable_unison?(item)
  334.     return unison_skill_usable?(item) if item.is_a?(RPG::Skill)
  335.     return false unless item.is_a?(RPG::Item) && item_conditions_met?(item)
  336.     unison_item_usable?(item)
  337.     #
  338.   end # usable?
  339.  
  340.   #----------------------------------------------------------------------------|
  341.   #  (New)Checks if all unison actors can use the unison skill                 |
  342.   #----------------------------------------------------------------------------|
  343.   def unison_skill_usable?(item)
  344.     # Checks if all unison actors are inputable and has the unison skill as well
  345.     battle = SceneManager.scene_is?(Scene_Battle)
  346.     (item.unison_actor_ids - [id]).each { |actor_id|
  347.       actor = $game_actors[actor_id]
  348.       return false unless actor.battle_member? && actor.inputable_unison?
  349.       return false if battle && actor.actions.select { |a| a.item }.size >=
  350.       actor.actions.size - actor.temp_unison_inputs
  351.       return false unless actor.skill_conditions_met?(item)
  352.       return false unless actor.skills.any? { |s| s == $data_skills[item.id] }
  353.     }
  354.     true
  355.     #
  356.   end # unison_skill_usable?
  357.  
  358.   #----------------------------------------------------------------------------|
  359.   #  (New)Checks if all unison actors can use the unison item                  |
  360.   #----------------------------------------------------------------------------|
  361.   def unison_item_usable?(item)
  362.     # Checks if all unison actors are inputable as well
  363.     (item.unison_actor_ids - [id]).each { |actor_id|
  364.       return false unless actor.battle_member? && actor.inputable?
  365.     }
  366.     true
  367.     #
  368.   end # unison_item_usable?
  369.  
  370. end # Game_BattlerBase
  371.  
  372. #------------------------------------------------------------------------------|
  373. #  * (Edit)Changes unison skill/item's user's defs and unison cost payments    |
  374. #------------------------------------------------------------------------------|
  375. class Game_Battler < Game_BattlerBase
  376.  
  377.   #----------------------------------------------------------------------------|
  378.   #  New public instance variable                                              |
  379.   #----------------------------------------------------------------------------|
  380.   attr_writer :unison_item # The unison skill/item for setting user's defs
  381.  
  382.   #----------------------------------------------------------------------------|
  383.   #  (Alias)Changes all user's defs to their unison versions                   |
  384.   #----------------------------------------------------------------------------|
  385.   alias make_damage_value_unison make_damage_value
  386.   def make_damage_value(user, item)
  387.     # Added to set all user's defs to use their unison rules
  388.     user.unison_item = item if user.actor? && item.unison_actor_ids.size > 1
  389.     #
  390.     make_damage_value_unison(user, item)
  391.     # Added to reset all user's defs to their defaults
  392.     user.unison_item = nil
  393.     #
  394.   end # make_damage_value
  395.  
  396.   #----------------------------------------------------------------------------|
  397.   #  (Alias)Asks all unison actors to pay the unison skill cost                |
  398.   #----------------------------------------------------------------------------|
  399.   alias use_item_unison use_item
  400.   def use_item(item)
  401.     # Rewritten to asks all unison invokees to pay the unison skill cost only
  402.     unless item.is_a?(RPG::Skill) && !item.unison_actor_ids.empty?
  403.       return use_item_unison(item)
  404.     end
  405.     item.unison_actor_ids.each { |id| $game_actors[id].pay_skill_cost(item) }
  406.     item.effects.each { |effect| item_global_effect_apply(effect) }
  407.     #
  408.   end # use_item
  409.  
  410.   #----------------------------------------------------------------------------|
  411.   #  (New)Returns the result of the user's defs after using their unison rules |
  412.   #----------------------------------------------------------------------------|
  413.   module_eval(DoubleX_RMVXA::YEA_BattleEngine_Unison::UNISON_RULES)
  414.  
  415. end # Game_Battler
  416.  
  417. #------------------------------------------------------------------------------|
  418. #  * (Edit)Changes action slot inputability check                              |
  419. #------------------------------------------------------------------------------|
  420. class Game_Actor < Game_Battler
  421.  
  422.   #----------------------------------------------------------------------------|
  423.   #  New public instance variable                                              |
  424.   #----------------------------------------------------------------------------|
  425.   attr_accessor :temp_unison_inputs # The number of temporarily reserved ones
  426.   attr_accessor :unison_inputs # The list of reserved action slots' indices
  427.  
  428.   #----------------------------------------------------------------------------|
  429.   #  (Alias)Initializes the number and list of reserved action slots           |
  430.   #----------------------------------------------------------------------------|
  431.   alias setup_unison setup
  432.   def setup(actor_id)
  433.     setup_unison(actor_id)
  434.     # Added to initialize both the pretended and real ones as 0 and empty
  435.     @temp_unison_inputs = 0
  436.     @unison_inputs = []
  437.     #
  438.   end # setup
  439.  
  440.   #----------------------------------------------------------------------------|
  441.   #  (Alias)Resets the number and list of reserved action slots                |
  442.   #----------------------------------------------------------------------------|
  443.   alias clear_actions_unison clear_actions
  444.   def clear_actions
  445.     clear_actions_unison
  446.     # Added to reset both the pretended and real ones as 0 as empty
  447.     @temp_unison_inputs = 0
  448.     @unison_inputs = []
  449.     #
  450.   end # clear_actions
  451.  
  452.   #----------------------------------------------------------------------------|
  453.   #  (Alias)Prevents reserved action slots from being selected                 |
  454.   #----------------------------------------------------------------------------|
  455.   alias next_command_unison next_command
  456.   def next_command
  457.     # Rewritten to skip the next action slot if it's reserved for unison skills
  458.     last_act_input_index = @action_input_index
  459.     begin
  460.       inputable = next_command_unison
  461.     end while inputable && @unison_inputs.include?(@action_input_index)
  462.     @action_input_index = last_act_input_index unless inputable
  463.     inputable
  464.     #
  465.   end # next_command
  466.  
  467.   #----------------------------------------------------------------------------|
  468.   #  (v1.00b+; Alias)Prevents reserved action slots from being selected        |
  469.   #----------------------------------------------------------------------------|
  470.   alias prior_command_unison prior_command
  471.   def prior_command
  472.     # Rewritten to skip the prior action slot if it's reserved for unison skills
  473.     last_act_input_index = @action_input_index
  474.     begin
  475.       inputable = prior_command_unison
  476.     end while inputable && @unison_inputs.include?(@action_input_index)
  477.     @action_input_index = last_act_input_index unless inputable
  478.     inputable
  479.     #
  480.   end # prior_command
  481.  
  482.   #----------------------------------------------------------------------------|
  483.   #  (v1.00b+; New)Ensures the action input index won't point to reserved ones |
  484.   #----------------------------------------------------------------------------|
  485.   # i: The reserved action slot's index
  486.   # prior: Whether this actor's a prior actor to the unison invoker
  487.   def set_unison_input_index(i, prior)
  488.     # Points to the prior or next action slot according to the prior flag
  489.     return unless (@unison_inputs << i).include?(@action_input_index)
  490.     prior ? prior_command : next_command
  491.     #
  492.   end # set_unison_input_index
  493.  
  494. end # Game_Actor
  495.  
  496. #------------------------------------------------------------------------------|
  497. #  * (Edit)Changes unison item usability check                                 |
  498. #------------------------------------------------------------------------------|
  499. class Window_ItemList < Window_Selectable
  500.  
  501.   #----------------------------------------------------------------------------|
  502.   #  (Alias)Checks if an unison item's enabled in battles                      |
  503.   #----------------------------------------------------------------------------|
  504.   alias enable_unison? enable?
  505.   def enable?(item)
  506.     # Rewritten to set disable unison items when unison conditions aren't met
  507.     return enable_unison?(item) unless SceneManager.scene_is?(Scene_Battle) &&
  508.     item && item.is_a?(RPG::Item) && !item.unison_actor_ids.empty?
  509.     BattleManager.actor.usable?(item)
  510.     #
  511.   end # enable?
  512.  
  513. end # Window_ItemList
  514.  
  515. #------------------------------------------------------------------------------|
  516. #  * (Edit)Shows all unison actors' names when using unison skills/items       |
  517. #------------------------------------------------------------------------------|
  518. class Window_BattleLog < Window_Selectable
  519.  
  520.   #----------------------------------------------------------------------------|
  521.   #  (Alias)Displays all unison actors' names if show_unison_actor? is true    |
  522.   #----------------------------------------------------------------------------|
  523.   alias display_use_item_unison display_use_item
  524.   def display_use_item(subject, item)
  525.     # Rewritten to display all unison actors while using unison skills/items
  526.     return display_use_unison(item) if !item.unison_actor_ids.empty? &&
  527.     DoubleX_RMVXA::YEA_BattleEngine_Unison.show_unison_actor?
  528.     display_use_item_unison(subject, item)
  529.     #
  530.   end # display_use_item
  531.  
  532.   #----------------------------------------------------------------------------|
  533.   #  (New)Shows all unison actor names when using the unison skill/item        |
  534.   #----------------------------------------------------------------------------|
  535.   def display_use_unison(item)
  536.     # Shows the unison skill/item usage messages according to the item class
  537.     names = unison_actor_names(item.unison_actor_ids)
  538.     unless item.is_a?(RPG::Skill)
  539.       return add_text(sprintf(Vocab::UseItem, names, item.name))
  540.     end
  541.     add_text(names + item.message1)
  542.     return if item.message2.empty?
  543.     wait
  544.     add_text(item.message2)
  545.     #
  546.   end # display_use_unison
  547.  
  548.   #----------------------------------------------------------------------------|
  549.   #  (New)Collects all unison actors' names into the same string               |
  550.   #----------------------------------------------------------------------------|
  551.   def unison_actor_names(ids)
  552.     # Separates the names with comma, and "and" for the last unison actor's one
  553.     names = ""
  554.     size = ids.size
  555.     ids.each_with_index { |actor_id, index|
  556.       if index > 0 && index < size - 1
  557.         names += ", "
  558.       elsif size > 1 && index == size - 1
  559.         names += " and "
  560.       end
  561.       names += $game_actors[actor_id].name
  562.     }
  563.     names
  564.     #
  565.   end # unison_actor_names
  566.  
  567. end # Window_BattleLog
  568.  
  569. #------------------------------------------------------------------------------|
  570. #  * (Edit)Reserves unison invokees' action slots for unison skills/items      |
  571. #------------------------------------------------------------------------------|
  572. class Scene_Battle < Scene_Base
  573.  
  574.   #----------------------------------------------------------------------------|
  575.   #  (Alias)Initializes the unison action linkage tracker                      |
  576.   #----------------------------------------------------------------------------|
  577.   alias start_unison start
  578.   def start
  579.     start_unison
  580.     # Added to use a hash to track the unison action linkages
  581.     @unison_actor_ids = {}
  582.     #
  583.   end # start
  584.  
  585.   #----------------------------------------------------------------------------|
  586.   #  (Alias)Ensures the correctness of actor inputable? and item usable? check |
  587.   #----------------------------------------------------------------------------|
  588.   alias next_command_unison next_command
  589.   def next_command
  590.     # Added to update the unison linkage of the currently selected action
  591.     if (actor = BattleManager.actor) && actor.input && actor.input.item
  592.       clear_unison_actor_ids
  593.       add_unison_actor_ids unless actor.input.item.unison_actor_ids.empty?
  594.     end
  595.     #
  596.     next_command_unison
  597.   end # next_command
  598.  
  599.   #----------------------------------------------------------------------------|
  600.   #  (Alias)Ensures the correctness of unison skills/items' usability check    |
  601.   #----------------------------------------------------------------------------|
  602.   alias prior_command_unison prior_command
  603.   def prior_command
  604.     prior_command_unison
  605.     # Added to unlock the currently selected action but keep the reserved ones
  606.     return unless a = BattleManager.actor
  607.     return unless act_slots = @unison_actor_ids[[a.index, a.action_input_index]]
  608.     act_slots.each { |a_s| $game_actors[a_s[0]].temp_unison_inputs -= 1 }
  609.     #
  610.   end # prior_command
  611.  
  612.   #----------------------------------------------------------------------------|
  613.   #  (Alias)Ensures supposedly valid actions will be indeed valid as well      |
  614.   #----------------------------------------------------------------------------|
  615.   alias turn_start_unison turn_start
  616.   def turn_start
  617.     # Added to reset the links of the unison action slots to the unison invokees
  618.     @unison_actor_ids = {}
  619.     $game_party.alive_members.each { |mem|
  620.       mem.temp_unison_inputs = -1
  621.       mem.unison_inputs = nil
  622.     }
  623.     #
  624.     turn_start_unison
  625.   end # turn_start
  626.  
  627.   #----------------------------------------------------------------------------|
  628.   #  (Alias)Clears the currently selected action's unison linkage as well      |
  629.   #----------------------------------------------------------------------------|
  630.   alias clear_cur_act_unison clear_cur_act
  631.   def clear_cur_act
  632.     clear_cur_act_unison
  633.     # Added to free all reserved action slots of the unison skill/item if any
  634.     clear_unison_actor_ids
  635.     #
  636.   end # clear_cur_act
  637.  
  638.   #----------------------------------------------------------------------------|
  639.   #  (New)Sets the link of the unison action slots to the unison invokees      |
  640.   #----------------------------------------------------------------------------|
  641.   def add_unison_actor_ids
  642.     # Reserves an inputable action slot from each unison invokee
  643.     ids = (actor = BattleManager.actor).input.item.unison_actor_ids - [actor.id]
  644.     act_slots = []
  645.     index = actor.index
  646.     ids.each { |id| act_slots << add_unison_actor_id(index, id) }
  647.     @unison_actor_ids[[index, actor.action_input_index]] = act_slots
  648.     #
  649.   end # add_unison_actor_ids
  650.  
  651.   #----------------------------------------------------------------------------|
  652.   #  (v1.00b+; New)Tries not to reserve a selected inputable action slot       |
  653.   #----------------------------------------------------------------------------|
  654.   # actor_index: The index of the unison invoker of the unison skill/item
  655.   # id: The id of the unison invokee to be added
  656.   def add_unison_actor_id(actor_index, id)
  657.     # Reserves the 1st/last one if the unison invokee's prior/next actors
  658.     (a = $game_actors[id]).temp_unison_inputs += 1
  659.     index = 0
  660.     prior = a.index < actor_index
  661.     a.actions.each_with_index { |act, i|
  662.       next if act.item || (a.unison_inputs ||= []).include?(i)
  663.       prior ? (break index = i) : (next index = i)
  664.     }
  665.     a.set_unison_input_index(index, prior)
  666.     [id, index]
  667.     #
  668.   end # add_unison_actor_id
  669.  
  670.   #----------------------------------------------------------------------------|
  671.   #  (New)Clears the link of the unison action slots with the unison invokees  |
  672.   #----------------------------------------------------------------------------|
  673.   def clear_unison_actor_ids
  674.     # Frees the linked reserved action slot from each unison invokee
  675.     a = BattleManager.actor
  676.     return unless act_slots = @unison_actor_ids[[a.index, a.action_input_index]]
  677.     @unison_actor_ids.delete([a.index, a.action_input_index])
  678.     act_slots.each { |a_s| $game_actors[a_s[0]].unison_inputs.delete(a_s[1]) }
  679.     #
  680.   end # clear_unison_actor_ids
  681.  
  682. end # Scene_Battle
  683.  
  684. # Aliases methods using unison method rules
  685. DoubleX_RMVXA::YEA_BattleEngine_Unison::UNISON_DEFS.each { |klass, defs|
  686.   defs.each { |name|
  687.     name = name.id2name
  688.     eval(%Q(
  689. class #{klass[0].id2name}#{klass[1] ? " < #{klass[1].id2name}" : ""}
  690.  
  691.   alias #{name}_unison #{name}
  692.   def #{name}(*argv, &argb)
  693.     return #{name}_unison(*argv, &argb) unless @unison_item
  694.     defs = @unison_item.unison_def_actor_ids[:#{name}]
  695.     return #{name}_unison(*argv, &argb) unless defs
  696.     defs = [#{name}_unison(*argv, &argb)] + (defs - [id]).collect! { |i|
  697.     $game_actors[i].#{name}(*argv, &argb) }
  698.     rule = @unison_item.unison_rules[:#{name}]
  699.     rule ||= DoubleX_RMVXA::YEA_BattleEngine_Unison.unison_def_rule
  700.     unison_rules(defs, rule)
  701.   end
  702.  
  703. end
  704.     ))
  705.   }
  706. }
  707.  
  708. #------------------------------------------------------------------------------|
  709.  
  710. end # if $imported["DoubleX RMVXA Unison Item"]
  711.  
  712. else
  713.  
  714.   # Informs users that they didn't put YEA_BattleEngine_Clear above this script
  715.   msgbox("To use DoubleX RMVXA Unison Addon to Yanfly Engine Ace - Ace " +
  716.          "Battle Engine, put it below:\nDoubleX RMVXA Clear Addon to Yanfly " +
  717.          "Engine Ace - Ace Battle Engine\nbut above Main")
  718.  
  719. end
  720.  
  721. else
  722.  
  723.   # Informs users that they didn't put YEA-BattleEngine above this script
  724.   msgbox("To use DoubleX RMVXA Unison Addon to Yanfly Engine Ace - Ace " +
  725.          "Battle Engine, put it below:\n" +
  726.          "Yanfly Engine Ace - Ace Battle Engine\nbut above Main")
  727.  
  728. end
  729.  
  730. #==============================================================================|
Add Comment
Please, Sign In to add comment