Advertisement
Maliki79

MalAddExtraState

Dec 24th, 2017
1,071
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // MalAddExtraState
  3. // MalAddExtraState.js
  4. // version 1.2
  5. //=============================================================================
  6. /*:
  7.  * @plugindesc Allows Devs to give to give Battlers unique state reactions.
  8.  * These reactions are expressed as secondary states which can be set per Battler.
  9.  *
  10.  * @author Maliki79
  11.  *
  12.  * @param ExChainable
  13.  * @desc Type 1 to allow Ex States to add other Ex States.
  14.  * Default: 0
  15.  * @default 0
  16.  *
  17.  * @param ProgChainable
  18.  * @desc Type 1 to allow Progressive Primary states to trigger from the right-most active state.
  19.  * Default: 0
  20.  * @default 0
  21.  *
  22.  * @help
  23.  * Actor or Enemy Notetags :
  24.  * <addExtraState: x, y, z>
  25.  * with x being the original state, y the "extra" state and z being the chance to
  26.  * add the state from 0 to 100.
  27.  * Multiple sets of the tag can be used to give a single original state multiple
  28.  * extra states.
  29.  *
  30.  * You can make y a negative number to remove that state.
  31.  * For example, if poison was state ID 5 and Blind was state ID 6, using
  32.  * <addExtraState: 5, 6, 100> would add the Blind state to the enemy any time
  33.  * Poison is added to it.
  34.  * <addExtraState: 5, -6, 100> would REMOVE the Blind state if the enemy has it
  35.  * and Poison is then added.
  36.  *
  37.  * The order of the tags in the database determine when the Extra states are added,
  38.  * so using tags carefully, various combinations of states can be added or removed.
  39.  *  
  40.  * By changing the plugin param ExChainable to 1, all extra states will behave
  41.  * like original states and can have other ex states added to them in the same attack.    
  42.  * (This does not apply to Progressive State Chains.)
  43.  *
  44.  * <addProgState: A, b, c...>
  45.  * with A, b and c being different different state Ids.
  46.  * Adds Progressive states.  After successfully adding the first "intial" state on the list to a battler,
  47.  * the plugin will attempt to add the next unafflicted state to the battler every time the initial state
  48.  * is successfully readded.
  49.  * (Only one state will be added at a time and it will ALWAYS be the leftmost one that is not already
  50.  * on the battler.)
  51.  * You can make the chain as long as you like, but copies of the same Id will NOT work.
  52.  * You can use Ids that were in another chain as a new initial Id.
  53.  * Example: <addProgState: 5, 6, 7, 8, 9, 10>
  54.  * and
  55.  * <addProgState: 8, 9 , 5>
  56.  * can both be successfully used on one enemy.
  57.  *
  58.  * By changing the plugin param ProgChainable to 1, the plugin will look for
  59.  * the most advanced state in the state list (the rightmost one) that is already added, then add
  60.  * the next state.
  61.  * (This does not apply to Progressive State Chains.)
  62.  *  Ex: <addProgState: 5, 6, 7, 8, 9 ,10>
  63.  * Normally, you would have to add state 5 before 6, then 7, etc., but if another attack was
  64.  * to add state 8, the next time state 5 was attemped to be added, it would apply state 9 whether
  65.  * states 5, 6 or 7 were previously added or not.
  66.  * Note that these Extra States only work in battle.
  67.  */
  68.  
  69. //Begin database setup
  70. var MalAddExStDatabaseLoad = DataManager.isDatabaseLoaded;
  71. DataManager.isDatabaseLoaded = function() {
  72.   if (!MalAddExStDatabaseLoad.call(this)) return false;
  73.   if (!DataManager._MalExSt_DatabaseLoaded) {
  74.     this.processExStNotetags($dataEnemies);
  75.     this.processExStNotetags($dataActors);
  76.     DataManager._MalExSt_DatabaseLoaded = true;
  77.   }
  78.   return true;
  79. };
  80.  
  81. DataManager.processExStNotetags = function(group) {
  82.     for (var n = 1; n < group.length; n++) {
  83.         var obj = group[n];
  84.         obj.extraState = [];
  85.         obj.exStates = [];
  86.         obj.exProgStates = new Array($dataStates.length + 1);
  87.         this.createExtraStateArray(obj);
  88.     }
  89. };
  90.  
  91. DataManager.createExtraStateArray = function(object) {
  92.         var noteread = object.note;
  93.  
  94.         while(noteread.indexOf("addExtraState") > -1)
  95.         {
  96.             var notereg = noteread.split("<addExtraState: ");
  97.             var match = notereg[1].split(", ");
  98.             var match2 = match[2].split(">");
  99.             object.extraState.push([parseInt(match[0]), parseInt(match[1]), parseInt(match2[0])]);
  100.             object.exStates.push(parseInt(match[0]));
  101.             noteread = noteread.replace("<addExtraState: ", " ");
  102.         }
  103.        
  104.         noteread = object.note;
  105.        
  106.  
  107.         while(noteread.indexOf("addProgState") > -1)
  108.         {
  109.             var notereg2 = noteread.split("<addProgState: ");
  110.             var match = notereg2[1].split(">");
  111.             var match2 = match[0].split(", ");
  112.             for (var n = 1; n < match2.length; n++) {
  113.                 if (!object.exProgStates[match2[0]]) object.exProgStates[match2[0]] = [];
  114.                 object.exProgStates[match2[0]].push(parseInt(match2[n]));
  115.             }
  116.             noteread = noteread.replace("<addProgState: ", " ");
  117.         }
  118.     };
  119. //End Database Setup
  120.  
  121. var MalExChains =  PluginManager.parameters('MalAddExtraState')['ExChainable'];
  122. var MalProgChain = PluginManager.parameters('MalAddExtraState')['ProgChainable'];
  123.  
  124. var MalAddExStActorSetup = Game_Actor.prototype.setup;
  125. Game_Actor.prototype.setup = function(actorId) {
  126.     MalAddExStActorSetup.call(this, actorId);
  127.     this.extraState   = $dataActors[this._actorId].extraState;
  128.     this.exStates     = $dataActors[this._actorId].exStates;
  129.     this.exProgStates = $dataActors[this._actorId].exProgStates;
  130.     this._exStates    = [];
  131. };
  132.    
  133. var MalAddExStEnemySetup = Game_Enemy.prototype.setup;
  134. Game_Enemy.prototype.setup = function(enemyId, x, y) {
  135.     MalAddExStEnemySetup.call(this, enemyId, x, y);
  136.     this.extraState   = $dataEnemies[this._enemyId].extraState;
  137.     this.exStates     = $dataEnemies[this._enemyId].exStates;
  138.     this.exProgStates = $dataEnemies[this._enemyId].exProgStates;
  139.     this._exStates    = [];
  140. };
  141.  
  142. var mal_addState = Game_Battler.prototype.addState;
  143. Game_Battler.prototype.addState = function(stateId) {
  144.     var stateId = stateId;
  145.     var lock = -1;
  146.     var prog = this.exProgStates[stateId];
  147.     if ($gameParty.inBattle() && prog) { // ) {
  148.         if (MalProgChain == 0) {
  149.             if (this._states.contains(stateId)) {
  150.                 for (var i = 0; i < prog.length; i++) {
  151.                     if (!this._states.contains(prog[i])) {
  152.                         lock = prog[i];
  153.                         break;
  154.                     }
  155.                 }
  156.             }
  157.         } else {
  158.             for (var i = prog.length - 1; i > -1; i--) {
  159.                 if (this._states.contains(prog[i])) {
  160.                     lock = prog[(i + 1)];
  161.                     break;
  162.                 }
  163.             }
  164.             if(lock == -1 && this._states.contains(stateId)) lock = prog[0];
  165.         }
  166.         if (lock != -1) stateId = lock;
  167.         mal_addState.call(this, stateId);
  168.     } else {
  169.         mal_addState.call(this, stateId);
  170.     }
  171.     if ($gameParty.inBattle() && this.exStates.contains(stateId) && !this._exStates.contains(stateId)) this.addExState(stateId);
  172. };
  173.    
  174. Game_Battler.prototype.addExState = function (stateId) {
  175.     for (var i = 0; i < this.extraState.length; i++) {
  176.         var ex = this.extraState[i];
  177.         if (ex[0] == stateId) {
  178.             if (Math.randomInt(100) < ex[2]) {
  179.                 if (MalExChains == 0 && ex[1] > 0) this._exStates.push(ex[1]);
  180.                 if (ex[1] < 0) {
  181.                     this.removeState(ex[1] * -1);
  182.                 } else {
  183.                     this.addState(ex[1]);
  184.                 }
  185.             }
  186.         }
  187.     }
  188. };
  189.  
  190. var MalExStateClearResult = Game_Battler.prototype.clearResult;
  191. Game_Battler.prototype.clearResult = function() {
  192. MalExStateClearResult.call(this);
  193. this._exStates = [];
  194. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement