Advertisement
heroofhyla

BattleCommonEvents.js

Jan 2nd, 2017
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*:
  2.  * @plugindesc Calls common events during battle
  3.  * @param battleStartEventID
  4.  * @desc The common event to call at the start of each battle
  5.  * @default -1
  6.  *
  7.  * @param battleWinEventID
  8.  * @desc The common event to call after winning a battle
  9.  * @default -1
  10.  *
  11.  * @param battleEscapeEventID
  12.  * @desc The common event to call after fleeing from a battle
  13.  * @default -1
  14.  *
  15.  * @param partyWipeEventID
  16.  * @desc The common event to call if all characters are knocked
  17.  * out during battle
  18.  * @default -1
  19.  *
  20.  * @param turnStartEventID
  21.  * @desc The common event to call at the start of each turn after actions
  22.  * are chosen
  23.  * @default -1
  24.  *
  25.  * @param turnEndEventID
  26.  * @desc The common event to call at the end of each turn.
  27.  * @default -1
  28.  *
  29.  * @param actionEndEventID
  30.  * @desc The common event to call at the end of each action
  31.  * @default -1
  32.  *
  33.  * @author Michael Stroud
  34.  * No warranty, express or implied. I can't guarantee that it will
  35.  * work at all. If it's useful to you, credit is appreciated.
  36.  * You may redistribute, but do not remove any of the above.
  37.  *
  38.  * @help A negative value disables the event call.
  39.  * After-battle common events do not trigger until the party has been
  40.  * returned to the map. If the battle was triggered by an event, that
  41.  * event will finish processing first.
  42.  *
  43.  * After-turn and after-action common events do not trigger at the end
  44.  * of a battle.
  45.  */
  46.  
  47. (function(){
  48.     var parameters = PluginManager.parameters('BattleCommonEvents');
  49.     var battleStart = Number(parameters['battleStartEventID'] || -1);
  50.     var battleWin = Number(parameters['battleWinEventID'] || -1);
  51.     var battleEscape = Number(parameters['battleEscapeEventID'] || -1);
  52.     var partyWipe = Number(parameters['partyWipeEventID'] || -1);
  53.     var inputStart = Number(parameters['inputStartEventID'] || -1);
  54.     var turnStart = Number(parameters['turnStartEventID'] || -1);
  55.     var turnEnd = Number(parameters['turnEndEventID'] || -1);
  56.     var actionStart = Number(parameters['actionStartEventID'] || -1);
  57.     var actionEnd = Number(parameters['actionEndEventID'] || -1);
  58.  
  59.     var _BattleManagerStartBattle = BattleManager.startBattle;
  60.     BattleManager.startBattle = function() {
  61.         _BattleManagerStartBattle.call(this);
  62.         if (battleStart > 0){
  63.             $gameTemp.reserveCommonEvent(battleStart);
  64.         }
  65.     };
  66.    
  67.     var _GameSystemOnBattleWin = Game_System.prototype.onBattleWin;
  68.     Game_System.prototype.onBattleWin = function() {
  69.         _GameSystemOnBattleWin.call(this);
  70.         if (battleWin > 0){
  71.             $gameTemp.reserveCommonEvent(battleWin);
  72.         }
  73.     }
  74.    
  75.     var _GameSystemOnBattleEscape = Game_System.prototype.onBattleEscape;
  76.     Game_System.prototype.onBattleEscape = function() {
  77.         _GameSystemOnBattleEscape.call(this);
  78.         if (battleEscape > 0){
  79.             $gameTemp.reserveCommonEvent(battleEscape);
  80.         }
  81.     }
  82.    
  83.     BattleManager.updateBattleEnd = function() {
  84.     if (this.isBattleTest()) {
  85.         AudioManager.stopBgm();
  86.         SceneManager.exit();
  87.     } else if ($gameParty.isAllDead()) {
  88.         if (partyWipe > 0){
  89.             $gameTemp.reserveCommonEvent(partyWipe);
  90.             $gameParty.reviveBattleMembers();
  91.             SceneManager.pop();
  92.         }else{
  93.             if (this._canLose) {
  94.                 $gameParty.reviveBattleMembers();
  95.                 SceneManager.pop();
  96.             } else {
  97.                 SceneManager.goto(Scene_Gameover);
  98.             }
  99.         }
  100.     } else {
  101.         SceneManager.pop();
  102.     }
  103.     this._phase = null;
  104.     };
  105.    
  106.     var _BattleManagerStartTurn = BattleManager.startTurn;
  107.     BattleManager.startTurn = function() {
  108.         _BattleManagerStartTurn.call(this);
  109.         if (turnStart > 0){
  110.             $gameTemp.reserveCommonEvent(turnStart);
  111.         }
  112.     };
  113.    
  114.     var _BattleManagerEndTurn = BattleManager.endTurn;
  115.     BattleManager.endTurn = function(){
  116.         _BattleManagerEndTurn.call(this);
  117.         if (turnEnd > 0){
  118.             $gameTemp.reserveCommonEvent(turnEnd);
  119.         }
  120.     }
  121.  
  122.     var _BattleManagerEndAction = BattleManager.endAction;
  123.     BattleManager.endAction = function() {
  124.         _BattleManagerEndAction.call(this);
  125.         if (actionEnd > 0){
  126.             $gameTemp.reserveCommonEvent(actionEnd);
  127.         }
  128.     };
  129. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement