Maliki79

MalEncounterRateOptions

May 13th, 2016
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Maliki's Random Encounter Step Options
  3. // MalEncounterRateOptions.js
  4. // version 1.5
  5. //=============================================================================
  6. /*:  
  7. * @plugindesc ver1.5 - Allows players to set a general random encounter rate in the Options Menu.  
  8.  * @author Maliki79
  9.  *
  10.  * @param RateUpperLimit
  11.  * @desc The highest percentage the Encounter Rate can reach.  This number MUST be at or above 100.
  12.  * Default: 100
  13.  * @default 100
  14.  *
  15.  * @param RateLowerLimit
  16.  * @desc The lowest percentage the Encounter Rate can reach.  This number MUST be at or below 100.
  17.  * Default: 0
  18.  * @default 0
  19.  *
  20.  * @param EncounterOffset
  21.  * @desc The value that the Encounter Rate will change when a direction or ok is pressed.
  22.  * Default: 50
  23.  * @default 50
  24.  *
  25.  * @param EncounterRateShow
  26.  * @desc Forces Encounter rate to be shown in Options even when locked. 0 = true 1 = false
  27.  * Default: 0
  28.  * @default 0
  29.  *
  30.  * @param EncounterSpeed
  31.  * @desc Enter an Interger higher than 0 to allow encounters to occur event when standing still.
  32.  * Default: 0
  33.  * @default 0
  34.  *
  35.  * @help Allows players to set a general random encounter rate in the Options Menu.  
  36.  * This rate can be reduced to 0 to eliminate ALL random encounters.
  37.  * Also allows developers to lock/unlock the encounter rate directly and set
  38.  * values to whatever they want.
  39.  *
  40.  * Once installed, run your game and go to Options to find the
  41.  * Encounter Rate setting. (If EncounterRateShow is NOT set to 0, the encounter rate will NOT appear
  42.  * on the Title Screen's Option Menu as the rate is considered locked when on the Title Screen.)
  43.  *
  44.  * Optional: You can set the Upper limit of the Encounter rate to any number over 100.
  45.  * If set below, or to a non-number, it will default to 100.
  46.  *
  47.  * Optional: You can set the amount the Encounter Rate rises or falls via the Encounter Offset Param.
  48.  *
  49.  * You can set a timer to allow encounters while standing still.
  50.  * If the param EncounterSpeed is set to a number higher than 0, encounters will be able to occur
  51.  * even while players are not moving!
  52.  * Increasing the number will speed up the enocounter rate.
  53.  * Leaving it at 0 will disable this option.
  54.  * (Other encounter rate option will still be in effect)
  55.  *
  56.  *  SCRIPT CALLS
  57.  *
  58.  * $gameSystem.lockEncounterRate();
  59.  * This call will LOCK the Encounter Rate setting at whatever number it was when called.
  60.  * You can add a number in the () to set the rate while locking it.
  61.  * Note: Unless EncounterRateShow is set to 0, the Encounter Rate will not show on the Option
  62.  * Menu while locked.
  63.  *
  64.  * $gameSystem.unlockEncounterRate();
  65.  * This call will allow players to change the Encounter Rate again after it hs been locked.
  66.  * You can add a number in the () to set the rate while unlocking it.
  67.  *
  68.  * $gameSystem.setEncounterRate(x);
  69.  * This call will change the Encounter Rate to any positive integer.
  70.  * Note that the player can change the number if the Encounter Rate is not locked.
  71.  *
  72.  * $gameSystem.getEncounterRate();
  73.  * This call will return the current Encounter Rate.
  74.  */
  75.  
  76. ConfigManager.commandEncounter = 100;
  77.  
  78. var MalEncounterTitle = Scene_Title.prototype.create;
  79. Scene_Title.prototype.create = function() {
  80. MalEncounterTitle.call(this);
  81. $gameSystem._encountersLocked = true;
  82. }
  83.  
  84. var MalEncounterInitialize = Game_System.prototype.initialize;
  85. Game_System.prototype.initialize = function() {
  86. MalEncounterInitialize.call(this);
  87. this._encountersLocked = false;
  88. }
  89.  
  90. Game_System.prototype.lockEncounterRate = function(setting) {
  91. $gameSystem._encountersLocked = true;
  92. if (setting) this.setEncounterRate(setting);
  93. }
  94.  
  95. Game_System.prototype.unlockEncounterRate = function(setting) {
  96. $gameSystem._encountersLocked = false;
  97. if (setting) this.setEncounterRate(setting);
  98. }
  99.  
  100. Game_System.prototype.getEncounterRate = function() {
  101. return $gameSystem._encounterRate;
  102. }
  103.  
  104. Game_System.prototype.setEncounterRate = function(setting) {
  105. var numb = Number(eval(setting)) || 100;
  106. if (numb < 0) numb = 0;
  107. ConfigManager['commandEncounterVolume'] = numb;
  108. $gameSystem._encounterRate = numb;
  109. }
  110.  
  111. Object.defineProperty(ConfigManager, 'encounterRate', {
  112.     get: function() {
  113.         return ConfigManager.commandEncounterVolume;
  114.     },
  115.     set: function(value) {
  116.         ConfigManager.commandEncounterVolume = value;
  117.     },
  118.     configurable: true
  119. });
  120.  
  121. var Mal_Config_MakeData = ConfigManager.makeData;
  122. ConfigManager.makeData = function() {
  123.     var config = Mal_Config_MakeData.call(this);
  124.     config.encounterRate = this.encounterRate; 
  125.     return config;
  126. };
  127.  
  128. var Mal_Config_applyData = ConfigManager.applyData;
  129. ConfigManager.applyData = function(config) {
  130.     Mal_Config_applyData.call(this, config);
  131.     this.encounterRate = this.readEncounter(config, 'encounterRate');
  132. };
  133.  
  134. ConfigManager.readEncounter = function(config, name) {
  135.     var value = config[name];
  136.     if (value !== undefined) {
  137.         return Number(value);
  138.     } else {
  139.         return 100;
  140.     }
  141. };
  142.  
  143. Window_Options.prototype.encounterOffset = function() {
  144.     var num = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterOffset']) || 50;
  145.     if (num !== undefined) {
  146.     return Math.floor(num);
  147.     } else {
  148.     return 50;
  149. }  
  150. };
  151.  
  152. var Mal_Window_addGeneralOptions = Window_Options.prototype.addGeneralOptions;
  153. Window_Options.prototype.addGeneralOptions = function() {
  154.     Mal_Window_addGeneralOptions.call(this);
  155.     if (PluginManager.parameters('MalEncounterRateOptions')['EncounterRateShow'] == 0 || $gameSystem._encountersLocked == false ) this.addCommand("Encounter Rate", 'commandEncounterVolume');
  156.     };
  157.    
  158. Game_Player.prototype.encounterProgressValue = function() {
  159.     var value = $gameMap.isBush(this.x, this.y) ? 2 : 1;
  160.     var val2 = ConfigManager.encounterRate;
  161.     if ($gameParty.hasEncounterHalf()) {
  162.         value *= 0.5;
  163.     }
  164.     if (this.isInShip()) {
  165.         value *= 0.5;
  166.     }
  167.     return value * (val2 / 100.0);
  168. };
  169.  
  170. ConfigManager.readEncounter = function(config, name) {
  171.     var value = config[name];
  172.     var limit = Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit']);
  173.     var lowLimit = Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit']);
  174.     if (limit < 100) limit = 100;
  175.     if (lowLimit < 0) lowLimit = 0;
  176.     if (value !== undefined) {
  177.         return Number(value).clamp(lowLimit, limit);
  178.     } else {
  179.         return 100;
  180.     }
  181. };
  182.  
  183. Window_Options.prototype.isEncounterSymbol = function(symbol) {
  184.     return symbol.contains('Encounter');
  185. };
  186.  
  187. var Mal_Win_Options_processOk = Window_Options.prototype.processOk
  188. Window_Options.prototype.processOk = function() {
  189.     var index = this.index();
  190.     var symbol = this.commandSymbol(index);
  191.     if (this.isEncounterSymbol(symbol) ) {
  192.         var value = this.getConfigValue(symbol);
  193.         var offset = this.encounterOffset();
  194.         var limit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit'])) || 100;
  195.         var lowLimit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit'])) || 0;
  196.         if (limit < 100) limit = 100;
  197.         if ($gameSystem._encountersLocked == false){
  198.         if (value + offset > limit && value != limit) {
  199.         value = limit;
  200.         } else {
  201.         value += offset;
  202.         }
  203.         if (value > limit) value = lowLimit;
  204.         this.changeValue(symbol, value);
  205.         $gameSystem._encounterRate = value;
  206.         } else {
  207.         SoundManager.playBuzzer();
  208.         }
  209.         } else {
  210.             Mal_Win_Options_processOk.call(this);
  211.         }
  212. };
  213.  
  214. var Mal_Win_Options_cursorRight = Window_Options.prototype.cursorRight
  215. Window_Options.prototype.cursorRight = function(wrap) {
  216.     var index = this.index();
  217.     var symbol = this.commandSymbol(index);
  218.     if (this.isEncounterSymbol(symbol)) {
  219.         var value = this.getConfigValue(symbol);
  220.         var offset = this.encounterOffset();
  221.         var limit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit'])) || 100;
  222.         var lowLimit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit'])) || 0;
  223.         if (limit < 100) limit = 100;
  224.         if ($gameSystem._encountersLocked == false){
  225.         if (value + offset > limit && value != limit) {
  226.         value = limit;
  227.         } else {
  228.         value += offset;
  229.         }
  230.         if (value > limit) value = lowLimit;
  231.         this.changeValue(symbol, value);
  232.         $gameSystem._encounterRate = value;
  233.         } else {
  234.         SoundManager.playBuzzer();
  235.         }
  236.         } else {
  237.             Mal_Win_Options_cursorRight.call(this, wrap);
  238.         }
  239. };
  240.  
  241. var Mal_Win_Options_cursorLeft = Window_Options.prototype.cursorLeft
  242. Window_Options.prototype.cursorLeft = function(wrap) {
  243.     var index = this.index();
  244.     var symbol = this.commandSymbol(index);
  245.     if (this.isEncounterSymbol(symbol)) {
  246.         var value = this.getConfigValue(symbol);
  247.         var offset = this.encounterOffset();
  248.         var limit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit'])) || 100;
  249.         var lowLimit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit'])) || 0;
  250.         if (limit < 100) limit = 100;
  251.         if ($gameSystem._encountersLocked == false){
  252.         if (value - offset < lowLimit && value != lowLimit) {
  253.         value = lowLimit;
  254.         } else {
  255.         value -= offset;
  256.         }
  257.         if (value < lowLimit) value = limit;
  258.         this.changeValue(symbol, value);
  259.         $gameSystem._encounterRate = value;
  260.         } else {
  261.         SoundManager.playBuzzer();
  262.         }
  263.         } else {
  264.             Mal_Win_Options_cursorLeft.call(this, wrap);
  265.         }
  266. };
  267.  
  268. var MalEncounter_onLoadSuccess = Scene_Load.prototype.onLoadSuccess;
  269. Scene_Load.prototype.onLoadSuccess = function() {
  270. MalEncounter_onLoadSuccess.call(this);
  271. ConfigManager['commandEncounterVolume'] = $gameSystem._encounterRate || 100;
  272. //$gamePlayer.encounterTick = 0;
  273. }
  274.  
  275. //var MalEncounter_updateNonmoving = Game_Player.prototype.updateNonmoving;
  276. Game_Player.prototype.updateNonmoving = function(wasMoving) {
  277.     if (!$gamePlayer.encounterTick) $gamePlayer.encounterTick = 0;
  278.     if (!$gameMap.isEventRunning()) {
  279.         if (wasMoving) {
  280.             $gameParty.onPlayerWalk();
  281.             this._firstStep = false;
  282.             this.checkEventTriggerHere([1,2]);
  283.             if ($gameMap.setupStartingEvent()) {
  284.                 return;
  285.             }
  286.         }
  287.         if (this.triggerAction()) {
  288.             return;
  289.         }
  290.         if ($gamePlayer.encounterTick >= 1000) {
  291.             this.updateEncounterCount();
  292.             $gamePlayer.encounterTick = 0;
  293.         } else {
  294.             if(!this._firstStep) $gamePlayer.encounterTick += 1 * Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterSpeed']));
  295.             //console.log($gamePlayer.encounterTick);
  296.         }
  297.         if (wasMoving) {
  298.             this.updateEncounterCount();
  299.         } else {
  300.             $gameTemp.clearDestination();
  301.         }
  302.     }
  303. };
  304.  
  305. var MalEncounterCount = Game_Player.prototype.makeEncounterCount;
  306. Game_Player.prototype.makeEncounterCount = function() {
  307.     MalEncounterCount.call(this);
  308.     if(PluginManager.parameters('MalEncounterRateOptions')['EncounterSpeed'] != 0) this._encounterCount += 3;
  309.     this._firstStep = true;
  310. };
Add Comment
Please, Sign In to add comment