Advertisement
Maliki79

MalDynamicStateResistance

Nov 21st, 2017
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Maliki's Dynamic State Resistance
  3. // MalDynamicStateResistance.js
  4. // version 1.0
  5. //=============================================================================
  6. /*:  
  7. * @plugindesc ver1.0 - Allows Devs to allow battlers to build up "immunity" to states
  8.  * @author Maliki79
  9.  * @param defaultDynamicRate
  10.  * @desc The amount of immunity build-up that battlers gain when a state is applied as a percent.
  11.  * Default: 25
  12.  * @default 25
  13.  *
  14.  * @help This plugin makes it so that battlers (Enemy or Ally) can build resistance and
  15.  * eventual immunity to specific states.
  16.  * This immunity builds each time the state is added.  
  17.  * As the immunity builds, it becomes more difficult to place the state until complete
  18.  * immunity occurs.
  19.  *
  20.  * Setup is simple as all you need is to add the tag <dynamticStates: x,x,x...>
  21.  * with x being your different state Id numbers separated by commas(,).
  22.  * The Plugin param defaultDynamicRate governs how much the resistance raises each time
  23.  * the state is applied.  Larger number means less time before full immunity.
  24.  */
  25.  
  26. var Mal = Mal || {};
  27.  
  28. Mal.Parameters = PluginManager.parameters('MalDynamicStateResistance');
  29. Mal.Param = Mal.Param || {};
  30.  
  31. var MalDynamicSDatabaseLoad = DataManager.isDatabaseLoaded;
  32. DataManager.isDatabaseLoaded = function() {
  33.   if (!MalDynamicSDatabaseLoad.call(this)) return false;
  34.   if (!DataManager._malDynamicS_DatabaseLoaded) {
  35.     this.makeDynamicStateList($dataActors);
  36.     this.makeDynamicStateList($dataEnemies);
  37.     DataManager._malDynamicS_DatabaseLoaded = true;
  38.   }
  39.   return true;
  40. };
  41.  
  42. DataManager.makeDynamicStateList = function(group) {
  43.     for (var n = 1; n < group.length; n++) {
  44.         if (group[n].meta.dynamticStates) this.createDynamicStateObjects(group[n]);
  45.     }
  46. };
  47.  
  48.  
  49. DataManager.createDynamicStateObjects = function(object) {
  50. var noteread = object.note;
  51.     object.dynamicStateSet = [];
  52.     while(noteread.indexOf("dynamticStates") > -1)
  53.     {
  54.     var notereg = noteread.split("<dynamticStates: ");
  55.     var match = notereg[1].split(">");
  56.     var set1 = match[0].split(",");
  57.     for (var i = 0; i < set1.length; i++) {
  58.         if(object.dynamicStateSet.indexOf(Number(set1[i])) == -1) object.dynamicStateSet.push(Number(set1[i]));
  59.     }
  60.     noteread = noteread.replace("dynamticStates", " ");
  61.     }
  62. };
  63.  
  64. var MalDynamicSInit = Game_BattlerBase.prototype.initMembers;
  65. Game_BattlerBase.prototype.initMembers = function() {
  66.     MalDynamicSInit.call(this);
  67.     this.resetDynamicStateCount($dataStates.length);
  68. };
  69.  
  70. var MalDynamicActorSetup = Game_Actor.prototype.setup;
  71. Game_Actor.prototype.setup = function(actorId) {
  72.     MalDynamicActorSetup.call(this, actorId);
  73.     this._dynamicStateSet = [];
  74.     if($dataActors[this.actorId()].dynamicStateSet) this._dynamicStateSet = $dataActors[this.actorId].dynamicStateSet;
  75. };
  76.  
  77. var MalDynamicEnemySetup = Game_Enemy.prototype.setup;
  78. Game_Enemy.prototype.setup = function(enemyId, x, y) {
  79.     MalDynamicEnemySetup.call(this, enemyId, x, y);
  80.     this._dynamicStateSet = [];
  81.     if($dataEnemies[this._enemyId].dynamicStateSet) this._dynamicStateSet = $dataEnemies[this._enemyId].dynamicStateSet;
  82. };
  83.  
  84. Game_BattlerBase.prototype.resetDynamicStateCount = function(numb) {
  85.     this._dynamicStateBuildup = Array.apply(null, Array(numb)).map(Number.prototype.valueOf,0);
  86. };
  87.  
  88. Game_BattlerBase.prototype.isStateResist = function(stateId) {
  89.     if (this._dynamicStateBuildup[stateId] >= 100) return true;
  90.     return this.stateResistSet().contains(stateId);
  91. };
  92.  
  93. Game_Action.prototype.itemEffectAddAttackState = function(target, effect) {
  94.     this.subject().attackStates().forEach(function(stateId) {
  95.         var chance = effect.value1;
  96.         chance *= target.stateRate(stateId);
  97.         chance *= this.subject().attackStatesRate(stateId);
  98.         chance *= this.lukEffectRate(target);
  99.         chance *= 1.0 - (target._dynamicStateBuildup[stateId] / 100)
  100.         if (Math.random() < chance) {
  101.             target.addState(stateId);
  102.             this.makeSuccess(target);
  103.         }
  104.     }.bind(this), target);
  105. };
  106.  
  107. Game_Action.prototype.itemEffectAddNormalState = function(target, effect) {
  108.     var chance = effect.value1;
  109.     if (!this.isCertainHit()) {
  110.         chance *= target.stateRate(effect.dataId);
  111.         chance *= this.lukEffectRate(target);
  112.         chance *= 1.0 - (target._dynamicStateBuildup[effect.dataId] / 100)
  113.     }
  114.     if (Math.random() < chance) {
  115.         target.addState(effect.dataId);
  116.         this.makeSuccess(target);
  117.     }
  118. };
  119.  
  120. var MalDynamic_addState = Game_Battler.prototype.addState;
  121. Game_Battler.prototype.addState = function(stateId) {
  122.     MalDynamic_addState.call(this, stateId)
  123.     if (this.isStateAddable(stateId)) {
  124.         if (this._dynamicStateSet.contains(stateId)) this._dynamicStateBuildup[stateId] += Number(Mal.Parameters['defaultDynamicRate']);
  125.     }
  126. };
  127.  
  128. var MalDynamic_updateBattleEnd = BattleManager.updateBattleEnd
  129. BattleManager.updateBattleEnd = function() {
  130.     $gameParty.allMembers().forEach(function(actor) {
  131.         actor.resetDynamicStateCount($dataStates.length);
  132.     });
  133. MalDynamic_updateBattleEnd.call(this); 
  134. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement