jeneeus

Autolife

Nov 1st, 2015
2,925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //==============================================================================
  2. // ** Special State: Autolife
  3. // by: Jeneeus Guruman
  4. //------------------------------------------------------------------------------
  5.  
  6. var Imported = Imported || {};
  7. var Jene = Jene || {};
  8.  
  9. /*:
  10.  * @plugindesc Special State: Autolife v1.1.0
  11.  * @author Jeneeus Guruman
  12.  *
  13.  * @param Autolife Animation ID
  14.  * @desc The ID of the animation to be played when autoreviving.
  15.  * @default 49
  16.  *
  17.  * @help
  18.  *
  19.  *     This plugin allows to include a state that will automatically
  20.  *   revive the KO-ed target whenever the state is active. Once the
  21.  *   target is automatically revive, the state will be removed.
  22.  *
  23.  *       <autolife: value[%]>
  24.  *
  25.  *       value: The value of HP to be recovered to revive. Putting
  26.  *     a percent sign will be based on the amount of MHP instead of
  27.  *     fixed values. Multiple tags will take the value
  28.  *     of the tagged state that has the highest state priority.
  29.  *
  30.  *       Notes:
  31.  *       * None.
  32.  *
  33.  *   Changelog:
  34.  *
  35.  *     * v1.1.0: Now fixed numbers are accepted and adds a percent
  36.  *     sign for percentage values.
  37.  *     * v1.0.1: Made compatible with Yanfly Engine Core.
  38.  */
  39.  
  40. parameters = PluginManager.parameters('Autolife');
  41.  
  42. Jene.autolifeAnimationId = String(parameters['Autolife Animation ID']);
  43.  
  44. Jene.battleManagerCheckBattleEnd = BattleManager.checkBattleEnd;
  45.  
  46. BattleManager.checkBattleEnd = function() {
  47.     $gameParty.deadMembers().forEach(function(actor) {
  48.         if (actor.autolifeStateId() > 0) {
  49.             console.log(actor.mhp * actor.autolife);
  50.             actor.removeState(actor.deathStateId());
  51.             actor.gainHp(actor.autolife);
  52.             actor.removeState(actor.autolifeStateId());
  53.             actor.startAnimation(Jene.autolifeAnimationId, true, $dataAnimations[Jene.autolifeAnimationId].frames * 4);
  54.             if (Imported.YEP_BattleEngineCore) {
  55.                 BattleManager.actionWaitForAnimation();
  56.             }
  57.         }
  58.     });
  59.     $gameTroop.deadMembers().forEach(function(enemy) {
  60.         if (enemy.autolifeStateId() > 0) {
  61.             enemy.removeState(enemy.deathStateId());
  62.             enemy.gainHp(enemy.autolife);
  63.             enemy.removeState(enemy.autolifeStateId());
  64.             enemy.startAnimation(Jene.autolifeAnimationId, false, $dataAnimations[Jene.autolifeAnimationId].frames * 4);
  65.             if (Imported.YEP_BattleEngineCore) {
  66.                 BattleManager.actionWaitForAnimation();
  67.             }
  68.         }
  69.     });
  70.     return Jene.battleManagerCheckBattleEnd.call(this);
  71. };
  72.  
  73. Object.defineProperty(Game_BattlerBase.prototype, 'autolife', {
  74.     get: function() {
  75.         if (this.autolifeStateId() > 0) {
  76.             var state = $dataStates[this.autolifeStateId()];
  77.             var isPercent = state.meta.autolife.contains('%');
  78.             var value = Number(state.meta.autolife.replace('%', ''));
  79.             if (isPercent) {
  80.                 return Math.ceil(this.mhp * value / 100) - 1;
  81.             }
  82.             else {
  83.                 return Math.min(value, this.mhp) - 1;
  84.             }
  85.         }
  86.         else {
  87.             return 0;
  88.         }
  89.     },
  90.     configurable: true
  91. });
  92.  
  93. Game_BattlerBase.prototype.autolifeStateId = function() {
  94.     var stateId = 0;
  95.     this.states().forEach(function(state) {
  96.         if (state.meta.autolife) {
  97.             stateId = state.id;
  98.             return;
  99.         }
  100.     });
  101.     return stateId;
  102. };
  103.  
  104. Jene.gameBattlerBaseClearStates2 = Game_BattlerBase.prototype.clearStates;
  105.  
  106. Game_BattlerBase.prototype.clearStates = function() {
  107.     if (this._states) {
  108.         autolifeStates = []
  109.         this.states().forEach(function(state) {
  110.             if (state.meta.autolife) {
  111.                 autolifeStates.push(state.id);
  112.             }
  113.         });
  114.         Jene.gameBattlerBaseClearStates2.call(this);
  115.         this._states = autolifeStates;
  116.     }
  117.     else {
  118.         Jene.gameBattlerBaseClearStates2.call(this);
  119.     }
  120. };
Advertisement
Add Comment
Please, Sign In to add comment