Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // Maliki's Random Encounter Step Options
- // MalEncounterRateOptions.js
- // version 1.8
- //=============================================================================
- /*:
- * @plugindesc ver1.8 - Allows players to set a general random encounter rate in the Options Menu.
- * @author Maliki79
- *
- * @param RateUpperLimit
- * @desc The highest percentage the Encounter Rate can reach. This number MUST be at or above 100.
- * Default: 100
- * @default 100
- *
- * @param RateLowerLimit
- * @desc The lowest percentage the Encounter Rate can reach. This number MUST be at or below 100.
- * Default: 0
- * @default 0
- *
- * @param EncounterOffset
- * @desc The value that the Encounter Rate will change when a direction or ok is pressed.
- * Default: 50
- * @default 50
- *
- * @param EncounterRateShow
- * @desc Forces Encounter rate to be shown in Options even when locked. 0 = true 1 = false
- * Default: 0
- * @default 0
- *
- * @param EncounterSpeed
- * @desc Enter an Interger higher than 0 to allow encounters to occur even when standing still.
- * Default: 0
- * @default 0
- *
- * @param EncounterCancelTimer
- * @desc Enter an Interger higher than 0 to allow encounters to be cancellable. 60 is about 10 seconds.
- * Default: 30
- * @default 30
- *
- * @param EncounterCancelXRate
- * @desc Enter a float value to determine multiplier for exp and gold gained from cancelled battles. Enter 0 to not use.
- * Default: 0.5
- * @default 0.5
- *
- * @param EncounterGetReadyBalloon
- * @desc Enter a number to show corresponding balloon emote when deciding to cancel battles. Enter 0 to not use.
- * Default: 2
- * @default 2
- *
- * @param EncounterGetReadyAnimation
- * @desc Enter a number to show corresponding animation when deciding to cancel battles. Enter 0 to not use.
- * Default: 0
- * @default 0
- *
- * @param EncounterSuccessfulCancelCE
- * @desc Enter a number to run corresponding common event after successfully cancelling battles. Enter 0 to not use.
- * Default: 0
- * @default 0
- *
- * @help Allows players to set a general random encounter rate in the Options Menu.
- * This rate can be reduced to 0 to eliminate ALL random encounters.
- * Also allows developers to lock/unlock the encounter rate directly and set
- * values to whatever they want.
- *
- * Once installed, run your game and go to Options to find the
- * Encounter Rate setting. (If EncounterRateShow is NOT set to 0, the encounter rate will NOT appear
- * on the Title Screen's Option Menu as the rate is considered locked when on the Title Screen.)
- *
- * Optional: You can set the Upper limit of the Encounter rate to any number over 100.
- * If set below, or to a non-number, it will default to 100.
- *
- * Optional: You can set the amount the Encounter Rate rises or falls via the Encounter Offset Param.
- *
- * You can set a timer to allow encounters while standing still.
- * If the param EncounterSpeed is set to a number higher than 0, encounters will be able to occur
- * even while players are not moving!
- * Increasing the number will speed up the enocounter rate.
- * Leaving it at 0 will disable this option.
- * (Other encounter rate option will still be in effect)
- *
- * This plugin now also allows you to adjust the "weight" of random encounters by enemy troop Id.
- * In map notes, you can add the notetag:
- *
- * <malEncAdj: troopId, amount, condition >>>
- * with troopId being the troop Id number in the database,
- * amount being the amount the weight will be adjusted (this can be negative, but it must be an integer.)
- * and condition can be a javascript eval that returns true or false.
- * (And note the 3 >>> at the end of the tag.)
- *
- * For example, the tag <malEncAdj: 1, 10, $gameSwitches.value(1)>>>
- * will increase the weight of all instances of troop one on that map by 10 if switch 1 is turned ON.
- *
- * <malEncAdj: 4, -25, $gameVariables.value(1) > 10>>>
- * will decrease the weight of all instances of troop 4 on that map by 25 if variable 1 is greater than 10.
- *
- * <malEncAdj: 7, $gameVariables.value(2) * 5, $gameVariables.value(2) > 0>>>
- * will increase the weight of all instances of troop 7 on that map by 5 * variable 2 if variable 2 is greater than 0.
- *
- * If you set the troop ID to -1, it will affect ALL troops on that map if the conditions are met.
- *
- * weights are cumulative, meaning you could potentially have a troop affected by multiple tages.
- * Note that any weight values that change to a value below 0 will NOT be encountered at all.
- * Conversely, any troops initially set to 0 in the database but brought above 1 or higher CAN be encountered.
- * (You can eval weight to an integer)
- *
- * <malNulRegionEnc: regionID, condition >>>
- * with region ID being the region ID of the tile the player is standing on and condition being a
- * boolean that equates to true/false.
- * (Using -1 will effect ALL regions AND regionless areas (basically the entire map)
- *
- * This note tag will REMOVE ALL encounters on the specified region ID on that map if the conditions are true.
- *
- * Note that this tag supersides the malEncAdj tag meaning if you negate all encounters, their weight will hot matter.
- *
- * CANCELABLE BATTLES
- *
- * Now battles can be canceled outright!
- * To utilize this, first set this tag in Map Notes:
- *
- * <malInstantBattEnd: regionID, condition >>>
- *
- * with region ID being the region ID of the tile the player is standing on and condition being a boolean
- * that equates to true/false.
- * (Using -1 will effect ALL regions AND regionless areas (basically the entire map)
- * If the condition is true, the player will momentarily be unable to move and must press the ok or cancel buttons in a certain time window.
- * You can set this window using the EncounterCancelTimer param.
- * You can also use the EncounterGetReadyBalloon and/or EncounterGetReadyAnimation params to set a balloon emote
- * or animation to play at the start of the wait period.
- * If the player presses ok, the battle will be skipped!
- * Gold, Exp and items can be obtained as in normal battles.
- * You can use the param EncounterCancelXRate to determine if the players get reduced gold and XP.
- * Lastly, you can use the EncounterSuccessfulCancelCE param to set a common event to run if a battle is
- * cancelled.
- *
- * SCRIPT CALLS
- *
- * $gameSystem.lockEncounterRate();
- * This call will LOCK the Encounter Rate setting at whatever number it was when called.
- * You can add a number in the () to set the rate while locking it.
- * Note: Unless EncounterRateShow is set to 0, the Encounter Rate will not show on the Option
- * Menu while locked.
- *
- * $gameSystem.unlockEncounterRate();
- * This call will allow players to change the Encounter Rate again after it hs been locked.
- * You can add a number in the () to set the rate while unlocking it.
- *
- * $gameSystem.setEncounterRate(x);
- * This call will change the Encounter Rate to any positive integer.
- * Note that the player can change the number if the Encounter Rate is not locked.
- *
- * $gameSystem.getEncounterRate();
- * This call will return the current Encounter Rate.
- */
- ConfigManager.commandEncounter = 100;
- var MalEncounterTitle = Scene_Title.prototype.create;
- Scene_Title.prototype.create = function() {
- MalEncounterTitle.call(this);
- $gameSystem._encountersLocked = true;
- }
- var MalEncounterInitialize = Game_System.prototype.initialize;
- Game_System.prototype.initialize = function() {
- MalEncounterInitialize.call(this);
- this._encountersLocked = false;
- }
- Game_System.prototype.lockEncounterRate = function(setting) {
- $gameSystem._encountersLocked = true;
- if (setting) this.setEncounterRate(setting);
- }
- Game_System.prototype.unlockEncounterRate = function(setting) {
- $gameSystem._encountersLocked = false;
- if (setting) this.setEncounterRate(setting);
- }
- Game_System.prototype.getEncounterRate = function() {
- return $gameSystem._encounterRate;
- }
- Game_System.prototype.setEncounterRate = function(setting) {
- var numb = Number(eval(setting)) || 100;
- if (numb < 0) numb = 0;
- ConfigManager['commandEncounterVolume'] = numb;
- $gameSystem._encounterRate = numb;
- }
- Object.defineProperty(ConfigManager, 'encounterRate', {
- get: function() {
- return ConfigManager.commandEncounterVolume;
- },
- set: function(value) {
- ConfigManager.commandEncounterVolume = value;
- },
- configurable: true
- });
- var Mal_Config_MakeData = ConfigManager.makeData;
- ConfigManager.makeData = function() {
- var config = Mal_Config_MakeData.call(this);
- config.encounterRate = this.encounterRate;
- return config;
- };
- var Mal_Config_applyData = ConfigManager.applyData;
- ConfigManager.applyData = function(config) {
- Mal_Config_applyData.call(this, config);
- this.encounterRate = this.readEncounter(config, 'encounterRate');
- };
- ConfigManager.readEncounter = function(config, name) {
- var value = config[name];
- if (value !== undefined) {
- return Number(value);
- } else {
- return 100;
- }
- };
- Window_Options.prototype.encounterOffset = function() {
- var num = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterOffset']) || 50;
- if (num !== undefined) {
- return Math.floor(num);
- } else {
- return 50;
- }
- };
- var Mal_Window_addGeneralOptions = Window_Options.prototype.addGeneralOptions;
- Window_Options.prototype.addGeneralOptions = function() {
- Mal_Window_addGeneralOptions.call(this);
- if (PluginManager.parameters('MalEncounterRateOptions')['EncounterRateShow'] == 0 || $gameSystem._encountersLocked == false ) this.addCommand("Encounter Rate", 'commandEncounterVolume');
- };
- Game_Player.prototype.encounterProgressValue = function() {
- var value = $gameMap.isBush(this.x, this.y) ? 2 : 1;
- var val2 = ConfigManager.encounterRate;
- if ($gameParty.hasEncounterHalf()) {
- value *= 0.5;
- }
- if (this.isInShip()) {
- value *= 0.5;
- }
- return value * (val2 / 100.0);
- };
- ConfigManager.readEncounter = function(config, name) {
- var value = config[name];
- var limit = Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit']);
- var lowLimit = Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit']);
- if (limit < 100) limit = 100;
- if (lowLimit < 0) lowLimit = 0;
- if (value !== undefined) {
- return Number(value).clamp(lowLimit, limit);
- } else {
- return 100;
- }
- };
- Window_Options.prototype.isEncounterSymbol = function(symbol) {
- return symbol.contains('Encounter');
- };
- var Mal_Win_Options_processOk = Window_Options.prototype.processOk
- Window_Options.prototype.processOk = function() {
- var index = this.index();
- var symbol = this.commandSymbol(index);
- if (this.isEncounterSymbol(symbol) ) {
- var value = this.getConfigValue(symbol);
- var offset = this.encounterOffset();
- var limit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit'])) || 100;
- var lowLimit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit'])) || 0;
- if (limit < 100) limit = 100;
- if ($gameSystem._encountersLocked == false){
- if (value + offset > limit && value != limit) {
- value = limit;
- } else {
- value += offset;
- }
- if (value > limit) value = lowLimit;
- this.changeValue(symbol, value);
- $gameSystem._encounterRate = value;
- } else {
- SoundManager.playBuzzer();
- }
- } else {
- Mal_Win_Options_processOk.call(this);
- }
- };
- var Mal_Win_Options_cursorRight = Window_Options.prototype.cursorRight
- Window_Options.prototype.cursorRight = function(wrap) {
- var index = this.index();
- var symbol = this.commandSymbol(index);
- if (this.isEncounterSymbol(symbol)) {
- var value = this.getConfigValue(symbol);
- var offset = this.encounterOffset();
- var limit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit'])) || 100;
- var lowLimit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit'])) || 0;
- if (limit < 100) limit = 100;
- if ($gameSystem._encountersLocked == false){
- if (value + offset > limit && value != limit) {
- value = limit;
- } else {
- value += offset;
- }
- if (value > limit) value = lowLimit;
- this.changeValue(symbol, value);
- $gameSystem._encounterRate = value;
- } else {
- SoundManager.playBuzzer();
- }
- } else {
- Mal_Win_Options_cursorRight.call(this, wrap);
- }
- };
- var Mal_Win_Options_cursorLeft = Window_Options.prototype.cursorLeft
- Window_Options.prototype.cursorLeft = function(wrap) {
- var index = this.index();
- var symbol = this.commandSymbol(index);
- if (this.isEncounterSymbol(symbol)) {
- var value = this.getConfigValue(symbol);
- var offset = this.encounterOffset();
- var limit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit'])) || 100;
- var lowLimit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit'])) || 0;
- if (limit < 100) limit = 100;
- if ($gameSystem._encountersLocked == false){
- if (value - offset < lowLimit && value != lowLimit) {
- value = lowLimit;
- } else {
- value -= offset;
- }
- if (value < lowLimit) value = limit;
- this.changeValue(symbol, value);
- $gameSystem._encounterRate = value;
- } else {
- SoundManager.playBuzzer();
- }
- } else {
- Mal_Win_Options_cursorLeft.call(this, wrap);
- }
- };
- var MalEncounter_onLoadSuccess = Scene_Load.prototype.onLoadSuccess;
- Scene_Load.prototype.onLoadSuccess = function() {
- MalEncounter_onLoadSuccess.call(this);
- ConfigManager['commandEncounterVolume'] = $gameSystem._encounterRate || 100;
- //$gamePlayer.encounterTick = 0;
- }
- var malEROGPMBInput = Game_Player.prototype.moveByInput;
- Game_Player.prototype.moveByInput = function() {
- if (!$gameMap._EncCancLoop) malEROGPMBInput.call(this);
- };
- Game_Player.prototype.updateNonmoving = function(wasMoving) {
- if (!$gamePlayer.encounterTick) $gamePlayer.encounterTick = 0;
- if (!$gameMap.isEventRunning()) {
- if (wasMoving) {
- $gameParty.onPlayerWalk();
- this._firstStep = false;
- this.checkEventTriggerHere([1,2]);
- if ($gameMap.setupStartingEvent()) {
- return;
- }
- }
- if (this.triggerAction()) {
- return;
- }
- if ($gamePlayer.encounterTick >= 1000) {
- this.updateEncounterCount();
- $gamePlayer.encounterTick = 0;
- } else {
- if(!this._firstStep) $gamePlayer.encounterTick += 1 * Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterSpeed']));
- }
- if (wasMoving) {
- this.updateEncounterCount();
- } else {
- $gameTemp.clearDestination();
- }
- }
- };
- var MalEncounterCount = Game_Player.prototype.makeEncounterCount;
- Game_Player.prototype.makeEncounterCount = function() {
- MalEncounterCount.call(this);
- if(PluginManager.parameters('MalEncounterRateOptions')['EncounterSpeed'] != 0) this._encounterCount += 3;
- this._firstStep = true;
- };
- Game_Player.prototype.executeEncounter = function() {
- if (!$gameMap.isEventRunning() && this._encounterCount <= 0 && !$gameMap._EncCancLoop) {
- this.makeEncounterCount();
- var troopId = this.makeEncounterTroopId();
- this._savedTroopId = troopId;
- if ($dataTroops[troopId]) {
- if(!$gameMap._EncCancLoop) this.checkBattleInterrupt($dataTroops[troopId]);
- BattleManager.setup(troopId, true, false);
- BattleManager.onEncounter();
- if(BattleManager._surprise) {
- $gameMap._EncCancLoop = false;
- this._savedTroopId = -1;
- return true;
- }
- if($gameMap._EncCancLoop) return false;
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- };
- Game_Player.prototype.checkBattleInterrupt = function(troop) {
- if(Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterCancelTimer']) == 0) return;
- if ($gameMap.nulBattle(this.regionId(), troop)) {
- $gameMap._EncCancLoop = true;
- var balloon = 0;
- var anima = 0;
- if(Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterGetReadyBalloon']) != 0) {
- balloon = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterGetReadyBalloon']);
- };
- if(Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterGetReadyAnimation']) != 0) {
- anima = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterGetReadyAnimation']);
- };
- if (balloon != 0) this.requestBalloon(balloon);
- if (anima != 0) this.requestAnimation(anima);
- };
- };
- var malEROGPTriggBAct = Game_Player.prototype.triggerButtonAction;
- Game_Player.prototype.triggerButtonAction = function() {
- if($gameMap._EncCancLoop) {
- if (Input.isPressed('ok')) {
- if (this.battlecancel()) {
- return true;
- }
- }
- if (Input.isPressed('cancel') || this._battleCanceltimer <= 0) {
- if (this.cBattlecancel()) {
- return true;
- }
- }
- this._battleCanceltimer--;
- }
- return malEROGPTriggBAct.call(this);
- };
- Game_Player.prototype.battlecancel = function () {
- BattleManager.setup(this._savedTroopId, true, false);
- $gameMap._EncCancLoop = false;
- BattleManager.processVictory();
- this._savedTroopId == -1;
- $gamePlayer._battleCanceltimer = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterCancelTimer']);
- this.requestBalloon(2);
- var comE = 0;
- if(Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterSuccessfulCancelCE']) != 0) {
- comE = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterSuccessfulCancelCE']);
- };
- if (comE != 0) $gameTemp.reserveCommonEvent(comE);
- };
- Game_Player.prototype.cBattlecancel = function () {
- $gameMap._EncCancLoop = false;
- $gamePlayer._battleCanceltimer = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterCancelTimer']);
- BattleManager.setup(this._savedTroopId, true, false);
- this._savedTroopId == -1;
- SceneManager.push(Scene_Battle);
- };
- var malEROGBBIsDead = Game_BattlerBase.prototype.isDead;
- Game_BattlerBase.prototype.isDead = function() {
- if ($gameMap._EncCancLoop && this.isEnemy()) return true;
- return malEROGBBIsDead.call(this);
- };
- var malEncounterGMSetup = Game_Map.prototype.setup;
- Game_Map.prototype.setup = function(mapId) {
- if (!$dataMap) {
- throw new Error('The map data is not available');
- }
- malEncounterGMSetup.call(this, mapId);
- this.setupEncounterAdjusts();
- };
- Game_Map.prototype.setupEncounterAdjusts = function() {
- this._encounterAdjusts = [];
- this._regionCond = [];
- this._instantBattCond = [];
- this._EncCancLoop = false;
- $gamePlayer._savedTroopId = -1;
- $gamePlayer._battleCanceltimer = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterCancelTimer']);
- var noteread = $dataMap.note;
- while(noteread.indexOf("malEncAdj") > -1)
- {
- var notereg = noteread.split("<malEncAdj: ");
- var match = notereg[1].split(">>>");
- match = match[0].split(", ");
- match[0] = parseInt(match[0]);
- //match[1] = parseInt(match[1]);
- this._encounterAdjusts.push(match);
- noteread = noteread.replace("<malEncAdj: ", " ");
- }
- var noteread = $dataMap.note;
- while(noteread.indexOf("malNulRegionEnc") > -1)
- {
- var notereg = noteread.split("<malNulRegionEnc: ");
- var match = notereg[1].split(">>>");
- var match2 = match[0].split(",");
- match2[0] = Number(match2[0]);
- this._regionCond.push(match2);
- noteread = noteread.replace("<malNulRegionEnc: ", " ");
- }
- var noteread = $dataMap.note;
- while(noteread.indexOf("malInstantBattEnd") > -1)
- {
- var notereg = noteread.split("<malInstantBattEnd: ");
- var match = notereg[1].split(">>>");
- var match2 = match[0].split(",");
- match2[0] = Number(match2[0]);
- this._instantBattCond.push(match2);
- noteread = noteread.replace("<malInstantBattEnd: ", " ");
- }
- };
- Game_Player.prototype.makeEncounterTroopId = function() {
- var encounterList = [];
- var weightSum = 0;
- $gameMap.encounterList().forEach(function(encounter) {
- if (this.meetsEncounterConditions(encounter)) {
- var encounterCopy = encounter;
- encounterCopy = this.malEncounterAdjust(encounterCopy);
- if (encounterCopy.weight > 0) {
- encounterList.push(encounterCopy);
- weightSum += encounterCopy.weight;
- }
- }
- }, this);
- if (weightSum > 0) {
- var value = Math.randomInt(weightSum);
- for (var i = 0; i < encounterList.length; i++) {
- value -= encounterList[i].weight;
- if (value < 0) {
- return encounterList[i].troopId;
- }
- }
- }
- return 0;
- };
- Game_Player.prototype.malEncounterAdjust = function (encounter) {
- var ec = encounter;
- var id = ec.troopId;
- var ea = $gameMap._encounterAdjusts;
- s = $gameSwitches._data;
- v = $gameVariables._data;
- for (var i = 0; i < ea.length; i++) {
- var line = ea[i];
- var value = Number(eval(line[1])) || 0;
- var check = eval(line[2]);
- if ((line[0] == id || line[0] == -1) && check) ec.weight += value;
- }
- return ec;
- }
- var MalGPMeetsEncCond = Game_Player.prototype.meetsEncounterConditions
- Game_Player.prototype.meetsEncounterConditions = function(encounter) {
- if ($gameMap.nulRegion(this.regionId())) return false;
- return MalGPMeetsEncCond.call(this, encounter);
- };
- Game_Map.prototype.nulRegion = function(region) {
- if (this._regionCond.length < 1) return false;
- s = $gameSwitches._data;
- v = $gameVariables._data;
- var region = Number(region);
- for (var i = 0; i < this._regionCond.length; i++) {
- if ((this._regionCond[i][0] == region || this._regionCond[i][0] == -1) && eval(this._regionCond[i][1])) return true;
- }
- return false;
- };
- Game_Map.prototype.nulBattle = function(region, troop) {
- if (this._instantBattCond.length < 1) return false;
- t = troop;
- s = $gameSwitches._data;
- v = $gameVariables._data;
- var region = Number(region);
- for (var i = 0; i < this._instantBattCond.length; i++) {
- if ((this._instantBattCond[i][0] == region || this._instantBattCond[i][0] == -1) && eval(this._instantBattCond[i][1])) return true;
- }
- return false;
- };
- var malEROGAFinExRate = Game_Actor.prototype.finalExpRate
- Game_Actor.prototype.finalExpRate = function() {
- var newRate = malEROGAFinExRate.call(this);
- var isBattleCancelled = $gameMap._EncCancLoop;
- var cancelRate = isBattleCancelled ? parseFloat(PluginManager.parameters('MalEncounterRateOptions')['EncounterCancelXRate']) : 1;
- return newRate * cancelRate;
- };
- var malEROGTGoldRate =Game_Troop.prototype.goldRate;
- Game_Troop.prototype.goldRate = function() {
- var newRate = malEROGTGoldRate.call(this);
- var isBattleCancelled = $gameMap._EncCancLoop;
- var cancelRate = isBattleCancelled ? parseFloat(PluginManager.parameters('MalEncounterRateOptions')['EncounterCancelXRate']) : 1;
- return newRate * cancelRate;
- };
- var malEROBMSB = BattleManager.startBattle;
- BattleManager.startBattle = function() {
- malEROBMSB.call(this);
- $gamePlayer._savedTroopId = -1;
- };
Advertisement
Add Comment
Please, Sign In to add comment