Advertisement
Double_X

DoubleX RMMV Item Triggers v101a

Dec 17th, 2015 (edited)
511
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 Item Triggers                                            
  6.  *----------------------------------------------------------------------------
  7.  *    # Terms Of Use                                                          
  8.  *      You shall keep this plugin's Plugin Info part's contents intact      
  9.  *      You shalln't claim that this plugin's written by anyone other than    
  10.  *      DoubleX or his aliases                                                
  11.  *      None of the above applies to DoubleX or his aliases                  
  12.  *----------------------------------------------------------------------------
  13.  *    # Prerequisites                                                        
  14.  *      Abilities:                                                            
  15.  *      1. Decent Javascript coding proficiency to fully utilize this plugin  
  16.  *----------------------------------------------------------------------------
  17.  *    # Links                                                                
  18.  *      This plugin:                                                          
  19.  *      1. http://pastebin.com/Caw27X83                                      
  20.  *      Mentioned Patreon Supporters:
  21.  *      https://www.patreon.com/posts/71738797
  22.  *----------------------------------------------------------------------------
  23.  *    # Author                                                                
  24.  *      DoubleX                                                              
  25.  *----------------------------------------------------------------------------
  26.  *    # Changelog                                                            
  27.  *      v1.01a(GMT 1300 26-2-2016):                                          
  28.  *      1. ITCX and ITAX take the skill/item using them as an argument as well
  29.  *      v1.00b(GMT 1400 27-1-2016):                                          
  30.  *      1. Fixed calling current action via battler function upon action end  
  31.  *      v1.00a(GMT 1500 17-12-2015):                                          
  32.  *      1. 1st version of this plugin finished                                
  33.  *============================================================================*/
  34. /*:
  35.  * @plugindesc Sets some items to trigger some actions when conditions are met
  36.  * @author DoubleX
  37.  *
  38.  * @help
  39.  * You're supposed to edit the plugin js file directly to set notetag values
  40.  *============================================================================
  41.  *    ## Notetag Info                                                        
  42.  *----------------------------------------------------------------------------
  43.  *    # Skill/Item Notetags:                                                  
  44.  *      1. <timing item trigger: ITCX, ITAX>                                  
  45.  *         - Sets a skill/item to trigger ITAX when timing and ITCX are met  
  46.  *         - timing can be pre, post or custom timings set by you            
  47.  *         - preBattle means right before using the skill/item in battles    
  48.  *         - postBattle means right after using the skill/item in battles    
  49.  *         - preMap means right before using the skill/item outside battles  
  50.  *         - postMap means right after using the skill/item outside battles  
  51.  *         - timing must only consist of alphanumeric characters              
  52.  *         - ITCX can be set in Item Trigger Condition Functions              
  53.  *         - ITAX can be set in Item Trigger Action Functions                
  54.  *============================================================================
  55.  *    ## Plugin Call Info                                                    
  56.  *----------------------------------------------------------------------------
  57.  *    # Configuration manipulations                                          
  58.  *      1. DoubleX_RMMV.Item_Triggers.prop                                    
  59.  *         - Returns the property prop under DoubleX_RMMV.Item_Triggers      
  60.  *      2. DoubleX_RMMV.Item_Triggers.prop = function                        
  61.  *         - Sets the property prop under DoubleX_RMMV.Item_Triggers as      
  62.  *           function which will be bound to the battler upon use            
  63.  *         - No DoubleX_RMMV.Item_Triggers.prop change will be saved          
  64.  *    # Item manipulations                                                    
  65.  *      All meta.itemTriggers changes can be saved if                        
  66.  *      DoubleX RMMV Dynamic Data is used                                    
  67.  *      1. meta.itemTriggers[timing]                                          
  68.  *         - Returns the array of all ITCX-ITAX pairs of timing timing        
  69.  *      2. meta.itemTriggers[timing] = [[ITCX, ITAX], [ITCX, ITAX], ...]      
  70.  *         - Adds a new timing with some ITCX-ITAX pairs or overwrites all the
  71.  *           existing ones with those pairs if timing is an existing timing  
  72.  *      3. meta.itemTriggers[timing][i] = [ITCX, ITAX]                        
  73.  *         - Set the ith ITCX-ITAX pair as the new ITCX-ITAX pair            
  74.  *    # Battler manipulations                                                
  75.  *      1. GBB.execItemTriggers.call(battler, item, timing)                  
  76.  *         - Executes all item triggers with timing timing of item of battler
  77.  *           battler                                                          
  78.  *         - GBB is DoubleX_RMMV.Item_Triggers.Game_BattlerBase              
  79.  *============================================================================
  80.  */
  81.  
  82. "use strict";
  83. var DoubleX_RMMV = DoubleX_RMMV || {};
  84. DoubleX_RMMV["Item Triggers"] = "v1.01a";
  85.  
  86. /*============================================================================
  87.  *    ## Script Configurations                                                
  88.  *       You only need to edit this part as it's about what this script does  
  89.  *----------------------------------------------------------------------------*/
  90.  
  91. DoubleX_RMMV.Item_Triggers = {
  92.  
  93.     /*------------------------------------------------------------------------
  94.      *    Item Trigger Condition Functions                                    
  95.      *    - Setups ITCX used by <timing item trigger: ITCX, ITAX>            
  96.      *------------------------------------------------------------------------*/
  97.     /* ITCX are used at:
  98.        1. DoubleX_RMMV.Item_Triggers.Game_BattlerBase
  99.           - if (IT[trigger[0]].call(this)) { IT[trigger[1]].call(this); } in
  100.           - execItemTriggers
  101.        ITCX are Javascript functions which will be bound to the battler upon use
  102.        ITCX names can only use alphanumeric characters
  103.        item is the skill/item using the ITCX
  104.        The below ITCX are examples added to help you set your ITCX
  105.        You can freely use, rewrite and/or delete these examples */
  106.  
  107.     // Sets the item trigger condition as always true
  108.     ITC1: function(item) { return true; },
  109.  
  110.     // Sets the item trigger condition as needing switch with id x to be on
  111.     ITC2: function(item) { return $gameSwitches.value(x); },
  112.  
  113.     // Adds new ITCX here
  114.    
  115.  
  116.     /*------------------------------------------------------------------------
  117.      *    Item Trigger Action Values                                          
  118.      *    - Setups ITAX used by <timing item trigger: ITCX, ITAX>            
  119.      *------------------------------------------------------------------------*/
  120.     /* ITAX are used at:
  121.        1. DoubleX_RMMV.Item_Triggers.Game_BattlerBase
  122.           - if (IT[trigger[0]].call(this)) { IT[trigger[1]].call(this); } in
  123.           - execItemTriggers
  124.        ITAX are Javascript functions which will be bound to the battler upon use
  125.        ITAX names can only use alphanumeric characters
  126.        item is the skill/item using the ITAX
  127.        The below ITAX are examples added to help you set your ITAX
  128.        You can freely use, rewrite and/or delete these examples */
  129.  
  130.     // Sets the item trigger action as what Special Effect Escape does
  131.     ITA1: function(item) { this.hide(); },
  132.  
  133.     // Sets the item trigger action as setting the battler's hp to full
  134.     ITA2: function(item) { this._hp = this.mhp; },
  135.  
  136.     // Adds new ITAX here
  137.    
  138.  
  139. }; // DoubleX_RMMV.Item_Triggers
  140.  
  141. /*============================================================================
  142.  *    ## Plugin Implementations                                              
  143.  *       You need not edit this part as it's about how this plugin works      
  144.  *----------------------------------------------------------------------------
  145.  *    # Plugin Support Info:                                                  
  146.  *      1. Prerequisites                                                      
  147.  *         - Some Javascript coding proficiency to fully comprehend this      
  148.  *           plugin                                                          
  149.  *      2. Function documentation                                            
  150.  *         - The 1st part describes why this function's rewritten/extended for
  151.  *           rewritten/extended functions or what the function does for new  
  152.  *           functions                                                        
  153.  *         - The 2nd part describes what the arguments of the function are    
  154.  *         - The 3rd part informs which version rewritten, extended or created
  155.  *           this function                                                    
  156.  *         - The 4th part informs whether the function's rewritten or new    
  157.  *         - The 5th part informs whether the function's a real or potential  
  158.  *           hotspot                                                          
  159.  *         - The 6th part describes how this function works for new functions
  160.  *           only, and describes the parts added, removed or rewritten for    
  161.  *           rewritten or extended functions only                            
  162.  *         Example:                                                          
  163.  * /*----------------------------------------------------------------------
  164.  *  *    Why rewrite/extended/What this function does                      
  165.  *  *----------------------------------------------------------------------*/
  166. /* // arguments: What these arguments are                                    
  167.  * functionName = function(arguments) { // Version X+; Hotspot                
  168.  *     // Added/Removed/Rewritten to do something/How this function works    
  169.  *     functionContents                                                      
  170.  *     //                                                                    
  171.  * } // functionName                                                          
  172.  *----------------------------------------------------------------------------*/
  173.  
  174. (function(IT) {
  175.  
  176.     IT.DataManager = {};
  177.     var DM = IT.DataManager;
  178.  
  179.     DM.isDatabaseLoaded = DataManager.isDatabaseLoaded;
  180.     DataManager.isDatabaseLoaded = function() {
  181.         // Rewritten
  182.         return DM.isDatabaseLoaded.apply(this, arguments) && DM.loadAllNotes();
  183.         //
  184.     }; // DataManager.isDatabaseLoaded
  185.  
  186.     DM.loadAllNotes = function() {
  187.         [$dataSkills, $dataItems].forEach(function(type) {
  188.             type.forEach(function(data) {
  189.                 if (data) { DM.loadItemNotes(data); }
  190.             });
  191.         });
  192.         return true;
  193.     }; // DM.loadAllNotes
  194.  
  195.     // data: The data to have its notetags read
  196.     DM.loadItemNotes = function(data) {
  197.         var regExp = /< *(\w+) +item +trigger *: *(\w+) *, *(\w+) *>/i;
  198.         var timing, triggers;
  199.         data.meta.itemTriggers = {};
  200.         triggers = data.meta.itemTriggers;
  201.         data.note.split(/[\r\n]+/).forEach(function(line) {
  202.             if (!line.match(regExp)) { return; }
  203.             timing = RegExp.$1;
  204.             triggers[timing] = triggers[timing] || [];
  205.             triggers[timing].push([RegExp.$2, RegExp.$3]);
  206.         });
  207.     }; // DM.loadItemNotes
  208.  
  209.     IT.BattleManager = {};
  210.     var BM = IT.BattleManager;
  211.  
  212.     BM.startAction = BattleManager.startAction;
  213.     BattleManager.startAction = function() {
  214.         // Added
  215.         var item = this._subject.currentAction().item();
  216.         GBB.execItemTriggers.call(this._subject, item, "preBattle");
  217.         //
  218.         BM.startAction.apply(this, arguments);
  219.     }; // BattleManager.startAction
  220.  
  221.     BM.endAction = BattleManager.endAction;
  222.     BattleManager.endAction = function() {
  223.         BM.endAction.apply(this, arguments);
  224.         // Added
  225.         var item = this._action ? this._action.item() : null;
  226.         if (!item) { return; }
  227.         GBB.execItemTriggers.call(this._subject, item, "postBattle");
  228.         //
  229.     }; // BattleManager.endAction
  230.  
  231.     IT.Game_BattlerBase = {};
  232.     var GBB = IT.Game_BattlerBase;
  233.  
  234.     /*------------------------------------------------------------------------
  235.      *    Triggers each item action when each respective condition's met      
  236.      *------------------------------------------------------------------------*/
  237.     // timing: The timing of the item triggering its actions
  238.     GBB.execItemTriggers = function(item, timing) {
  239.         var triggers = item.meta.itemTriggers[timing];
  240.         if (!triggers) { return; }
  241.         // Calls each ITCX to see if its ITAX should be called as well
  242.         triggers.forEach(function(trigger) {
  243.             if (!IT[trigger[0]].call(this, item)) { return; }
  244.             IT[trigger[1]].call(this, item);
  245.         }, this);
  246.         //
  247.     }; // GBB.execItemTriggers
  248.  
  249.     IT.Scene_ItemBase = {};
  250.     var SIB = IT.Scene_ItemBase;
  251.  
  252.     SIB.useItem = Scene_ItemBase.prototype.useItem;
  253.     Scene_ItemBase.prototype.useItem = function() {
  254.         GBB.execItemTriggers.call(this.user(), this.item(), "preMap"); // Added
  255.         SIB.useItem.apply(this, arguments);
  256.         GBB.execItemTriggers.call(this.user(), this.item(), "postMap"); // Added
  257.     }; // Scene_ItemBase.prototype.useItem
  258.  
  259. })(DoubleX_RMMV.Item_Triggers);
  260.  
  261. /*============================================================================*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement