/*:
* @target MZ
* @plugindesc Attack animation trait tags (base, offset).
* @author Caethyril
* @url https://forums.rpgmakerweb.com/threads/156047/
* @help For use in the Note box of any trait-bearing object:
* <attack anim base: 5> => attacks without a weapon use anim ID 5.
* <attack anim plus: 2> => add 2 to the base ID value.
* If multiple base/plus tags apply, the highest value will be used.
* Default values (when no tags present): base = 1, plus = 0.
*
* ----------------------------------------------------------------------------
* Terms of use:
* MIT License: https://opensource.org/licenses/mit-license.html
*
* [[ BEGIN LICENSE TEXT ]]
*
* Copyright © 2023 Caethyril
*
* 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, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* 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.
*
* [[ END LICENSE TEXT ]]
*/
// Q11) Attack animation trait tags.
void (() => {
'use strict';
/**
* Tag name for base attack animation ID.
* Use on Actor/Class/Weapon/Armor/State/Enemy/Skill/Item.
*
* Applies for enemies, or actors without a weapon.
*/
const TAG_NAME_BASE = 'attack anim base';
/**
* Tag name for additive bonus to attack animation ID.
* Use on Actor/Class/Weapon/Armor/State/Enemy/Skill/Item.
*
* E.g. for an elemental power-up state.
*/
const TAG_NAME_PLUS = 'attack anim plus'; // e.g. ice power-up state
/** @returns {?$dataItem|$dataSkill} Item/Skill reference for current action, or `null`. */
const getActionItem = function() {
return BattleManager._action?.item() ?? null;
};
/**
* @param {object} o
* Reference meta-bearing object
* @param {boolean} isBase -
* - `true` => read {@linkcode TAG_NAME_BASE},
* - `false` => read {@linkcode TAG_NAME_PLUS}.
* @returns {?number}
* Animation ID/offset from tag, or `null`.
*/
const parseTag = function(o, isBase = false) {
const v = parseInt(o?.meta[isBase ? TAG_NAME_BASE : TAG_NAME_PLUS]);
return isNaN(v) ? null : v;
};
/**
* Returns largest applicable value from `dFault` or tags.
* @param {Game_Battler} battler reference battler
* @param {number} [dFault=1] base value if no tags found (default: 1)
* @returns {number} override base value for animation ID
*/
const getAttackAnimBase = function(battler, dFault = 1) {
const i = parseTag(getActionItem(), true);
if (i)
return i; // has tag from item/skill - specific beats general
return battler.traitObjects().reduce((a, c) => {
const v = parseTag(c, true);
return v > a ? v : a;
}, dFault);
};
/**
* Returns largest applicable offset.
* @param {Game_Battler} battler reference battler
* @returns {number} additive offset for attack animation ID
*/
const getAttackAnimOffset = function(battler) {
const i = parseTag(getActionItem(), false);
if (i)
return i; // has tag from item/skill - specific beats general
return battler.traitObjects().reduce((a, c) => {
const v = parseTag(c, false);
return v > a ? v : a;
}, 0);
};
/**
* @param {Game_Enemy} subject reference enemy
* @returns {number} attack animation ID
*/
Game_Enemy.prototype.attackAnimationId1 = function() {
const base = getAttackAnimBase(this);
if (!base)
return 0; // do not offset if anim ID = 0.
return base + getAttackAnimOffset(this);
};
// Let enemies show attack animation (mirroring is done via anim target check).
void (alias => {
Window_BattleLog.prototype.showEnemyAttackAnimation = function(subject, targets) {
alias.apply(this, arguments);
this.showNormalAnimation(targets, subject.attackAnimationId1());
};
})(Window_BattleLog.prototype.showEnemyAttackAnimation);
// Override bare hands attack animation for actors.
void (alias => {
Game_Actor.prototype.bareHandsAnimationId = function() {
return getAttackAnimBase(this, alias.apply(this, arguments));
};
})(Game_Actor.prototype.bareHandsAnimationId);
// Apply offsets for actor attack animations.
void (alias => {
Game_Actor.prototype.attackAnimationId1 = function() {
const base = alias.apply(this, arguments);
if (!base)
return 0; // do not offset if anim ID = 0 (e.g. weapon anim 0).
return base + getAttackAnimOffset(this);
};
})(Game_Actor.prototype.attackAnimationId1);
void (alias => {
Game_Actor.prototype.attackAnimationId2 = function() {
const base = alias.apply(this, arguments);
if (!base)
return 0; // do not offset if anim ID = 0 (e.g. no secondary weapon).
return base + getAttackAnimOffset(this);
};
})(Game_Actor.prototype.attackAnimationId2);
})();