Maliki79

Mal_AttachAugments_Ext

Jul 5th, 2016
875
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Maliki's Attach Augments EX
  3. // Mal_AttachAugments_Ext.js
  4. // version 1.5b
  5. //=============================================================================
  6. /*:  
  7.  * @plugindesc Version 1.5b Allows you to preset Augments on items.  Also allows for mandatory slot fills.
  8.  * @author Maliki79
  9.  * @help You need two steps to use this plugin:
  10.  * 1: To set an item's pre-loaded Augments add this tag to the item's note
  11.  * field: <preAugment: "item" number, etc, none>
  12.  *
  13.  *    where "item" is the augment's type in the database(item, weapon, or armor)
  14.  *    and number is the item Id.
  15.  *    Augment slots left open must have "none" in that slot's place on the list.
  16.  *
  17.  * Example: <preAugment:item 1, armor 2, none, weapon 1>
  18.  *
  19.  * This will add item 1 to the item's first Augment slot, armor 2 to the second,
  20.  * nothing to the third and weapon 1 to the forth.
  21.  * Note that you can put ANY item in the slots, but bear YanFly's rules regarding
  22.  * non-instance items in mind to prevent potential issues.
  23.  *
  24.  * Example 2: <preAugment:item 1 or item 2, armor 2, none or armor 4, weapon 1 or weapon 5 or weapon 5>
  25.  *
  26.  * This will add item 1 OR item 2 to the item's first Augment slot, armor 2 to
  27.  * the second, nothing OR armor 4 to the third and weapon 1
  28.  * OR weapon 5 to the forth with weapon 5 having an increased chance to be added.
  29.  * (There is no limit to the number of augments in the augment pool.)
  30.  *
  31.  * 1a: You can also set up augment tags with percentages in the following format:
  32.  * <preAugment: "item" number number%, etc>
  33.  *
  34.  *     where "item" is the augment's type in the database, number is the item's
  35.  *     Id and number% is the percentage chance of it being added.
  36.  *     DO NOT use "none" with percentage tags and do not mix percentage with
  37.  *     non-percentage tags for the same slot.  "None" must still be present in
  38.  *     slots with no augments.
  39.  *     Also, while you can technically set any percentages you like, any going
  40.  *     over 100% total chance will mess up the results.
  41.  *
  42.  * Example 3: <preAugment:item 1, armor 2, none, weapon 1 10%>
  43.  * This will add item 1 to the item's first Augment slot, armor 2 to the second,
  44.  * nothing to the third and a 10% chance to add weapon 1 to the forth.
  45.  *
  46.  * Example 4: <preAugment:item 1 or item 2, armor 2, armor 4 50%, weapon 1 25% or weapon 5 6% or weapon 5 60%>
  47.  * This will add item 1 OR item 2 at 50% each to the item's first Augment slot,
  48.  * armor 2 to the second, 50% chance of armor 4 to the third and weapon 1
  49.  * or weapon 5 to the forth with weapon 1 having 25% success and weapon 5
  50.  * with a combined chance of 66%.
  51.  *
  52.  * Any percentage chance slots that do not add up to 100% have a chance for
  53.  * failure equal to leftover percentage.
  54.  * So looking at example 4's final slot, the combined percentage is
  55.  * 25 + 6 + 60 = 91%.
  56.  * So in that slot, there will be a 9% chance of nothing being placed there.
  57.  *
  58.  * 2:  Adding the tag <augreplaceonly> to items will make it so once an
  59.  *     augment slot on the tagged item is filled, the
  60.  *     augment(s) can only be replaced, not removed leaving the slot empty.
  61.  *
  62.  * 2a: You can also specify which slots on an item are affected by the tag
  63.  *     using <augreplaceonly: slotId, slotId, etc > (Note the space at the end)
  64.  *     with slotId being the slot Ids for any slots on the item.
  65.  *     (The slots are numbered in the order you place when tagging the item
  66.  *     with slot names in the database.  The first slot is numbered 0.)
  67.  * Note that you can start with an empty slot, but once filled will remain that way.
  68.  *
  69.  * With this add-on, Augments are represented properly in shops when buying.
  70.  * With this comes the need to purchase weapons and armors one at a time during
  71.  * the current Shop Scene.  If you wish to have more than 1, simply add copies
  72.  * of the weapon when calling the Shop.
  73.  * This will affect ALL weapons and armor, regardless of whether they have
  74.  * pre-loaded augments or not.
  75.  */
  76.  
  77. Window_AugmentItemList.prototype.makeItemList = function() {
  78.     this._data = $gameParty.allItems().filter(function(item) {
  79.       return this.includes(item);
  80.     }, this);
  81.     if (this._item.augmentSlotItems[this._slotId] !== 'none' && this.augreplaceonly(this._item, this._slotId)) {  
  82.       this._data.unshift(null);
  83.     }
  84. };
  85.  
  86. Window_AugmentItemList.prototype.augreplaceonly = function(item, slot){
  87.  
  88.     if (!item.meta.augreplaceonly) return true;
  89.     if (item.meta.augreplaceonly == true) return false;
  90.     var augs = item.meta.augreplaceonly.split(", ");
  91.     if (augs.length == -1) return false;
  92.     for (var i = 0; i < augs.length; i++) augs[i] = Number(augs[i]);
  93.     for (var i = 0; i < augs.length; i++) {
  94.         if (augs[i] == slot) return false;
  95.     }
  96.     return true;
  97. }
  98.  
  99. var MalNewIndieItem = ItemManager.customizeNewIndependentItem
  100. ItemManager.customizeNewIndependentItem = function(baseItem, newItem) {
  101.     MalNewIndieItem.call(this, baseItem, newItem);
  102.     this.PreloadAugment(newItem);
  103. };
  104.  
  105. ItemManager.PreloadAugment = function(item) {
  106.     if (!item.meta.preAugment) return;
  107.     var augs = item.meta.preAugment.split(", ");
  108.     item.augmentSlotItems = [];
  109.     item.augmentSlotEnable = [];
  110.     if (SceneManager._scene instanceof Scene_Shop) return;
  111.     for (var i = 0; i < item.augmentSlots.length; i++) {
  112.         var pick = augs[i].split(" or ");
  113.         pick2 = [];
  114.         var choice = 0;
  115.         for (var k = 0; k < pick.length; k++) {
  116.             var newpick = pick[k].split(" ");
  117.             if(newpick[0] === "none") continue;
  118.             if(newpick[2]) {
  119.             newpick[2] = Number(newpick[2].replace('%',''));
  120.             } else {
  121.             newpick[2] = 100 / pick.length;
  122.             }
  123.             newpick[2] += choice;
  124.             choice = newpick[2];
  125.             pick2.push(newpick[0] + ' ' + newpick[1] + ' ' + newpick[2]);
  126.         }
  127.         var chance = Math.randomInt(100);
  128.         if (choice > 100) chance = Math.randomInt(choice);
  129.         var done = 0;
  130.         for (var k = 0; k < pick2.length; k++) {
  131.         if (done == 1) continue;
  132.             var finalpick = pick2[k].split(" ");
  133.             if (finalpick[2] > chance){
  134.                 done = 1;
  135.                 if (finalpick[0] == "item")   this.installAugmentToSlot(item, $dataItems[Number(finalpick[1])], i);
  136.                 if (finalpick[0] == "weapon") this.installAugmentToSlot(item, $dataWeapons[Number(finalpick[1])], i);
  137.                 if (finalpick[0] == "armor")  this.installAugmentToSlot(item, $dataArmors[Number(finalpick[1])], i);
  138.     }
  139.     }
  140.     }
  141. };
  142.  
  143. ItemManager.PreloadTemp = function(item, slot) {
  144.     if (!slot) return;
  145.     item.augmentSlotItems = [];
  146.     for (var i = 0; i < item.augmentSlots.length; i++) {
  147.     var newSlot = "none";
  148.     if (slot[i]) newSlot = slot[i].split(" "); 
  149.     if (!newSlot[1]) this.installAugmentToSlot(item, null, i);
  150.     if (newSlot[0] == "item") this.installAugmentToSlot(item, $dataItems[Number(newSlot[1])], i);
  151.     if (newSlot[0] == "weapon") this.installAugmentToSlot(item, $dataWeapons[Number(newSlot[1])], i);
  152.     if (newSlot[0] == "armor") this.installAugmentToSlot(item, $dataArmors[Number(newSlot[1])], i);
  153.     }
  154. }
  155.  
  156. Window_AugmentItemList.prototype.playOkSound = function() {
  157.     //SoundManager.playEquip();
  158. };
  159.  
  160. var MalonAugmentListOk = Scene_Item.prototype.onAugmentListOk
  161. Scene_Item.prototype.onAugmentListOk = function() {
  162.     var effectItem = this._augmentListWindow.item();
  163.     var slotId = this._itemActionWindow.currentExt();
  164.     if (effectItem === undefined) {
  165.     SoundManager.playBuzzer();
  166.     } else {
  167.     ItemManager.applyAugmentEffects(this.item(), effectItem, slotId, 1);
  168.     SoundManager.playEquip();
  169.     }
  170.     this._augmentListWindow.refresh();
  171.     this._augmentListWindow.activate();
  172.     this._statusWindow.refresh();
  173.     this._infoWindow.refresh();
  174.     this._itemWindow.refresh();
  175.     this._itemActionWindow.refresh();
  176.     var index = this._augmentListWindow.index();
  177.     this.onAugmentListCancel();
  178. };
  179.  
  180. Game_Interpreter.prototype.command302 = function() {
  181.     if (!$gameParty.inBattle()) {
  182.         var goods = [this._params];
  183.         while (this.nextEventCode() === 605) {
  184.             this._index++;
  185.             goods.push(this.currentCommand().parameters);
  186.         }
  187.         for (var i = 0; i < goods.length; i++) {
  188.         if (goods[i][0] == 1) goods[i].push(DataManager.registerTempItem($dataWeapons[goods[i][1]], 1, goods[i][1]));
  189.         if (goods[i][0] == 2) goods[i].push(DataManager.registerTempItem($dataArmors[goods[i][1]], 2, goods[i][1]));
  190.         }
  191.         SceneManager.push(Scene_Shop);
  192.         SceneManager.prepareNextScene(goods, this._params[4]);
  193.     }
  194.     return true;
  195. };
  196.  
  197. DataManager.registerTempItem = function(item) {
  198.     if (!this.isNewItemValid(item)) return item;
  199.     var newItem = JsonEx.makeDeepCopy(item);
  200.     ItemManager.PreloadAugment(newItem);
  201.     return newItem;
  202. };
  203.  
  204. Window_ShopBuy.prototype.makeItemList = function() {
  205.     this._data = [];
  206.     this._price = [];
  207.     this._shopGoods.forEach(function(goods) {
  208.         var item = null;
  209.         switch (goods[0]) {
  210.         case 0:
  211.             item = $dataItems[goods[1]];
  212.             break;
  213.         case 1:
  214.             item = $dataWeapons[goods[1]];
  215.             break;
  216.         case 2:
  217.             item = $dataArmors[goods[1]];
  218.             break;
  219.         }
  220.         if (goods[goods.length - 1].name && goods[0] > 0) {
  221.         item = goods[goods.length - 1];
  222.         item.id = goods[1];
  223.         }
  224.         if (item) {
  225.             this._data.push(item);
  226.             this._price.push(goods[2] === 0 ? item.price : goods[3]);
  227.         }
  228.     }, this);
  229. };
  230.  
  231. DataManager.isWeapon = function(item) {
  232.     return item && ($dataWeapons.contains(item) || item.wtypeId);
  233. };
  234.  
  235. DataManager.isArmor = function(item) {
  236.     return item && ($dataArmors.contains(item) || item.atypeId);
  237. };
  238.  
  239. Scene_Shop.prototype.doBuy = function(number) {
  240. ItemManager.shopFlag = true;
  241.     $gameParty.loseGold(number * this.buyingPrice());
  242.     if (this._item.itypeId) $gameParty.gainItem($dataItems[this._item.id], number);
  243.     if (this._item.wtypeId) {
  244.     if (this._item.augmentSlotItems) var slots = this._item.augmentSlotItems;
  245.     $gameParty.gainItem($dataWeapons[this._item.id], number);
  246.     var newItem = $gameParty.weapons()[$gameParty.weapons().length - 1];
  247.     ItemManager.PreloadTemp(newItem, slots);
  248.     }
  249.     if (this._item.atypeId) {
  250.     if (this._item.augmentSlotItems) var slots = this._item.augmentSlotItems;
  251.     $gameParty.gainItem($dataArmors[this._item.id], number);
  252.     var newItem = $gameParty.armors()[$gameParty.armors().length - 1];
  253.     ItemManager.PreloadTemp(newItem, slots);
  254.     }
  255. };
RAW Paste Data