Maliki79

MalEncounterRateOptions

May 13th, 2016 (edited)
792
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.8
  5. //=============================================================================
  6. /*:  
  7. * @plugindesc ver1.8 - 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 even when standing still.
  32.  * Default: 0
  33.  * @default 0
  34.  *
  35.  * @param EncounterCancelTimer
  36.  * @desc Enter an Interger higher than 0 to allow encounters to be cancellable. 60 is about 10 seconds.
  37.  * Default: 30
  38.  * @default 30
  39.  *
  40.  * @param EncounterCancelXRate
  41.  * @desc Enter a float value to determine multiplier for exp and gold gained from cancelled battles.  Enter 0 to not use.
  42.  * Default: 0.5
  43.  * @default 0.5
  44.  *
  45.  * @param EncounterGetReadyBalloon
  46.  * @desc Enter a number to show corresponding balloon emote when deciding to cancel battles.  Enter 0 to not use.
  47.  * Default: 2
  48.  * @default 2
  49.  *
  50.  * @param EncounterGetReadyAnimation
  51.  * @desc Enter a number to show corresponding animation when deciding to cancel battles.  Enter 0 to not use.
  52.  * Default: 0
  53.  * @default 0
  54.  *
  55.  * @param EncounterSuccessfulCancelCE
  56.  * @desc Enter a number to run corresponding common event after successfully cancelling battles.  Enter 0 to not use.
  57.  * Default: 0
  58.  * @default 0
  59.  *
  60.  * @help Allows players to set a general random encounter rate in the Options Menu.  
  61.  * This rate can be reduced to 0 to eliminate ALL random encounters.
  62.  * Also allows developers to lock/unlock the encounter rate directly and set
  63.  * values to whatever they want.
  64.  *
  65.  * Once installed, run your game and go to Options to find the
  66.  * Encounter Rate setting. (If EncounterRateShow is NOT set to 0, the encounter rate will NOT appear
  67.  * on the Title Screen's Option Menu as the rate is considered locked when on the Title Screen.)
  68.  *
  69.  * Optional: You can set the Upper limit of the Encounter rate to any number over 100.
  70.  * If set below, or to a non-number, it will default to 100.
  71.  *
  72.  * Optional: You can set the amount the Encounter Rate rises or falls via the Encounter Offset Param.
  73.  *
  74.  * You can set a timer to allow encounters while standing still.
  75.  * If the param EncounterSpeed is set to a number higher than 0, encounters will be able to occur
  76.  * even while players are not moving!
  77.  * Increasing the number will speed up the enocounter rate.
  78.  * Leaving it at 0 will disable this option.
  79.  * (Other encounter rate option will still be in effect)
  80.  *
  81.  * This plugin now also allows you to adjust the "weight" of random encounters by enemy troop Id.
  82.  * In map notes, you can add the notetag:
  83.  *
  84.  * <malEncAdj: troopId, amount, condition >>>
  85.  * with troopId being the troop Id number in the database,
  86.  * amount being the amount the weight will be adjusted (this can be negative, but it must be an integer.)
  87.  * and condition can be a javascript eval that returns true or false.
  88.  * (And note the 3 >>> at the end of the tag.)
  89.  *
  90.  * For example, the tag <malEncAdj: 1, 10, $gameSwitches.value(1)>>>
  91.  * will increase the weight of all instances of troop one on that map by 10 if switch 1 is turned ON.
  92.  *
  93.  * <malEncAdj: 4, -25, $gameVariables.value(1) > 10>>>
  94.  * will decrease the weight of all instances of troop 4 on that map by 25 if variable 1 is greater than 10.
  95.  *
  96.  * <malEncAdj: 7, $gameVariables.value(2) * 5, $gameVariables.value(2) > 0>>>
  97.  * will increase the weight of all instances of troop 7 on that map by 5 * variable 2 if variable 2 is greater than 0.
  98.  *
  99.  * If you set the troop ID to -1, it will affect ALL troops on that map if the conditions are met.
  100.  *
  101.  * weights are cumulative, meaning you could potentially have a troop affected by multiple tages.
  102.  * Note that any weight values that change to a value below 0 will NOT be encountered at all.
  103.  * Conversely, any troops initially set to 0 in the database but brought above 1 or higher CAN be encountered.
  104.  * (You can eval weight to an integer)
  105.  *
  106.  * <malNulRegionEnc: regionID, condition >>>
  107.  * with region ID being the region ID of the tile the player is standing on and condition being a
  108.  * boolean that equates to true/false.  
  109.  * (Using -1 will effect ALL regions AND regionless areas (basically the entire map)
  110.  *
  111.  * This note tag will REMOVE ALL encounters on the specified region ID on that map if the conditions are true.
  112.  *
  113.  * Note that this tag supersides the malEncAdj tag meaning if you negate all encounters, their weight will hot matter.
  114.  *
  115.  * CANCELABLE BATTLES
  116.  *
  117.  * Now battles can be canceled outright!
  118.  * To utilize this, first set this tag in Map Notes:
  119.  *  
  120.  * <malInstantBattEnd: regionID, condition >>>
  121.  *
  122.  * with region ID being the region ID of the tile the player is standing on and condition being a boolean
  123.  * that equates to true/false.  
  124.  * (Using -1 will effect ALL regions AND regionless areas (basically the entire map)
  125.  * 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.
  126.  * You can set this window using the EncounterCancelTimer param.
  127.  * You can also use the EncounterGetReadyBalloon and/or EncounterGetReadyAnimation params to set a balloon emote
  128.  * or animation to play at the start of the wait period.
  129.  * If the player presses ok, the battle will be skipped!
  130.  * Gold, Exp and items can be obtained as in normal battles.  
  131.  * You can use the param EncounterCancelXRate to determine if the players get reduced gold and XP.
  132.  * Lastly, you can use the EncounterSuccessfulCancelCE param to set a common event to run if a battle is
  133.  * cancelled.
  134.  *
  135.  *  SCRIPT CALLS
  136.  *
  137.  * $gameSystem.lockEncounterRate();
  138.  * This call will LOCK the Encounter Rate setting at whatever number it was when called.
  139.  * You can add a number in the () to set the rate while locking it.
  140.  * Note: Unless EncounterRateShow is set to 0, the Encounter Rate will not show on the Option
  141.  * Menu while locked.
  142.  *
  143.  * $gameSystem.unlockEncounterRate();
  144.  * This call will allow players to change the Encounter Rate again after it hs been locked.
  145.  * You can add a number in the () to set the rate while unlocking it.
  146.  *
  147.  * $gameSystem.setEncounterRate(x);
  148.  * This call will change the Encounter Rate to any positive integer.
  149.  * Note that the player can change the number if the Encounter Rate is not locked.
  150.  *
  151.  * $gameSystem.getEncounterRate();
  152.  * This call will return the current Encounter Rate.
  153.  */
  154.  
  155. ConfigManager.commandEncounter = 100;
  156.  
  157. var MalEncounterTitle = Scene_Title.prototype.create;
  158. Scene_Title.prototype.create = function() {
  159. MalEncounterTitle.call(this);
  160. $gameSystem._encountersLocked = true;
  161. }
  162.  
  163. var MalEncounterInitialize = Game_System.prototype.initialize;
  164. Game_System.prototype.initialize = function() {
  165. MalEncounterInitialize.call(this);
  166. this._encountersLocked = false;
  167. }
  168.  
  169. Game_System.prototype.lockEncounterRate = function(setting) {
  170. $gameSystem._encountersLocked = true;
  171. if (setting) this.setEncounterRate(setting);
  172. }
  173.  
  174. Game_System.prototype.unlockEncounterRate = function(setting) {
  175. $gameSystem._encountersLocked = false;
  176. if (setting) this.setEncounterRate(setting);
  177. }
  178.  
  179. Game_System.prototype.getEncounterRate = function() {
  180. return $gameSystem._encounterRate;
  181. }
  182.  
  183. Game_System.prototype.setEncounterRate = function(setting) {
  184. var numb = Number(eval(setting)) || 100;
  185. if (numb < 0) numb = 0;
  186. ConfigManager['commandEncounterVolume'] = numb;
  187. $gameSystem._encounterRate = numb;
  188. }
  189.  
  190. Object.defineProperty(ConfigManager, 'encounterRate', {
  191.     get: function() {
  192.         return ConfigManager.commandEncounterVolume;
  193.     },
  194.     set: function(value) {
  195.         ConfigManager.commandEncounterVolume = value;
  196.     },
  197.     configurable: true
  198. });
  199.  
  200. var Mal_Config_MakeData = ConfigManager.makeData;
  201. ConfigManager.makeData = function() {
  202.     var config = Mal_Config_MakeData.call(this);
  203.     config.encounterRate = this.encounterRate; 
  204.     return config;
  205. };
  206.  
  207. var Mal_Config_applyData = ConfigManager.applyData;
  208. ConfigManager.applyData = function(config) {
  209.     Mal_Config_applyData.call(this, config);
  210.     this.encounterRate = this.readEncounter(config, 'encounterRate');
  211. };
  212.  
  213. ConfigManager.readEncounter = function(config, name) {
  214.     var value = config[name];
  215.     if (value !== undefined) {
  216.         return Number(value);
  217.     } else {
  218.         return 100;
  219.     }
  220. };
  221.  
  222. Window_Options.prototype.encounterOffset = function() {
  223.     var num = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterOffset']) || 50;
  224.     if (num !== undefined) {
  225.     return Math.floor(num);
  226.     } else {
  227.     return 50;
  228. }  
  229. };
  230.  
  231. var Mal_Window_addGeneralOptions = Window_Options.prototype.addGeneralOptions;
  232. Window_Options.prototype.addGeneralOptions = function() {
  233.     Mal_Window_addGeneralOptions.call(this);
  234.     if (PluginManager.parameters('MalEncounterRateOptions')['EncounterRateShow'] == 0 || $gameSystem._encountersLocked == false ) this.addCommand("Encounter Rate", 'commandEncounterVolume');
  235.     };
  236.    
  237. Game_Player.prototype.encounterProgressValue = function() {
  238.     var value = $gameMap.isBush(this.x, this.y) ? 2 : 1;
  239.     var val2 = ConfigManager.encounterRate;
  240.     if ($gameParty.hasEncounterHalf()) {
  241.         value *= 0.5;
  242.     }
  243.     if (this.isInShip()) {
  244.         value *= 0.5;
  245.     }
  246.     return value * (val2 / 100.0);
  247. };
  248.  
  249. ConfigManager.readEncounter = function(config, name) {
  250.     var value = config[name];
  251.     var limit = Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit']);
  252.     var lowLimit = Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit']);
  253.     if (limit < 100) limit = 100;
  254.     if (lowLimit < 0) lowLimit = 0;
  255.     if (value !== undefined) {
  256.         return Number(value).clamp(lowLimit, limit);
  257.     } else {
  258.         return 100;
  259.     }
  260. };
  261.  
  262. Window_Options.prototype.isEncounterSymbol = function(symbol) {
  263.     return symbol.contains('Encounter');
  264. };
  265.  
  266. var Mal_Win_Options_processOk = Window_Options.prototype.processOk
  267. Window_Options.prototype.processOk = function() {
  268.     var index = this.index();
  269.     var symbol = this.commandSymbol(index);
  270.     if (this.isEncounterSymbol(symbol) ) {
  271.         var value = this.getConfigValue(symbol);
  272.         var offset = this.encounterOffset();
  273.         var limit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit'])) || 100;
  274.         var lowLimit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit'])) || 0;
  275.         if (limit < 100) limit = 100;
  276.         if ($gameSystem._encountersLocked == false){
  277.         if (value + offset > limit && value != limit) {
  278.         value = limit;
  279.         } else {
  280.         value += offset;
  281.         }
  282.         if (value > limit) value = lowLimit;
  283.         this.changeValue(symbol, value);
  284.         $gameSystem._encounterRate = value;
  285.         } else {
  286.         SoundManager.playBuzzer();
  287.         }
  288.         } else {
  289.             Mal_Win_Options_processOk.call(this);
  290.         }
  291. };
  292.  
  293. var Mal_Win_Options_cursorRight = Window_Options.prototype.cursorRight
  294. Window_Options.prototype.cursorRight = function(wrap) {
  295.     var index = this.index();
  296.     var symbol = this.commandSymbol(index);
  297.     if (this.isEncounterSymbol(symbol)) {
  298.         var value = this.getConfigValue(symbol);
  299.         var offset = this.encounterOffset();
  300.         var limit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit'])) || 100;
  301.         var lowLimit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit'])) || 0;
  302.         if (limit < 100) limit = 100;
  303.         if ($gameSystem._encountersLocked == false){
  304.         if (value + offset > limit && value != limit) {
  305.         value = limit;
  306.         } else {
  307.         value += offset;
  308.         }
  309.         if (value > limit) value = lowLimit;
  310.         this.changeValue(symbol, value);
  311.         $gameSystem._encounterRate = value;
  312.         } else {
  313.         SoundManager.playBuzzer();
  314.         }
  315.         } else {
  316.             Mal_Win_Options_cursorRight.call(this, wrap);
  317.         }
  318. };
  319.  
  320. var Mal_Win_Options_cursorLeft = Window_Options.prototype.cursorLeft
  321. Window_Options.prototype.cursorLeft = function(wrap) {
  322.     var index = this.index();
  323.     var symbol = this.commandSymbol(index);
  324.     if (this.isEncounterSymbol(symbol)) {
  325.         var value = this.getConfigValue(symbol);
  326.         var offset = this.encounterOffset();
  327.         var limit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateUpperLimit'])) || 100;
  328.         var lowLimit = Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['RateLowerLimit'])) || 0;
  329.         if (limit < 100) limit = 100;
  330.         if ($gameSystem._encountersLocked == false){
  331.         if (value - offset < lowLimit && value != lowLimit) {
  332.         value = lowLimit;
  333.         } else {
  334.         value -= offset;
  335.         }
  336.         if (value < lowLimit) value = limit;
  337.         this.changeValue(symbol, value);
  338.         $gameSystem._encounterRate = value;
  339.         } else {
  340.         SoundManager.playBuzzer();
  341.         }
  342.         } else {
  343.             Mal_Win_Options_cursorLeft.call(this, wrap);
  344.         }
  345. };
  346.  
  347. var MalEncounter_onLoadSuccess = Scene_Load.prototype.onLoadSuccess;
  348. Scene_Load.prototype.onLoadSuccess = function() {
  349. MalEncounter_onLoadSuccess.call(this);
  350. ConfigManager['commandEncounterVolume'] = $gameSystem._encounterRate || 100;
  351. //$gamePlayer.encounterTick = 0;
  352. }
  353.  
  354. var malEROGPMBInput = Game_Player.prototype.moveByInput;
  355. Game_Player.prototype.moveByInput = function() {
  356.     if (!$gameMap._EncCancLoop) malEROGPMBInput.call(this);
  357. };
  358.  
  359. Game_Player.prototype.updateNonmoving = function(wasMoving) {
  360.     if (!$gamePlayer.encounterTick) $gamePlayer.encounterTick = 0;
  361.     if (!$gameMap.isEventRunning()) {
  362.         if (wasMoving) {
  363.             $gameParty.onPlayerWalk();
  364.             this._firstStep = false;
  365.             this.checkEventTriggerHere([1,2]);
  366.             if ($gameMap.setupStartingEvent()) {
  367.                 return;
  368.             }
  369.         }
  370.         if (this.triggerAction()) {
  371.             return;
  372.         }
  373.         if ($gamePlayer.encounterTick >= 1000) {
  374.             this.updateEncounterCount();
  375.             $gamePlayer.encounterTick = 0;
  376.         } else {
  377.             if(!this._firstStep) $gamePlayer.encounterTick += 1 * Math.floor(Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterSpeed']));
  378.         }
  379.         if (wasMoving) {
  380.             this.updateEncounterCount();
  381.         } else {
  382.             $gameTemp.clearDestination();
  383.         }
  384.     }
  385. };
  386.  
  387. var MalEncounterCount = Game_Player.prototype.makeEncounterCount;
  388. Game_Player.prototype.makeEncounterCount = function() {
  389.     MalEncounterCount.call(this);
  390.     if(PluginManager.parameters('MalEncounterRateOptions')['EncounterSpeed'] != 0) this._encounterCount += 3;
  391.     this._firstStep = true;
  392. };
  393.  
  394. Game_Player.prototype.executeEncounter = function() {
  395.     if (!$gameMap.isEventRunning() && this._encounterCount <= 0 && !$gameMap._EncCancLoop) {
  396.         this.makeEncounterCount();
  397.         var troopId = this.makeEncounterTroopId();
  398.         this._savedTroopId = troopId;
  399.         if ($dataTroops[troopId]) {
  400.             if(!$gameMap._EncCancLoop) this.checkBattleInterrupt($dataTroops[troopId]);
  401.             BattleManager.setup(troopId, true, false);
  402.             BattleManager.onEncounter();
  403.             if(BattleManager._surprise) {
  404.                 $gameMap._EncCancLoop = false;
  405.                 this._savedTroopId = -1;
  406.                 return true;
  407.             }
  408.             if($gameMap._EncCancLoop) return false;
  409.             return true;
  410.         } else {
  411.             return false;
  412.         }
  413.     } else {
  414.         return false;
  415.     }
  416. };
  417.  
  418. Game_Player.prototype.checkBattleInterrupt = function(troop) {
  419.     if(Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterCancelTimer']) == 0) return;
  420.     if ($gameMap.nulBattle(this.regionId(), troop)) {
  421.         $gameMap._EncCancLoop = true;
  422.         var balloon = 0;
  423.         var anima = 0;
  424.         if(Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterGetReadyBalloon']) != 0) {
  425.             balloon = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterGetReadyBalloon']);
  426.         };
  427.         if(Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterGetReadyAnimation']) != 0) {
  428.             anima = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterGetReadyAnimation']);
  429.         };
  430.         if (balloon != 0) this.requestBalloon(balloon);
  431.         if (anima != 0) this.requestAnimation(anima);
  432.     };
  433. };
  434.  
  435. var malEROGPTriggBAct = Game_Player.prototype.triggerButtonAction;
  436. Game_Player.prototype.triggerButtonAction = function() {
  437.     if($gameMap._EncCancLoop) {
  438.         if (Input.isPressed('ok')) {
  439.             if (this.battlecancel()) {
  440.                 return true;
  441.             }
  442.         }
  443.         if (Input.isPressed('cancel') || this._battleCanceltimer <= 0) {
  444.             if (this.cBattlecancel()) {
  445.                 return true;
  446.             }
  447.         }
  448.         this._battleCanceltimer--;
  449.     }
  450.     return malEROGPTriggBAct.call(this);
  451. };
  452.  
  453. Game_Player.prototype.battlecancel = function () {
  454.     BattleManager.setup(this._savedTroopId, true, false);
  455.     $gameMap._EncCancLoop = false;
  456.     BattleManager.processVictory();
  457.     this._savedTroopId == -1;
  458.     $gamePlayer._battleCanceltimer = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterCancelTimer']);
  459.     this.requestBalloon(2);
  460.     var comE = 0;
  461.         if(Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterSuccessfulCancelCE']) != 0) {
  462.             comE = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterSuccessfulCancelCE']);
  463.         };
  464.     if (comE != 0) $gameTemp.reserveCommonEvent(comE);
  465. };
  466.  
  467. Game_Player.prototype.cBattlecancel = function () {
  468.     $gameMap._EncCancLoop = false;
  469.     $gamePlayer._battleCanceltimer = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterCancelTimer']);
  470.     BattleManager.setup(this._savedTroopId, true, false);
  471.     this._savedTroopId == -1;
  472.     SceneManager.push(Scene_Battle);
  473. };
  474.  
  475. var malEROGBBIsDead = Game_BattlerBase.prototype.isDead;
  476. Game_BattlerBase.prototype.isDead = function() {
  477.     if ($gameMap._EncCancLoop && this.isEnemy()) return true;
  478.     return malEROGBBIsDead.call(this);
  479. };
  480.  
  481. var malEncounterGMSetup = Game_Map.prototype.setup;
  482. Game_Map.prototype.setup = function(mapId) {
  483.     if (!$dataMap) {
  484.         throw new Error('The map data is not available');
  485.     }
  486.     malEncounterGMSetup.call(this, mapId);
  487.     this.setupEncounterAdjusts();
  488. };
  489.  
  490. Game_Map.prototype.setupEncounterAdjusts = function() {
  491.     this._encounterAdjusts = [];
  492.     this._regionCond = [];  
  493.     this._instantBattCond = [];
  494.     this._EncCancLoop = false;
  495.     $gamePlayer._savedTroopId = -1;
  496.     $gamePlayer._battleCanceltimer = Number(PluginManager.parameters('MalEncounterRateOptions')['EncounterCancelTimer']);
  497. var noteread = $dataMap.note;
  498. while(noteread.indexOf("malEncAdj") > -1)
  499. {
  500.     var notereg = noteread.split("<malEncAdj: ");
  501.     var match = notereg[1].split(">>>");
  502.     match = match[0].split(", ");
  503.     match[0] = parseInt(match[0]);
  504.     //match[1] = parseInt(match[1]);
  505.     this._encounterAdjusts.push(match);
  506.     noteread = noteread.replace("<malEncAdj: ", " ");
  507. }
  508.  
  509.      
  510.     var noteread = $dataMap.note;  
  511.     while(noteread.indexOf("malNulRegionEnc") > -1)  
  512.     {  
  513.         var notereg = noteread.split("<malNulRegionEnc: ");  
  514.         var match = notereg[1].split(">>>");    
  515.         var match2 = match[0].split(",");  
  516.         match2[0] = Number(match2[0]);
  517.         this._regionCond.push(match2);    
  518.         noteread = noteread.replace("<malNulRegionEnc: ", " ");  
  519.     }  
  520.    
  521.     var noteread = $dataMap.note;  
  522.     while(noteread.indexOf("malInstantBattEnd") > -1)  
  523.     {  
  524.         var notereg = noteread.split("<malInstantBattEnd: ");  
  525.         var match = notereg[1].split(">>>");    
  526.         var match2 = match[0].split(",");  
  527.         match2[0] = Number(match2[0]);
  528.         this._instantBattCond.push(match2);    
  529.         noteread = noteread.replace("<malInstantBattEnd: ", " ");  
  530.     }
  531. };
  532.  
  533. Game_Player.prototype.makeEncounterTroopId = function() {
  534.     var encounterList = [];
  535.     var weightSum = 0;
  536.     $gameMap.encounterList().forEach(function(encounter) {
  537.         if (this.meetsEncounterConditions(encounter)) {
  538.             var encounterCopy = encounter;
  539.             encounterCopy = this.malEncounterAdjust(encounterCopy);
  540.             if (encounterCopy.weight > 0) {
  541.                 encounterList.push(encounterCopy);
  542.                 weightSum += encounterCopy.weight;
  543.             }
  544.         }
  545.     }, this);
  546.     if (weightSum > 0) {
  547.         var value = Math.randomInt(weightSum);
  548.         for (var i = 0; i < encounterList.length; i++) {
  549.             value -= encounterList[i].weight;
  550.             if (value < 0) {
  551.                 return encounterList[i].troopId;
  552.             }
  553.         }
  554.     }
  555.     return 0;
  556. };
  557.  
  558. Game_Player.prototype.malEncounterAdjust = function (encounter) {
  559.     var ec = encounter;
  560.     var id = ec.troopId;
  561.     var ea = $gameMap._encounterAdjusts;
  562.     s = $gameSwitches._data;
  563.     v = $gameVariables._data;
  564.     for (var i = 0; i < ea.length; i++) {
  565.         var line = ea[i];
  566.         var value = Number(eval(line[1])) || 0;
  567.         var check = eval(line[2]);
  568.         if ((line[0] == id || line[0] == -1) && check) ec.weight += value;
  569.     }
  570.     return ec;
  571. }
  572.  
  573. var MalGPMeetsEncCond = Game_Player.prototype.meetsEncounterConditions
  574. Game_Player.prototype.meetsEncounterConditions = function(encounter) {
  575.     if ($gameMap.nulRegion(this.regionId())) return false;
  576.     return MalGPMeetsEncCond.call(this, encounter);
  577. };
  578.  
  579. Game_Map.prototype.nulRegion = function(region) {
  580.     if (this._regionCond.length < 1) return false;
  581.     s = $gameSwitches._data;
  582.     v = $gameVariables._data;
  583.     var region = Number(region);
  584.      for (var i = 0; i < this._regionCond.length; i++) {
  585.         if ((this._regionCond[i][0] == region || this._regionCond[i][0] == -1) && eval(this._regionCond[i][1])) return true;
  586.     }
  587.     return false;
  588. };
  589.  
  590. Game_Map.prototype.nulBattle = function(region, troop) {
  591.     if (this._instantBattCond.length < 1) return false;
  592.     t = troop;
  593.     s = $gameSwitches._data;
  594.     v = $gameVariables._data;
  595.     var region = Number(region);
  596.      for (var i = 0; i < this._instantBattCond.length; i++) {
  597.         if ((this._instantBattCond[i][0] == region || this._instantBattCond[i][0] == -1) && eval(this._instantBattCond[i][1])) return true;
  598.     }
  599.     return false;
  600. };
  601.  
  602. var malEROGAFinExRate = Game_Actor.prototype.finalExpRate
  603. Game_Actor.prototype.finalExpRate = function() {
  604.     var newRate = malEROGAFinExRate.call(this);
  605.     var isBattleCancelled = $gameMap._EncCancLoop;
  606.     var cancelRate = isBattleCancelled ? parseFloat(PluginManager.parameters('MalEncounterRateOptions')['EncounterCancelXRate']) : 1;
  607.     return newRate * cancelRate;
  608. };
  609.  
  610. var malEROGTGoldRate =Game_Troop.prototype.goldRate;
  611. Game_Troop.prototype.goldRate = function() {
  612.     var newRate = malEROGTGoldRate.call(this);
  613.     var isBattleCancelled = $gameMap._EncCancLoop;
  614.     var cancelRate = isBattleCancelled ? parseFloat(PluginManager.parameters('MalEncounterRateOptions')['EncounterCancelXRate']) : 1;
  615.     return newRate * cancelRate;
  616. };
  617.  
  618. var malEROBMSB = BattleManager.startBattle;
  619. BattleManager.startBattle = function() {
  620.     malEROBMSB.call(this);
  621.     $gamePlayer._savedTroopId = -1;
  622. };
Advertisement
Add Comment
Please, Sign In to add comment