Advertisement
Maliki79

Mal_AttachAugments_Ext2_AugRestictions

Jun 30th, 2018 (edited)
1,079
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Maliki's Attach Augments EX2 Augment Type Restrictions
  3. // Mal_AttachAugments_Ext2_AugRestictions.js
  4. // version 1.1
  5. //=============================================================================
  6. /*:  
  7.  * @plugindesc Version 1.1 Allows you to render groups of Augments unequippable
  8.  * @author Maliki79
  9.  * @param GlobalRestrictions
  10.  * @desc Set of globally active restrict types separated by commas.  
  11.  *
  12.  * @help With this Plugin Extension, YanFly's Attach Augments can now have
  13.  * limitations placed on general Augment types that are defined by the Dev.
  14.  * These limitations are linked to the specific Equipment being Augmented.
  15.  *
  16.  * The first step is to define a Augment Restrict Type.
  17.  * This is done with the notetag:
  18.  *
  19.  * <augRestrictType: x>
  20.  *
  21.  * with x being a whole number above 0.
  22.  * (These tags work independantly of the equip type used.)
  23.  * You can tag anything with this tag, but the effect will only work with
  24.  * Augmenting Items.
  25.  *
  26.  * To lock a set of Augments by type, use the following Script Call:
  27.  *
  28.  * $gameParty.addAugmentRestrictType(item, x);
  29.  *
  30.  * where "item" is the equipment to add the restriction to and x is the
  31.  * Augment's restriction group number.
  32.  * The easiest way to use this is within the Lunatic calls when adding
  33.  * the Augment.  For example:
  34.  *
  35.  * <Augment Attach Eval: Orb>
  36.  * $gameParty.addAugmentRestrictType(item, 1);
  37.  * </Augment Attach Eval: Orb>
  38.  *
  39.  * To remove the restriction, use the following Script Call:
  40.  *
  41.  * $gameParty.removeAugmentRestrictType(item, x);
  42.  *
  43.  * Again where "item" is the equipment to add the restriction to and x is
  44.  * the Augment's restriction group number.
  45.  * Example of use:
  46.  *
  47.  * <Augment Detach Eval: Orb>
  48.  * $gameParty.removeAugmentRestrictType(item, 1);
  49.  * </Augment Detach Eval: Orb>
  50.  *
  51.  * Note that this only restricts placing of new Augments on an equip.
  52.  * Previously unrestricted items WILL REMAIN on the equip untill manually
  53.  * removed.
  54.  *
  55.  * Added Global Restriction Types.
  56.  * Global Restriction Types are Types you can added that will restrict Augments on
  57.  * ALL Weapons/Armors without having to add them to each equip manually.
  58.  * There are two ways to add these.
  59.  * The first is by adding them to the plugin parameters.
  60.  * This will take effect right at the start of your game and will persist until changed.
  61.  * The second is to use the script call $gameParty.addGlobalRType(x);
  62.  * with x being an integer abouve 0.
  63.  * You can remove the global Restriction with the script call $gameParty.removeGlobalRType(x);
  64.  * again with x being an integer.
  65.  */
  66.  
  67. var Mal = Mal || {};
  68.  
  69. Mal.Augment2Parameters = PluginManager.parameters('Mal_AttachAugments_Ext2_AugRestictions');
  70. Mal.Param = Mal.Param || {};
  71. Mal.Param.A2_Global = [];
  72.  
  73. var a2Params = Mal.Augment2Parameters['GlobalRestrictions']
  74. if (a2Params !== '') {
  75.     if (a2Params.contains(',')) {
  76.         var array = a2Params.split(',');
  77.         console.log(array);
  78.         array = array.map(function(str) {
  79.             console.log("Converting!");
  80.             return parseInt(str);
  81.     }); } else {
  82.         var array = [];
  83.         array.push(parseInt(a2Params));
  84.     };
  85. } else {
  86.     var array = [];
  87. };
  88. var array2 = [];
  89. for (var x = 0; x < array.length; x++){
  90.     if(array2.indexOf(array[x]) == -1) array2.push(array[x]);
  91. }
  92. Mal.Param.A2_Global = array2;
  93. console.log(Mal.Param.A2_Global);
  94.  
  95. var MalDBPAN1 = DataManager.processAugmentNotetags1
  96. DataManager.processAugmentNotetags1 = function(group, isWeapon) {
  97. MalDBPAN1.call(this, group, isWeapon);
  98.     for (var n = 1; n < group.length; n++) {
  99.         var obj = group[n];
  100.         if (obj) obj.augRestrict = [];
  101.     }
  102. };
  103.  
  104. var MalDBPAN2 = DataManager.processAugmentNotetags2
  105. DataManager.processAugmentNotetags2 = function(group, isWeapon) {
  106. MalDBPAN2.call(this, group, isWeapon);
  107. for (var n = 1; n < group.length; n++) {
  108.     var obj = group[n];
  109.     if (obj) obj.augRestrictType = -1;
  110.     if (obj.meta.augRestrictType) obj.augRestrictType = Number(obj.meta.augRestrictType);
  111. }
  112. };
  113.  
  114. var mal_gameParty_init = Game_Party.prototype.initialize;
  115. Game_Party.prototype.initialize = function() {
  116.     mal_gameParty_init.call(this);
  117.     this._globalAugRestricts = Mal.Param.A2_Global;
  118. };
  119.  
  120. Game_Party.prototype.addGlobalRType = function (type) {
  121.     var type = Number(type);
  122.     if (this._globalAugRestricts.indexOf(type) == -1) {
  123.         this._globalAugRestricts.push(Number(type));
  124.     };
  125. };
  126.  
  127. Game_Party.prototype.removeGlobalRType = function (type) {
  128.     var type = Number(type);
  129.     var pick = this._globalAugRestricts.indexOf(type);
  130.     if (pick == -1) return;
  131.     this._globalAugRestricts.splice(pick, 1);
  132.     };
  133.  
  134. Game_Party.prototype.addAugmentRestrictType = function(obj, type) {
  135.     if (!obj) return;
  136.     obj.augRestrict.push(type);
  137. };
  138.  
  139. Game_Party.prototype.removeAugmentRestrictType = function(obj, type) {
  140.     if (!obj) return;
  141.     var pick = obj.augRestrict.indexOf(type);
  142.     if (pick == -1) return;
  143.     obj.augRestrict.splice(pick, 1);
  144. };
  145.  
  146. Window_AugmentItemList.prototype.includes = function(item) {
  147.     if (!item) return false;
  148.     if (DataManager.isIndependent(item)) return false;
  149.     if (!this.containsType(item)) return false;
  150.     if (this.isAugTypeRestricted(item)) return false;
  151.     return true;
  152. };
  153.  
  154. Window_AugmentItemList.prototype.isAugTypeRestricted = function(item) {
  155.     var pick = Number(item.augRestrictType);
  156.     if (this._item.augRestrict.indexOf(pick) > -1) return true;
  157.     if ($gameParty._globalAugRestricts.indexOf(pick) > -1) return true;
  158.     return false;
  159. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement