daily pastebin goal
28%
SHARE
TWEET

LudoSwap

ludovicodes Dec 10th, 2017 (edited) 478 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //==
  2. //LudoSwap.js
  3. //==
  4.  
  5.  
  6. /*:
  7.  * @plugindesc plugin that swaps out dead party members with alive backup members.
  8.  * @author Alessio De Santis
  9.  *
  10.  * @help This plugin does not provide plugin commands.
  11.  *
  12.  * @param Number of turns till swap
  13.  * @desc Number of turns until a dead character is swapped out with a character from the reserve
  14.  *
  15.  * Default : 3
  16.  * @default 3
  17.  *
  18.  * @param Swap when Ko
  19.  * @desc Swap when main party is ko'ed ? swaps instantly after turn end. (0 = false, any other value = true)
  20.  *
  21.  * Default : 1
  22.  * @default 1
  23.  */
  24.  
  25. var $maxTurns = Number(PluginManager.parameters("LudoSwap")["Number of turns till swap"]) || 3;
  26. var $swapWhenKo = Number(PluginManager.parameters("LudoSwap")["Swap when Ko"]) || 1;
  27.  
  28. (function(){
  29.  
  30.     var _BattleManager_updateTurnEnd = BattleManager.prototype.updateTurnEnd;
  31.     var _BattleManager_startBattle = BattleManager.prototype.startBattle;
  32.  
  33.     BattleManager._deadActors = [];
  34.  
  35.     BattleManager.updateTurnEnd = function() {
  36.         var i;
  37.         //Checks for dead actor;
  38.         for(i = 0; i < $gameParty.battleMembers().length; i++){
  39.             var member = $gameParty.battleMembers()[i];
  40.             if(member.isDead() && this._deadActors.indexOf(member) == -1){
  41.                 this._deadActors.push(member);
  42.             }
  43.         }
  44.  
  45.         if(this._deadActors.length > 0){
  46.             if($gameParty.allMembers().length > $gameParty.battleMembers().length){
  47.                 $gameParty.allMembers().forEach( function(actor){
  48.                     if(actor){
  49.                         if($gameParty.battleMembers().indexOf(actor) == -1 && !actor.isDead() && this._deadActors.length > 0) {
  50.                             var index1 = $gameParty.allMembers().indexOf(actor);
  51.                             var index2 = $gameParty.allMembers().indexOf(this._deadActors[0]);
  52.                             var actortarget = $gameParty.allMembers()[index2];
  53.                             this._deadActors = this._deadActors.slice(1, this._deadActors.length+1)
  54.                             if(actortarget._turns == null || actortarget._turns >= $maxTurns){
  55.                                 actortarget._turns = 0;
  56.                             }
  57.                             if(actortarget._turns >= $maxTurns){
  58.                                 $gameParty.swapOrder(index1, index2);
  59.                             }
  60.                             else {actortarget._turns++;}
  61.                         }
  62.                     }
  63.                 }.bind(this) )
  64.             }
  65.         }
  66.  
  67.         this.startInput();
  68.     };
  69.  
  70.     // $gameMessage.add()
  71.  
  72.     Game_Unit.prototype.isAllDead = function() {
  73.         return this.aliveMembers().length === 0;
  74.     };
  75.    
  76.  
  77.     BattleManager.checkBattleEnd = function() {
  78.         if (this._phase) {
  79.             if (this.checkAbort()) {
  80.                 return true;
  81.             } else if ($gameParty.isAllDead()) {
  82.                 if($gameParty.isAllMembersDead() === true || $swapWhenKo === 0){
  83.                     this.processDefeat();
  84.                 }
  85.                 else {
  86.                     var temp = $maxTurns;
  87.                     $maxTurns = 0;
  88.                     this.updateTurnEnd();
  89.                     $maxTurns = temp;
  90.                 }
  91.                 return true;
  92.             } else if ($gameTroop.isAllDead()) {
  93.                 this.processVictory();
  94.                 return true;
  95.             }
  96.         }
  97.         return false;
  98.     };
  99.  
  100.     Game_Party.prototype.isAllMembersDead = function(){
  101.         var t = true;
  102.         $gameParty.allMembers().forEach( function(member){
  103.             if(member.isAlive()){
  104.                 t = false;
  105.             };
  106.         } )
  107.         return t
  108.     }
  109.  
  110.  
  111. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top