//===================================================================================
// Astfgl's Shield counter and Break
// Date 19/08/2018
// Free to use non commercially, repost and
// edit, as long as the final product is kept under the same terms of use.
// Credits required, any of Astfgl, Astgfl (Pierre MATEO), Pierre MATEO
// Credits goes to yanfly for modified parts of battle engine core
// v1.0 19/08: release
// v1.1 21/08 modified shield display modes
// v1.2 25/08 created weakness display, added parameters for shield mode, made weakness display save
// Time spent : 6h
//====================================================================================
/*:
* @plugindesc OT Shield and Break System
* @author Astfgl
*
* @param globalMode
* @text Shield usage
* @type number
* @default 0
* @desc 0-> all, 1-> actors only -> 2 -> enemies only
* @param defaultState
* @text State Id when shield = 0
* @type number
* @default 4
* @desc Which state will be applied when a battler shield reaches 0.
*
* @param defaultElemCutoff
* @text Elemental weakness cutoff
* @type number
* @default 1
* @desc Attacks must have an elemental value strictly superior to this to remove from the shield counter.
*
* @param baseIcon
* @text Base shield Icon
* @type number
* @default 16
* @desc The icon id to display shields.
*
* @param mode
* @text Shield display mode
* @type number
* @default 0
* @desc 0->number in brackets, 1 -> number in icon
*
* @param showWeaknesses
* @text Show weaknesses below enemy name
* @type number
* @default 1
* @desc 0-> don't show weaknesses, 1 -> show weaknesses
*
* @param wIArray
* @text Weakness Icon Array
* @default [0,0,0,0,0,0,0,0,0,0]
* @desc Icons for each elemental weakness, in order from your elements list in the system tab with a leading "0,".
*
* @param defautWeaknessIcon
* @text Undiscovered Weakness icon
* @type number
* @default 16
* @desc The icon id that will be used to display undiscovered weaknesses.
*
*
* @help
*Allows you to set up a shield and break system similar to Octopath traveler's
*Recommended plugins:
* - Yanfly's Battle engine core
* - Yanfly's Element core
* - Yanfly's Buffs and state core
*It has not been tested without these plugins and thus may not function.
*
*==========================================
* What it does:
*==========================================
*In battle, if an attack hits an elemental weakness,
*it will decrease a shield counter, once that counter reaches 0
*a state will be applied to the battler.
*
*It will reduce the shield counter by 1 for each element of the attack
*the recipient is weak to.
*So if your attack deals fire and ice damage and the enemy is weak to both
*shields will be reduced by 2.
*
*Display of the shield amount is done via the battler name in brackets or with an icon.
*
*It also creates a weakness icon array below the monster.
*If the show weakness parameter is set to 1, it will display any element
*weakness reaching the default cutoff with the icon corresponding to the defined id
*in the weakness icon array below the battler name.
*
*==========================================
* How to use:
*==========================================
*Set max shield notetags:
*
*Order for max shield calculation:
*actor, class, equipment, passive states, states then floored
*Notetags: <mSh: >, Ex: <mSh: num += 5>
*
*Each time calculations are made with the num variable.
*Ex: num += 5 in actor, num *= 2 in class will result in a max shield of 10
*The same thing but with a state using num = 1 will result in a max shield of 1
*
*Enemies are the same except you remove class and equipment calculations
*
*If you don't set anything, battlers have a default shield value of 1.
*
*If you want it to function like octopath traveler, I recommend
*using a state with the cannot move property, set to expire in 2 turns
*and with the following notetag:
*<Custom Remove Effect>
*user._sh = user._mSh;
*</Custom Remove Effect>
*This will restore shields to maximum when the broken state expires.
*
*==========================================
* Changing break state
*==========================================
*If you want to change what state enemies are inflected with upon break use:
*<DBS: > in an enemy note box
*Else it will use what's inside plugin parameters
*
*==========================================
* Modifying enemy shields:
*==========================================
* Use the following script calls:
* (battler).modMaxSh(number)
* This will add number to max shields, after all other calculations.
* This bonus will never be reset.
* Use states for temporary modifications for actors.
*
* (battler).changeSh(number), this will withdraw number from current shields
*
*All parameters and notetags are evaled
*
*==========================================
* How to setup weakness display array:
*==========================================
*
* The parametert is an array of icon ids with a leading 0.
* For default projects it would be:
* [0,physicalIconId,fireIconId,...,darknessIconId]
*/
var Astfgl = Astfgl || {};
Astfgl.enemies = Astfgl.enemies || {};
Astfgl.enemies.disWeak = [];
(function(){
//get parameters value
var defaultState = eval(PluginManager.parameters("AstfglSCB").defaultState);
var defaultElemCutoff = eval(PluginManager.parameters("AstfglSCB").defaultElemCutoff);
var mode = eval(PluginManager.parameters("AstfglSCB").mode)
var shieldIcon = eval(PluginManager.parameters("AstfglSCB").baseIcon)
var showWeaknesses = eval(PluginManager.parameters("AstfglSCB").showWeaknesses)
var wIArray = eval(PluginManager.parameters("AstfglSCB").wIArray)
var defautWeaknessIcon = eval(PluginManager.parameters("AstfglSCB").defautWeaknessIcon)
var globalMode = eval(PluginManager.parameters("AstfglSCB").globalMode)
//Weakness setup
var _aliasGAI = Game_Actor.prototype.initialize
Game_Actor.prototype.initialize = function(actorId) {
_aliasGAI.call(this,actorId);
if (this._actorId === 0) {return}
if (globalMode !== 2) {
this._mShB = 0;
this._mSh = this.getMaxSh();
this._sh = this._mSh
}
};
//get max shield value from notetags
Game_Actor.prototype.getMaxSh = function() {
var num = 0;
var a = this;
var user = this;
var id = this.actorId();
if ($dataActors[id].meta.mSh) {
num = eval($dataActors[id].meta.mSh)
}
if ($dataClasses[this._classId].meta.mSh) {
num = eval($dataActors[id].meta.mSh)
}
for (var i = 0; i < this._equips.length; i++) {
var it = this._equips[i];
if (it._dataClass === "weapon" && it._itemId !== 0) {
if ($dataWeapons[it._itemId].meta.mSh) {
num = eval($dataWeapons[it._itemId].meta.mSh)
}
}
if (it._dataClass === "armor" && it._itemId !== 0) {
if ($dataArmors[it._itemId].meta.mSh) {
num = eval($dataArmors[it._itemId].meta.mSh)
}
}
}
if (this._passiveStatesRaw) {
for (var i = 0; i < this._passiveStatesRaw.length; i ++) {
if ($dataStates[this._passiveStatesRaw[i]].meta.mSh) {
num = eval($dataStates[this._passiveStatesRaw[i]].meta.mSh)
}
}
}
for (var i = 0; i < this._states.length; i ++) {
if ($dataStates[this._states[i]].meta.mSh) {
num = eval($dataStates[this._states[i]].meta.mSh)
}
}
num += this._mShB
num = Math.floor(num)
if (num === 0 || isNaN(num)) {num = 1}
return num
}
//setup enemies shield
var _aliasGEI = Game_Enemy.prototype.initialize
Game_Enemy.prototype.initialize = function(enemyId, x, y) {
_aliasGEI.call(this,enemyId, x, y);
if (this._enemyId === 0) {return};
if (globalMode !== 1) {
this._mShB = 0;
this._mSh = this.getMaxSh()
this._sh = this._mSh;
}
//create known weakness array the first time an enemy is initialized
if (Astfgl.enemies.disWeak.length === 0) {
for (var i = 0; i < $dataEnemies.length; i++) {
var _WI = [];
for (var i = 0; i < $dataSystem.elements.length; i ++) {
_WI.push(0);
}
Astfgl.enemies.disWeak.push(_WI)
}
}
};
//get max enemy shield value from enemy and state notetags
Game_Enemy.prototype.getMaxSh = function() {
var num = 0;
var a = this;
var user = this;
var id = this._enemyId;
if ($dataEnemies[id].meta.mSh) {
num = eval($dataEnemies[id].meta.mSh)
}
if (this._passiveStatesRaw) {
for (var i = 0; i < this._passiveStatesRaw.length; i ++) {
if ($dataStates[this._passiveStatesRaw[i]].meta.mSh) {
num = eval($dataStates[this._passiveStatesRaw[i]].meta.mSh)
}
}
}
for (var i = 0; i < this._states.length; i ++) {
if ($dataStates[this._states[i]].meta.mSh) {
num = eval($dataStates[this._states[i]].meta.mSh)
}
}
num += this._mShB;
num = Math.floor(num)
if (num === 0 || isNaN(num)) {num = 1}
return num
}
//store known weaknesses in global array
Game_Enemy.prototype.checkWeaknessDisplay = function (num) {
if (Astfgl.enemies.disWeak[this._enemyId][num] === 0) {
Astfgl.enemies.disWeak[this._enemyId][num] = 1
}
}
//Action modifying
var _aliasGAA = Game_Action.prototype.apply
Game_Action.prototype.apply = function(target) {
_aliasGAA.call(this,target)
var mod = 0;
var elements = this.getItemElements();
for (var i = 0; i < elements.length; i++) {
if (target.elementRate(elements[i]) > defaultElemCutoff) {
mod +=1;
if (!target.isActor()) {
target.checkWeaknessDisplay(elements[i])
}
}
}
target.changeSh(mod);
}
Game_Battler.prototype.changeSh = function(num) {
if (this._sh === 0) {return}
if (globalMode === 2 && this.isActor()) {return}
if (globalMode === 1 && this.isEnemy()) {return}
this._sh -= num;
this._sh = this._sh.clamp(0,this._mSh);
if (this._sh === 0) {
if (this.isActor()) {if ($dataActors[this.actorId()].meta.DBS) {defaultState = eval($dataActors[this.actorId()].meta.DBS)}}
else {if ($dataEnemies[this._enemyId].meta.DBS) {defaultState = eval($dataEnemies[this._enemyId].meta.DBS)}}
this.addState(defaultState)
};
}
/*
//Modify name function to display shield amount
var _aliasGEN = Game_Enemy.prototype.name
Game_Enemy.prototype.name = function() {
if ( mode === 0 ) {return _aliasGEN.call(this); }
return "[" + this._sh + "]" + this.originalName() + (this._plural ? this._letter : '');
}*/
//Modify battle window draw name function to display shield amount
var _aliasWBSDAN = Window_BattleStatus.prototype.drawActorName
Window_BattleStatus.prototype.drawActorName = function(actor, x, y, width) {
if (globalMode === 2) {_aliasWBSDAN.call(this,actor,x,y,width); return}
width = width || 168;
this.changeTextColor(this.hpColor(actor));
if (mode === 1) {
var fs = this.contents.fontSize
this.contents.fontSize = Yanfly.Param.BECEnemyFontSize;
this.drawIcon(shieldIcon,x,y+3)
var wd = this.textWidth(String(actor._sh));
this.drawText(actor._sh, x + 16 - wd/2, y, 40);
this.contents.fontSize = fs
this.drawText(actor.name(), x + 40, y, width - 48);
} else {
this.drawText("["+ actor._sh + "]" + actor.name(), x, y, width);
}
}
//Modify enemy name display
var _aliasWEVS = Window_EnemyVisualSelect.prototype.refresh
Window_EnemyVisualSelect.prototype.refresh = function() {
this.contents.clear();
if (!this._battler) return;
if (!this._showEnemyName) return;
if (this._battler.isHidden()) return;
this._requestRefresh = false;
this.contents.fontSize = Yanfly.Param.BECEnemyFontSize;
var text = this._battler.name();
var wy = this.contents.height - this.lineHeight() * 2;
if (globalMode !== 1) {
if (mode === 1) {
this.drawIcon(shieldIcon,0,wy+3)
var wd = this.textWidth(String(this._battler._sh));
this.drawText(this._battler._sh, 16 - wd/2, wy, 40);
this.drawText(text, 40, wy, this.contents.width, 'left');
} else {
this.drawText("[" + this._battler._sh + "]" + text, 0, wy, this.contents.width, 'center');
}
} else {
this.drawText(text, 0, wy, this.contents.width, 'center');
}
if (showWeaknesses === 1) {
var elemWeak = [];
for (var i = 1; i < $dataSystem.elements.length; i++) {
if (this._battler.elementRate(i) > defaultElemCutoff) {
elemWeak.push(i)
}
}
wy = wy + this.lineHeight();
if (this.width < 32 * elemWeak.length) {
this.width = 32 * elemWeak.length
this.contents.width = 32 * elemWeak.length
}
var x = 0;
for (var i = 0; i < elemWeak.length; i++) {
var iconId = defautWeaknessIcon;
if (Astfgl.enemies.disWeak[this._battler._enemyId][elemWeak[i]] === 1) {
iconId = wIArray[elemWeak[i]];
}
this.drawIcon(iconId,x,wy)
x += 32;
}
}
};
//change window size to display the right width for weaknesses icons
Window_EnemyVisualSelect.prototype.updateWindowSize = function() {
if (showWeaknesses === 1) {
var elemWeak = [];
for (var i = 1; i < $dataSystem.elements.length; i++) {
if (this._battler.elementRate(i) > defaultElemCutoff) {
elemWeak.push(i)
}
}
var num = elemWeak.length * 32;
} else {
num = 0;
}
var spriteWidth = this._battler.spriteWidth();
this.contents.fontSize = Yanfly.Param.BECEnemyFontSize;
if (this._nameTextWidth === undefined) {
this._nameTextWidth = this.textWidth(this._battler.name());
}
var textWidth = this._nameTextWidth;
textWidth += this.textPadding() * 2;
var width = Math.max(spriteWidth, textWidth, num) + this.standardPadding() * 2;
width = Math.ceil(width);
var height = this._battler.spriteHeight() + this.standardPadding() * 2;
height = Math.ceil(height);
height = Math.max(height, this.lineHeight() + this.standardPadding() * 2);
if (width === this.width && height === this.height) return;
this.width = width;
this.height = height;
this.createContents();
this._requestRefresh = true;
this.makeWindowBoundaries();
};
// Accessory functions
Game_Battler.prototype.modMaxSh = function (num) {
if (globalMode === 2 && this.isActor()) {return}
if (globalMode === 1 && this.isEnemy()) {return}
this._mShB += num;
this._mSh = this.getMaxSh();
this._sh.clamp(0,this._mSh);
}
//save and lot weakness array
var _aliasDMMSC = DataManager.makeSaveContents
DataManager.makeSaveContents = function() {
var contents = _aliasDMMSC.call(this)
contents.astfgl = Astfgl
return contents
}
var _aliasDMESC = DataManager.extractSaveContents
DataManager.extractSaveContents = function(contents) {
_aliasDMESC.call(this,contents);
Astfgl = contents.astfgl
}
})()