Advertisement
MV_Musashi

Drop Items Conditions

Nov 4th, 2015
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //====================================================================================
  2. //
  3. // Drop Items Conditions
  4. //
  5. //====================================================================================
  6. /*:
  7.  * @plugindesc v1.03 Set conditions for enemies item/equip drops.
  8.  * Read 'Help' for more information.
  9.  * @author Musashii
  10.  *
  11.  *
  12.  * @help
  13.  * ===================================================================================
  14.  * Introduction
  15.  * ===================================================================================
  16.  *
  17.  * You can set extra condidions to items to drop using the notetag:
  18.  * <DropRestriction: formula>
  19.  * Be aware that you can't use the "greater than" comparison operator
  20.  * inside the notetag or it'll close it, use the "less than" instead.
  21.  *
  22.  * Use the tag <CancelRestriction: itemId> inside Enemy notes to cancel the item
  23.  *'itemId' restriction.
  24.  *
  25.  * Use the tag <ChangeRestriction:itemId,NewFormula> inside Enemy notes to change the
  26.  * item  'itemId' restriction only for the enemy.
  27.  * ===================================================================================
  28.  * Notetags - Special Formula Codes
  29.  * ===================================================================================
  30.  * Exclusive codes you can use in your formulas:
  31.  *
  32.  * ElementId(id)
  33.  *Will check if enemy was killed by a skill with a certain element (id). For
  34.  *multiple elements use: ElementId([id1,id2,id3])
  35.  *You can use it inside Items and Enemies notes. Example:
  36.  *
  37.  *<DropRestriction:ElementId([2,4])>
  38.  *Item will drop if enemy is killed by a skill with element 2 or 4
  39.  *
  40.  *<ChangeRestriction:1,ElementId([2])>
  41.  *Enemy will drop item 1 from database only if killed by skill with element 2
  42.  * ===================================================================================
  43.  * Notetags - Formula Examples
  44.  * ===================================================================================
  45.  *
  46.  *   Items, Weapons and Armors Notetags:
  47.  *Here are some examples of what can be done, but you can create your own formulas!
  48.  *
  49.  *<DropRestriction: $gameParty.isAnyMemberEquipped($dataWeapons[id])>
  50.  *Item will drop only if any party member have the first weapon in the
  51.  *database equipped.
  52.  *  
  53.  *<DropRestriction: $gameActors.actor(actorId).equips().contains($dataArmors[id])>
  54.  *True if actor(id) is equipped with the armor(id).
  55.  *  
  56.  *<DropRestriction: 100 < $gameVariables.value(id)>
  57.  *True if variable[id] is greater than 100.
  58.  *  
  59.  *<DropRestriction: $gameParty.hasItem($dataItems[itemID]) &&
  60.  *50 <= $gameActors.actor(id).level>
  61.  *True if player has item(itemID) in the inventory AND if actor(id) has level
  62.  *greater than or equal to 50.
  63.  *
  64.  *   Enemies Notetags:
  65.  *
  66.  *<CancelRestriction: 1>
  67.  * Will cancel the drop condition of the first item of the database for the
  68.  * enemy.
  69.  *
  70.  *<ChangeRestriction:1,$gameSwitches.value(1) === true>
  71.  * Make a different item drop condition (will drop if switch 1 is ON, despite the
  72.  original condition) for the enemy.
  73.  * ===================================================================================
  74.  * Changelog
  75.  * ===================================================================================
  76.  *
  77.  * Version 1.03:
  78.  * - New 'killed by element' code to use in your conditions.
  79.  * Version 1.02:
  80.  * - Enemies can now change item drop conditions for themselves.
  81.  * Version 1.01:
  82.  * - Added option to cancel specified item drop restrictions for certain enemies.
  83.  */
  84. //====================================================================================
  85.  var killedByElement = [];
  86.  var indexCounter = -1;
  87.  
  88. (function() {
  89.  
  90. //===================================================================================
  91. // Game_Battler.prototype.onBattleEnd
  92. // Reset Counter after each battle
  93. //===================================================================================
  94. var _Game_Battler_onBattleEndResetCounter = Game_Battler.prototype.onBattleEnd;
  95.  
  96. Game_Battler.prototype.onBattleEnd = function() {
  97. _Game_Battler_onBattleEndResetCounter.call
  98.  indexCounter = -1;
  99. };
  100.  
  101. //===================================================================================
  102. // Game_Troop.prototype.makeDropItems
  103. // REPLACE function
  104. // Count index to get which troop's reward is being given
  105. //===================================================================================
  106. Game_Troop.prototype.makeDropItems = function() {
  107.     return this.deadMembers().reduce(function(r, enemy) {
  108.    
  109.  indexCounter = indexCounter + 1;
  110.  
  111.         return r.concat(enemy.makeDropItems());
  112.     }, []);
  113. };
  114.  
  115. //===================================================================================
  116. // Game_Action.prototype.calcElementRate
  117. // Store data (Target Index and damage element) in variable 'killedByElement'
  118. //===================================================================================
  119.  var _Game_Action_calcElementRate = Game_Action.prototype.calcElementRate;
  120.  
  121. Game_Action.prototype.calcElementRate = function(target) {
  122. // KilledByElement[index] = [Element]
  123.  killedByElement[target.index()] = this.item().damage.elementId
  124.         return _Game_Action_calcElementRate.call(this, target);};      
  125.        
  126. //===================================================================================
  127. // Game_Enemy.prototype.makeDropItems
  128. // Replace makeDropItems function
  129. //===================================================================================
  130. Game_Enemy.prototype.makeDropItems = function() {
  131.  
  132. //===================================================================================
  133. // New Function :ElementId:
  134. // Make the formula => ElementId(id) or ElementId([id1,id2])
  135. //===================================================================================
  136. function ElementId(arrayOfElements){
  137. return "[" + [arrayOfElements] + "]" + ".contains(killedByElement[indexCounter])";}
  138.  
  139. //
  140. // START: CHECK CONDITIONS AND FORMULAS
  141. //
  142.     return this.enemy().dropItems.reduce(function(r, di) {
  143.         if (di.kind > 0 && Math.random() * di.denominator < this.dropItemRate()) {
  144.        
  145. // Check if the item don't have the DropRestriction note AND a ChangeRestriction note.
  146.   if ($dataItems[di.dataId].meta.DropRestriction === undefined && $dataEnemies[this._enemyId].meta.ChangeRestriction === undefined ){
  147.                 return r.concat(this.itemObject(di.kind, di.dataId));
  148.                 }else{
  149. // Check if itemId match a possible CancelRestriction note     
  150. if (di.dataId === Number($dataEnemies[this._enemyId].meta.CancelRestriction)) {
  151. return r.concat(this.itemObject(di.kind, di.dataId));}
  152. else {
  153. // Check if enemy have an overwriting tag <ChangeRestriction>
  154. if  ($dataEnemies[this._enemyId].meta.ChangeRestriction === undefined){
  155. //Don't Have <ChangeRestriction> tag, apply <DropRestriction>
  156.      if (eval(eval($dataItems[di.dataId].meta.DropRestriction))){
  157.                             return r.concat(this.itemObject(di.kind, di.dataId));
  158.                                         } else{
  159.                                         return r}
  160.                                         } else{
  161. // Have <ChangeRestriction> tag, check if item is the same
  162. if (Number($dataEnemies[this._enemyId].meta.ChangeRestriction[0]) === di.dataId){
  163. // Same Item, use <ChangeRestriction> new formula
  164. // Start Formula will read formula after the "," in the tag
  165. var startFormula = $dataEnemies[this._enemyId].meta.ChangeRestriction.indexOf(",",0);
  166.             if (eval(eval($dataEnemies[this._enemyId].meta.ChangeRestriction.slice(startFormula + 1)))){
  167.                     return r.concat(this.itemObject(di.kind, di.dataId));
  168.                                   } else{
  169.                                     return r}}
  170. else{
  171. // Item is not the same, use original information
  172.             if (eval(eval($dataItems[di.dataId].meta.DropRestriction))){
  173.                     return r.concat(this.itemObject(di.kind, di.dataId));
  174.                                   } else{
  175.                                     return r}}
  176.  
  177.                                             }}}} else {
  178.             return r;}
  179.     }.bind(this), []);
  180. }
  181.  
  182.  
  183.  
  184.  
  185.  
  186.   })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement