Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // Maliki's Mutable Items MZ
- // MalMZMutableItems.js
- // version 1.5
- //=============================================================================
- /*:
- * @target MZ
- *
- * @plugindesc ver1.5 - Allows you to have items in your inventory automatically change to other items after a set amount of player steps
- * @author Maliki79
- *
- * @param defaultStepReduction
- * @desc The default amount of "step-points" an items mutate score will drop before it changes.
- * Default: 1
- * @default 1
- *
- * @param skipStep
- * @desc Whether or not the step timer activates upon player steps.
- * Default: 1
- * @default 1
- *
- * @help You need two steps to use this plugin:
- *
- * 1: Setup the item(s) you want your olditem to potentially change into.
- * You do this with the following notetag:
- *
- * <nextId: x, y, z>
- *
- * with x being a letter i, w, or a. (Item, Weapon, or Armor respectively)
- * y being the id number in the database and z being the percentange chance as an integer.
- * Example: <nextId: i, 8, 20> will give this item a 20% chance to change into item 8 from your database.
- * You can have as many of these tags on a single item as you want.
- * Note that if the total percentage chance does not equal 100, there will be a chance for failure equal
- * to the left over percentage.
- * Also note that if the total percentage goes beyond 100%, it becomes a "rating" chance instead.
- * In other words, you can safely go beyond 100% total chance.
- *
- * 2: Set the timing for this change via the notetag
- *
- * <newItemStepCount: x>
- *
- * with x being the number of step-points required before the item will change.
- * Every time the player moves a step, the total steps required for the item to change (x) will be reduced
- * by the number of step-points chosen. (Default is 1).
- *
- * 3a: (Optional) Evals have been added so advanced users can input different effects for successful and failing changes.
- * Use the notetags <newItemSuccessEval: >>> or <newItemFailureEval: >>> noting the space after the : as well as the 3 >.
- *
- * 3b: The <stepPointAdjustEval: >>> tag has been added to allow different influences to change how fast or slow the
- * Step-points are reduced.
- * Add an eval that returns a number and that number will be added to the step-point total.
- * Higher numbers make the item change sooner, while lower ones make the change slower.
- * You can reduce the number to 0 to stall the change indefinately, but cannot reduce below that.
- *
- * Using skipStep Param
- *
- * If you set skipStep to a number other than 1, Step-Points will NOT be calculated when players take steps in-game.
- * This can be used for games that do not want to use steps to countdown the item changing.
- *
- * To force the count change, use the script call: $gameParty.muteStepCountdown();
- * (this call can be used regardless of the skipStep param.)
- */
- var MalMuteableDatabaseLoad = DataManager.isDatabaseLoaded;
- DataManager.isDatabaseLoaded = function() {
- if (!MalMuteableDatabaseLoad.call(this)) return false;
- if (!DataManager._malMute_DatabaseLoaded) {
- this.processMuteNotetags($dataItems);
- this.processMuteNotetags($dataWeapons);
- this.processMuteNotetags($dataArmors);
- DataManager._malMute_DatabaseLoaded = true;
- }
- return true;
- };
- DataManager.processMuteNotetags = function(group) {
- for (var n = 1; n < group.length; n++) {
- var obj = group[n];
- if(!obj) continue;
- obj.newItemSet = [];
- obj.newItemSuccessEval = [];
- obj.newItemFailureEval = [];
- obj.stepPointAdjustEval = [];
- var noteread = obj.note;
- while(noteread.indexOf("nextId") > -1) {
- var match = noteread.split("<nextId: ");
- var match2 = match[1].split(">");
- obj.newItemSet.push(match2[0]);
- noteread = noteread.replace("<nextId: ", " ");
- }
- obj.newItemStepCount = -2;
- if(obj.meta.newItemStepCount) obj.newItemStepCount = parseInt(obj.meta.newItemStepCount);
- var noteread = obj.note;
- while(noteread.indexOf("newItemSuccessEval") > -1)
- {
- var notereg = noteread.split("<newItemSuccessEval: ");
- var match = notereg[1].split(">>>");
- obj.newItemSuccessEval.push(match[0]);
- noteread = noteread.replace("<newItemSuccessEval: ", " ");
- }
- noteread = obj.note;
- while(noteread.indexOf("newItemFailureEval") > -1)
- {
- var notereg = noteread.split("<newItemFailureEval: ");
- var match = notereg[1].split(">>>");
- obj.newItemFailureEval.push(match[0]);
- noteread = noteread.replace("<newItemFailureEval: ", " ");
- }
- noteread = obj.note;
- while(noteread.indexOf("stepPointAdjustEval") > -1)
- {
- var notereg = noteread.split("<stepPointAdjustEval: ");
- var match = notereg[1].split(">>>");
- obj.stepPointAdjustEval.push(match[0]);
- noteread = noteread.replace("<stepPointAdjustEval: ", " ");
- }
- };
- };
- var MalMuteGPInit = Game_Party.prototype.initialize
- Game_Party.prototype.initialize = function() {
- MalMuteGPInit.call(this);
- this.newItemSet = this.newItemSet || [];
- };
- var MalMuteGPGainItem = Game_Party.prototype.gainItem
- Game_Party.prototype.gainItem = function(item, amount, includeEquip){
- var plusAmount = amount;
- var current = this.numItems(item);
- var max = this.maxItems(item);
- if(current + plusAmount > max && plusAmount > 0) plusAmount = max - current;
- if (!$gameTemp.skipmutables) if(item.newItemStepCount != -2 && plusAmount > 0) this.addNewItemTimer(item, plusAmount);
- MalMuteGPGainItem.call(this, item, amount, includeEquip);
- };
- Game_Party.prototype.addNewItemTimer = function(item, amount) {
- for (i =0; i < amount; i++) {
- this.newItemSet.push([item, item.newItemStepCount]);
- }
- };
- var MalMuteGPWalk = Game_Party.prototype.onPlayerWalk;
- Game_Party.prototype.onPlayerWalk = function() {
- MalMuteGPWalk.call(this);
- var useStepCount = Number(PluginManager.parameters('MalMZMutableItems')['skipStep']);
- if (useStepCount == 1) this.muteStepCountdown();
- };
- Game_Party.prototype.muteStepCountdown = function() {
- for(i = 0; i < this.newItemSet.length; i++){
- var item = this.newItemSet[i][0];
- if(item.itypeId !== undefined) item = $dataItems[item.id];
- if(item.wtypeId !== undefined) item = $dataWeapons[item.id];
- if(item.atypeId !== undefined) item = $dataArmors[item.id];
- var offset = this.countOffset(item) + Number(PluginManager.parameters('MalMZMutableItems')['defaultStepReduction']);
- if(offset < 0) offset = 0;
- this.newItemSet[i][1] -= offset;
- if(this.newItemSet[i][1] <= 0) {
- if($gameParty.hasItem(item, true)) {
- this.grantMutedItem(item);
- }
- }
- };
- this.muteCleanup();
- };
- Game_Party.prototype.muteCleanup = function() {
- var firstCount = -1;
- while (firstCount != this.newItemSet.length) {
- firstCount = this.newItemSet.length;
- for(i = 0; i < this.newItemSet.length; i++){
- var item = this.newItemSet[i][0];
- if(this.newItemSet[i][1] <= 0) {
- this.newItemSet.splice(i, 1);
- };
- }
- }
- };
- Game_Party.prototype.countOffset = function(item) {
- var set = item.stepPointAdjustEval;
- var count = 0;
- var item = item;
- var s = $gameSwitches._data;
- var v = $gameVariables._data;
- if (set.length > 0){
- for(k = 0; k < set.length; k++){
- count += parseInt(eval(set[k])) || 0;
- };
- };
- return count;
- };
- Game_Party.prototype.grantMutedItem = function(item) {
- var oldItem = item;
- if(!oldItem) return;
- var newItem = null;
- var done = false;
- var set = oldItem.newItemSet;
- var pick = 0;
- var chance = 0;
- for (i = 0; i < set.length; i++) {
- chance += parseInt(set[i][2])
- };
- if(chance > 100) {chance = Math.randomInt(chance)} else { chance = Math.randomInt(100)};
- for (i = 0; i < set.length; i++) {
- if(done) continue;
- var splitSet = set[i].split(",");
- pick += parseInt(splitSet[2]);
- if(pick > chance) {
- if(splitSet[0] === "i") newItem = $dataItems[parseInt(splitSet[1])];
- if(splitSet[0] === "w") newItem = $dataWeapons[parseInt(splitSet[1])];
- if(splitSet[0] === "a") newItem = $dataArmors[parseInt(splitSet[1])];
- this.gainItem(newItem, 1);
- this.processSuccessEvals(oldItem, newItem);
- done = true;
- }
- }
- this.loseItem(oldItem, 1, true);
- if(done == false) this.processFailureEvals(oldItem);
- };
- var MalMuteGPLoseItem = Game_Party.prototype.loseItem
- Game_Party.prototype.loseItem = function(item, amount, includeEquip) {
- if (!$gameTemp.skipmutables) this.removeItemTimer(item, amount);
- MalMuteGPLoseItem.call(this, item, amount, includeEquip);
- };
- Game_Party.prototype.removeItemTimer = function (item, amount){
- var times = amount;
- for (j = 0; j < times; j++){
- for(i = 0; i < this.newItemSet.length; i++){
- var timerItem = this.newItemSet[i][0];
- var discardItem = item;
- if(timerItem.itypeId && discardItem.itypeId){
- if(timerItem.itypeId == discardItem.itypeId) {
- this.newItemSet[i][1] = -1;
- break;
- };
- };
- if(timerItem.wtypeId && discardItem.wtypeId){
- if(timerItem.wtypeId == discardItem.wtypeId) {
- this.newItemSet[i][1] = -1;
- break;
- };
- };
- if(timerItem.atypeId && discardItem.atypeId){
- if(timerItem.atypeId == discardItem.atypeId) {
- this.newItemSet[i][1] = -1;
- break;
- };
- };
- };
- };
- };
- Game_Party.prototype.processSuccessEvals = function (oldItem, newItem){
- var evals = oldItem.newItemSuccessEval;
- var oldItem = oldItem;
- var newItem = newItem;
- var s = $gameSwitches._data;
- var v = $gameVariables._data;
- for (var i = 0; i < evals.length; i++) {
- var SEval = evals[i];
- eval(SEval);
- };
- };
- Game_Party.prototype.processFailureEvals = function (oldItem){
- var evals = oldItem.newItemFailureEval;
- var oldItem = oldItem;
- var s = $gameSwitches._data;
- var v = $gameVariables._data;
- for (var i = 0; i < evals.length; i++) {
- var SEval = evals[i];
- eval(SEval);
- };
- };
- Game_Actor.prototype.tradeItemWithParty = function(newItem, oldItem) {
- if (newItem && !$gameParty.hasItem(newItem)) {
- return false;
- } else {
- $gameTemp.skipmutables = true;
- $gameParty.gainItem(oldItem, 1);
- $gameParty.loseItem(newItem, 1);
- $gameTemp.skipmutables = false;
- return true;
- }
- };
Add Comment
Please, Sign In to add comment