100 lines
3.5 KiB
JavaScript
100 lines
3.5 KiB
JavaScript
/*:
|
||
* @target MZ
|
||
* @plugindesc [MZ] スキル266:変数55≥7 かつ スイッチ783 ON のときのみ表示&使用可 v1.1
|
||
* @author You
|
||
* @help
|
||
* 指定スキルは「変数が閾値以上」かつ「スイッチON」の場合のみ
|
||
* 1) スキル一覧に表示され、2) 使用できます。
|
||
* 条件未達のときはスキル一覧から非表示になります。
|
||
*
|
||
* 戦闘中・メニュー画面の両方で有効。通常の使用可否(MP/TP/ステート等)は従来どおり。
|
||
*
|
||
* ■デフォルト
|
||
* - スキルID: 266
|
||
* - 変数ID: 55
|
||
* - 閾値(以上): 7
|
||
* - スイッチID: 783
|
||
*
|
||
* @param SkillId
|
||
* @text 対象スキルID
|
||
* @type number
|
||
* @min 1
|
||
* @default 266
|
||
*
|
||
* @param VariableId
|
||
* @text 判定する変数ID
|
||
* @type variable
|
||
* @default 55
|
||
*
|
||
* @param MinValue
|
||
* @text 変数の最小値(以上)
|
||
* @type number
|
||
* @default 7
|
||
*
|
||
* @param SwitchId
|
||
* @text 必須スイッチID(ONで有効)
|
||
* @type switch
|
||
* @default 783
|
||
*
|
||
* @param OnlyWhenLearned
|
||
* @text 習得済みのときのみ対象
|
||
* @type boolean
|
||
* @on はい
|
||
* @off いいえ
|
||
* @desc ONだと、アクターが当該スキルを習得しているときのみ本条件を適用します。
|
||
* @default true
|
||
*/
|
||
(() => {
|
||
"use strict";
|
||
const PLUGIN_NAME = document.currentScript?.src?.match(/([^\/]+)\.js$/)?.[1] || "SkillVarAndSwitchGate_Hide";
|
||
const P = PluginManager.parameters(PLUGIN_NAME);
|
||
|
||
const SKILL_ID = Number(P.SkillId || 266);
|
||
const VAR_ID = Number(P.VariableId || 55);
|
||
const MIN_VAL = Number(P.MinValue || 7);
|
||
const SW_ID = Number(P.SwitchId || 783);
|
||
const ONLY_LEARNED = String(P.OnlyWhenLearned || "true") === "true";
|
||
|
||
function isEligible(actor) {
|
||
if (!actor) return false;
|
||
if (ONLY_LEARNED && !actor.skills().some(s => s && s.id === SKILL_ID)) return false; // 習得済み前提なら未表示
|
||
const okVar = $gameVariables.value(VAR_ID) >= MIN_VAL;
|
||
const okSw = $gameSwitches.value(SW_ID) === true;
|
||
return okVar && okSw;
|
||
}
|
||
|
||
// 使用可否:条件未達なら使用不可
|
||
const _canUse = Game_BattlerBase.prototype.canUse;
|
||
Game_BattlerBase.prototype.canUse = function(item) {
|
||
if (DataManager.isSkill(item) && item && item.id === SKILL_ID) {
|
||
if (this.isActor && this.isActor()) {
|
||
if (!isEligible(this)) return false;
|
||
}
|
||
}
|
||
return _canUse.call(this, item);
|
||
};
|
||
|
||
// 表示可否:条件未達なら一覧に載せない(メニュー/戦闘 共通)
|
||
const _Window_SkillList_includes = Window_SkillList.prototype.includes;
|
||
Window_SkillList.prototype.includes = function(item) {
|
||
const base = _Window_SkillList_includes.call(this, item); // タイプ一致など従来条件
|
||
if (!base) return false;
|
||
if (item && item.id === SKILL_ID) {
|
||
const actor = this._actor;
|
||
return isEligible(actor); // 未達なら非表示
|
||
}
|
||
return true;
|
||
};
|
||
|
||
// 変数/スイッチ変化で即時反映したい場合の軽い対応(任意)
|
||
// ウィンドウが開いている間は軽く再描画して最新状態に保つ
|
||
const _Window_SkillList_update = Window_SkillList.prototype.update;
|
||
Window_SkillList.prototype.update = function() {
|
||
_Window_SkillList_update.call(this);
|
||
// 30フレームごとに再構成(負荷を抑えつつ追従)
|
||
this._svsgTick = (this._svsgTick || 0) + 1;
|
||
if (this._svsgTick % 30 === 0) {
|
||
this.refresh();
|
||
}
|
||
};
|
||
})();
|