prison-brave/js/plugins/IM_HitBeforeMessageCommon.js
2025-08-28 10:38:20 -05:00

56 lines
2.2 KiB
JavaScript

/*:
* @target MZ
* @plugindesc ヒットしたときだけ、スキル計算式実行直前にメモ欄のコモンイベントを起動
* @author Umu
*
* メモ欄タグ:
* <命中前コモン:123>
* <HitCommon:123> // 英語表記でも可
* └ 123 = コモンイベントID
*
* ・ミス/回避時は予約されません
* ・全体攻撃でも 1 回だけ呼び出します
*/
(() => {
"use strict";
// ─────────────────────────────────────
// ① タグ読み取り
// ─────────────────────────────────────
const TAG_JP = "命中前コモン";
const TAG_EN = "HitCommon";
const hitCommonId = item =>
Number(item?.meta[TAG_JP] ?? item?.meta[TAG_EN] ?? 0);
// ─────────────────────────────────────
// ② Game_Action.apply をエイリアス
// - damage 計算後・ログ表示前に確実に通る
// ─────────────────────────────────────
const _Game_Action_apply = Game_Action.prototype.apply;
Game_Action.prototype.apply = function (target) {
// 元処理(命中判定 + ダメージ計算)
_Game_Action_apply.call(this, target);
// ヒット判定
if (!target.result().isHit()) return;
// タグがあれば 1 回だけ予約
const commonId = hitCommonId(this.item());
if (commonId > 0 && !BattleManager._hitCommonFlag) {
$gameTemp.reserveCommonEvent(commonId);
BattleManager._hitCommonFlag = true;
}
};
// ─────────────────────────────────────
// ③ 行動終了時にフラグをリセット
// ─────────────────────────────────────
const _BattleManager_endAction = BattleManager.endAction;
BattleManager.endAction = function () {
_BattleManager_endAction.call(this);
this._hitCommonFlag = false;
};
})();