Skip to content

Instantly share code, notes, and snippets.

@armornick
Created August 17, 2018 16:04
Show Gist options
  • Save armornick/20a7e5c178da46d50321aa975050f060 to your computer and use it in GitHub Desktop.
Save armornick/20a7e5c178da46d50321aa975050f060 to your computer and use it in GitHub Desktop.
Make States Canceled by Elements (RPG Maker MV)
/*:
@plugindesc States Cancelled by Elements
@author armornick
@help
This plugin adds states which are canceled when the inflicted person is hit with
an attack with a certain element.
=== Usage ===
To make a state which can be canceled by certain elements, use the following notetag:
<canceling-element: n>
where n is one or more element ids. If multiple elements should cancel the state, the
ids should be delimited by comma's.
For example, to make a state get canceled by elements 2 and 8:
<canceling-element: 2, 8>
=== License ====
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
(function () {
//-----------------------------------------------------------------------------
// DataManager
const RE_CANCELING_ELEMENT = /<canceling[-_ ]elements?\s*:\s*([^>]+)>/i;
function preloadStateCancelingElements ($dataStates) {
for (let state of $dataStates) {
// skip the state at index 0
if (state === null) continue;
let cancelElmt = RE_CANCELING_ELEMENT.exec(state.note);
if (cancelElmt) {
let elements = [],
rawElements = cancelElmt[1].split(",");
for (let element of rawElements) {
let numVal = parseInt(element.trim(), 10);
if (!isNaN(numVal)) {
elements.push(numVal);
}
}
state.cancelingElements = elements;
}
}
}
var NIA_StateCancelElement_DataManager_onLoad = DataManager.onLoad;
DataManager.onLoad = function(object) {
NIA_StateCancelElement_DataManager_onLoad.call(this, object);
if (object === $dataStates) {
preloadStateCancelingElements(object);
}
};
//-----------------------------------------------------------------------------
// Game_Action
var NIA_StateCancelElement_GameAction_makeDamageValue = Game_Action.prototype.makeDamageValue;
Game_Action.prototype.makeDamageValue = function(target, critical) {
var value = NIA_StateCancelElement_GameAction_makeDamageValue.call(this, target, critical);
this.calculateElementsCancelingState(target);
return value;
};
Game_Action.prototype.calculateElementsCancelingState = function (target) {
var attackerElement = this.item().damage.elementId,
states = target.states();
for (let state of states) {
if (state.cancelingElements
&& state.cancelingElements.contains(attackerElement)) {
target.removeState(state.id);
}
}
};
}())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment