pure-full-lily/js/plugins/AltVariableEvasion.js
2025-09-16 10:12:44 -05:00

100 lines
No EOL
4.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*:
* @target MZ
* @plugindesc 変数11が'NP'等かつ指定スイッチOFFの時、スキルを回避。指定ステート中は無効。v1.05a
* @author IvI
*
* @param RequireOffSwitchId
* @text 回避有効条件スイッチID
* @type switch
* @default 74
* @desc このスイッチがOFFの時のみ、このプラグインによる回避が有効になります。
*
* @param ResultSwitchId
* @text 回避成功時ONスイッチID
* @type switch
* @default 73
* @desc 回避成功時にONになるスイッチIDです。0で無効
*
* @param DisableEvasionStateId
* @text 回避無効化ステートID
* @type state
* @default 0
* @desc このステートにかかっていると回避が発動しなくなります。0で無効
*
* @help
* スキルのメモ欄に <SpecialVariableEvasion> と書くと、
* 特定の条件下でそのスキルを回避できるようになります。
*
* 【回避が発動する条件】
* 1. 変数11番の値が 'NP' または 'NPH' である。
* 2. パラメータ「回避有効条件スイッチID」で指定したスイッチがOFFである。
* 3. スキルのメモ欄に <SpecialVariableEvasion> の記述がある。
* 4. [v1.05a追加] パラメータ「回避無効化ステートID」で指定したステートに
* かかっていない。(ステートIDが0の場合はこのチェックを無視します)
*
* 【回避率の指定】
* スキルのメモ欄で回避率をパーセントで指定できます。
* 例: <SpecialVariableEvasion: 80> // 回避率が80%になる
*
* 指定がない場合は、プラグイン内の設定既定で70%)が適用されます。
*
* ---
* v1.05a:
* - 指定したステートにかかっている場合、このプラグインによる
* 特殊回避が発動しないようにする機能を追加しました。
* v1.04a:
* - 最初のリリース
*/
(() => {
// ── パラメータ取得 ──
const PLUGIN_NAME = "AltVariableEvasion";
const params = PluginManager.parameters(PLUGIN_NAME);
const REQUIRE_OFF_ID = Number(params.RequireOffSwitchId || 74);
const RESULT_SW_ID = Number(params.ResultSwitchId || 73);
const DISABLE_STATE_ID = Number(params.DisableEvasionStateId || 0); //追加
// ── 固定設定 ──
const VAR_ID = 11; // 変数 ID
const VALID_VALS = ['NP', 'NPH']; // 有効文字列
const DEFAULT_RT = 0.70; // 既定回避率 (01)
const NOTE_TAG = 'SpecialVariableEvasion'; // メモタグ名
// ────────────
const _apply = Game_Action.prototype.apply;
Game_Action.prototype.apply = function (target) {
const item = this.item();
const meta = item ? item.meta[NOTE_TAG] : undefined;
if (meta !== undefined) {
const curVal = String($gameVariables.value(VAR_ID));
const requireOff = !$gameSwitches.value(REQUIRE_OFF_ID);
// ▼▼▼ 追加 ▼▼▼
const isStateBlocking = DISABLE_STATE_ID > 0 && target.isStateAffected(DISABLE_STATE_ID);
// ▲▲▲ 追加 ▲▲▲
// ▼▼▼ 修正 ▼▼▼
if (VALID_VALS.includes(curVal) && requireOff && !isStateBlocking) {
// ▲▲▲ 修正 ▲▲▲
// ── 回避率取得 ──
let rate = DEFAULT_RT;
if (meta !== true) {
const n = parseFloat(meta);
if (!isNaN(n)) rate = Math.min(Math.max(n / 100, 0), 1);
}
// ── 判定 ──
if (Math.random() < rate) {
target.result().clear();
target.result().used = true;
target.result().evaded = true;
if (RESULT_SW_ID > 0) {
$gameSwitches.setValue(RESULT_SW_ID, true);
}
return;
}
}
}
_apply.call(this, target);
};
})();