Double_X

DoubleX RMMV Unison Item Config v103a

Dec 25th, 2015 (edited)
1,059
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*============================================================================
  2.  *    ## Plugin Info                                                          
  3.  *----------------------------------------------------------------------------
  4.  *    # Plugin Name                                                          
  5.  *      DoubleX RMMV Unison Item Config                                      
  6.  *----------------------------------------------------------------------------
  7.  *    # Introduction                                                          
  8.  *      In the default RMMV battle system, no skill/item needs more than 1    
  9.  *      battlers to use                                                      
  10.  *      With this plugin, you can set some skills/items to be unison ones    
  11.  *      needing more than 1 battlers to use them                              
  12.  *      Unison battlers are those needed to use the unison skill/item        
  13.  *      Unison invoker is the battler actually selecting and invoking the    
  14.  *      unison skill/item                                                    
  15.  *      Unison invokees are all unison battlers besides the unison invoker    
  16.  *      There can only be 1 unison invoker for each selected unison skill/item
  17.  *      - (v1.02a+)A synchronous unison skill/item is one without any        
  18.  *               <async unison item> notetag                                  
  19.  *      - (v1.02a+)An asynchronous unison skill/item is one with at least 1  
  20.  *               <async unison item> notetags                                
  21.  *----------------------------------------------------------------------------
  22.  *    # Terms Of Use                                                          
  23.  *      You shall keep this plugin's Plugin Info part's contents intact      
  24.  *      You shalln't claim that this plugin's written by anyone other than    
  25.  *      DoubleX or his aliases                                                
  26.  *      None of the above applies to DoubleX or his aliases                  
  27.  *----------------------------------------------------------------------------
  28.  *    # Prerequisites                                                        
  29.  *      Abilities:                                                            
  30.  *      1. Some Javascript coding proficiency to fully utilize this plugin    
  31.  *----------------------------------------------------------------------------
  32.  *    # Links                                                                
  33.  *      This plugin:                                                          
  34.  *      1. http://pastebin.com/igFhrKja                                      
  35.  *      Mentioned Patreon Supporters:
  36.  *      https://www.patreon.com/posts/71738797
  37.  *----------------------------------------------------------------------------
  38.  *    # Instructions                                                          
  39.  *      1. To use this plugin with the default battle system, place          
  40.  *         DoubleX RMMV Unison Item Default below this plugin                
  41.  *      2. To use this plugin with YEP_X_BattleSysCTB, place                  
  42.  *         DoubleX RMMV Unison Item YEP_X_BattleSysCTB below                  
  43.  *         DoubleX RMMV Unison Item Default, which should be placed below this
  44.  *         plugin                                                            
  45.  *      3. To use this plugin with YEP_X_BattleSysATB, place                  
  46.  *         DoubleX RMMV Unison Item YEP_X_BattleSysATB below                  
  47.  *         DoubleX RMMV Unison Item Default, which should be placed below this
  48.  *         plugin                                                            
  49.  *----------------------------------------------------------------------------
  50.  *    # Author                                                                
  51.  *      DoubleX                                                              
  52.  *----------------------------------------------------------------------------
  53.  *    # Changelog                                                            
  54.  *      DoubleX RMMV Unison Item YEP_X_BattleSysATB:                          
  55.  *      v1.00a(GMT 0600 21-5-2016):                                          
  56.  *      1. 1st version of this plugin finished                                
  57.  *      DoubleX RMMV Unison Item YEP_X_BattleSysCTB:                          
  58.  *      v1.00b(GMT 1300 14-5-2016):                                          
  59.  *      1. In sync with the latest version of DoubleX RMMV Unison Item Config
  60.  *      v1.00a(GMT 1500 28-2-2016):                                          
  61.  *      1. 1st version of this plugin finished                                
  62.  *      2. Unison skills/items needing charging might be executed immediately
  63.  *         and/or cause the action order queue to be incorrect and/or outdated
  64.  *      DoubleX RMMV Unison Item Default:                                    
  65.  *      v1.00f(GMT 1300 14-5-2016):                                          
  66.  *      1. Fixed a bug where unison items can have unison invokees with no    
  67.  *         empty action slots                                                
  68.  *      2. In sync with the latest version of this plugin                    
  69.  *      v1.00e(GMT 1500 30-1-2016):                                          
  70.  *      1. Fixed not passing this to canUseUnisonSkill and canUseUnisonItem  
  71.  *      2. Fixed not checking if item exist first in canUse bug              
  72.  *      3. Fixed unison invoker might not have the smallest party member index
  73.  *      v1.00d(GMT 1100 4-1-2016):                                            
  74.  *      1. Fixed all unison item being unusable due to typo bug              
  75.  *      2. Added plugin description and author name in the plugin manager    
  76.  *      v1.00c(GMT 0100 1-1-2016):                                            
  77.  *      1. Fixed undefined SceneManager.scene by using $gameParty.inBattle()  
  78.  *      v1.00b(GMT 0300 26-12-2015):                                          
  79.  *      1. Fixed unison skills/items not usable outside battles bug          
  80.  *      2. Simplified the unison skill usability checks                      
  81.  *      v1.00a(GMT 1400 25-12-2015):                                          
  82.  *      1. 1st version of this plugin finished                                
  83.  *      This plugin:                                                          
  84.  *      v1.03a(GMT 0500 23-7-2016):                                          
  85.  *      1. Added <unison item actor function drain: weights>                  
  86.  *      v1.02a(GMT 1300 14-5-2016):                                          
  87.  *      1. Added <unison item actor learn: flags> and <async unison item>    
  88.  *      v1.01b(GMT 1300 17-3-2016):                                          
  89.  *      1. Fixed undefined uIFAs[RegExp.$1] in DM.loadItemNotes bug          
  90.  *      2. Fixed incorrect unison battler stat when using unison rules bug    
  91.  *      v1.01a(GMT 1400 15-3-2016):                                          
  92.  *      1. Added <unison item actor mp cost: ids> and                        
  93.  *               <unison item actor tp cost: ids>                            
  94.  *      v1.00f(GMT 1000 28-2-2016):                                          
  95.  *      1. Fixed unison invokees not stepping forward when executing actions  
  96.  *      v1.00e(GMT 1500 30-1-2016):                                          
  97.  *      1. Fixed not returning value in makeDamageValue bug                  
  98.  *      2. Fixed not showing unison item names in the battle log window bug  
  99.  *      3. Fixed enemy using actor unison item showing unison actor names bug
  100.  *      v1.00d(GMT 0200 3-1-2016):                                            
  101.  *      1. FUNCTIONS now store all battler functions instead of merely getters
  102.  *      v1.00c(GMT 1300 31-12-2015):                                          
  103.  *      1. Fixed writing getter contents directly instead of using String bug
  104.  *      v1.00b(GMT 0900 30-12-2015):                                          
  105.  *      1. Fixed failed to extend battler property name descriptors bug      
  106.  *      2. Fixed using new Function and class instead of eval and prototype  
  107.  *      3. Fixed unintentionally declaring global variable in strict mode bug
  108.  *      4. Fixed calling push for an Object instead of its Array values bug  
  109.  *      5. Fixed using 1 single variable to store all old getter functions bug
  110.  *      v1.00a(GMT 1400 25-12-2015):                                          
  111.  *      1. 1st version of this plugin finished                                
  112.  *============================================================================*/
  113. /*:
  114.  * @plugindesc Lets you set some skills/items needing mutiple battlers to use
  115.  * @author DoubleX
  116.  *
  117.  * @param showAllUnisonBattlers
  118.  * @desc Sets if the battlelog will show all unison battlers instead of only
  119.  *       the unison invoker
  120.  * @default true
  121.  *
  122.  * @param unisonFunctionRule
  123.  * @desc Sets the string of the rule used for setting the user's functions in
  124.  *       the damage formula of the unison skill/item by using those of all
  125.  *       unison battlers
  126.  *       It'll only be used for those functions not having their unison rules
  127.  *       It must be implemented by function RULES, which must be edited by
  128.  *       opening this plugin js file directly
  129.  * @default avg
  130.  *
  131.  * @help
  132.  * The default plugin file name is DoubleX RMMV Unison Item Config v103a
  133.  * If you want to change that, you must edit the value of
  134.  * DoubleX_RMMV.Unison_Item_File, which must be done via opening this plugin
  135.  * js file directly
  136.  *============================================================================
  137.  *    ## Notetag Info                                                        
  138.  *----------------------------------------------------------------------------
  139.  *    # Skill/Item Notetags:                                                  
  140.  *      1. <unison item actors: ids>                                          
  141.  *         - Sets the list of id of actors needed for the skill/item as ids  
  142.  *           , is used to separate the actor id in ids                        
  143.  *           E.g.:                                                            
  144.  *           <unison item actors: 1> means actor with id 1 is needed to use it
  145.  *           <unison item actors: 4, 2> means actors with id 4 and 2 are      
  146.  *           needed to use it                                                
  147.  *         - All actors included in ids needs to be inputable, able to use the
  148.  *           skills/item and pay its cost                                    
  149.  *         - All unison actors will pay the unison skill costs after using it
  150.  *         - Only actors included in ids can select the skill/item            
  151.  *         - If ids only contains 1 actor id, this notetag will become only  
  152.  *           letting the actor with that actor id to use the skill/item      
  153.  *      2. <unison item function rule: rule>                                  
  154.  *         - Sets the rule of setting user's function in the skill/item's    
  155.  *           damage formula as rule which is implemented by function          
  156.  *           RULES, which must be edited by opening this plugin js file      
  157.  *           directly                                                        
  158.  *         - function must be a battler function name included in            
  159.  *           FUNCTIONS, which must be edited by opening this plugin js file  
  160.  *           directly                                                        
  161.  *      3. <unison item function actors: ids>                                
  162.  *         - Sets user's function in the skill/item's damage formula to use  
  163.  *           its unison item rule to combine those of actors with id included
  164.  *           in ids                                                          
  165.  *           E.g.:                                                            
  166.  *           <unison item atk actors: 1> means the user's atk in its damage  
  167.  *           formula uses that of actor with id 1 under the skill/item's      
  168.  *           unison rule applied to atk                                      
  169.  *           <unison item mat actors: 4, 2> means the user's mat in its damage
  170.  *           formula uses those of actors with id 4 and 2 under the          
  171.  *           skill/item's unison rule applied to mat                          
  172.  *         - function must be a battler function name included in            
  173.  *           FUNCTIONS, which must be edited by opening this plugin js file  
  174.  *           directly                                                        
  175.  *      4. (v1.01a+)<unison item actor mp cost: costs>                        
  176.  *         - Sets the list of mp costs needed for each of the corresponding id
  177.  *           of the unison actor in <unison item actors: ids>                
  178.  *           , is used to separate the mp costs in ids                        
  179.  *           E.g.:                                                            
  180.  *           If <unison item actors: 1> is used, then                        
  181.  *           <unison item actor mp cost: 5> means actor with id 1 needs to pay
  182.  *           the 5 mp cost for using the unison skill/item                    
  183.  *           If <unison item actors: 4, 2> is used, then                      
  184.  *           <unison item actor mp cost: 5, 10> means actor with id 4 and 2  
  185.  *           need to pay the 5 and 10 mp cost respectively for using the      
  186.  *           unison skill/item                                                
  187.  *           If <unison item actors: 4, 2> is used, then                      
  188.  *           <unison item actor mp cost: 5> means actor with id 4 needs to pay
  189.  *           the 5 mp cost while that with id 2 needs to pay the default      
  190.  *           skill/item mp cost for using the unison skill/item              
  191.  *         - MCR will be applied to the mp costs for all unison actors        
  192.  *      5. (v1.01a+)<unison item actor tp cost: costs>                        
  193.  *         - Sets the list of tp costs needed for each of the corresponding id
  194.  *           of the unison actor in <unison item actors: ids>                
  195.  *           , is used to separate the tp costs in ids                        
  196.  *           E.g.:                                                            
  197.  *           If <unison item actors: 1> is used, then                        
  198.  *           <unison item actor tp cost: 5> means actor with id 1 needs to pay
  199.  *           the 5 tp cost for using the unison skill/item                    
  200.  *           If <unison item actors: 4, 2> is used, then                      
  201.  *           <unison item actor tp cost: 5, 10> means actor with id 4 and 2  
  202.  *           need to pay the 5 and 10 tp cost respectively for using the      
  203.  *           unison skill/item                                                
  204.  *           If <unison item actors: 4, 2> is used, then                      
  205.  *           <unison item actor tp cost: 5> means actor with id 4 needs to pay
  206.  *           the 5 tp cost while that with id 2 needs to pay the default      
  207.  *           skill/item tp cost for using the unison skill/item              
  208.  *      6. (v1.02a+)<unison item actor learn: flags>                          
  209.  *         - Sets the list of skill learn requirement flags for each of the  
  210.  *           corresponding id of the unison actor in <unison item actors: ids>
  211.  *           , is used to separate the skill learn requirement flags          
  212.  *           Flag can be either t or f, meaning true or false respectively    
  213.  *           The default unison skill learn requirement is true              
  214.  *           This notetag only works on skills and has no effects on items    
  215.  *           E.g.:                                                            
  216.  *           If <unison item actors: 1> is used, then                        
  217.  *           <unison item actor skill learn: t> means actor with id 1 needs to
  218.  *           learn the skill in order to use it                              
  219.  *           If <unison item actors: 4, 2> is used, then                      
  220.  *           <unison item actor skill learn: t, f> means actor with id 4 needs
  221.  *           to learn the skill in order to use it while actor with id 2      
  222.  *           doesn't need to                                                  
  223.  *           If <unison item actors: 4, 2> is used, then                      
  224.  *           <unison item actor skill learn: f> means actor with id 4 doesn't
  225.  *           need to learn the skill in order to use it while actor with id 2
  226.  *           needs to due to the default unison skill learn requirement      
  227.  *      7. (v1.02a+)<async unison item>                                      
  228.  *         - Sets the unison skill/item to be inputable when any battler      
  229.  *           needed for that skill/item is inputable                          
  230.  *         - That skill/item and all battlers inputted it will wait for all  
  231.  *           battlers needed for that skill/item to input it in order for them
  232.  *           to execute it altogether                                        
  233.  *         - This notetag will be ignored in the default RMMV battle system  
  234.  *           and all unison skills/items will be synchronous ones            
  235.  *         - This notetag will be ignored in ATB systems that will always wait
  236.  *           when there are inputable actors and all unison skills/items will
  237.  *           be asynchronous ones                                            
  238.  *      8. (v1.03a+)<unison item actor function drain: weights>              
  239.  *         - Sets user's drained hp/mp/etc for skills/items draining hp/mp/etc
  240.  *           to use redistribute the drained hp/mp/etc to all those of actors
  241.  *           with id included in ids in <unison item actors: ids>            
  242.  *         - function must be a battler getter name                          
  243.  *         - The redistribution amount to each actor is the minimum value of  
  244.  *           the corresponding weight / sum of weights and the difference    
  245.  *           between the hp and the mhp                                      
  246.  *         - If the sum of weights is 0, then no actor will receive any amount
  247.  *           of the drained hp/mp/etc                                        
  248.  *         - All the undistributed drained hp/mp/etc will be taken by the    
  249.  *           unison invoker, and any amount left by the unison invoker will be
  250.  *           lost                                                            
  251.  *           E.g.:                                                            
  252.  *           If <unison item actors: 1> is used, then                        
  253.  *           <unison item actor hp drain: 0> means actor with id 1 won't      
  254.  *           receive any drained hp from skills/items draining hp            
  255.  *           If <unison item actors: 4, 2> is used, then                      
  256.  *           <unison item actor mp drain: 1, 2> means actor with id 4 and 2  
  257.  *           will receive 1/3 and 2/3 of the drained mp from skills/items    
  258.  *           draining mp respectively                                        
  259.  *           If <unison item actors: 4, 2> is used, then                      
  260.  *           <unison item actor mp cost: 1> means actor with id 4 and 2 will  
  261.  *           receive 100% and 0% of the drained mp from skills/items draining
  262.  *           mp respectively                                                  
  263.  *============================================================================
  264.  *    ## Plugin Call Info                                                    
  265.  *----------------------------------------------------------------------------
  266.  *    # Configuration manipulations                                          
  267.  *      1. DoubleX_RMMV.Unison_Item.prop                                      
  268.  *         - Returns the property prop under DoubleX_RMMV.Unison_Item        
  269.  *      2. DoubleX_RMMV.Unison_Item.prop = val                                
  270.  *         - Sets the property prop under DoubleX_RMMV.Unison_Item as val    
  271.  *         - No DoubleX_RMMV.Unison_Item.prop change will be saved            
  272.  *      3. $gameSystem.unisonItem.param                                      
  273.  *         - Returns the value of param listed in the plugin manager          
  274.  *      4. $gameSystem.unisonItem.param = val                                
  275.  *         - Sets the value of param listed in the plugin manager as val      
  276.  *         - All $gameSystem.unisonItem.param changes will be saved          
  277.  *    # Skill/Item manipulations                                              
  278.  *      1. meta.unisonItemActors                                              
  279.  *         - Returns the Array of ids of actors needed to use this skill/item
  280.  *      2. meta.unisonItemActors = [id, id, ...]                              
  281.  *         - Sets the Array of ids of actors needed to use this skill/item    
  282.  *         - All meta.unisonItemActors changes can be saved if                
  283.  *           DoubleX RMMV Dynamic Data is used                                
  284.  *      3. meta.unisonItemRules[functionName]                                
  285.  *         - Returns the unison item rule as String for function with name    
  286.  *           functionName as a String                                        
  287.  *      4. meta.unisonItemRules[functionName] = rule                          
  288.  *         - Sets the unison item rule for function with name functionName as
  289.  *           String as String rule, which must be implemented by              
  290.  *           RULES, which must be edited by opening this plugin js file      
  291.  *           directly                                                        
  292.  *         - function with name functionName must be included in              
  293.  *           FUNCTIONS, which must be edited by opening this plugin js file  
  294.  *           directly                                                        
  295.  *         - All meta.unisonItemRules changes can be saved if                
  296.  *           DoubleX RMMV Dynamic Data is used                                
  297.  *      5. meta.unisonItemFunctionActors[functionName]                        
  298.  *         - Returns the Array of ids of actors included for combining their  
  299.  *           function functionName as String using its unison item rule      
  300.  *      6. meta.unisonItemFunctionActors[functionName] = [id, id, ...]        
  301.  *         - Sets the Array of ids of actors included for combining their    
  302.  *           function functionName as String using its unison item rule      
  303.  *         - function with name functionName must be included in              
  304.  *           FUNCTIONS, which must be edited by opening this plugin js file  
  305.  *           directly                                                        
  306.  *         - All meta.unisonItemFunctionActors changes can be saved if        
  307.  *           DoubleX RMMV Dynamic Data is used                                
  308.  *      7. (v1.01a+)meta.unisonItemActorMpCosts                              
  309.  *         - Returns the Array of mp costs each needed by its corresponding  
  310.  *           actor with id in meta.unisonItemActors to use this skill/item    
  311.  *      8. (v1.01a+)meta.unisonItemActorMpCosts = [cost, cost, ...]          
  312.  *         - Sets the Array of of mp costs each needed by its corresponding  
  313.  *           actor with id in meta.unisonItemActors to use this skill/item    
  314.  *         - All meta.unisonItemActorMpCosts changes can be saved if          
  315.  *           DoubleX RMMV Dynamic Data is used                                
  316.  *      9. (v1.01a+)meta.unisonItemActorTpCosts                              
  317.  *         - Returns the Array of tp costs each needed by its corresponding  
  318.  *           actor with id in meta.unisonItemActors to use this skill/item    
  319.  *      10. (v1.01a+)meta.unisonItemActorTpCosts = [cost, cost, ...]          
  320.  *          - Sets the Array of of tp costs each needed by its corresponding  
  321.  *            actor with id in meta.unisonItemActors to use this skill/item  
  322.  *          - All meta.unisonItemActorTpCosts changes can be saved if        
  323.  *            DoubleX RMMV Dynamic Data is used                              
  324.  *      11. (v1.02a+)meta.unisonItemActorLearn                                
  325.  *          - Returns the Array of skill learn requirement flags for each    
  326.  *            corresponding actor with id in meta.unisonItemActors to use this
  327.  *            skill/item                                                      
  328.  *      12. (v1.02a+)meta.unisonItemActorLearn = [cost, cost, ...]            
  329.  *          - Sets the Array of skill requirement flags for each corresponding
  330.  *            actor with id in meta.unisonItemActors to use this skill/item  
  331.  *          - All meta.unisonItemActorTpCosts changes can be saved if        
  332.  *            DoubleX RMMV Dynamic Data is used                              
  333.  *      13. (v1.02a+)meta.asyncUnisonItem                                    
  334.  *          - Returns whether the unison skill/item is an asynchronous one    
  335.  *      14. (v1.02a+)meta.asyncUnisonItem = boolean                          
  336.  *          - Sets the unison skill/item to be an asynchronous one if boolean
  337.  *            is true and a synchronous one if otherwise                      
  338.  *      15. (v1.03a+)meta.unisonItemActorFunctionDrain[functionName]          
  339.  *          - Returns the Array of weights for actors included in the        
  340.  *            corresponding meta.unisonItemActors for redistributing the      
  341.  *            drained function functionName  as String from skills/items      
  342.  *            draining functionName to all those actors                      
  343.  *      16. (v1.03a+)meta.unisonItemActorFunctionDrain[functionName] = [w, ..]
  344.  *          - Sets the Array of weights for actors included in the            
  345.  *            corresponding meta.unisonItemActors for redistributing the      
  346.  *            drained function functionName  as String from skills/items      
  347.  *            draining functionName to all those actors                      
  348.  *          - function with name functionName must be a battler getter name  
  349.  *          - All meta.unisonItemActorFunctionDrain changes can be saved if  
  350.  *            DoubleX RMMV Dynamic Data is used                              
  351.  *============================================================================
  352.  */
  353.  
  354. var DoubleX_RMMV = DoubleX_RMMV || {};
  355. DoubleX_RMMV["Unison Item Config"] = 'v1.03a';
  356.  
  357. // The plugin file name must be the same as DoubleX_RMMV.Unison_Item_Config_File
  358. DoubleX_RMMV.Unison_Item_Config_File = 'DoubleX RMMV Unison Item Config v103a';
  359.  
  360. /*============================================================================
  361.  *    ## Plugin Configurations                                                
  362.  *       You only need to edit this part as it's about what this plugin does  
  363.  *----------------------------------------------------------------------------*/
  364.  
  365. DoubleX_RMMV.Unison_Item = {
  366.  
  367.     /* Implements the unison item function rules
  368.      * The unison item function rule can be referenced by rule
  369.      * The Array of unison item function value of all unison battlers can be
  370.      * referneced by vals
  371.      * RULES will be bound to the unison invoker upon use
  372.      * It must return a Number
  373.      */
  374.     RULES: function(rule, vals) {
  375.         if (rule === 'min') {
  376.             return vals.sort(function(a, b) { return a - b; })[0];
  377.         } else if (rule === 'avg') {
  378.             return vals.reduce(function(a, b) { return a + b; }) / vals.length;
  379.         } else if (rule === 'max') {
  380.             return vals.sort(function(a, b) { return b - a; })[0];
  381.         }
  382.         console.log('The unison item rule ' + rule + " isn't implemented");
  383.         return 0;
  384.     },
  385.  
  386.     /* Sets the battler functions using the unison item rules
  387.      * Its function names must be the class of the battler functions
  388.      * Its values must be those battler functions as Strings
  389.      * All the included battler functions will be extended
  390.      */
  391.     FUNCTIONS: {
  392.  
  393.       /* General form:
  394.        * class: [
  395.        *     'battler function name',
  396.        *     'battler function name',
  397.        *     'battler function name',
  398.        *     ...,
  399.        *     'battler function name'
  400.        * ]
  401.        */
  402.  
  403.         Game_BattlerBase: [
  404.             'param',
  405.             'xparam',
  406.             'sparam'
  407.             // Adds new battler function names here
  408.            
  409.         ]
  410.  
  411.         // Adds new classes here
  412.        
  413.  
  414.     }
  415.  
  416. }; // DoubleX_RMMV.Unison_Item
  417.  
  418. /*============================================================================
  419.  *    ## Plugin Implementations                                              
  420.  *       You need not edit this part as it's about how this plugin works      
  421.  *----------------------------------------------------------------------------
  422.  *    # Plugin Support Info:                                                  
  423.  *      1. Prerequisites                                                      
  424.  *         - Solid understanding to the implementation parts independent from
  425.  *           any action input nor execution flows in battles                  
  426.  *         - Decent battled related RMMV plugin developement proficiency to  
  427.  *           fully comprehend this plugin                                    
  428.  *      2. Function documentation                                            
  429.  *         - The 1st part describes why this function's rewritten/extended for
  430.  *           rewritten/extended functions or what the function does for new  
  431.  *           functions                                                        
  432.  *         - The 2nd part describes what the arguments of the function are    
  433.  *         - The 3rd part informs which version rewritten, extended or created
  434.  *           this function                                                    
  435.  *         - The 4th part informs whether the function's rewritten or new    
  436.  *         - The 5th part informs whether the function's a real or potential  
  437.  *           hotspot                                                          
  438.  *         - The 6th part describes how this function works for new functions
  439.  *           only, and describes the parts added, removed or rewritten for    
  440.  *           rewritten or extended functions only                            
  441.  *         Example:                                                          
  442.  * /*----------------------------------------------------------------------
  443.  *  *    Why rewrite/extended/What this function does                      
  444.  *  *----------------------------------------------------------------------*/
  445. /* // arguments: What these arguments are                                    
  446.  * functionName = function(arguments) { // Version X+; Hotspot                
  447.  *     // Added/Removed/Rewritten to do something/How this function works    
  448.  *     functionContents                                                      
  449.  *     //                                                                    
  450.  * } // functionName                                                          
  451.  *----------------------------------------------------------------------------*/
  452.  
  453. (function(UI) {
  454.  
  455.     'use strict';
  456.  
  457.     UI.DataManager = {};
  458.     var DM = UI.DataManager;
  459.  
  460.     DM.isDatabaseLoaded = DataManager.isDatabaseLoaded;
  461.     DataManager.isDatabaseLoaded = function() {
  462.         // Rewritten
  463.         return DM.isDatabaseLoaded.apply(this, arguments) && DM.loadAllNotes();
  464.         //
  465.     }; // DataManager.isDatabaseLoaded
  466.  
  467.     DM.loadAllNotes = function() {
  468.         [$dataSkills, $dataItems].forEach(function(type) {
  469.             type.forEach(function(data) {
  470.                 if (data) { DM.loadItemNotes(data); }
  471.             });
  472.         });
  473.         return true;
  474.     }; // DM.loadAllNotes
  475.  
  476.     // data: The data to have its notetags read
  477.     DM.loadItemNotes = function(data) {
  478.         var uIAs = data.meta.unisonItemActors = [];
  479.         var uIRs = data.meta.unisonItemRules = {};
  480.         var uIFAs = data.meta.unisonItemFunctionActors = {};
  481.         var uIAMCs = data.meta.unisonItemActorMpCosts = [];
  482.         var uIATCs = data.meta.unisonItemActorTpCosts= [];
  483.         var uIASLs = data.meta.unisonItemActorLearn = [];
  484.         var uIAFDs = data.meta.unisonItemActorFunctionDrain = {};
  485.         var actors = /< *unison +item +actors *: *(\d+(?: *, *\d+)*) *>/i;
  486.         var rule = /< *unison +item +(\w+) +rule*: *(\w+) *>/i;
  487.         var fAs = /< *unison +item +(\w+) +actors *: *(\d+(?: *, *\d+)*) *>/i;
  488.         var MCs = /< *unison +item +actor +mp +cost *: *(\d+(?: *, *\d+)*) *>/i;
  489.         var TCs = /< *unison +item +actor +tp +cost *: *(\d+(?: *, *\d+)*) *>/i;
  490.         var SLs = /< *unison +item +actor +learn *: *(\w+(?: *, *\w+)*) *>/i;
  491.         var async = /< *async +unison +item *>/i, func;
  492.         var aFDs = /<unison +item +actor +(\w+) +drain:(\d+(?: *, *\d+)*)>/i;
  493.         data.note.split(/[\r\n]+/).forEach(function(line) {
  494.             if (line.match(rule)) { return uIRs[RegExp.$1] = RegExp.$2; }
  495.             if (line.match(async)) { return data.meta.asyncUnisonItem = true; }
  496.             if (line.match(actors)) { return DM.storeItemNotes(uIAs); }
  497.             if (line.match(MCs)) { return DM.storeItemNotes(uIAMCs); }
  498.             if (line.match(TCs)) { return DM.storeItemNotes(uIATCs); }
  499.             if (line.match(SLs)) {
  500.                 if (uIASLs.length > 0) { return; }
  501.                 RegExp.$1.trim().split(/,/).forEach(function(id) {
  502.                     uIASLs.push(id === 't');
  503.                 });
  504.             } else if (line.match(fAs)) {
  505.                 func = RegExp.$1;
  506.                 uIFAs[func] = uIFAs[func] || [];
  507.                 if (uIFAs[func].length > 0) { return; }
  508.                 RegExp.$2.trim().split(/,/).forEach(function(id) {
  509.                     uIFAs[func].push(+id);
  510.                 });
  511.             } else if (line.match(aFDs)) {
  512.                 func = RegExp.$1;
  513.                 uIAFDs[func] = uuIAFDs[func] || [];
  514.                 if (uIAFDs[func].length > 0) { return; }
  515.                 RegExp.$2.trim().split(/,/).forEach(function(id) {
  516.                     uIAFDs[func].push(+id);
  517.                 });
  518.             }
  519.         });
  520.     }; // DM.loadItemNotes
  521.  
  522.     // list: A list storing all the effective values of a notetag
  523.     DM.storeItemNotes = function(list) { // v1.02a+
  524.         if (list.length > 0) { return; }
  525.         RegExp.$1.trim().split(/,/).forEach(function(id) { list.push(+id); });
  526.     }; // DM.storeItemNotes
  527.  
  528.     UI.BattleManager = {};
  529.     var BM = UI.BattleManager;
  530.  
  531.     BM.endAction = BattleManager.endAction;
  532.     BattleManager.endAction = function() { // v1.00f+
  533.         this._action.item().meta.unisonItemActors.forEach(function(actorId) {
  534.             if (actorId === this._subject.actorId()) { return; }
  535.             $gameActors.actor(actorId).performActionEnd();
  536.         }, this);
  537.         BM.endAction.apply(this, arguments);
  538.     }; // BattleManager.endAction
  539.  
  540.     UI.Game_System = {};
  541.     var GS = UI.Game_System;
  542.  
  543.     /*------------------------------------------------------------------------
  544.      *    New public instance variable                                        
  545.      *------------------------------------------------------------------------*/
  546.     // The storage of all configuration values
  547.     Object.defineProperty(Game_System.prototype, 'unisonItem', {
  548.         get: function() { return this._unisonItem; },
  549.         configurable: true
  550.     });
  551.  
  552.     GS.initialize = Game_System.prototype.initialize;
  553.     Game_System.prototype.initialize = function() {
  554.         GS.initialize.apply(this, arguments);
  555.         GS.initUnisonItemParams.call(this); // Added
  556.     }; // Game_System.prototype.initialize
  557.  
  558.     GS.initUnisonItemParams = function() {
  559.         var params;
  560.         this._unisonItem = {};
  561.         params = PluginManager.parameters(DoubleX_RMMV.Unison_Item_Config_File);
  562.         Object.keys(params).forEach(function(param) {
  563.             this._unisonItem[param] = params[param] === 'true';
  564.         }, this);
  565.         this._unisonItem.unisonFunctionRule = params.unisonFunctionRule;
  566.     }; // GS.initUnisonItemParams
  567.  
  568.     UI.Game_Action = {};
  569.     var GA = UI.Game_Action;
  570.  
  571.     GA.makeDamageValue = Game_Action.prototype.makeDamageValue;
  572.     Game_Action.prototype.makeDamageValue = function(target, critical) {
  573.         // Added to set all user functions to use their unison item rules
  574.         var item = this.item(), subject = this.subject();
  575.         if (subject.isActor() && item.meta.unisonItemActors.length > 1) {
  576.             subject.unisonItem = item;
  577.         }
  578.         //
  579.         var value = GA.makeDamageValue.apply(this, arguments);
  580.         subject.unisonItem = null; // Added to set all user functions to normal
  581.         return value;
  582.     }; // Game_Action.prototype.makeDamageValue
  583.  
  584.     GA.gainDrainedHp = Game_Action.prototype.gainDrainedHp;
  585.     Game_Action.prototype.gainDrainedHp = function(v) { // v1.03a+
  586.         // Rewritten
  587.         if (!this.isDrain()) { return; }
  588.         GA.gainUnisonDrainedFunc.call(this, 'hp', 0, 'mhp', 'gainDrainedHp', v);
  589.         //
  590.     }; // Game_Action.prototype.gainDrainedHp
  591.  
  592.     GA.gainDrainedMp = Game_Action.prototype.gainDrainedMp;
  593.     Game_Action.prototype.gainDrainedMp = function(v) { // v1.03a+
  594.         // Rewritten
  595.         if (!this.isDrain()) { return; }
  596.         GA.gainUnisonDrainedFunc.call(this, 'mp', 0, 'mmp', 'gainDrainedMp', v);
  597.         //
  598.     }; // Game_Action.prototype.gainDrainedMp
  599.  
  600.     GA.gainUnisonDrainedFunc = function(func, min, max, drainFunc, value) {
  601.     // v1.03a+
  602.         var subject = this.subject();
  603.         if (!subject.isActor()) { return GA[drainFunc].call(this, value); }
  604.         var item = this.item(), mems = item.meta.unisonItemActors;
  605.         if (mems.length <= 1) { return GA[drainFunc].call(this, value); }
  606.         var actorId = subject.actorId(), index = mems.indexOf(actorId);
  607.         if (index >= 0) { mems.splice(index, 1); }
  608.         mems.push(actorId);
  609.         var weights = item.meta.unisonItemActorFunctionDrain[func];
  610.         var weightSum = weights.reduce(function(a, b) { return a + b; }, 0);
  611.         if (weightSum === 0) { return; }
  612.         var statChange, newStat, maxStat, mem, weight;
  613.         for (var index = 0, length = mems.length; index < length; index++) {
  614.             weight = weights[index];
  615.             if (!weight) { continue; }
  616.             statChange = Math.trunc(value * weight / weightSum);
  617.             mem = $gameActors.actor(mems[index]);
  618.             maxStat = mem[max], newStat = mem[func] + statChange;
  619.             if (newStat < min) {
  620.                 statChange = min - mem[func];
  621.             } else if (newStat > maxStat) {
  622.                 statChange = maxStat - mem[func];
  623.             }
  624.             GA[drainFunc].call(this, statChange);
  625.             statDiff -= statChange, weightSum -= weight;
  626.         }
  627.     }; // GA.gainUnisonDrainedFunc
  628.  
  629.     UI.Game_BattlerBase = {}; // v1.01a+
  630.     var GBB = UI.Game_BattlerBase;
  631.  
  632.     GBB.skillMpCost = Game_BattlerBase.prototype.skillMpCost;
  633.     Game_BattlerBase.prototype.skillMpCost = function(skill) {
  634.         // Rewritten to return mp cost in <unison item actor mp cost: costs>
  635.         var cost = 'unisonItemActorMpCosts', func = 'skillMpCost';
  636.         return GBB.unisonSkillCost.call(this, skill, cost, func);
  637.         //
  638.     }; // Game_BattlerBase.prototype.skillMpCost
  639.  
  640.     GBB.skillTpCost = Game_BattlerBase.prototype.skillTpCost;
  641.     Game_BattlerBase.prototype.skillTpCost = function(skill) {
  642.         // Rewritten to return tp cost in <unison item actor tp cost: costs>
  643.         var cost = 'unisonItemActorTpCosts', func = 'skillTpCost';
  644.         return GBB.unisonSkillCost.call(this, skill, cost, func);
  645.         //
  646.     }; // Game_BattlerBase.prototype.skillTpCost
  647.  
  648.     GBB.unisonSkillCost = function(skill, cost, func) { // v1.02a+
  649.         if (this.isActor()) {
  650.             var index = skill.meta.unisonItemActors.indexOf(this.actorId());
  651.             if (index >= 0) {
  652.                 var unisonCost = skill.meta[cost][index];
  653.                 if (!isNaN(unisonCost)) { return unisonCost; }
  654.             }
  655.         }
  656.         //
  657.         return GBB[func].apply(this, arguments);
  658.     }; // GBB.unisonSkillCost
  659.  
  660.     UI.Game_Battler = {};
  661.     var GB = UI.Game_Battler;
  662.  
  663.     /*------------------------------------------------------------------------
  664.      *    New public instance variables                                      
  665.      *------------------------------------------------------------------------*/
  666.     Object.defineProperties(Game_Battler.prototype, {
  667.         // Read by Game_BattlerBase to get the other battlers' action slot list
  668.         'actions': {
  669.             get: function() { return this._actions; },
  670.             configurable: true
  671.         },
  672.         // The cached unison skill/item when executing its damage formula
  673.         'unisonItem': {
  674.             set: function(item) { this._unisonItem = item; },
  675.             configurable: true
  676.         }
  677.     });
  678.  
  679.     GB.useItem = Game_Battler.prototype.useItem;
  680.     Game_Battler.prototype.useItem = function(item) {
  681.         // Rewritten to ask all unison invokees to pay the skill/item cost only
  682.         if (!DataManager.isSkill(item)) {
  683.             return GB.useItem.apply(this, arguments);
  684.         } else if (item.meta.unisonItemActors.length <= 1) {
  685.             return GB.useItem.apply(this, arguments);
  686.         }
  687.         item.meta.unisonItemActors.forEach(function(actorId) {
  688.             $gameActors.actor(actorId).paySkillCost(item);
  689.         });
  690.         //
  691.     }; // Game_Battler.prototype.useItem
  692.  
  693.     UI.Window_ItemList = {};
  694.     var WIL = UI.Window_ItemList;
  695.  
  696.     WIL.isEnabled = Window_ItemList.prototype.isEnabled;
  697.     Window_ItemList.prototype.isEnabled = function(item) {
  698.         // Rewritten to disable unison items when unison conditions aren't met
  699.         if (!DataManager.isItem(item)) {
  700.             return WIL.isEnabled.apply(this, arguments);
  701.         } else if (item.meta.unisonItemActors.length <= 1) {
  702.             return WIL.isEnabled.apply(this, arguments);
  703.         } else if (!$gameParty.inBattle()) {
  704.             return WIL.isEnabled.apply(this, arguments);
  705.         }
  706.         var actor = BattleManager.actor();
  707.         return actor && actor.canUse(item);
  708.         //
  709.     }; // Window_ItemList.prototype.isEnabled
  710.  
  711.     UI.Window_BattleLog = {};
  712.     var WBL = UI.Window_BattleLog;
  713.  
  714.     WBL.performActionStart = Window_BattleLog.prototype.performActionStart;
  715.     Window_BattleLog.prototype.performActionStart = function(subject, action) {
  716.     // v1.00f+
  717.         // Rewritten to ask all unison actor sprites to perform act start
  718.         action.item().meta.unisonItemActors.forEach(function(actorId) {
  719.             $gameActors.actor(actorId).performActionStart(action);
  720.         });
  721.         //
  722.     }; // Window_BattleLog.prototype.performActionStart
  723.  
  724.     WBL.performAction = Window_BattleLog.prototype.performAction;
  725.     Window_BattleLog.prototype.performAction = function(subject, action) {
  726.     // v1.00f+
  727.         // Rewritten to ask all unison actor sprites to perform act
  728.         action.item().meta.unisonItemActors.forEach(function(actorId) {
  729.             $gameActors.actor(actorId).performAction(action);
  730.         });
  731.         //
  732.     }; // Window_BattleLog.prototype.performActionStart
  733.  
  734.     WBL.displayAction = Window_BattleLog.prototype.displayAction;
  735.     Window_BattleLog.prototype.displayAction = function(subject, item) {
  736.         // Rewritten to display all unison actor names if users set so
  737.         if (!subject.isActor()) {
  738.             return WBL.displayAction.apply(this, arguments);
  739.         } else if (!$gameSystem.unisonItem.showAllUnisonBattlers) {
  740.             return WBL.displayAction.apply(this, arguments);
  741.         } else if (item.meta.unisonItemActors.length <= 1) {
  742.             return WBL.displayAction.apply(this, arguments);
  743.         }
  744.         WBL.displayUnisonAct.call(this, item);
  745.         //
  746.     }; // Window_BattleLog.prototype.displayAction
  747.  
  748.     WBL.displayUnisonAct = function(item) {
  749.         var names = WBL.unisonActorNames(item.meta.unisonItemActors);
  750.         var numMethods = this._methods.length;
  751.         if (DataManager.isSkill(item)) {
  752.             if (item.message1) {
  753.                 this.push('addText', names + item.message1.format(item.name));
  754.             }
  755.             if (item.message2) {
  756.                 this.push('addText', item.message2.format(item.name));
  757.             }
  758.         } else {
  759.             var text = TextManager.useItem.format(names, item.name);
  760.             this.push('addText', text);
  761.         }
  762.         if (this._methods.length === numMethods) { this.push('wait'); }
  763.     }; // WBL.displayUnisonAct
  764.  
  765.     WBL.unisonActorNames = function(actorIds) {
  766.         var names = '';
  767.         for (var index = 0, length = actorIds.length; index < length; index++) {
  768.             if (index > 0 && index < length - 1) {
  769.                 names += ', ';
  770.             } else if (index === length - 1) {
  771.                 names += ' and ';
  772.             }
  773.             names += $gameActors.actor(actorIds[index]).name();
  774.         }
  775.         return names;
  776.     }; // WBL.unisonActorNames
  777.  
  778.     var Proto;
  779.     for (var Klass in UI.FUNCTIONS) {
  780.         if (!UI.FUNCTIONS.hasOwnProperty(Klass)) { continue; }
  781.         // Ensures container GBB and GB won't be rewritten
  782.         UI[Klass] = UI[Klass] || {};
  783.         //
  784.         Proto = eval(Klass + '.prototype'); // Actual class prototype
  785.         UI.FUNCTIONS[Klass].forEach(function(f) {
  786.  
  787.             /*------------------------------------------------------------
  788.              *    Extends all battler functions using unison item rules  
  789.              *------------------------------------------------------------*/
  790.             UI[Klass][f] = Proto[f];
  791.             Proto[f] = new Function([
  792.                 'var UI = DoubleX_RMMV.Unison_Item, item = this._unisonItem;',
  793.                 'if (!item) {',
  794.                 '    return UI.' + Klass + '.' + f + '.apply(this, arguments);',
  795.                 '}',
  796.                 'var actorIds = item.meta.unisonItemFunctionActors.' + f + ';',
  797.                 'if (!actorIds) {',
  798.                 '    return UI.' + Klass + '.' + f + '.apply(this, arguments);',
  799.                 '}',
  800.                 'var args = arguments;',
  801.                 'var vals = actorIds.map(function(actorId) {',
  802.                 '    var actor = $gameActors.actor(actorId);',
  803.                 '    return UI.' + Klass + '.' + f + '.apply(actor, args);',
  804.                 '});',
  805.                 'var rule = item.meta.unisonItemRules.' + f + ';',
  806.                 'rule = rule || $gameSystem.unisonItem.unisonFunctionRule;',
  807.                 'return UI.RULES.call(this, rule, vals);',
  808.             ].join('\n'));
  809.  
  810.         });
  811.     }
  812.  
  813. })(DoubleX_RMMV.Unison_Item);
  814.  
  815. /*============================================================================*/
Add Comment
Please, Sign In to add comment