Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // Maliki's Dynamic State Resistance
- // MalDynamicStateResistance.js
- // version 1.0
- //=============================================================================
- /*:
- * @plugindesc ver1.0 - Allows Devs to allow battlers to build up "immunity" to states
- * @author Maliki79
- * @param defaultDynamicRate
- * @desc The amount of immunity build-up that battlers gain when a state is applied as a percent.
- * Default: 25
- * @default 25
- *
- * @help This plugin makes it so that battlers (Enemy or Ally) can build resistance and
- * eventual immunity to specific states.
- * This immunity builds each time the state is added.
- * As the immunity builds, it becomes more difficult to place the state until complete
- * immunity occurs.
- *
- * Setup is simple as all you need is to add the tag <dynamticStates: x,x,x...>
- * with x being your different state Id numbers separated by commas(,).
- * The Plugin param defaultDynamicRate governs how much the resistance raises each time
- * the state is applied. Larger number means less time before full immunity.
- */
- var Mal = Mal || {};
- Mal.Parameters = PluginManager.parameters('MalDynamicStateResistance');
- Mal.Param = Mal.Param || {};
- var MalDynamicSDatabaseLoad = DataManager.isDatabaseLoaded;
- DataManager.isDatabaseLoaded = function() {
- if (!MalDynamicSDatabaseLoad.call(this)) return false;
- if (!DataManager._malDynamicS_DatabaseLoaded) {
- this.makeDynamicStateList($dataActors);
- this.makeDynamicStateList($dataEnemies);
- DataManager._malDynamicS_DatabaseLoaded = true;
- }
- return true;
- };
- DataManager.makeDynamicStateList = function(group) {
- for (var n = 1; n < group.length; n++) {
- if (group[n].meta.dynamticStates) this.createDynamicStateObjects(group[n]);
- }
- };
- DataManager.createDynamicStateObjects = function(object) {
- var noteread = object.note;
- object.dynamicStateSet = [];
- while(noteread.indexOf("dynamticStates") > -1)
- {
- var notereg = noteread.split("<dynamticStates: ");
- var match = notereg[1].split(">");
- var set1 = match[0].split(",");
- for (var i = 0; i < set1.length; i++) {
- if(object.dynamicStateSet.indexOf(Number(set1[i])) == -1) object.dynamicStateSet.push(Number(set1[i]));
- }
- noteread = noteread.replace("dynamticStates", " ");
- }
- };
- var MalDynamicSInit = Game_BattlerBase.prototype.initMembers;
- Game_BattlerBase.prototype.initMembers = function() {
- MalDynamicSInit.call(this);
- this.resetDynamicStateCount($dataStates.length);
- };
- var MalDynamicActorSetup = Game_Actor.prototype.setup;
- Game_Actor.prototype.setup = function(actorId) {
- MalDynamicActorSetup.call(this, actorId);
- this._dynamicStateSet = [];
- if($dataActors[this.actorId()].dynamicStateSet) this._dynamicStateSet = $dataActors[this.actorId].dynamicStateSet;
- };
- var MalDynamicEnemySetup = Game_Enemy.prototype.setup;
- Game_Enemy.prototype.setup = function(enemyId, x, y) {
- MalDynamicEnemySetup.call(this, enemyId, x, y);
- this._dynamicStateSet = [];
- if($dataEnemies[this._enemyId].dynamicStateSet) this._dynamicStateSet = $dataEnemies[this._enemyId].dynamicStateSet;
- };
- Game_BattlerBase.prototype.resetDynamicStateCount = function(numb) {
- this._dynamicStateBuildup = Array.apply(null, Array(numb)).map(Number.prototype.valueOf,0);
- };
- Game_BattlerBase.prototype.isStateResist = function(stateId) {
- if (this._dynamicStateBuildup[stateId] >= 100) return true;
- return this.stateResistSet().contains(stateId);
- };
- Game_Action.prototype.itemEffectAddAttackState = function(target, effect) {
- this.subject().attackStates().forEach(function(stateId) {
- var chance = effect.value1;
- chance *= target.stateRate(stateId);
- chance *= this.subject().attackStatesRate(stateId);
- chance *= this.lukEffectRate(target);
- chance *= 1.0 - (target._dynamicStateBuildup[stateId] / 100)
- if (Math.random() < chance) {
- target.addState(stateId);
- this.makeSuccess(target);
- }
- }.bind(this), target);
- };
- Game_Action.prototype.itemEffectAddNormalState = function(target, effect) {
- var chance = effect.value1;
- if (!this.isCertainHit()) {
- chance *= target.stateRate(effect.dataId);
- chance *= this.lukEffectRate(target);
- chance *= 1.0 - (target._dynamicStateBuildup[effect.dataId] / 100)
- }
- if (Math.random() < chance) {
- target.addState(effect.dataId);
- this.makeSuccess(target);
- }
- };
- var MalDynamic_addState = Game_Battler.prototype.addState;
- Game_Battler.prototype.addState = function(stateId) {
- MalDynamic_addState.call(this, stateId)
- if (this.isStateAddable(stateId)) {
- if (this._dynamicStateSet.contains(stateId)) this._dynamicStateBuildup[stateId] += Number(Mal.Parameters['defaultDynamicRate']);
- }
- };
- var MalDynamic_updateBattleEnd = BattleManager.updateBattleEnd
- BattleManager.updateBattleEnd = function() {
- $gameParty.allMembers().forEach(function(actor) {
- actor.resetDynamicStateCount($dataStates.length);
- });
- MalDynamic_updateBattleEnd.call(this);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement