Maliki79

Mal_Durability_EX

Jul 7th, 2016 (edited)
2,860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Maliki's Item Durability EX
  3. // Mal_Durability_EX.js
  4. // version 1.9
  5. //=============================================================================
  6. /*:  
  7. * @plugindesc This plugin gives extra functionality to YanFly's ItemDurability Plugin
  8.  * @author Maliki79
  9.  * @param DestroyEquipMode
  10.  * @desc 0 = destroy item. 1 = no destroy. 2 = becomes unequippable.
  11.  * Default: 1
  12.  * @default 1
  13.  *
  14.  * @param DurabilityAdjust
  15.  * @desc Percentage of durability an equip must be reduced to before it's stats are affected.
  16.  * Default: 50
  17.  * @default 50
  18.  *
  19.  * @param DurabilityReverseEdge
  20.  * @desc Set to 1 to make durability percentage INCREASE stats rather than decrease them.
  21.  * Default: 0
  22.  * @default 0
  23.  *
  24.  * @help Version 1.9
  25.  * You will need YanFly's ItemDurability Plugin as well as any supporting Plugins.
  26.  * Place this plugin right under the ItemDurability one.
  27.  *
  28.  * This plugin is plug-and-play with 2 parameters to customize it for your project.
  29.  *
  30.  * Destroy Equip Mode:
  31.  * This setting dictates what happens to equips once their durability hits 0.
  32.  *
  33.  * Type 0 will use Yanfly's original design and destroy the item, removing
  34.  * it from the actor and inventory permanently.
  35.  *
  36.  * Type 1 will keep the equip with no other changes.
  37.  *
  38.  * Type 2 will unequip the item upon break and render it
  39.  * unequippable until repaired.
  40.  *
  41.  *
  42.  * Durability Adjust:
  43.  * Durability now affects the stats of items while equipped.
  44.  * This is done via a direct percentage change
  45.  * based on current durability.
  46.  * So, if Max durability is set to 200 and and item with 500 attack
  47.  * has durability of 100, the attack stat would 1ower to 250.  
  48.  * (50% durability = 50% stat reduction)
  49.  * Of course, this means that a 0 durability item would give no stat boosts at all.
  50.  * (Percentage and trait based boosts will still be active.)
  51.  *
  52.  * You can set when the stats begin to get affected by using the
  53.  * Durability Adjust Param.
  54.  * Setting it to 100 would make any change in durability
  55.  * immediately affect that equipment's stats.
  56.  * Setting it to 0 would see no change to stats until
  57.  * the item breaks.
  58.  * Note that the percentage of the stat change itself is fixed.
  59.  * Also note that the percentage is based on the MAX durability of the
  60.  * item, not it's STARTING durability.
  61.  *
  62.  * So revisiting the above example, if the durability adjust was set at 20,
  63.  * the above equip would still have 500 attack even though the
  64.  * durability is at 100.
  65.  * However, if the durability were to drop to 40, the
  66.  * stats would change to 100!  (20% of 500)
  67.  *
  68.  * However, using the Plugin Param DurabilityReverseEdge will reverse this, so that reduced
  69.  * Durability will instead INCREASE stats by the percentage!
  70.  * You can also use the notetag <dReverseEdge> on equips to do this on a per equip basis.
  71.  *
  72.  * Some Script Calls were also added.
  73.  *
  74.  * $gameParty.totalDurability();
  75.  * This call totals the amount of durability present for each equip item in
  76.  * both the party equips AND inventory and returns the value.
  77.  * It does not count Unbreakable items.
  78.  *
  79.  * $gameParty.totalDurability(true);
  80.  * This call totals the MAX durability present for each equip item in both
  81.  * the party equips AND inventory and returns the value.
  82.  * It does not count Unbreakable items.
  83.  *
  84.  * $gameParty.fixAllDurability();
  85.  * This call resets each item's durability to it's max value.
  86.  *
  87.  * $gameParty.fixAllDurability(amount);
  88.  * This call changes each item's durability by the percentage amount.
  89.  * For example, $gameParty.fixAllDurability(25); will increase ALL item durability
  90.  * by 25% of thier MAX value.  
  91.  * (Negative numbers will cause damage and can break items)
  92.  *
  93.  * The basic use I saw for these calls was to enable a "Blacksmith"
  94.  * that can charge a certain amount based on current durability.
  95.  * You can use the script calls to put these values into
  96.  * variables for general purpose use.
  97.  * The percentage call can be used to either rapair items over time, or make
  98.  * "Acid pools" which can damage durability over time.
  99.  *
  100.  * $gameParty.changeItemDurability(type, id, amount);
  101.  * With type being either "weapon" or "armor", id being the item's Id
  102.  * and amount being the change value(must be negative to damage).
  103.  * Example: $gameParty.changeItemDurability("weapon", $gameParty.members()[0]._equips[0]._itemId, -300);
  104.  * This will give 300 durability damage to whatever weapon is
  105.  * in the 1st party member's first equip slot.
  106.  * (You can kinda consider this call a Lunatic Call, since you'd
  107.  * likely need some scripting know-how to find the Id you need.)
  108.  *
  109.  * Game_Actor.isWeaponBroken(type);
  110.  * Game_Actor.isArmorBroken(type);
  111.  * With type being the appropriate equipment type ID.
  112.  * Will check to see if an equip type is broken and will return true if one is found.
  113.  * For weapons, it will check both weapon slots and for armors, all armor slots.
  114.  * (Will check slot 1 for both)
  115.  * This can be used for conditionals for things like passive states, etc.
  116.  *
  117.  * Element effects:
  118.  * Durability can now be affected by elements!
  119.  * To utilize this, use the following tag on equipment items:
  120.  *
  121.  * <DurabilityElement: x y >
  122.  *
  123.  * with x being the element Id from the database and y being a
  124.  * number multiplier. (Note the space near the end)
  125.  * So, assuming each hit with a weapon normally does
  126.  * 50 durability damage, having the tag
  127.  * <DurabilityElement: 1 0.5 >
  128.  * will cause each hit to instead do 75. (50 + 50% = 75)
  129.  *
  130.  * <DurabilityElement: 1 -1 >
  131.  *
  132.  * This tag, on the other hand, will negate any
  133.  * durability damage to the weapon.
  134.  *
  135.  * <DurabilityElement: 2 1000000 > (Or some other crazy number)
  136.  *
  137.  * This tag will make fire attacks (default element 2) do 1,000,000
  138.  * times the durability damage, very likely destroying the item.
  139.  *
  140.  * You can have multiple element tags and the applicable
  141.  * multipliers will be added before applying it to the damage.
  142.  * (And yes, negative numbers lower than -1 WILL heal the
  143.  * item's durability if the item is affected.)
  144.  *
  145.  * Other Tags:
  146.  * You can tag an equip with <NoBattleDD> to make it so equips
  147.  * will not suffer any durability damage (or healing) in battle but can
  148.  * still be affected by Script calls that affect durability directly.
  149.  * (Such as the changeItemDurability call.)
  150.  * You can also tag Actor, class or states with this tag and it will protect ALL equips on that actor.
  151.  *
  152.  * Salvage upon Break
  153.  * Items can now be created upon breaking of a weapon or armor!
  154.  * Just use the notetag
  155.  *
  156.  * <DurabilityScrap: a, b, c, d>
  157.  * on weapon/armor notes.
  158.  *
  159.  * a is the type. (1 = item. 2 = weapon. 3 = armor)
  160.  * b is the item's id in the database.
  161.  * c is the amount of the salvaged item.
  162.  * d is the percentage chance from 0 to 100.
  163.  * Note that this will work with any of the destroy modes.
  164.  * Multiple tags can be used to give varying amounts or items if desired.
  165.  *
  166.  * User SPECIFIC ITEM EQUIP Durability Change
  167.  * You can now have skills/items damage/heal specific equip types when using them.
  168.  * Just add the following to skill or item notes:
  169.  *
  170.  * <UserEquipTypeDur: x, y, z>
  171.  *
  172.  * x being the general type (1 = weapon. 2 = armor)
  173.  * y being the specific type Id of the equipment.
  174.  * And z being the amount of change (negative numbers to damage).
  175.  * This will cause ALL equipped types to take durability damage while leaving other equip types alone.
  176.  * So if you want a spell to damage durability of a Swordmage's wand without damaging the sword she also
  177.  * has equipped, using this tag, it is now possible.
  178.  * Multiple versions of this tag can be used to cause different amounts of damage to different equips.
  179.  *
  180.  * MAX DURABILITY Changes
  181.  *
  182.  * Max Durability can now be changed by accessing an equip's durMax.
  183.  * (for example, object.durmax + 50;)
  184.  * Note that you cannot make a breakable object's durabity any number below 1.
  185.  */
  186.  
  187.  
  188. var Mal = Mal || {};
  189.  
  190. Mal.DurabilityParameters = PluginManager.parameters('Mal_Durability_EX');
  191. Mal.Param = Mal.Param || {};
  192.  
  193. Mal.Param.DestroyEquip = Number(Mal.DurabilityParameters['DestroyEquipMode']);
  194. Mal.Param.DestroyEquip = Mal.Param.DestroyEquip.clamp(0, 2);
  195.  
  196. Mal.DAdjust = Number(Mal.DurabilityParameters['DurabilityAdjust']) || 0;
  197. Mal.DREdge = Number(Mal.DurabilityParameters['DurabilityReverseEdge']) != 0;
  198.  
  199. //begin database setup
  200. var MalDurDatabaseLoad = DataManager.isDatabaseLoaded;
  201. DataManager.isDatabaseLoaded = function() {
  202.   if (!MalDurDatabaseLoad.call(this)) return false;
  203.   if (!DataManager._MalDur_DatabaseLoaded) {
  204.     this.processDurNotetags($dataWeapons);
  205.     this.processDurNotetags($dataArmors);
  206.     this.processDurNotetags2($dataSkills);
  207.     this.processDurNotetags2($dataItems);
  208.     this.processDurNotetags3($dataActors);
  209.     this.processDurNotetags3($dataClasses);
  210.     this.processDurNotetags3($dataStates);
  211.     DataManager._MalDur_DatabaseLoaded = true;
  212.   }
  213.   return true;
  214. };
  215.  
  216. DataManager.processDurNotetags = function(group) {
  217.     for (var n = 1; n < group.length; n++) {
  218.         var obj = group[n];
  219.         obj.durScrapData = [];
  220.         this.createDurArray(obj);
  221.     }
  222. };
  223.  
  224. DataManager.processDurNotetags2 = function(group) {
  225.     for (var n = 1; n < group.length; n++) {
  226.         var obj = group[n];
  227.         obj.userEquipDurChange = [];
  228.         this.createDurArray2(obj);
  229.     }
  230. };
  231.  
  232. DataManager.processDurNotetags3 = function(group) {
  233.     for (var n = 1; n < group.length; n++) {
  234.         var obj = group[n];
  235.         obj.noBattleDD = false;
  236.         var noteread = obj.note;
  237.         if (noteread.indexOf("NoBattleDD") > -1) obj.noBattleDD = true;
  238.     }
  239. };
  240.  
  241. DataManager.createDurArray = function(object) {
  242.         var noteread = object.note;
  243.  
  244.         while(noteread.indexOf("DurabilityScrap") > -1)
  245.         {
  246.             var notereg = noteread.split("<DurabilityScrap: ");
  247.             var match = notereg[1].split(", ");
  248.             var match2 = match[3].split(">");
  249.             object.durScrapData.push([parseInt(match[0]), parseInt(match[1]), parseInt(match[2]), parseInt(match2[0])]);
  250.             noteread = noteread.replace("<DurabilityScrap: ", " ");
  251.         }
  252.     };
  253.  
  254. DataManager.createDurArray2 = function(object) {
  255.         var noteread = object.note;
  256.  
  257.         while(noteread.indexOf("UserEquipTypeDur") > -1)
  258.         {
  259.             var notereg = noteread.split("<UserEquipTypeDur: ");
  260.             var match = notereg[1].split(", ");
  261.             var match2 = match[2].split(">");
  262.             object.userEquipDurChange.push([parseInt(match[0]), parseInt(match[1]), parseInt(match2[0])]);
  263.             noteread = noteread.replace("<UserEquipTypeDur: ", " ");
  264.         }
  265.     };
  266.    
  267. DataManager.getMaxDurability = function(item) {
  268.     if (this.isItem(item)) return -1;
  269.     if (!this.isIndependent(item)) return -1;
  270.     var baseItem = this.getBaseItem(item);
  271.     if (baseItem.durMax == -1) return -1;
  272.     if (baseItem.durMax > 0 && item.durMax < 0) return 1;
  273.     if (baseItem.durMax != item.durMax) return item.durMax;
  274.     return baseItem.durMax;
  275. };
  276. //End Database Setup
  277.  
  278. Game_Actor.prototype.durabilityBreakScrapItem = function(obj) {
  279. if (obj.durScrapData == []) return;
  280. for (var i = 0; i < obj.durScrapData.length; ++i) {
  281.     var code = obj.durScrapData[i][0];
  282.     if (Math.randomInt(100) < obj.durScrapData[i][3]){
  283.         if (code == 1) var item = $dataItems[obj.durScrapData[i][1]];
  284.         if (code == 2) var item = $dataWeapons[obj.durScrapData[i][1]];
  285.         if (code == 3) var item = $dataArmors[obj.durScrapData[i][1]];
  286.         $gameParty.gainItem(item, obj.durScrapData[i][2]);
  287.         var text = '\\i[' + item.iconIndex + ']' + item.name + " salvaged!";
  288.         if (Imported.YEP_BattleEngineCore) text = '<CENTER>' + text;
  289.         SceneManager._scene._logWindow._lines.push(text);
  290.         SceneManager._scene._logWindow.refresh();
  291.     }
  292. }
  293. };
  294.  
  295. Game_Actor.prototype.isWeaponBroken = function(type) {
  296. var type = Number(type) || 0;
  297. for (var i = 0; i < 2; i++) {
  298. if (this.equips()[i] && this.equips()[i].wtypeId && this.equips()[i].wtypeId == type) {
  299.     if(this.equips()[i].durability == 0) return true;
  300. }
  301. }
  302. return false;
  303. };
  304.  
  305. Game_Enemy.prototype.isWeaponBroken = function(type) {
  306. return false;
  307. };
  308.  
  309. Game_Actor.prototype.isArmorBroken = function(type) {
  310. var type = Number(type) || 0;
  311. for (var i = 1; i < 5; i++) {
  312. if (this.equips()[i] && this.equips()[i].atypeId && this.equips()[i].atypeId == type) {
  313.     if(this.equips()[i].durability == 0) return true;
  314. }
  315. }
  316. return false;
  317. };
  318.  
  319. Game_Enemy.prototype.isArmorBroken = function(type) {
  320. return false;
  321. };
  322.  
  323. var MalDuraApply = Game_Action.prototype.apply
  324. Game_Action.prototype.apply = function(target) {
  325. if (this.subject().isActor()) this.subject().makeElementSet(this.item());
  326. if (target && target.isActor()) target.makeElementSet(this.item());
  327. MalDuraApply.call(this, target);
  328. }
  329.  
  330. Game_Actor.prototype.makeElementSet = function(item) {
  331. this.lastElements = [];
  332. this.lastElements.push(item.damage.elementId);
  333. }
  334.  
  335. Game_Actor.prototype.DuraElementMul = function(note){
  336.  
  337.     var mul = 1;
  338.     var objele = this.lastElements;
  339.     var noteread = note;
  340.     while(noteread.indexOf("DurabilityElement") > -1)
  341.     {
  342.         var notereg = noteread.split("<DurabilityElement: ");
  343.         var match = notereg[1].split(" ");
  344.         var bonuselem = Number(match[0]);
  345.         var bonusvalue = Number(match[1]);
  346.         noteread = noteread.replace("DurabilityElement", " ");
  347.         for(var i = 0; i < objele.length; ++i){
  348.         if (objele[i] == bonuselem) mul += bonusvalue;
  349.         }
  350.     }
  351.     return mul;
  352. }
  353.  
  354. Game_Actor.prototype.equipDuraProtect = function () {
  355.     if (this.noBattleDD) return true;
  356.     if (this.currentClass().noBattleDD) return true;
  357.     var states = this.states();
  358.     for (var i = 0; i < states.length; i++) {
  359.         var id = states[i].id;
  360.         if($dataStates[id].noBattleDD) return true;
  361.     }
  362.     return false;
  363. };
  364.  
  365. Game_Actor.prototype.damageAllDurability = function(value, group) {
  366.     if (value === 0) return;
  367.     if (this.equipDuraProtect()) return;
  368.     var length = group.length;
  369.     var removed = [];
  370.     for (var i = 0; i < length; ++i) {
  371.       var obj = group[i];
  372.       if (!obj) continue;
  373.       if (!obj.baseItemId) continue;
  374.       if (obj.durability < 1) continue;
  375.       if (obj.meta.NoBattleDD) continue;
  376.       obj.durability += value * this.DuraElementMul(obj.note);
  377.       if (obj.durability > obj.durMax) obj.durability = obj.durMax;
  378.       if (obj.durability <= 0) {
  379.       removed.push(obj);
  380.       obj.durability = 0;
  381.       }
  382.     }
  383.     length = removed.length;
  384.     for (var i = 0; i < length; ++i) {
  385.       var obj = removed[i];
  386.       this.durabilityBreakItem(obj);
  387.     }
  388. };
  389.  
  390. Game_Actor.prototype.damageRandomDurability = function(value, group) {
  391.     if (Mal.Param.DestroyEquip == 3) return;
  392.     if (value === 0) return;
  393.     if (this.equipDuraProtect()) return;
  394.     var length = group.length;
  395.     var valid = [];
  396.     for (var i = 0; i < length; ++i) {
  397.       var obj = group[i];
  398.       if (!obj) continue;
  399.       if (!obj.baseItemId) continue;
  400.       if (obj.durability < 1) continue;
  401.       if (obj.meta.NoBattleDD) continue;
  402.       valid.push(obj)
  403.     }
  404.     var item = valid[Math.floor(Math.random() * valid.length)];
  405.     if (!item) return;
  406.     item.durability += value * this.DuraElementMul(obj.note);
  407.     if (item.durability > item.durMax) item.durability = item.durMax;
  408.     if (item.durability < 1) {
  409.     item.durability = 0;
  410.     this.durabilityBreakItem(item);
  411.     }
  412. };
  413.  
  414. Game_Actor.prototype.damageSpItemDurability = function(value, equip) {
  415.     if (Mal.Param.DestroyEquip == 3) return;
  416.     if (value == 0) return;
  417.     if (this.equipDuraProtect()) return;
  418.       var obj = equip;
  419.       if (!obj) return;
  420.       if (!obj.baseItemId) return;
  421.       if (obj.durability < 1) return;
  422.       if (obj.meta.NoBattleDD) return;
  423.     obj.durability += value; // * this.DuraElementMul(obj.note);
  424.     if (obj.durability > obj.durMax) obj.durability = obj.durMax;
  425.     if (obj.durability < 1) {
  426.     obj.durability = 0;
  427.     this.durabilityBreakItem(obj);
  428.     }
  429. };
  430.  
  431. Game_Actor.prototype.durabilityBreakItem = function(obj) {
  432.     if (!obj) return;
  433.     if (Mal.Param.DestroyEquip == 0) this.discardEquip(obj);
  434.     var slotId = this.equips().indexOf(obj);
  435.     if (Mal.Param.DestroyEquip == 2) {
  436.         this.releaseUnequippableItems();
  437.     }
  438.     this.playDurabilityBreakSound(obj);
  439.     this.customDurabilityBreakEval(obj);
  440.     this.durabilityBreakScrapItem(obj);
  441.     var scene = SceneManager._scene;
  442.     var win = scene._logWindow;
  443.     if (!win) return;
  444.     var fmt = Yanfly.Param.IDurBrokenText;
  445.     var text = fmt.format(this.name(), obj.name, '\\i[' + obj.iconIndex + ']');
  446.     if (Imported.YEP_BattleEngineCore) text = '<CENTER>' + text;
  447.     win._lines.push(text);
  448.     win.refresh();
  449.     if (!Imported.YEP_BattleEngineCore) return;
  450.     if (this._waitEnabled) return;
  451.     this._waitEnabled = true;
  452.     var frames = Yanfly.Param.IDurBrokenWait;
  453.     if (frames > 0) BattleManager._actionList.push(['WAIT', [frames]]);
  454. };
  455.  
  456. var MalparamPlus2 = Game_Actor.prototype.paramPlus
  457. Game_Actor.prototype.paramPlus = function(paramId) {
  458.     var value = MalparamPlus2.call(this, paramId);
  459.     var equips = this.equips();
  460.     for (var i = 0; i < equips.length; i++) {
  461.         var item = equips[i];
  462.         if (item) {
  463.             var perc = item.durability / item.durMax;
  464.             if (Mal.DREdge || item.meta.dReverseEdge) perc = (2 - perc);
  465.             if (item.durability == 0) perc = 0;
  466.             value -= item.params[paramId];
  467.             if (Mal.DAdjust >= perc && item.durability > -1) {
  468.             value += item.params[paramId] * perc;
  469.             } else {
  470.             value += item.params[paramId];
  471.             }
  472.                 }
  473.         }
  474.     return value;
  475. };
  476.  
  477. Game_Actor.prototype.releaseUnequippableItems = function(forcing) {
  478.     for (;;) {
  479.         var slots = this.equipSlots();
  480.         var equips = this.equips();
  481.         var changed = false;
  482.         for (var i = 0; i < equips.length; i++) {
  483.             var item = equips[i];
  484.             if (item && (!this.canEquip(item) || item.etypeId !== slots[i])) {
  485.                 if (!forcing) {
  486.                     this.tradeItemWithParty(null, item);
  487.                     if (i == 0 && this.equips()[1]) {
  488.                         var offhanditem = this.equips()[1];
  489.                         this.tradeItemWithParty(null, this.equips()[1]);
  490.                         if (offhanditem.wtypeId != 5) this._equips[i].setObject(offhanditem);
  491.                     }
  492.                 }
  493.                 this._equips[i].setObject(null);
  494.                 changed = true;
  495.             }
  496.         }
  497.         if (!changed) {
  498.             break;
  499.         }
  500.     }
  501. };
  502.  
  503. var MalApplyDurabilityEffects = Game_Action.prototype.applyDurabilityEffects
  504. Game_Action.prototype.applyDurabilityEffects = function(target) {
  505.     MalApplyDurabilityEffects.call(this, target);
  506.     if (this.item().userEquipDurChange != []) {
  507.         if (this.subject().isActor()) {
  508.             this.applySpecEquipDurChange(this.subject().equips(), this.item().userEquipDurChange);
  509.         }
  510.     }
  511. };
  512.  
  513. Game_Action.prototype.applySpecEquipDurChange = function(equips, durData) {
  514.     for (var i = 0; i < equips.length; i++) {
  515.         if (equips[i]) {
  516.             for (var j = 0; j < durData.length; j++) {
  517.                 if (DataManager.isWeapon(equips[i]) && durData[j][0] == 1) {
  518.                     if (equips[i].wtypeId == durData[j][1]) {
  519.                         this.subject().damageSpItemDurability(durData[j][2], equips[i]);
  520.                     }
  521.                 }
  522.                 if (DataManager.isArmor(equips[i]) && durData[j][0] == 2) {
  523.                     if (equips[i].atypeId == durData[j][1]) {
  524.                         this.subject().damageSpItemDurability(durData[j][2], equips[i]);
  525.                     }
  526.                 }
  527.             }
  528.         }
  529.     }
  530. };
  531.  
  532. Game_BattlerBase.prototype.canEquipWeapon = function(item) {
  533.     return this.isEquipWtypeOk(item.wtypeId) && !this.isEquipTypeSealed(item.etypeId) && !this.isEquipBroken(item);
  534. };
  535.  
  536. Game_BattlerBase.prototype.canEquipArmor = function(item) {
  537.     return this.isEquipAtypeOk(item.atypeId) && !this.isEquipTypeSealed(item.etypeId) && !this.isEquipBroken(item);
  538. };
  539.  
  540. Game_BattlerBase.prototype.isEquipBroken = function(item) {
  541.     if (Mal.Param.DestroyEquip != 2) return false;
  542.     return item.durability == 0;
  543. };
  544.  
  545. Game_Party.prototype.durabilityBreakScrapItem = function(obj) {
  546. if (obj.durScrapData == []) return;
  547. for (var i = 0; i < obj.durScrapData.length; ++i) {
  548.     var code = obj.durScrapData[i][0];
  549.     if (Math.randomInt(100) < obj.durScrapData[i][3]){
  550.         if (code == 1) var item = $dataItems[obj.durScrapData[i][1]];
  551.         if (code == 2) var item = $dataWeapons[obj.durScrapData[i][1]];
  552.         if (code == 3) var item = $dataArmors[obj.durScrapData[i][1]];
  553.         $gameParty.gainItem(item, obj.durScrapData[i][2]);
  554.         var amount = obj.durScrapData[i][2];
  555.         if (amount == 1) {
  556.             var text = '\\i[' + item.iconIndex + ']' + item.name + " salvaged!";
  557.         } else {
  558.             var text = '\\i[' + item.iconIndex + ']' + item.name + " x " + amount + " salvaged!";
  559.         }
  560.         $gameMessage.add(text);
  561.     }
  562. }
  563. };
  564.  
  565. Game_Party.prototype.totalDurability = function(type) {
  566.     var dur = 0;
  567.     var durmax = 0;
  568.    
  569.     for (var i = 0; i < this.weapons().length; i++) {
  570.         if (this.weapons()[i].durability == -1) continue;
  571.         dur += this.weapons()[i].durability;
  572.         durmax += this.weapons()[i].durMax;
  573.     }
  574.    
  575.     for (var i = 0; i < this.armors().length; i++) {
  576.         if (this.armors()[i].durability == -1) continue;
  577.         dur += this.armors()[i].durability;
  578.         durmax += this.armors()[i].durMax;
  579.     }
  580.    
  581.     for (var i = 0; i < this.members().length; i++) {
  582.     var mem = this.members()[i].equips();
  583.         for (var j = 0; j < mem.length; j++) {
  584.             if (!mem[j]) continue;
  585.             if (mem[j].durability == -1) continue;
  586.             dur += mem[j].durability;
  587.             durmax += mem[j].durMax;
  588.         }
  589.     }
  590.     if (type) return durmax;
  591.     return dur;
  592. }
  593.  
  594. Game_Party.prototype.fixAllDurability = function(perc) {
  595.     var percent = 100;
  596.     if (typeof perc !== "undefined" ) percent = Number(perc);
  597.     for (var i = 0; i < this.weapons().length; i++) {
  598.         if (this.weapons()[i].durability == -1) continue;
  599.         if (this.weapons()[i].durability <= 0 && percent < 0) continue;
  600.         this.weapons()[i].durability += this.weapons()[i].durMax * (percent / 100);
  601.         this.weapons()[i].durability = this.weapons()[i].durability.clamp(0, this.weapons()[i].durMax);
  602.         if (this.weapons()[i].durability < 1) {
  603.         this.weapons()[i].durability = 0;
  604.         this.durabilityBreakItem(this.weapons()[i]);
  605.         }
  606.     }
  607.    
  608.     for (var i = 0; i < this.armors().length; i++) {
  609.         if (this.armors()[i].durability == -1) continue;
  610.         if (this.armors()[i].durability <= 0 && percent < 0) continue;
  611.         this.armors()[i].durability += this.armors()[i].durMax * (percent / 100.0);
  612.         this.armors()[i].durability = this.armors()[i].durability.clamp(0, this.armors()[i].durMax);
  613.         if (this.armors()[i].durability < 1) {
  614.         this.armors()[i].durability = 0;
  615.         this.durabilityBreakItem(this.armors()[i]);
  616.         }
  617.     }
  618.  
  619.     for (var i = 0; i < this.members().length; i++) {
  620.     var mem = this.members()[i].equips();
  621.         for (var j = 0; j < mem.length; j++) {
  622.             if (!mem[j]) continue;
  623.             if (mem[j].durability == -1) continue;
  624.             if (mem[j].durability <= 0 && percent < 0) continue;
  625.             mem[j].durability += mem[j].durMax * (percent / 100.0);
  626.             mem[j].durability = mem[j].durability.clamp(0, mem[j].durMax);
  627.         if (mem[j].durability < 1) {
  628.         mem[j].durability = 0;
  629.         this.durabilityBreakItem(mem[j]);
  630.         }
  631.         }
  632.     }
  633. };
  634.  
  635. Game_Party.prototype.changeItemDurability = function(type, id, amount) {
  636.    
  637.     if (type == "weapon"){
  638.     for (var i = 0; i < this.weapons().length; i++) {
  639.         if (this.weapons()[i].id != id || this.weapons()[i].durability == -1) continue;
  640.         this.weapons()[i].durability += amount;
  641.       if (this.weapons()[i].durability > this.weapons()[i].durMax) this.weapons()[i].durability = this.weapons()[i].durMax;
  642.         if (this.weapons()[i].durability < 1) {
  643.         this.weapons()[i].durability = 0;
  644.         this.durabilityBreakItem(this.weapons()[i]);
  645.         }
  646.         return;
  647.     }
  648.     }
  649.    
  650.     if (type == "armor"){
  651.     for (var i = 0; i < this.armors().length; i++) {
  652.         if (this.armors()[i].id != id || this.armors()[i].durability == -1) continue;
  653.         this.armors()[i].durability += amount;
  654.         if (this.armors()[i].durability > this.armors()[i].durMax) this.armors()[i].durability = this.armors()[i].durMax;
  655.         if (this.armors()[i].durability < 1) {
  656.         this.armors()[i].durability = 0;
  657.         this.durabilityBreakItem(this.armors()[i]);
  658.         }
  659.         return;
  660.     }
  661.     }
  662.    
  663.     for (var i = 0; i < this.members().length; i++) {
  664.     var mem = this.members()[i].equips();
  665.         for (var j = 0; j < mem.length; j++) {
  666.             if (!mem[j]) continue;
  667.             if (mem[j].durability == -1) continue;
  668.             if (type == "weapon" && mem[j].wtypeId && mem[j].id == id) {
  669.             mem[j].durability += amount;
  670.             if (mem[j].durability > mem[j].durMax) mem[j].durability = mem[j].durMax;
  671.             if (mem[j].durability < 1) {
  672.             mem[j].durability == 0;
  673.             this.durabilityBreakItem(mem[j], i, j);
  674.             return;
  675.             }
  676.             }
  677.             if (type == "armor" && mem[j].atypeId && mem[j].id == id) {
  678.             mem[j].durability += amount;
  679.             if (mem[j].durability > mem[j].durMax) mem[j].durability = mem[j].durMax;
  680.             if (mem[j].durability < 1) {
  681.             mem[j].durability == 0;
  682.             this.durabilityBreakItem(mem[j], i, j);
  683.             return;
  684.             }
  685.             }
  686.         }
  687.     }
  688. }
  689.  
  690. Game_Party.prototype.durabilityBreakItem = function(obj, memberId, equipSlot) {
  691.     if (!obj) return;
  692.     if (Mal.Param.DestroyEquip == 0) this.members()[memberId].discardEquip(obj);
  693.     if (Mal.Param.DestroyEquip == 2) {
  694.         obj.durability = 0;
  695.         this.members()[memberId].releaseUnequippableItems();
  696.     }
  697.     this.durabilityBreakScrapItem(obj);
  698.     this.playDurabilityBreakSound(obj);
  699. };
  700.  
  701. Game_Party.prototype.playDurabilityBreakSound = function(obj) {
  702.     var sound = obj.breakSound;
  703.     if (!sound) {
  704.       sound = {
  705.         name:   Yanfly.Param.IDurBreakName,
  706.         volume: Yanfly.Param.IDurBreakVol,
  707.         pitch:  Yanfly.Param.IDurBreakPitch,
  708.         pan:    Yanfly.Param.IDurBreakPan
  709.       }
  710.     }
  711.     AudioManager.playSe(sound);
  712. };
  713.  
  714. Window_ItemInfo.prototype.drawItemDurability = function(dy) {
  715.     this.resetFontSettings();
  716.     this.changeTextColor(this.systemColor());
  717.     var text = Yanfly.Param.IDurText;
  718.     var dx = this.textPadding();
  719.     var dw = this.contents.width - this.textPadding() * 2;
  720.     this.drawText(text, dx, dy, dw);
  721.     var fmt = Yanfly.Param.IDurFmt;
  722.     var cur = DataManager.getDurability(this._item);
  723.     var max = DataManager.getMaxDurability(this._item);
  724.     if (cur > -1) {
  725.       this.changeTextColor(this.textColor(this.durabilityColor(cur, max)));
  726.       text = fmt.format(cur, max)
  727.     } else {
  728.       this.changeTextColor(this.textColor(Yanfly.Param.IDurColor['unbreak']));
  729.       text = Yanfly.Param.IDurUnbreakable;
  730.     }
  731.     this.drawText(text, dx, dy, dw, 'right');
  732.     this.resetFontSettings();
  733.     dy += this.lineHeight();
  734.     return dy;
  735.  
  736.     };
Add Comment
Please, Sign In to add comment